aboutsummaryrefslogtreecommitdiff
path: root/src/server/game
diff options
context:
space:
mode:
authorShauren <shauren.trinity@gmail.com>2011-07-15 12:33:03 +0200
committerShauren <shauren.trinity@gmail.com>2011-07-15 12:33:03 +0200
commit1e3c23a4e8de3ea1ee99d159f0ca34c9cc055ed3 (patch)
treee979780ed1c3adb4e6bed316ccf0cba4fdb3b9b9 /src/server/game
parent944fb4c1b77ca2a021c135100219fdc2bc62f0a8 (diff)
Core/Spells: Set UNIT_FIELD_TARGET to current spell cast target for proper facing the target
Diffstat (limited to 'src/server/game')
-rwxr-xr-xsrc/server/game/Entities/Creature/Creature.cpp2
-rwxr-xr-xsrc/server/game/Entities/Unit/Unit.cpp21
-rwxr-xr-xsrc/server/game/Entities/Unit/Unit.h34
-rwxr-xr-xsrc/server/game/Movement/MovementGenerators/ConfusedMovementGenerator.cpp4
-rwxr-xr-xsrc/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp4
-rwxr-xr-xsrc/server/game/Server/Protocol/Handlers/MiscHandler.cpp16
-rwxr-xr-xsrc/server/game/Server/Protocol/Handlers/QueryHandler.cpp2
-rwxr-xr-xsrc/server/game/Server/WorldSession.h1
-rwxr-xr-xsrc/server/game/Spells/Spell.cpp11
9 files changed, 62 insertions, 33 deletions
diff --git a/src/server/game/Entities/Creature/Creature.cpp b/src/server/game/Entities/Creature/Creature.cpp
index 73f09dcf43e..6b53576cb19 100755
--- a/src/server/game/Entities/Creature/Creature.cpp
+++ b/src/server/game/Entities/Creature/Creature.cpp
@@ -1489,7 +1489,7 @@ void Creature::setDeathState(DeathState s)
if (sWorld->getBoolConfig(CONFIG_SAVE_RESPAWN_TIME_IMMEDIATELY) || isWorldBoss())
SaveRespawnTime();
- SetUInt64Value(UNIT_FIELD_TARGET, 0); // remove target selection in any cases (can be set at aura remove in Unit::setDeathState)
+ SetTarget(0); // remove target selection in any cases (can be set at aura remove in Unit::setDeathState)
SetUInt32Value(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_NONE);
setActive(false);
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp
index 6baccfd5a4f..0f43e94efbb 100755
--- a/src/server/game/Entities/Unit/Unit.cpp
+++ b/src/server/game/Entities/Unit/Unit.cpp
@@ -235,6 +235,9 @@ m_vehicleKit(NULL), m_unitTypeMask(UNIT_MASK_NONE), m_HostileRefManager(this)
m_duringRemoveFromWorld = false;
m_serverSideVisibility.SetValue(SERVERSIDE_VISIBILITY_GHOST, GHOST_VISIBILITY_ALIVE);
+
+ _focusSpell = NULL;
+ _targetLocked = false;
}
////////////////////////////////////////////////////////////
@@ -9579,7 +9582,7 @@ bool Unit::Attack(Unit* victim, bool meleeAttack)
m_attacking->_addAttacker(this);
// Set our target
- SetUInt64Value(UNIT_FIELD_TARGET, victim->GetGUID());
+ SetTarget(victim->GetGUID());
if (meleeAttack)
AddUnitState(UNIT_STAT_MELEE_ATTACKING);
@@ -9621,7 +9624,7 @@ bool Unit::AttackStop()
m_attacking = NULL;
// Clear our target
- SetUInt64Value(UNIT_FIELD_TARGET, 0);
+ SetTarget(0);
ClearUnitState(UNIT_STAT_MELEE_ATTACKING);
@@ -14334,7 +14337,7 @@ void Unit::ProcDamageAndSpellFor(bool isVictim, Unit* pTarget, uint32 procFlag,
// no more charges to use, prevent proc
if (useCharges && !i->aura->GetCharges())
continue;
-
+
bool takeCharges = false;
SpellEntry const* spellInfo = i->aura->GetSpellProto();
uint32 Id = i->aura->GetId();
@@ -15729,7 +15732,7 @@ void Unit::SetStunned(bool apply)
{
if (apply)
{
- SetUInt64Value(UNIT_FIELD_TARGET, 0);
+ SetTarget(0);
SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED);
// MOVEMENTFLAG_ROOT cannot be used in conjunction with
@@ -15755,7 +15758,7 @@ void Unit::SetStunned(bool apply)
else
{
if (isAlive() && getVictim())
- SetUInt64Value(UNIT_FIELD_TARGET, getVictim()->GetGUID());
+ SetTarget(getVictim()->GetGUID());
// don't remove UNIT_FLAG_STUNNED for pet when owner is mounted (disabled pet's interface)
Unit* pOwner = GetOwner();
@@ -15830,7 +15833,7 @@ void Unit::SetFeared(bool apply)
{
if (apply)
{
- SetUInt64Value(UNIT_FIELD_TARGET, 0);
+ SetTarget(0);
Unit* caster = NULL;
Unit::AuraEffectList const& fearAuras = GetAuraEffectsByType(SPELL_AURA_MOD_FEAR);
@@ -15847,7 +15850,7 @@ void Unit::SetFeared(bool apply)
if (GetMotionMaster()->GetCurrentMovementGeneratorType() == FLEEING_MOTION_TYPE)
GetMotionMaster()->MovementExpired();
if (getVictim())
- SetUInt64Value(UNIT_FIELD_TARGET, getVictim()->GetGUID());
+ SetTarget(getVictim()->GetGUID());
}
}
@@ -15859,7 +15862,7 @@ void Unit::SetConfused(bool apply)
{
if (apply)
{
- SetUInt64Value(UNIT_FIELD_TARGET, 0);
+ SetTarget(0);
GetMotionMaster()->MoveConfused();
}
else
@@ -15869,7 +15872,7 @@ void Unit::SetConfused(bool apply)
if (GetMotionMaster()->GetCurrentMovementGeneratorType() == CONFUSED_MOTION_TYPE)
GetMotionMaster()->MovementExpired();
if (getVictim())
- SetUInt64Value(UNIT_FIELD_TARGET, getVictim()->GetGUID());
+ SetTarget(getVictim()->GetGUID());
}
}
diff --git a/src/server/game/Entities/Unit/Unit.h b/src/server/game/Entities/Unit/Unit.h
index 6f5ca9c3aa3..9ccf0859245 100755
--- a/src/server/game/Entities/Unit/Unit.h
+++ b/src/server/game/Entities/Unit/Unit.h
@@ -2128,6 +2128,37 @@ class Unit : public WorldObject
TempSummon* ToTempSummon() { if (isSummon()) return reinterpret_cast<TempSummon*>(this); else return NULL; }
const TempSummon* ToTempSummon() const { if (isSummon()) return reinterpret_cast<const TempSummon*>(this); else return NULL; }
+ void SetTarget(uint64 guid)
+ {
+ if (!_targetLocked)
+ SetUInt64Value(UNIT_FIELD_TARGET, guid);
+ }
+
+ void FocusTarget(Spell const* focusSpell, uint64 target)
+ {
+ // already focused
+ if (_focusSpell)
+ return;
+
+ _focusSpell = focusSpell;
+ _targetLocked = true;
+ SetUInt64Value(UNIT_FIELD_TARGET, target);
+ }
+
+ void ReleaseFocus(Spell const* focusSpell)
+ {
+ // focused to something else
+ if (focusSpell != _focusSpell)
+ return;
+
+ _focusSpell = NULL;
+ _targetLocked = false;
+ if (Unit* victim = getVictim())
+ SetUInt64Value(UNIT_FIELD_TARGET, victim->GetGUID());
+ else
+ SetUInt64Value(UNIT_FIELD_TARGET, 0);
+ }
+
protected:
explicit Unit ();
@@ -2244,6 +2275,9 @@ class Unit : public WorldObject
bool m_cleanupDone; // lock made to not add stuff after cleanup before delete
bool m_duringRemoveFromWorld; // lock made to not add stuff after begining removing from world
+
+ Spell const* _focusSpell;
+ bool _targetLocked; // locks the target during spell cast for proper facing
};
namespace Trinity
diff --git a/src/server/game/Movement/MovementGenerators/ConfusedMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/ConfusedMovementGenerator.cpp
index 59c624519e2..4e8b4b13ffa 100755
--- a/src/server/game/Movement/MovementGenerators/ConfusedMovementGenerator.cpp
+++ b/src/server/game/Movement/MovementGenerators/ConfusedMovementGenerator.cpp
@@ -85,7 +85,7 @@ ConfusedMovementGenerator<T>::Initialize(T &unit)
}
}
- unit.SetUInt64Value(UNIT_FIELD_TARGET, 0);
+ unit.SetTarget(0);
unit.SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED);
unit.CastStop();
unit.StopMoving();
@@ -170,7 +170,7 @@ ConfusedMovementGenerator<T>::Finalize(T &unit)
unit.RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_CONFUSED);
unit.ClearUnitState(UNIT_STAT_CONFUSED);
if (unit.GetTypeId() == TYPEID_UNIT && unit.getVictim())
- unit.SetUInt64Value(UNIT_FIELD_TARGET, unit.getVictim()->GetGUID());
+ unit.SetTarget(unit.getVictim()->GetGUID());
}
template void ConfusedMovementGenerator<Player>::Initialize(Player &player);
diff --git a/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp b/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp
index 74ee5b74a4f..2721235aa23 100755
--- a/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp
+++ b/src/server/game/Movement/MovementGenerators/FleeingMovementGenerator.cpp
@@ -304,7 +304,7 @@ FleeingMovementGenerator<T>::Initialize(T &owner)
owner.CastStop();
owner.AddUnitState(UNIT_STAT_FLEEING | UNIT_STAT_ROAMING);
owner.SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING);
- owner.SetUInt64Value(UNIT_FIELD_TARGET, 0);
+ owner.SetTarget(0);
owner.RemoveUnitMovementFlag(MOVEMENTFLAG_WALKING);
if (Unit* fright = ObjectAccessor::GetUnit(owner, i_frightGUID))
@@ -353,7 +353,7 @@ FleeingMovementGenerator<T>::Finalize(T &owner)
owner.RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_FLEEING);
owner.ClearUnitState(UNIT_STAT_FLEEING | UNIT_STAT_ROAMING);
if (owner.GetTypeId() == TYPEID_UNIT && owner.getVictim())
- owner.SetUInt64Value(UNIT_FIELD_TARGET, owner.getVictim()->GetGUID());
+ owner.SetTarget(owner.getVictim()->GetGUID());
}
template<class T>
diff --git a/src/server/game/Server/Protocol/Handlers/MiscHandler.cpp b/src/server/game/Server/Protocol/Handlers/MiscHandler.cpp
index 885165244b3..e6368a94471 100755
--- a/src/server/game/Server/Protocol/Handlers/MiscHandler.cpp
+++ b/src/server/game/Server/Protocol/Handlers/MiscHandler.cpp
@@ -489,22 +489,6 @@ void WorldSession::HandleZoneUpdateOpcode(WorldPacket & recv_data)
//GetPlayer()->SendInitWorldStates(true, newZone);
}
-void WorldSession::HandleSetTargetOpcode(WorldPacket & recv_data)
-{
- uint64 guid;
- recv_data >> guid;
-
- _player->SetUInt32Value(UNIT_FIELD_TARGET, uint32(guid));
-
- // update reputation list if need
- Unit* unit = ObjectAccessor::GetUnit(*_player, guid);
- if (!unit)
- return;
-
- if (FactionTemplateEntry const* factionTemplateEntry = sFactionTemplateStore.LookupEntry(unit->getFaction()))
- _player->GetReputationMgr().SetVisible(factionTemplateEntry);
-}
-
void WorldSession::HandleSetSelectionOpcode(WorldPacket & recv_data)
{
uint64 guid;
diff --git a/src/server/game/Server/Protocol/Handlers/QueryHandler.cpp b/src/server/game/Server/Protocol/Handlers/QueryHandler.cpp
index 6f766057cce..b080a0fee48 100755
--- a/src/server/game/Server/Protocol/Handlers/QueryHandler.cpp
+++ b/src/server/game/Server/Protocol/Handlers/QueryHandler.cpp
@@ -326,7 +326,7 @@ void WorldSession::HandleNpcTextQueryOpcode(WorldPacket & recv_data)
sLog->outDetail("WORLD: CMSG_NPC_TEXT_QUERY ID '%u'", textID);
recv_data >> guid;
- GetPlayer()->SetUInt64Value(UNIT_FIELD_TARGET, guid);
+ GetPlayer()->SetSelection(guid);
GossipText const* pGossip = sObjectMgr->GetGossipText(textID);
diff --git a/src/server/game/Server/WorldSession.h b/src/server/game/Server/WorldSession.h
index f45ee79847c..ef1b87d37da 100755
--- a/src/server/game/Server/WorldSession.h
+++ b/src/server/game/Server/WorldSession.h
@@ -467,7 +467,6 @@ class WorldSession
void HandleTogglePvP(WorldPacket& recvPacket);
void HandleZoneUpdateOpcode(WorldPacket& recvPacket);
- void HandleSetTargetOpcode(WorldPacket& recvPacket);
void HandleSetSelectionOpcode(WorldPacket& recvPacket);
void HandleStandStateChangeOpcode(WorldPacket& recvPacket);
void HandleEmoteOpcode(WorldPacket& recvPacket);
diff --git a/src/server/game/Spells/Spell.cpp b/src/server/game/Spells/Spell.cpp
index 1759f8bae08..97dfc8bd188 100755
--- a/src/server/game/Spells/Spell.cpp
+++ b/src/server/game/Spells/Spell.cpp
@@ -528,7 +528,7 @@ m_caster(Caster), m_spellValue(new SpellValue(m_spellInfo))
// Determine if spell can be reflected back to the caster
// Patch 1.2 notes: Spell Reflection no longer reflects abilities
- m_canReflect = m_spellInfo->DmgClass == SPELL_DAMAGE_CLASS_MAGIC && !(m_spellInfo->Attributes & SPELL_ATTR0_ABILITY)
+ m_canReflect = m_spellInfo->DmgClass == SPELL_DAMAGE_CLASS_MAGIC && !(m_spellInfo->Attributes & SPELL_ATTR0_ABILITY)
&& !(m_spellInfo->AttributesEx & SPELL_ATTR1_CANT_BE_REFLECTED) && !(m_spellInfo->Attributes & SPELL_ATTR0_UNAFFECTED_BY_INVULNERABILITY)
&& !IsPassiveSpell(m_spellInfo) && !IsPositiveSpell(m_spellInfo->Id);
@@ -2944,6 +2944,12 @@ void Spell::prepare(SpellCastTargets const* targets, AuraEffect const* triggered
m_caster->SetCurrentCastedSpell(this);
SendSpellStart();
+ // set target for proper facing
+ if (m_casttime && !m_IsTriggeredSpell)
+ if (uint64 target = m_targets.GetUnitTargetGUID())
+ if (m_caster->GetGUID() != target && m_caster->GetTypeId() == TYPEID_UNIT)
+ m_caster->FocusTarget(this, target);
+
TriggerGlobalCooldown();
//item: first cast may destroy item and second cast causes crash
@@ -3578,6 +3584,9 @@ void Spell::finish(bool ok)
((Puppet*)charm)->UnSummon();
}
+ if (m_caster->GetTypeId() == TYPEID_UNIT)
+ m_caster->ReleaseFocus(this);
+
if (!ok)
return;