aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Spells/Spell.cpp
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2012-07-03 12:35:06 +0200
committerShauren <shauren.trinity@gmail.com>2012-07-03 12:35:06 +0200
commit537caf33e9ee8d88b1c4f4835ee93ee0dd557d2a (patch)
tree0cefe56b35905ca84ccb0abb7c0d03fa1091eee4 /src/server/game/Spells/Spell.cpp
parent96014a70cba0d333d7e76cc90cf36468a8b3b247 (diff)
Core/SpellScript: Implemented OnObjectTargetSelect hook for use with spell target that selects a single object
Diffstat (limited to 'src/server/game/Spells/Spell.cpp')
-rwxr-xr-xsrc/server/game/Spells/Spell.cpp115
1 files changed, 81 insertions, 34 deletions
diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp
index 2c1cff0c74a..590f880a931 100755
--- a/src/server/game/Spells/Spell.cpp
+++ b/src/server/game/Spells/Spell.cpp
@@ -914,17 +914,25 @@ void Spell::SelectImplicitChannelTargets(SpellEffIndex effIndex, SpellImplicitTa
switch (targetType.GetTarget())
{
case TARGET_UNIT_CHANNEL_TARGET:
+ {
+ WorldObject* target = ObjectAccessor::GetUnit(*m_caster, channeledSpell->m_targets.GetUnitTargetGUID());
+ CallScriptObjectTargetSelectHandlers(target, effIndex);
// unit target may be no longer avalible - teleported out of map for example
- if (Unit* target = Unit::GetUnit(*m_caster, channeledSpell->m_targets.GetUnitTargetGUID()))
- AddUnitTarget(target, 1 << effIndex);
+ if (target && target->ToUnit())
+ AddUnitTarget(target->ToUnit(), 1 << effIndex);
else
sLog->outDebug(LOG_FILTER_SPELLS_AURAS, "SPELL: cannot find channel spell target for spell ID %u, effect %u", m_spellInfo->Id, effIndex);
break;
+ }
case TARGET_DEST_CHANNEL_TARGET:
if (channeledSpell->m_targets.HasDst())
m_targets.SetDst(channeledSpell->m_targets);
else if (WorldObject* target = ObjectAccessor::GetWorldObject(*m_caster, channeledSpell->m_targets.GetObjectTargetGUID()))
- m_targets.SetDst(*target);
+ {
+ CallScriptObjectTargetSelectHandlers(target, effIndex);
+ if (target)
+ m_targets.SetDst(*target);
+ }
else
sLog->outDebug(LOG_FILTER_SPELLS_AURAS, "SPELL: cannot find channel spell destination for spell ID %u, effect %u", m_spellInfo->Id, effIndex);
break;
@@ -1002,6 +1010,8 @@ void Spell::SelectImplicitNearbyTargets(SpellEffIndex effIndex, SpellImplicitTar
return;
}
+ CallScriptObjectTargetSelectHandlers(target, effIndex);
+
switch (targetType.GetObjectType())
{
case TARGET_OBJECT_TYPE_UNIT:
@@ -1492,27 +1502,27 @@ void Spell::SelectImplicitDestDestTargets(SpellEffIndex effIndex, SpellImplicitT
void Spell::SelectImplicitCasterObjectTargets(SpellEffIndex effIndex, SpellImplicitTargetInfo const& targetType)
{
+ WorldObject* target = NULL;
+ bool checkIfValid = true;
+
switch (targetType.GetTarget())
{
case TARGET_UNIT_CASTER:
- AddUnitTarget(m_caster, 1 << effIndex, false);
+ target = m_caster;
+ checkIfValid = false;
break;
case TARGET_UNIT_MASTER:
- if (Unit* owner = m_caster->GetCharmerOrOwner())
- AddUnitTarget(owner, 1 << effIndex);
+ target = m_caster->GetCharmerOrOwner();
break;
case TARGET_UNIT_PET:
- if (Guardian* pet = m_caster->GetGuardianPet())
- AddUnitTarget(pet, 1 << effIndex);
+ target = m_caster->GetGuardianPet();
break;
case TARGET_UNIT_SUMMONER:
if (m_caster->isSummon())
- if (Unit* unit = m_caster->ToTempSummon()->GetSummoner())
- AddUnitTarget(unit, 1 << effIndex);
+ target = m_caster->ToTempSummon()->GetSummoner();
break;
case TARGET_UNIT_VEHICLE:
- if (Unit *vehicle = m_caster->GetVehicleBase())
- AddUnitTarget(vehicle, 1 << effIndex);
+ target = m_caster->GetVehicleBase();
break;
case TARGET_UNIT_PASSENGER_0:
case TARGET_UNIT_PASSENGER_1:
@@ -1523,26 +1533,38 @@ void Spell::SelectImplicitCasterObjectTargets(SpellEffIndex effIndex, SpellImpli
case TARGET_UNIT_PASSENGER_6:
case TARGET_UNIT_PASSENGER_7:
if (m_caster->GetTypeId() == TYPEID_UNIT && m_caster->ToCreature()->IsVehicle())
- if (Unit *unit = m_caster->GetVehicleKit()->GetPassenger(targetType.GetTarget() - TARGET_UNIT_PASSENGER_0))
- AddUnitTarget(unit, 1 << effIndex);
+ target = m_caster->GetVehicleKit()->GetPassenger(targetType.GetTarget() - TARGET_UNIT_PASSENGER_0);
break;
default:
break;
}
+
+ CallScriptObjectTargetSelectHandlers(target, effIndex);
+
+ if (target && target->ToUnit())
+ AddUnitTarget(target->ToUnit(), 1 << effIndex, checkIfValid);
}
void Spell::SelectImplicitTargetObjectTargets(SpellEffIndex effIndex, SpellImplicitTargetInfo const& targetType)
{
ASSERT((m_targets.GetObjectTarget() || m_targets.GetItemTarget()) && "Spell::SelectImplicitTargetObjectTargets - no explicit object or item target available!");
- if (Unit* unit = m_targets.GetUnitTarget())
- AddUnitTarget(unit, 1 << effIndex, true, false);
- else if (GameObject* gobj = m_targets.GetGOTarget())
- AddGOTarget(gobj, 1 << effIndex);
- else
- AddItemTarget(m_targets.GetItemTarget(), 1 << effIndex);
- if (WorldObject* target = m_targets.GetObjectTarget())
+ WorldObject* target = m_targets.GetObjectTarget();
+
+ CallScriptObjectTargetSelectHandlers(target, effIndex);
+
+ if (target)
+ {
+ if (Unit* unit = target->ToUnit())
+ AddUnitTarget(unit, 1 << effIndex, true, false);
+ else if (GameObject* gobj = target->ToGameObject())
+ AddGOTarget(gobj, 1 << effIndex);
+
SelectImplicitChainTargets(effIndex, targetType, target, 1 << effIndex);
+ }
+ // Script hook can remove object target and we would wrongly land here
+ else if (Item* item = m_targets.GetItemTarget())
+ AddItemTarget(item, 1 << effIndex);
}
void Spell::SelectImplicitChainTargets(SpellEffIndex effIndex, SpellImplicitTargetInfo const& targetType, WorldObject* target, uint32 effMask)
@@ -1734,9 +1756,12 @@ void Spell::SelectEffectTypeImplicitTargets(uint8 effIndex)
case SPELL_EFFECT_SUMMON_PLAYER:
if (m_caster->GetTypeId() == TYPEID_PLAYER && m_caster->ToPlayer()->GetSelection())
{
- Player* target = ObjectAccessor::FindPlayer(m_caster->ToPlayer()->GetSelection());
- if (target)
- AddUnitTarget(target, 1 << effIndex, false);
+ WorldObject* target = ObjectAccessor::FindPlayer(m_caster->ToPlayer()->GetSelection());
+
+ CallScriptObjectTargetSelectHandlers(target, SpellEffIndex(effIndex));
+
+ if (target && target->ToPlayer())
+ AddUnitTarget(target->ToUnit(), 1 << effIndex, false);
}
return;
default:
@@ -1752,6 +1777,8 @@ void Spell::SelectEffectTypeImplicitTargets(uint8 effIndex)
if (!targetMask)
return;
+ WorldObject* target = NULL;
+
switch (m_spellInfo->Effects[effIndex].GetImplicitTargetType())
{
// add explicit object target or self to the target map
@@ -1760,40 +1787,46 @@ void Spell::SelectEffectTypeImplicitTargets(uint8 effIndex)
if (targetMask & (TARGET_FLAG_UNIT_MASK | TARGET_FLAG_CORPSE_MASK))
{
if (Unit* unitTarget = m_targets.GetUnitTarget())
- AddUnitTarget(unitTarget, 1 << effIndex, false);
+ target = unitTarget;
else if (targetMask & TARGET_FLAG_CORPSE_MASK)
{
if (Corpse* corpseTarget = m_targets.GetCorpseTarget())
{
// TODO: this is a workaround - corpses should be added to spell target map too, but we can't do that so we add owner instead
if (Player* owner = ObjectAccessor::FindPlayer(corpseTarget->GetOwnerGUID()))
- AddUnitTarget(owner, 1 << effIndex, false);
+ target = owner;
}
}
else //if (targetMask & TARGET_FLAG_UNIT_MASK)
- {
- AddUnitTarget(m_caster, 1 << effIndex, false);
- }
+ target = m_caster;
}
if (targetMask & TARGET_FLAG_ITEM_MASK)
{
if (Item* itemTarget = m_targets.GetItemTarget())
AddItemTarget(itemTarget, 1 << effIndex);
+ return;
}
if (targetMask & TARGET_FLAG_GAMEOBJECT_MASK)
- {
- if (GameObject* gObjTarget = m_targets.GetGOTarget())
- AddGOTarget(gObjTarget, 1 << effIndex);
- }
+ target = m_targets.GetGOTarget();
break;
// add self to the target map
case EFFECT_IMPLICIT_TARGET_CASTER:
if (targetMask & TARGET_FLAG_UNIT_MASK)
- AddUnitTarget(m_caster, 1 << effIndex, false);
+ target = m_caster;
break;
default:
break;
}
+
+ CallScriptObjectTargetSelectHandlers(target, SpellEffIndex(effIndex));
+
+ if (target)
+ {
+ if (target->ToUnit())
+ AddUnitTarget(target->ToUnit(), 1 << effIndex, false);
+ else if (target->ToGameObject())
+ AddGOTarget(target->ToGameObject(), 1 << effIndex);
+ }
}
uint32 Spell::GetSearcherTypeMask(SpellTargetObjectTypes objType, ConditionList* condList)
@@ -7053,6 +7086,20 @@ void Spell::CallScriptObjectAreaTargetSelectHandlers(std::list<WorldObject*>& ta
}
}
+void Spell::CallScriptObjectTargetSelectHandlers(WorldObject*& target, SpellEffIndex effIndex)
+{
+ for (std::list<SpellScript*>::iterator scritr = m_loadedScripts.begin(); scritr != m_loadedScripts.end(); ++scritr)
+ {
+ (*scritr)->_PrepareScriptCall(SPELL_SCRIPT_HOOK_OBJECT_TARGET_SELECT);
+ std::list<SpellScript::ObjectTargetSelectHandler>::iterator hookItrEnd = (*scritr)->OnObjectTargetSelect.end(), hookItr = (*scritr)->OnObjectTargetSelect.begin();
+ for (; hookItr != hookItrEnd; ++hookItr)
+ if ((*hookItr).IsEffectAffected(m_spellInfo, effIndex))
+ (*hookItr).Call(*scritr, target);
+
+ (*scritr)->_FinishScriptCall();
+ }
+}
+
bool Spell::CanExecuteTriggersOnHit(uint8 effMask, SpellInfo const* triggeredByAura) const
{
bool only_on_caster = (triggeredByAura && (triggeredByAura->AttributesEx4 & SPELL_ATTR4_PROC_ONLY_ON_CASTER));