mirror of
https://github.com/liyunfan1223/mod-playerbots.git
synced 2026-02-20 18:10:02 +01:00
Compare commits
No commits in common. "afc3bdb8af6954c33a46e9d4e60d70890cb37815" and "913039845d293e7268c4b28761ba4dd588c4e077" have entirely different histories.
afc3bdb8af
...
913039845d
@ -3321,17 +3321,11 @@ bool PlayerbotAI::CastSpell(uint32 spellId, Unit* target, Item* itemTarget)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!bot || !bot->GetSession() || bot->GetSession()->isLogingOut())
|
if (!target)
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!target || !target->IsInWorld() || target->IsDuringRemoveFromWorld())
|
|
||||||
target = bot;
|
target = bot;
|
||||||
|
|
||||||
Pet* pet = bot->GetPet();
|
Pet* pet = bot->GetPet();
|
||||||
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
|
SpellInfo const* spellInfo = sSpellMgr->GetSpellInfo(spellId);
|
||||||
if (!spellInfo)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (pet && pet->HasSpell(spellId))
|
if (pet && pet->HasSpell(spellId))
|
||||||
{
|
{
|
||||||
// List of spell IDs for which we do NOT want to toggle auto-cast or send message
|
// List of spell IDs for which we do NOT want to toggle auto-cast or send message
|
||||||
@ -3408,7 +3402,14 @@ bool PlayerbotAI::CastSpell(uint32 spellId, Unit* target, Item* itemTarget)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
Spell* spell = new Spell(bot, spellInfo, TRIGGERED_NONE);
|
// early return; bot/target world-state check
|
||||||
|
if (!bot->IsInWorld() || bot->IsDuringRemoveFromWorld() ||
|
||||||
|
(target && (!target->IsInWorld() || target->IsDuringRemoveFromWorld())))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
Spell* spell = new Spell(bot, spellInfo, TRIGGERED_NONE);
|
||||||
SpellCastTargets targets;
|
SpellCastTargets targets;
|
||||||
if (spellInfo->Effects[0].Effect != SPELL_EFFECT_OPEN_LOCK &&
|
if (spellInfo->Effects[0].Effect != SPELL_EFFECT_OPEN_LOCK &&
|
||||||
(spellInfo->Targets & TARGET_FLAG_ITEM || spellInfo->Targets & TARGET_FLAG_GAMEOBJECT_ITEM))
|
(spellInfo->Targets & TARGET_FLAG_ITEM || spellInfo->Targets & TARGET_FLAG_GAMEOBJECT_ITEM))
|
||||||
@ -3497,30 +3498,16 @@ bool PlayerbotAI::CastSpell(uint32 spellId, Unit* target, Item* itemTarget)
|
|||||||
// return false;
|
// return false;
|
||||||
|
|
||||||
|
|
||||||
// check if the actual target is valid, spell system uses targets.GetUnitTarget(), GetItemTarget(), GetGOTarget() internally.
|
// check bot/target world-state just before preparing the actual spell
|
||||||
Unit* uTarget = targets.GetUnitTarget();
|
Unit* unitTarget = targets.GetUnitTarget();
|
||||||
if (uTarget && (!uTarget->IsInWorld() || uTarget->IsDuringRemoveFromWorld()))
|
if (!bot->IsInWorld() || bot->IsDuringRemoveFromWorld() ||
|
||||||
|
(unitTarget && (!unitTarget->IsInWorld() || unitTarget->IsDuringRemoveFromWorld())))
|
||||||
{
|
{
|
||||||
// fail if the spell has a unit target that is invalid or being removed from the world
|
|
||||||
delete spell;
|
delete spell;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
Item* iTarget = targets.GetItemTarget();
|
|
||||||
if (!iTarget && (spellInfo->Targets & (TARGET_FLAG_ITEM | TARGET_FLAG_GAMEOBJECT_ITEM)))
|
|
||||||
{
|
|
||||||
// fail only if the spell requires a specific item or GO item to cast but the bot does not have one
|
|
||||||
delete spell;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
GameObject* gTarget = targets.GetGOTarget();
|
|
||||||
if (gTarget && !gTarget->isSpawned())
|
|
||||||
{
|
|
||||||
// fail if the spell has a GO target that is not spawned or does not exist
|
|
||||||
delete spell;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
SpellCastResult result = spell->prepare(&targets);
|
SpellCastResult result = spell->prepare(&targets);
|
||||||
|
|
||||||
if (result != SPELL_CAST_OK)
|
if (result != SPELL_CAST_OK)
|
||||||
{
|
{
|
||||||
// if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster())) {
|
// if (!sPlayerbotAIConfig->logInGroupOnly || (bot->GetGroup() && HasRealPlayerMaster())) {
|
||||||
@ -3580,7 +3567,6 @@ bool PlayerbotAI::CastSpell(uint32 spellId, Unit* target, Item* itemTarget)
|
|||||||
TellMasterNoFacing(out);
|
TellMasterNoFacing(out);
|
||||||
}
|
}
|
||||||
|
|
||||||
delete spell;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
// if (spellInfo->Effects[0].Effect == SPELL_EFFECT_OPEN_LOCK || spellInfo->Effects[0].Effect ==
|
// if (spellInfo->Effects[0].Effect == SPELL_EFFECT_OPEN_LOCK || spellInfo->Effects[0].Effect ==
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user