[10627] Use ObjectGuid for player's selection and unit's target

This commit is contained in:
VladimirMangos 2010-10-20 08:15:30 +04:00
parent e74d56f9d2
commit c955941b55
21 changed files with 66 additions and 73 deletions

View file

@ -3156,7 +3156,7 @@ INSERT INTO `mangos_string` VALUES
(174,'%s changed your runic power to %i/%i.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(175,'Liquid level: %f, ground: %f, type: %d, status: %d',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(200,'No selection.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(201,'Object GUID is: lowpart %u highpart %X',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(201,'Object GUID is: %s',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(202,'The name was too long by %i characters.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(203,'Error, name can only contain characters A-Z and a-z.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),
(204,'The subname was too long by %i characters.',NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL),

View file

@ -1156,7 +1156,7 @@ void ChatHandler::ExecuteCommand(const char* text)
if (m_session)
{
Player* p = m_session->GetPlayer();
ObjectGuid sel_guid = p->GetSelection();
ObjectGuid sel_guid = p->GetSelectionGuid();
sLog.outCommand(GetAccountId(),"Command: %s [Player: %s (Account: %u) X: %f Y: %f Z: %f Map: %u Selected: %s]",
fullcmd.c_str(),p->GetName(),GetAccountId(),p->GetPositionX(),p->GetPositionY(),p->GetPositionZ(),p->GetMapId(),
sel_guid.GetString().c_str());
@ -2012,9 +2012,9 @@ Player * ChatHandler::getSelectedPlayer()
if(!m_session)
return NULL;
uint64 guid = m_session->GetPlayer()->GetSelection();
ObjectGuid guid = m_session->GetPlayer()->GetSelectionGuid();
if (guid == 0)
if (guid.IsEmpty())
return m_session->GetPlayer();
return sObjectMgr.GetPlayer(guid);
@ -2025,9 +2025,9 @@ Unit* ChatHandler::getSelectedUnit()
if(!m_session)
return NULL;
uint64 guid = m_session->GetPlayer()->GetSelection();
ObjectGuid guid = m_session->GetPlayer()->GetSelectionGuid();
if (guid == 0)
if (guid.IsEmpty())
return m_session->GetPlayer();
// can be selected player at another map
@ -2039,7 +2039,7 @@ Creature* ChatHandler::getSelectedCreature()
if(!m_session)
return NULL;
return m_session->GetPlayer()->GetMap()->GetAnyTypeCreature(m_session->GetPlayer()->GetSelection());
return m_session->GetPlayer()->GetMap()->GetAnyTypeCreature(m_session->GetPlayer()->GetSelectionGuid());
}
/**

View file

@ -1385,7 +1385,7 @@ void Creature::SetDeathState(DeathState s)
if (s == JUST_DIED)
{
SetTargetGUID(0); // remove target selection in any cases (can be set at aura remove in Unit::SetDeathState)
SetTargetGuid(ObjectGuid()); // remove target selection in any cases (can be set at aura remove in Unit::SetDeathState)
SetUInt32Value(UNIT_NPC_FLAGS, UNIT_NPC_FLAG_NONE);
if (HasSearchedAssistance())

View file

@ -311,7 +311,7 @@ void
FleeingMovementGenerator<Creature>::_Init(Creature &owner)
{
owner.RemoveSplineFlag(SPLINEFLAG_WALKMODE);
owner.SetTargetGUID(0);
owner.SetTargetGuid(ObjectGuid());
is_water_ok = owner.CanSwim();
is_land_ok = owner.CanWalk();
}

View file

@ -1338,7 +1338,7 @@ void GameObject::Use(Unit* user)
Player* player = (Player*)user;
Player* targetPlayer = ObjectAccessor::FindPlayer(player->GetSelection());
Player* targetPlayer = ObjectAccessor::FindPlayer(player->GetSelectionGuid());
// accept only use by player from same group for caster except caster itself
if (!targetPlayer || targetPlayer == player || !targetPlayer->IsInSameGroupWith(player))

View file

@ -101,8 +101,8 @@ bool ChatHandler::HandleNpcWhisperCommand(char* args)
if (!ExtractPlayerTarget(&args, &target))
return false;
uint64 guid = m_session->GetPlayer()->GetSelection();
if (!guid)
ObjectGuid guid = m_session->GetPlayer()->GetSelectionGuid();
if (guid.IsEmpty())
return false;
Creature* pCreature = m_session->GetPlayer()->GetMap()->GetCreature(guid);

View file

@ -1201,16 +1201,16 @@ bool ChatHandler::HandleGameObjectNearCommand(char* args)
bool ChatHandler::HandleGUIDCommand(char* /*args*/)
{
uint64 guid = m_session->GetPlayer()->GetSelection();
ObjectGuid guid = m_session->GetPlayer()->GetSelectionGuid();
if (guid == 0)
if (guid.IsEmpty())
{
SendSysMessage(LANG_NO_SELECTION);
SetSentErrorMessage(true);
return false;
}
PSendSysMessage(LANG_OBJECT_GUID, GUID_LOPART(guid), GUID_HIPART(guid));
PSendSysMessage(LANG_OBJECT_GUID, guid.GetString().c_str());
return true;
}

View file

@ -3659,7 +3659,7 @@ bool ChatHandler::HandleDieCommand(char* /*args*/)
{
Unit* target = getSelectedUnit();
if(!target || !m_session->GetPlayer()->GetSelection())
if(!target || m_session->GetPlayer()->GetSelectionGuid().IsEmpty())
{
SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
SetSentErrorMessage(true);
@ -3687,7 +3687,7 @@ bool ChatHandler::HandleDamageCommand(char* args)
Unit* target = getSelectedUnit();
if (!target || !m_session->GetPlayer()->GetSelection())
if (!target || m_session->GetPlayer()->GetSelectionGuid().IsEmpty())
{
SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
SetSentErrorMessage(true);
@ -5649,16 +5649,16 @@ bool ChatHandler::HandleRespawnCommand(char* /*args*/)
// accept only explicitly selected target (not implicitly self targeting case)
Unit* target = getSelectedUnit();
if(pl->GetSelection() && target)
if (!pl->GetSelectionGuid().IsEmpty() && target)
{
if(target->GetTypeId()!=TYPEID_UNIT)
if (target->GetTypeId() != TYPEID_UNIT)
{
SendSysMessage(LANG_SELECT_CREATURE);
SetSentErrorMessage(true);
return false;
}
if(target->isDead())
if (target->isDead())
((Creature*)target)->Respawn();
return true;
}

View file

@ -382,14 +382,14 @@ void WorldSession::HandleZoneUpdateOpcode( WorldPacket & recv_data )
void WorldSession::HandleSetTargetOpcode( WorldPacket & recv_data )
{
// When this packet send?
uint64 guid ;
ObjectGuid guid ;
recv_data >> guid;
_player->SetTargetGUID(guid);
_player->SetTargetGuid(guid);
// update reputation list if need
Unit* unit = ObjectAccessor::GetUnit(*_player, guid );
if(!unit)
Unit* unit = ObjectAccessor::GetUnit(*_player, guid ); // can select group members at diff maps
if (!unit)
return;
if(FactionTemplateEntry const* factionTemplateEntry = sFactionTemplateStore.LookupEntry(unit->getFaction()))
@ -398,14 +398,14 @@ void WorldSession::HandleSetTargetOpcode( WorldPacket & recv_data )
void WorldSession::HandleSetSelectionOpcode( WorldPacket & recv_data )
{
uint64 guid;
ObjectGuid guid;
recv_data >> guid;
_player->SetSelection(guid);
_player->SetSelectionGuid(guid);
// update reputation list if need
Unit* unit = ObjectAccessor::GetUnit(*_player, guid );
if(!unit)
Unit* unit = ObjectAccessor::GetUnit(*_player, guid ); // can select group members at diff maps
if (!unit)
return;
if(FactionTemplateEntry const* factionTemplateEntry = sFactionTemplateStore.LookupEntry(unit->getFaction()))
@ -1075,11 +1075,11 @@ void WorldSession::HandlePlayedTime(WorldPacket& recv_data)
void WorldSession::HandleInspectOpcode(WorldPacket& recv_data)
{
uint64 guid;
ObjectGuid guid;
recv_data >> guid;
DEBUG_LOG("Inspected guid is (GUID: %u TypeId: %u)", GUID_LOPART(guid), GuidHigh2TypeId(GUID_HIPART(guid)));
DEBUG_LOG("Inspected guid is %s", guid.GetString().c_str());
_player->SetSelection(guid);
_player->SetSelectionGuid(guid);
Player *plr = sObjectMgr.GetPlayer(guid);
if(!plr) // wrong player

View file

@ -430,9 +430,6 @@ Player::Player (WorldSession *session): Unit(), m_mover(this), m_camera(this), m
if(GetSession()->GetSecurity() == SEC_PLAYER)
SetAcceptWhispers(true);
m_curSelection = 0;
m_lootGuid = 0;
m_comboTarget = 0;
m_comboPoints = 0;
@ -1840,7 +1837,7 @@ bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientati
return true;
}
SetSelection(0);
SetSelectionGuid(ObjectGuid());
CombatStop();
@ -15365,7 +15362,7 @@ bool Player::LoadFromDB( uint32 guid, SqlQueryHolder *holder )
// clear charm/summon related fields
SetCharm(NULL);
SetPet(NULL);
SetTargetGUID(0);
SetTargetGuid(ObjectGuid());
SetChannelObjectGUID(0);
SetCharmerGUID(0);
SetOwnerGUID(0);

View file

@ -1579,8 +1579,8 @@ class MANGOS_DLL_SPEC Player : public Unit
QuestStatusMap& getQuestStatusMap() { return mQuestStatus; };
const uint64& GetSelection( ) const { return m_curSelection; }
void SetSelection(const uint64 &guid) { m_curSelection = guid; SetTargetGUID(guid); }
ObjectGuid const& GetSelectionGuid( ) const { return m_curSelectionGuid; }
void SetSelectionGuid(ObjectGuid guid) { m_curSelectionGuid = guid; SetTargetGuid(guid); }
uint8 GetComboPoints() { return m_comboPoints; }
const uint64& GetComboTarget() const { return m_comboTarget; }
@ -2510,7 +2510,7 @@ class MANGOS_DLL_SPEC Player : public Unit
bool m_itemUpdateQueueBlocked;
uint32 m_ExtraFlags;
uint64 m_curSelection;
ObjectGuid m_curSelectionGuid;
uint64 m_comboTarget;
int8 m_comboPoints;

View file

@ -321,13 +321,14 @@ void WorldSession::HandleCorpseQueryOpcode(WorldPacket & /*recv_data*/)
void WorldSession::HandleNpcTextQueryOpcode( WorldPacket & recv_data )
{
uint32 textID;
uint64 guid;
ObjectGuid guid;
recv_data >> textID;
recv_data >> guid;
DETAIL_LOG("WORLD: CMSG_NPC_TEXT_QUERY ID '%u'", textID);
recv_data >> guid;
_player->SetTargetGUID(guid);
_player->SetTargetGuid(guid);
GossipText const* pGossip = sObjectMgr.GetGossipText(textID);

View file

@ -1955,7 +1955,7 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList&
{
// checked in Spell::CheckCast
if (m_caster->GetTypeId()==TYPEID_PLAYER)
if (Unit* target = m_caster->GetMap()->GetPet(((Player*)m_caster)->GetSelection()))
if (Unit* target = m_caster->GetMap()->GetPet(((Player*)m_caster)->GetSelectionGuid()))
targetUnitMap.push_back(target);
}
// Circle of Healing
@ -2314,7 +2314,7 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList&
else if(m_caster->getVictim())
pTarget = m_caster->getVictim();
else if(m_caster->GetTypeId() == TYPEID_PLAYER)
pTarget = ObjectAccessor::GetUnit(*m_caster, ((Player*)m_caster)->GetSelection());
pTarget = ObjectAccessor::GetUnit(*m_caster, ((Player*)m_caster)->GetSelectionGuid());
if(pTarget)
{
@ -2486,12 +2486,9 @@ void Spell::SetTargetMap(SpellEffectIndex effIndex, uint32 targetMode, UnitList&
targetUnitMap.push_back(m_caster);
break;
case SPELL_EFFECT_SUMMON_PLAYER:
if (m_caster->GetTypeId()==TYPEID_PLAYER && ((Player*)m_caster)->GetSelection())
{
Player* target = sObjectMgr.GetPlayer(((Player*)m_caster)->GetSelection());
if(target)
if (m_caster->GetTypeId()==TYPEID_PLAYER && !((Player*)m_caster)->GetSelectionGuid().IsEmpty())
if (Player* target = sObjectMgr.GetPlayer(((Player*)m_caster)->GetSelectionGuid()))
targetUnitMap.push_back(target);
}
break;
case SPELL_EFFECT_RESURRECT_NEW:
if (m_targets.getUnitTarget())
@ -4370,7 +4367,7 @@ SpellCastResult Spell::CheckCast(bool strict)
if (m_targets.m_targetMask == TARGET_FLAG_SELF &&
m_spellInfo->EffectImplicitTargetA[EFFECT_INDEX_1] == TARGET_CHAIN_DAMAGE)
{
if (target = m_caster->GetMap()->GetUnit(((Player *)m_caster)->GetSelection()))
if (target = m_caster->GetMap()->GetUnit(((Player *)m_caster)->GetSelectionGuid()))
m_targets.setUnitTarget(target);
else
return SPELL_FAILED_BAD_TARGETS;
@ -4752,9 +4749,9 @@ SpellCastResult Spell::CheckCast(bool strict)
if (m_caster->GetTypeId() != TYPEID_PLAYER)
return SPELL_FAILED_ERROR;
if (!((Player*)m_caster)->GetSelection())
if (((Player*)m_caster)->GetSelectionGuid().IsEmpty())
return SPELL_FAILED_BAD_IMPLICIT_TARGETS;
Pet* target = m_caster->GetMap()->GetPet(((Player*)m_caster)->GetSelection());
Pet* target = m_caster->GetMap()->GetPet(((Player*)m_caster)->GetSelectionGuid());
// alive
if (!target || target->isDead())
@ -5086,10 +5083,10 @@ SpellCastResult Spell::CheckCast(bool strict)
{
if(m_caster->GetTypeId() != TYPEID_PLAYER)
return SPELL_FAILED_BAD_TARGETS;
if(!((Player*)m_caster)->GetSelection())
if(((Player*)m_caster)->GetSelectionGuid().IsEmpty())
return SPELL_FAILED_BAD_TARGETS;
Player* target = sObjectMgr.GetPlayer(((Player*)m_caster)->GetSelection());
Player* target = sObjectMgr.GetPlayer(((Player*)m_caster)->GetSelectionGuid());
if( !target || ((Player*)m_caster) == target || !target->IsInSameRaidWith((Player*)m_caster) )
return SPELL_FAILED_BAD_TARGETS;

View file

@ -525,9 +525,7 @@ SingleEnemyTargetAura::SingleEnemyTargetAura(SpellEntry const* spellproto, Spell
Unit *caster, Item* castItem) : Aura(spellproto, eff, currentBasePoints, holder, target, caster, castItem)
{
if (caster)
m_casters_target_guid = caster->GetTypeId()==TYPEID_PLAYER ? ((Player*)caster)->GetSelection() : caster->GetTargetGUID();
else
m_casters_target_guid = 0;
m_castersTargetGuid = caster->GetTypeId()==TYPEID_PLAYER ? ((Player*)caster)->GetSelectionGuid() : caster->GetTargetGuid();
}
SingleEnemyTargetAura::~SingleEnemyTargetAura()
@ -536,7 +534,7 @@ SingleEnemyTargetAura::~SingleEnemyTargetAura()
Unit* SingleEnemyTargetAura::GetTriggerTarget() const
{
return ObjectAccessor::GetUnit(*(m_spellAuraHolder->GetTarget()), m_casters_target_guid);
return ObjectAccessor::GetUnit(*(m_spellAuraHolder->GetTarget()), m_castersTargetGuid);
}
Aura* CreateAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, SpellAuraHolder *holder, Unit *target, Unit *caster, Item* castItem)
@ -3776,7 +3774,7 @@ void Aura::HandleAuraModStun(bool apply, bool Real)
target->ModifyAuraState(AURA_STATE_FROZEN, apply);
target->addUnitState(UNIT_STAT_STUNNED);
target->SetTargetGUID(0);
target->SetTargetGuid(ObjectGuid());
target->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_STUNNED);
target->CastStop(target->GetGUID() == GetCasterGUID() ? GetId() : 0);
@ -3846,7 +3844,7 @@ void Aura::HandleAuraModStun(bool apply, bool Real)
if(!target->hasUnitState(UNIT_STAT_ROOT)) // prevent allow move if have also root effect
{
if(target->getVictim() && target->isAlive())
target->SetTargetGUID(target->getVictim()->GetGUID());
target->SetTargetGuid(target->getVictim()->GetObjectGuid());
WorldPacket data(SMSG_FORCE_MOVE_UNROOT, 8+4);
data << target->GetPackGUID();
@ -4063,7 +4061,7 @@ void Aura::HandleAuraModRoot(bool apply, bool Real)
target->ModifyAuraState(AURA_STATE_FROZEN, apply);
target->addUnitState(UNIT_STAT_ROOT);
target->SetTargetGUID(0);
target->SetTargetGuid(ObjectGuid());
//Save last orientation
if( target->getVictim() )
@ -4116,7 +4114,7 @@ void Aura::HandleAuraModRoot(bool apply, bool Real)
if(!target->hasUnitState(UNIT_STAT_STUNNED)) // prevent allow move if have also stun effect
{
if(target->getVictim() && target->isAlive())
target->SetTargetGUID(target->getVictim()->GetGUID());
target->SetTargetGuid(target->getVictim()->GetObjectGuid());
if(target->GetTypeId() == TYPEID_PLAYER)
{

View file

@ -20,6 +20,7 @@
#include "SpellAuraDefines.h"
#include "DBCEnums.h"
#include "ObjectGuid.h"
struct Modifier
{
@ -510,7 +511,7 @@ class MANGOS_DLL_SPEC SingleEnemyTargetAura : public Aura
protected:
SingleEnemyTargetAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, SpellAuraHolder *holder, Unit *target, Unit *caster = NULL, Item* castItem = NULL);
uint64 m_casters_target_guid;
ObjectGuid m_castersTargetGuid;
};
Aura* CreateAura(SpellEntry const* spellproto, SpellEffectIndex eff, int32 *currentBasePoints, SpellAuraHolder *holder, Unit *target, Unit *caster = NULL, Item* castItem = NULL);

View file

@ -2886,7 +2886,7 @@ void Spell::EffectJump(SpellEffectIndex eff_idx)
else if(unitTarget->getVictim())
pTarget = m_caster->getVictim();
else if(m_caster->GetTypeId() == TYPEID_PLAYER)
pTarget = m_caster->GetMap()->GetUnit(((Player*)m_caster)->GetSelection());
pTarget = m_caster->GetMap()->GetUnit(((Player*)m_caster)->GetSelectionGuid());
o = pTarget ? pTarget->GetOrientation() : m_caster->GetOrientation();
}
@ -2955,7 +2955,7 @@ void Spell::EffectTeleportUnits(SpellEffectIndex eff_idx)
else if(unitTarget->getVictim())
pTarget = unitTarget->getVictim();
else if(unitTarget->GetTypeId() == TYPEID_PLAYER)
pTarget = unitTarget->GetMap()->GetUnit(((Player*)unitTarget)->GetSelection());
pTarget = unitTarget->GetMap()->GetUnit(((Player*)unitTarget)->GetSelectionGuid());
// Init dest coordinates
float x = m_targets.m_destX;

View file

@ -5602,7 +5602,7 @@ bool Unit::Attack(Unit *victim, bool meleeAttack)
}
// Set our target
SetTargetGUID(victim->GetGUID());
SetTargetGuid(victim->GetObjectGuid());
if(meleeAttack)
addUnitState(UNIT_STAT_MELEE_ATTACKING);
@ -5637,7 +5637,7 @@ bool Unit::AttackStop(bool targetSwitch /*=false*/)
m_attacking = NULL;
// Clear our target
SetTargetGUID(0);
SetTargetGuid(ObjectGuid());
clearUnitState(UNIT_STAT_MELEE_ATTACKING);

View file

@ -1483,8 +1483,8 @@ class MANGOS_DLL_SPEC Unit : public WorldObject
void SetCharmerGUID(uint64 owner) { SetUInt64Value(UNIT_FIELD_CHARMEDBY, owner); }
uint64 GetCharmGUID() const { return GetUInt64Value(UNIT_FIELD_CHARM); }
void SetCharmGUID(uint64 charm) { SetUInt64Value(UNIT_FIELD_CHARM, charm); }
uint64 GetTargetGUID() const { return GetUInt64Value(UNIT_FIELD_TARGET); }
void SetTargetGUID(uint64 targetGuid) { SetUInt64Value(UNIT_FIELD_TARGET, targetGuid); }
ObjectGuid const& GetTargetGuid() const { return GetGuidValue(UNIT_FIELD_TARGET); }
void SetTargetGuid(ObjectGuid targetGuid) { SetGuidValue(UNIT_FIELD_TARGET, targetGuid); }
uint64 GetChannelObjectGUID() const { return GetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT); }
void SetChannelObjectGUID(uint64 targetGuid) { SetUInt64Value(UNIT_FIELD_CHANNEL_OBJECT, targetGuid); }

View file

@ -831,8 +831,7 @@ SpellAuraProcResult Unit::HandleDummyAuraProc(Unit *pVictim, uint32 damage, Aura
target = getVictim();
if(!target)
{
uint64 selected_guid = ((Player *)this)->GetSelection();
target = ObjectAccessor::GetUnit(*this,selected_guid);
target = ObjectAccessor::GetUnit(*this,((Player *)this)->GetSelectionGuid());
if(!target)
return SPELL_AURA_PROC_FAILED;
}

View file

@ -270,7 +270,7 @@ bool ChatHandler::HandleDebugPlaySoundCommand(char* args)
return false;
}
if (m_session->GetPlayer()->GetSelection())
if (!m_session->GetPlayer()->GetSelectionGuid().IsEmpty())
unit->PlayDistanceSound(dwSoundId,m_session->GetPlayer());
else
unit->PlayDirectSound(dwSoundId,m_session->GetPlayer());

View file

@ -1,4 +1,4 @@
#ifndef __REVISION_NR_H__
#define __REVISION_NR_H__
#define REVISION_NR "10626"
#define REVISION_NR "10627"
#endif // __REVISION_NR_H__