diff options
author | megamage <none@none> | 2009-03-24 13:13:00 -0600 |
---|---|---|
committer | megamage <none@none> | 2009-03-24 13:13:00 -0600 |
commit | c5969d6d03b661668a9893b0cca9f6df98f7ad4b (patch) | |
tree | ee3a45b2c5b2db7f01026f345f67bcbc316b5e24 | |
parent | 6b4d5c4a358d46c10c75a586cfbb0b4ee5de19e2 (diff) |
*Make sure the a player can only have one viewpoint.
--HG--
branch : trunk
-rw-r--r-- | src/game/Player.cpp | 47 | ||||
-rw-r--r-- | src/game/Player.h | 4 | ||||
-rw-r--r-- | src/game/SpellAuras.cpp | 11 | ||||
-rw-r--r-- | src/game/SpellEffects.cpp | 2 | ||||
-rw-r--r-- | src/game/Unit.cpp | 2 |
5 files changed, 39 insertions, 27 deletions
diff --git a/src/game/Player.cpp b/src/game/Player.cpp index f18e8551354..5f6d17b2ee7 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -1901,10 +1901,10 @@ void Player::RemoveFromWorld() if(m_uint32Values) { - if(GetUInt64Value(PLAYER_FARSIGHT)) + if(WorldObject *viewpoint = GetViewpoint()) { - sLog.outCrash("Player %s has viewpoint when removed from world", GetName()); - CreateViewpoint(NULL); + sLog.outCrash("Player %s has viewpoint %u %u when removed from world", GetName(), viewpoint->GetEntry(), viewpoint->GetTypeId()); + SetViewpoint(viewpoint, false); } } } @@ -20088,36 +20088,39 @@ void Player::StopCastingBindSight() } } -void Player::CreateViewpoint(WorldObject* target) +void Player::SetViewpoint(WorldObject* target, bool apply) { - if(!target || target == this) // remove viewpoint + if(apply) { - sLog.outDebug("Player::CreateViewpoint: Player %s remove seer", GetName()); - - if(WorldObject *viewpoint = GetViewpoint()) - if(viewpoint->isType(TYPEMASK_UNIT)) - ((Unit*)viewpoint)->RemovePlayerFromVision(this); - SetUInt64Value(PLAYER_FARSIGHT, 0); + sLog.outDebug("Player::CreateViewpoint: Player %s create seer %u (TypeId: %u).", GetName(), target->GetEntry(), target->GetTypeId()); - //must immediately set seer back otherwise may crash - m_seer = this; + if(!AddUInt64Value(PLAYER_FARSIGHT, target->GetGUID())) + { + sLog.outCrash("Player::CreateViewpoint: Player %s cannot add new viewpoint!", GetName()); + return; + } - //WorldPacket data(SMSG_CLEAR_FAR_SIGHT_IMMEDIATE, 0); - //GetSession()->SendPacket(&data); + if(target->isType(TYPEMASK_UNIT)) + ((Unit*)target)->AddPlayerToVision(this); } else { - sLog.outDebug("Player::CreateViewpoint: Player %s create seer %u (TypeId: %u).", GetName(), target->GetEntry(), target->GetTypeId()); + sLog.outDebug("Player::CreateViewpoint: Player %s remove seer", GetName()); - StopCastingBindSight(); - if(!AddUInt64Value(PLAYER_FARSIGHT, target->GetGUID())) + if(!RemoveUInt64Value(PLAYER_FARSIGHT, target->GetGUID())) { - sLog.outError("Player::CreateViewpoint: Player %s cannot remove current viewpoint!", GetName()); + sLog.outCrash("Player::CreateViewpoint: Player %s cannot remove current viewpoint!", GetName()); return; } if(target->isType(TYPEMASK_UNIT)) - ((Unit*)target)->AddPlayerToVision(this); + ((Unit*)target)->RemovePlayerFromVision(this); + + //must immediately set seer back otherwise may crash + m_seer = this; + + //WorldPacket data(SMSG_CLEAR_FAR_SIGHT_IMMEDIATE, 0); + //GetSession()->SendPacket(&data); } } @@ -20224,7 +20227,8 @@ void Player::EnterVehicle(Vehicle *vehicle) StopCastingCharm(); StopCastingBindSight(); - SetCharm(vehicle, true); // charm + SetCharm(vehicle, true); + SetViewpoint(vehicle, true); SetMover(vehicle); SetClientControl(vehicle, 1); // redirect controls to vehicle @@ -20264,6 +20268,7 @@ void Player::ExitVehicle(Vehicle *vehicle) vehicle->setFaction((GetTeam() == ALLIANCE) ? vehicle->GetCreatureInfo()->faction_A : vehicle->GetCreatureInfo()->faction_H); SetCharm(vehicle, false); + SetViewpoint(vehicle, false); SetMover(this); SetClientControl(vehicle, 0); diff --git a/src/game/Player.h b/src/game/Player.h index 53005250160..c00cba0ea2a 100644 --- a/src/game/Player.h +++ b/src/game/Player.h @@ -1982,9 +1982,9 @@ class TRINITY_DLL_SPEC Player : public Unit void EnterVehicle(Vehicle *vehicle); void ExitVehicle(Vehicle *vehicle); - void SetMover(Unit* target) { CreateViewpoint(target); m_mover = target; } + void SetMover(Unit* target) { m_mover = target; } void SetSeer(WorldObject *target) { m_seer = target; } - void CreateViewpoint(WorldObject *target); + void SetViewpoint(WorldObject *target, bool apply); WorldObject* GetViewpoint() const; void StopCastingCharm(); void StopCastingBindSight(); diff --git a/src/game/SpellAuras.cpp b/src/game/SpellAuras.cpp index 5fa8f0081f2..c6b24074e12 100644 --- a/src/game/SpellAuras.cpp +++ b/src/game/SpellAuras.cpp @@ -2048,10 +2048,15 @@ void Aura::HandleAuraDummy(bool apply, bool Real) // AT REMOVE else { - if( m_target->GetTypeId() == TYPEID_PLAYER && GetSpellProto()->Effect[0]==72 ) + if(GetSpellProto()->Effect[0]==72 ) { // spells with SpellEffect=72 and aura=4: 6196, 6197, 21171, 21425 - ((Player*)m_target)->CreateViewpoint(NULL); + if(DynamicObject* dynObj = m_target->GetDynObject(GetId(), 0)) + { + if(m_target->GetTypeId() == TYPEID_PLAYER) + ((Player*)m_target)->SetViewpoint(dynObj, false); + m_target->RemoveDynObject(GetId()); + } return; } @@ -3007,7 +3012,7 @@ void Aura::HandleBindSight(bool apply, bool Real) if(!caster || caster->GetTypeId() != TYPEID_PLAYER) return; - ((Player*)caster)->CreateViewpoint(apply ? m_target : NULL); + ((Player*)caster)->SetViewpoint(m_target, apply); } void Aura::HandleFarSight(bool apply, bool Real) diff --git a/src/game/SpellEffects.cpp b/src/game/SpellEffects.cpp index b286ed66b28..a95c1dac11f 100644 --- a/src/game/SpellEffects.cpp +++ b/src/game/SpellEffects.cpp @@ -3620,7 +3620,7 @@ void Spell::EffectAddFarsight(uint32 i) dynObj->GetMap()->Add(dynObj); //grid will also be loaded // Need to update visibility of object for client to accept farsight guid - ((Player*)m_caster)->CreateViewpoint(dynObj); + ((Player*)m_caster)->SetViewpoint(dynObj, true); //((Player*)m_caster)->UpdateVisibilityOf(dynObj); } diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp index 1850f9f1eeb..3c2713c6d91 100644 --- a/src/game/Unit.cpp +++ b/src/game/Unit.cpp @@ -13141,6 +13141,7 @@ void Unit::SetCharmedOrPossessedBy(Unit* charmer, bool possess) SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_UNK_24); ((Player*)charmer)->SetClientControl(this, 1); ((Player*)charmer)->SetMover(this); + ((Player*)charmer)->SetViewpoint(this, true); charmer->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_MOVE); } // Charm demon @@ -13223,6 +13224,7 @@ void Unit::RemoveCharmedOrPossessedBy(Unit *charmer) { ((Player*)charmer)->SetClientControl(charmer, 1); ((Player*)charmer)->SetMover(charmer); + ((Player*)charmer)->SetViewpoint(this, false); charmer->RemoveFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_DISABLE_MOVE); } // restore UNIT_FIELD_BYTES_0 |