From 972e2d56e2c9139340f7f2bda31ded5e1696c70d Mon Sep 17 00:00:00 2001 From: megamage Date: Sun, 2 Nov 2008 00:59:44 -0500 Subject: [PATCH] [svn] Add function GameObject::CastSpell. Used for hunter's trap and so. Use original caster instead caster to check spell hit result. Let spell triggers have the same faction as the summoner. Fix the bug that trigger creatures attack enemy. (no need use civilian extra flag in the future, 128 is enough) Fix shadow step. --HG-- branch : trunk --- sql/updates/153_world.sql | 1 + src/game/CreatureAIRegistry.cpp | 2 +- src/game/GameObject.cpp | 18 ++++++++++++++++-- src/game/GameObject.h | 2 ++ src/game/Object.cpp | 4 ++++ src/game/Spell.cpp | 27 +++++++++------------------ src/game/Spell.h | 6 +++--- src/game/SpellEffects.cpp | 3 ++- 8 files changed, 38 insertions(+), 25 deletions(-) create mode 100644 sql/updates/153_world.sql diff --git a/sql/updates/153_world.sql b/sql/updates/153_world.sql new file mode 100644 index 0000000000..dbff159285 --- /dev/null +++ b/sql/updates/153_world.sql @@ -0,0 +1 @@ +update creature_template set flags_extra = 128 where entry = 12999; \ No newline at end of file diff --git a/src/game/CreatureAIRegistry.cpp b/src/game/CreatureAIRegistry.cpp index 0416d2951b..6a0c563789 100644 --- a/src/game/CreatureAIRegistry.cpp +++ b/src/game/CreatureAIRegistry.cpp @@ -37,7 +37,7 @@ namespace AIRegistry { void Initialize() { - (new CreatureAIFactory("NullAI"))->RegisterSelf(); + (new CreatureAIFactory("NullCreatureAI"))->RegisterSelf(); (new CreatureAIFactory("AggressorAI"))->RegisterSelf(); (new CreatureAIFactory("ReactorAI"))->RegisterSelf(); (new CreatureAIFactory("GuardAI"))->RegisterSelf(); diff --git a/src/game/GameObject.cpp b/src/game/GameObject.cpp index 2a5b9fb186..57d206fa1a 100644 --- a/src/game/GameObject.cpp +++ b/src/game/GameObject.cpp @@ -341,9 +341,10 @@ void GameObject::Update(uint32 /*p_time*/) if (ok) { - Unit *caster = owner ? owner : ok; + //Unit *caster = owner ? owner : ok; - caster->CastSpell(ok, goInfo->trap.spellId, true); + //caster->CastSpell(ok, goInfo->trap.spellId, true); + CastSpell(ok, goInfo->trap.spellId); m_cooldownTime = time(NULL) + 4; // 4 seconds if(NeedDespawn) @@ -1263,3 +1264,16 @@ void GameObject::Use(Unit* user) spell->prepare(&targets); } + +void GameObject::CastSpell(Unit* target, uint32 spell) +{ + //summon world trigger + Creature *trigger = SummonCreature(12999, GetPositionX(), GetPositionY(), GetPositionZ(), 0, TEMPSUMMON_TIMED_DESPAWN, 1); + if(!trigger) return; + + Unit *owner = GetOwner(); + if(owner) trigger->setFaction(owner->getFaction()); + else trigger->setFaction(14); + trigger->SetVisibility(VISIBILITY_OFF); //should this be true? + trigger->CastSpell(target, spell, true, 0, 0, owner->GetGUID()); +} \ No newline at end of file diff --git a/src/game/GameObject.h b/src/game/GameObject.h index 58f1ee53e4..5ed3cfd1e6 100644 --- a/src/game/GameObject.h +++ b/src/game/GameObject.h @@ -572,6 +572,8 @@ class TRINITY_DLL_SPEC GameObject : public WorldObject GameObject* LookupFishingHoleAround(float range); GridReference &GetGridRef() { return m_gridRef; } + + void CastSpell(Unit *target, uint32 spell); protected: uint32 m_charges; // Spell charges for GAMEOBJECT_TYPE_SPELLCASTER (22) uint32 m_spellId; diff --git a/src/game/Object.cpp b/src/game/Object.cpp index d7ec1c110c..506acb6b7d 100644 --- a/src/game/Object.cpp +++ b/src/game/Object.cpp @@ -1483,7 +1483,11 @@ Creature* WorldObject::SummonCreature(uint32 id, float x, float y, float z, floa ((Creature*)this)->AI()->JustSummoned(pCreature); if(pCreature->GetCreatureInfo()->flags_extra & CREATURE_FLAG_EXTRA_TRIGGER && pCreature->m_spells[0]) + { + if(GetTypeId() == TYPEID_UNIT || GetTypeId() == TYPEID_PLAYER) + pCreature->setFaction(((Unit*)this)->getFaction()); pCreature->CastSpell(pCreature, pCreature->m_spells[0], true, 0, 0, GetGUID()); + } //return the creature therewith the summoner has access to it return pCreature; diff --git a/src/game/Spell.cpp b/src/game/Spell.cpp index a200ef8846..1bc7783d05 100644 --- a/src/game/Spell.cpp +++ b/src/game/Spell.cpp @@ -94,7 +94,7 @@ void SpellCastTargets::setUnitTarget(Unit *target) m_targetMask |= TARGET_FLAG_UNIT; } -void SpellCastTargets::setDestination(float x, float y, float z, bool send, uint32 mapId) +void SpellCastTargets::setDestination(float x, float y, float z, bool send, int32 mapId) { m_destX = x; m_destY = y; @@ -102,7 +102,7 @@ void SpellCastTargets::setDestination(float x, float y, float z, bool send, uint m_hasDest = true; if(send) m_targetMask |= TARGET_FLAG_DEST_LOCATION; - if(mapId) + if(mapId >= 0) m_mapId = mapId; } @@ -415,20 +415,8 @@ void Spell::FillTargetMap() std::list tmpUnitMap; - // Note: this hack with search required until GO casting not implemented - // environment damage spells already have around enemies targeting but this not help in case not existed GO casting support - // currently each enemy selected explicitly and self cast damage - if(m_spellInfo->EffectImplicitTargetA[i] == TARGET_ALL_AROUND_CASTER - && m_spellInfo->EffectImplicitTargetB[i]==TARGET_ALL_ENEMY_IN_AREA - && m_spellInfo->Effect[i]==SPELL_EFFECT_ENVIRONMENTAL_DAMAGE) - { - tmpUnitMap.push_back(m_targets.getUnitTarget()); - } - else - { - SetTargetMap(i,m_spellInfo->EffectImplicitTargetA[i],tmpUnitMap); - SetTargetMap(i,m_spellInfo->EffectImplicitTargetB[i],tmpUnitMap); - } + SetTargetMap(i,m_spellInfo->EffectImplicitTargetA[i],tmpUnitMap); + SetTargetMap(i,m_spellInfo->EffectImplicitTargetB[i],tmpUnitMap); if(m_targets.HasDest()) { @@ -716,7 +704,10 @@ void Spell::AddUnitTarget(Unit* pVictim, uint32 effIndex) target.processed = false; // Effects not apply on target // Calculate hit result - target.missCondition = m_caster->SpellHitResult(pVictim, m_spellInfo, m_canReflect); + if(m_originalCaster) + target.missCondition = m_originalCaster->SpellHitResult(pVictim, m_spellInfo, m_canReflect); + else + target.missCondition = SPELL_MISS_NONE; if (target.missCondition == SPELL_MISS_NONE) ++m_countOfHit; else @@ -1454,7 +1445,7 @@ void Spell::SetTargetMap(uint32 i,uint32 cur,std::list &TagUnitMap) if(m_spellInfo->Effect[0] == SPELL_EFFECT_TELEPORT_UNITS || m_spellInfo->Effect[1] == SPELL_EFFECT_TELEPORT_UNITS || m_spellInfo->Effect[2] == SPELL_EFFECT_TELEPORT_UNITS) - m_targets.setDestination(st->target_X, st->target_Y, st->target_Z, true, st->target_mapId); + m_targets.setDestination(st->target_X, st->target_Y, st->target_Z, true, (int32)st->target_mapId); else if(st->target_mapId == m_caster->GetMapId()) m_targets.setDestination(st->target_X, st->target_Y, st->target_Z); } diff --git a/src/game/Spell.h b/src/game/Spell.h index f6fa510357..8ec4a1d64d 100644 --- a/src/game/Spell.h +++ b/src/game/Spell.h @@ -111,7 +111,7 @@ class SpellCastTargets //m_srcY = target.m_srcY; //m_srcZ = target.m_srcZ; - m_mapId = 0; + m_mapId = -1; m_destX = target.m_destX; m_destY = target.m_destY; m_destZ = target.m_destZ; @@ -127,7 +127,7 @@ class SpellCastTargets uint64 getUnitTargetGUID() const { return m_unitTargetGUID; } Unit *getUnitTarget() const { return m_unitTarget; } void setUnitTarget(Unit *target); - void setDestination(float x, float y, float z, bool send = true, uint32 mapId = 0); + void setDestination(float x, float y, float z, bool send = true, int32 mapId = -1); void setDestination(Unit *target, bool send = true); uint64 getGOTargetGUID() const { return m_GOTargetGUID; } @@ -155,7 +155,7 @@ class SpellCastTargets void Update(Unit* caster); float m_srcX, m_srcY, m_srcZ; - uint32 m_mapId; + int32 m_mapId; float m_destX, m_destY, m_destZ; bool m_hasDest; std::string m_strTarget; diff --git a/src/game/SpellEffects.cpp b/src/game/SpellEffects.cpp index 58ece04a26..bfa14d9ceb 100644 --- a/src/game/SpellEffects.cpp +++ b/src/game/SpellEffects.cpp @@ -1978,7 +1978,8 @@ void Spell::EffectTeleportUnits(uint32 i) return; } // Init dest coordinates - uint32 mapid = m_targets.m_mapId; + int32 mapid = m_targets.m_mapId; + if(mapid < 0) mapid = (int32)unitTarget->GetMapId(); float x = m_targets.m_destX; float y = m_targets.m_destY; float z = m_targets.m_destZ;