*Add spell target type check in Unit::CastSpell. Allow CastSpell(Gameobject*) and CastSpell(NULL).

--HG--
branch : trunk
This commit is contained in:
megamage
2008-12-08 18:56:01 -06:00
parent 91ab0288c7
commit 069ca8746e
2 changed files with 69 additions and 11 deletions
+68 -10
View File
@@ -854,13 +854,33 @@ void Unit::CastSpell(Unit* Victim, uint32 spellId, bool triggered, Item *castIte
void Unit::CastSpell(Unit* Victim,SpellEntry const *spellInfo, bool triggered, Item *castItem, Aura* triggeredByAura, uint64 originalCaster) void Unit::CastSpell(Unit* Victim,SpellEntry const *spellInfo, bool triggered, Item *castItem, Aura* triggeredByAura, uint64 originalCaster)
{ {
assert(Victim);
if(!spellInfo) if(!spellInfo)
{ {
sLog.outError("CastSpell: unknown spell by caster: %s %u)", (GetTypeId()==TYPEID_PLAYER ? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER ? GetGUIDLow() : GetEntry())); sLog.outError("CastSpell: unknown spell by caster: %s %u)", (GetTypeId()==TYPEID_PLAYER ? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER ? GetGUIDLow() : GetEntry()));
return; return;
} }
SpellCastTargets targets;
uint32 targetMask = spellInfo->Targets;
if(targetMask & (TARGET_FLAG_UNIT|TARGET_FLAG_UNK2))
{
if(!Victim)
{
sLog.outError("CastSpell: spell id %i by caster: %s %u) does not have unit target", spellInfo->Id,(GetTypeId()==TYPEID_PLAYER ? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER ? GetGUIDLow() : GetEntry()));
return;
}
targets.setUnitTarget(Victim);
}
if(targetMask & (TARGET_FLAG_SOURCE_LOCATION|TARGET_FLAG_DEST_LOCATION))
{
if(!Victim)
{
sLog.outError("CastSpell: spell id %i by caster: %s %u) does not have destination", spellInfo->Id,(GetTypeId()==TYPEID_PLAYER ? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER ? GetGUIDLow() : GetEntry()));
return;
}
targets.setDestination(Victim);
}
if (castItem) if (castItem)
DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo->Id); DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo->Id);
@@ -869,9 +889,6 @@ void Unit::CastSpell(Unit* Victim,SpellEntry const *spellInfo, bool triggered, I
Spell *spell = new Spell(this, spellInfo, triggered, originalCaster ); Spell *spell = new Spell(this, spellInfo, triggered, originalCaster );
SpellCastTargets targets;
targets.setUnitTarget( Victim );
targets.setDestination( Victim->GetPositionX(), Victim->GetPositionY(), Victim->GetPositionZ(), false);
spell->m_CastItem = castItem; spell->m_CastItem = castItem;
spell->prepare(&targets, triggeredByAura); spell->prepare(&targets, triggeredByAura);
} }
@@ -897,6 +914,27 @@ void Unit::CastCustomSpell(Unit* Victim,SpellEntry const *spellInfo, int32 const
return; return;
} }
SpellCastTargets targets;
uint32 targetMask = spellInfo->Targets;
if(targetMask & (TARGET_FLAG_UNIT|TARGET_FLAG_UNK2))
{
if(!Victim)
{
sLog.outError("CastCustomSpell: spell id %i by caster: %s %u) does not have unit target", spellInfo->Id,(GetTypeId()==TYPEID_PLAYER ? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER ? GetGUIDLow() : GetEntry()));
return;
}
targets.setUnitTarget(Victim);
}
if(targetMask & (TARGET_FLAG_SOURCE_LOCATION|TARGET_FLAG_DEST_LOCATION))
{
if(!Victim)
{
sLog.outError("CastCustomSpell: spell id %i by caster: %s %u) does not have destination", spellInfo->Id,(GetTypeId()==TYPEID_PLAYER ? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER ? GetGUIDLow() : GetEntry()));
return;
}
targets.setDestination(Victim);
}
if (castItem) if (castItem)
DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo->Id); DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo->Id);
@@ -914,8 +952,6 @@ void Unit::CastCustomSpell(Unit* Victim,SpellEntry const *spellInfo, int32 const
if(bp2) if(bp2)
spell->m_currentBasePoints[2] = *bp2-int32(spellInfo->EffectBaseDice[2]); spell->m_currentBasePoints[2] = *bp2-int32(spellInfo->EffectBaseDice[2]);
SpellCastTargets targets;
targets.setUnitTarget( Victim );
spell->m_CastItem = castItem; spell->m_CastItem = castItem;
spell->prepare(&targets, triggeredByAura); spell->prepare(&targets, triggeredByAura);
} }
@@ -931,15 +967,37 @@ void Unit::CastSpell(float x, float y, float z, uint32 spellId, bool triggered,
return; return;
} }
CastSpell(x, y, z,spellInfo,triggered,castItem,triggeredByAura, originalCaster); if (castItem)
DEBUG_LOG("WORLD: cast Item spellId - %i", spellInfo->Id);
if(!originalCaster && triggeredByAura)
originalCaster = triggeredByAura->GetCasterGUID();
Spell *spell = new Spell(this, spellInfo, triggered, originalCaster );
SpellCastTargets targets;
targets.setDestination(x, y, z);
spell->m_CastItem = castItem;
spell->prepare(&targets, triggeredByAura);
} }
// used for scripting // used for scripting
void Unit::CastSpell(float x, float y, float z, SpellEntry const *spellInfo, bool triggered, Item *castItem, Aura* triggeredByAura, uint64 originalCaster) void Unit::CastSpell(GameObject *go, uint32 spellId, bool triggered, Item *castItem, Aura* triggeredByAura, uint64 originalCaster)
{ {
if(!go)
return;
SpellEntry const *spellInfo = sSpellStore.LookupEntry(spellId );
if(!spellInfo) if(!spellInfo)
{ {
sLog.outError("CastSpell(x,y,z): unknown spell by caster: %s %u)", (GetTypeId()==TYPEID_PLAYER ? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER ? GetGUIDLow() : GetEntry())); sLog.outError("CastSpell(x,y,z): unknown spell id %i by caster: %s %u)", spellId,(GetTypeId()==TYPEID_PLAYER ? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER ? GetGUIDLow() : GetEntry()));
return;
}
if(!(spellInfo->Targets & ( TARGET_FLAG_OBJECT | TARGET_FLAG_OBJECT_UNK)))
{
sLog.outError("CastSpell: spell id %i by caster: %s %u) is not gameobject spell", spellId,(GetTypeId()==TYPEID_PLAYER ? "player (GUID:" : "creature (Entry:"),(GetTypeId()==TYPEID_PLAYER ? GetGUIDLow() : GetEntry()));
return; return;
} }
@@ -952,7 +1010,7 @@ void Unit::CastSpell(float x, float y, float z, SpellEntry const *spellInfo, boo
Spell *spell = new Spell(this, spellInfo, triggered, originalCaster ); Spell *spell = new Spell(this, spellInfo, triggered, originalCaster );
SpellCastTargets targets; SpellCastTargets targets;
targets.setDestination(x, y, z); targets.setGOTarget(go);
spell->m_CastItem = castItem; spell->m_CastItem = castItem;
spell->prepare(&targets, triggeredByAura); spell->prepare(&targets, triggeredByAura);
} }
+1 -1
View File
@@ -1001,7 +1001,7 @@ class TRINITY_DLL_SPEC Unit : public WorldObject
void CastCustomSpell(Unit* Victim, uint32 spellId, int32 const* bp0, int32 const* bp1, int32 const* bp2, bool triggered, Item *castItem= NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0); void CastCustomSpell(Unit* Victim, uint32 spellId, int32 const* bp0, int32 const* bp1, int32 const* bp2, bool triggered, Item *castItem= NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0);
void CastCustomSpell(Unit* Victim,SpellEntry const *spellInfo, int32 const* bp0, int32 const* bp1, int32 const* bp2, bool triggered, Item *castItem= NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0); void CastCustomSpell(Unit* Victim,SpellEntry const *spellInfo, int32 const* bp0, int32 const* bp1, int32 const* bp2, bool triggered, Item *castItem= NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0);
void CastSpell(float x, float y, float z, uint32 spellId, bool triggered, Item *castItem = NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0); void CastSpell(float x, float y, float z, uint32 spellId, bool triggered, Item *castItem = NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0);
void CastSpell(float x, float y, float z, SpellEntry const *spellInfo, bool triggered, Item *castItem = NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0); void CastSpell(GameObject *go, uint32 spellId, bool triggered, Item *castItem = NULL, Aura* triggeredByAura = NULL, uint64 originalCaster = 0);
bool IsDamageToThreatSpell(SpellEntry const * spellInfo) const; bool IsDamageToThreatSpell(SpellEntry const * spellInfo) const;