Guest User

Untitled

a guest
Jan 23rd, 2018
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 24.97 KB | None | 0 0
  1. diff --git a/src/game/Group.cpp b/src/game/Group.cpp
  2. index a46b329..4af034b 100644
  3. --- a/src/game/Group.cpp
  4. +++ b/src/game/Group.cpp
  5. @@ -1733,7 +1733,7 @@ bool Group::InCombatToInstance(uint32 instanceId)
  6. for(GroupReference *itr = GetFirstMember(); itr != NULL; itr = itr->next())
  7. {
  8. Player *pPlayer = itr->getSource();
  9. - if(pPlayer->getAttackers().size() && pPlayer->GetInstanceId() == instanceId)
  10. + if(pPlayer->GetMap() && pPlayer->GetInstanceId() == instanceId && pPlayer->IsInCombat())
  11. return true;
  12. }
  13. return false;
  14. diff --git a/src/game/Map.cpp b/src/game/Map.cpp
  15. index 15f4071..0cd494f 100644
  16. --- a/src/game/Map.cpp
  17. +++ b/src/game/Map.cpp
  18. @@ -285,6 +285,7 @@ bool Map::Add(Player *player)
  19. {
  20. player->GetMapRef().link(this, player);
  21. player->SetMap(this);
  22. + CreateAttackersStorageFor(player->GetObjectGuid());
  23.  
  24. // update player state for other player and visa-versa
  25. CellPair p = MaNGOS::ComputeCellPair(player->GetPositionX(), player->GetPositionY());
  26. @@ -319,6 +320,8 @@ Map::Add(T *obj)
  27. }
  28.  
  29. obj->SetMap(this);
  30. + if (obj->GetTypeId() == TYPEID_UNIT)
  31. + CreateAttackersStorageFor(obj->GetObjectGuid());
  32.  
  33. Cell cell(p);
  34. if(obj->isActiveObject())
  35. @@ -610,6 +613,8 @@ void Map::Remove(Player *player, bool remove)
  36. SendRemoveTransports(player);
  37. UpdateObjectVisibility(player,cell,p);
  38.  
  39. + RemoveAttackersStorageFor(player->GetObjectGuid());
  40. +
  41. if (!remove && !player->GetPlayerbotAI())
  42. player->ResetMap();
  43.  
  44. @@ -647,6 +652,9 @@ Map::Remove(T *obj, bool remove)
  45. UpdateObjectVisibility(obj,cell,p); // i think will be better to call this function while object still in grid, this changes nothing but logically is better(as for me)
  46. RemoveFromGrid(obj,grid,cell);
  47.  
  48. + if (obj->GetTypeId() == TYPEID_UNIT)
  49. + RemoveAttackersStorageFor(obj->GetObjectGuid());
  50. +
  51. obj->ResetMap();
  52. if( remove )
  53. {
  54. @@ -3262,3 +3270,79 @@ void Map::PlayDirectSoundToMap(uint32 soundId)
  55. for (PlayerList::const_iterator itr = pList.begin(); itr != pList.end(); ++itr)
  56. itr->getSource()->SendDirectMessage(&data);
  57. }
  58. +
  59. +/**
  60. + * Function to operations with attackers per-map storage
  61. + *
  62. + * @param targetGuid (attackerGuid)
  63. + */
  64. +
  65. +void Map::AddAttackerFor(ObjectGuid targetGuid, ObjectGuid attackerGuid)
  66. +{
  67. + WriteGuard Guard(GetLock());
  68. + AttackersMap::iterator itr = m_attackersMap.find(targetGuid);
  69. + if (itr != m_attackersMap.end())
  70. + {
  71. + itr->second.insert(attackerGuid);
  72. + }
  73. +}
  74. +
  75. +void Map::RemoveAttackerFor(ObjectGuid targetGuid, ObjectGuid attackerGuid)
  76. +{
  77. + WriteGuard Guard(GetLock());
  78. + AttackersMap::iterator itr = m_attackersMap.find(targetGuid);
  79. + if (itr != m_attackersMap.end())
  80. + {
  81. + itr->second.erase(attackerGuid);
  82. + }
  83. +}
  84. +
  85. +void Map::RemoveAllAttackerFor(ObjectGuid targetGuid)
  86. +{
  87. + WriteGuard Guard(GetLock());
  88. + AttackersMap::iterator itr = m_attackersMap.find(targetGuid);
  89. + if (itr != m_attackersMap.end())
  90. + {
  91. + itr->second.clear();
  92. + }
  93. +}
  94. +
  95. +ObjectGuidSet const& Map::GetAttackersFor(ObjectGuid targetGuid)
  96. +{
  97. + if (targetGuid.IsEmpty())
  98. + return ObjectGuidSet();
  99. +
  100. + ReadGuard Guard(GetLock());
  101. + AttackersMap::const_iterator itr = m_attackersMap.find(targetGuid);
  102. + if (itr != m_attackersMap.end())
  103. + return itr->second;
  104. + else
  105. + {
  106. + DEBUG_LOG("Map::GetAttackersFor - requested attackers list for target (guid %u), but his hot have it!", targetGuid.GetRawValue());
  107. + if (!targetGuid.IsEmpty())
  108. + {
  109. + CreateAttackersStorageFor(targetGuid);
  110. + return m_attackersMap[targetGuid];
  111. + }
  112. + }
  113. + return ObjectGuidSet();
  114. +}
  115. +
  116. +void Map::CreateAttackersStorageFor(ObjectGuid targetGuid)
  117. +{
  118. + AttackersMap::iterator itr = m_attackersMap.find(targetGuid);
  119. + if (itr == m_attackersMap.end())
  120. + {
  121. + m_attackersMap.insert(std::make_pair(targetGuid,ObjectGuidSet()));
  122. + }
  123. +}
  124. +
  125. +void Map::RemoveAttackersStorageFor(ObjectGuid targetGuid)
  126. +{
  127. + WriteGuard Guard(GetLock());
  128. + AttackersMap::iterator itr = m_attackersMap.find(targetGuid);
  129. + if (itr != m_attackersMap.end())
  130. + {
  131. + m_attackersMap.erase(itr);
  132. + }
  133. +}
  134. diff --git a/src/game/Map.h b/src/game/Map.h
  135. index 024d2be..8595ea3 100644
  136. --- a/src/game/Map.h
  137. +++ b/src/game/Map.h
  138. @@ -29,6 +29,7 @@
  139. #include "GridDefines.h"
  140. #include "Cell.h"
  141. #include "Object.h"
  142. +#include "ObjectGuid.h"
  143. #include "Timer.h"
  144. #include "SharedDefines.h"
  145. #include "GridMap.h"
  146. @@ -90,6 +91,8 @@ enum LevelRequirementVsMode
  147.  
  148. #define MIN_UNLOAD_DELAY 1 // immediate unload
  149.  
  150. +typedef std::map<ObjectGuid,ObjectGuidSet> AttackersMap;
  151. +
  152. class MANGOS_DLL_SPEC Map : public GridRefManager<NGridType>
  153. {
  154. friend class MapReference;
  155. @@ -259,6 +262,20 @@ class MANGOS_DLL_SPEC Map : public GridRefManager<NGridType>
  156. void MonsterYellToMap(CreatureInfo const* cinfo, int32 textId, uint32 language, Unit* target, uint32 senderLowGuid = 0);
  157. void PlayDirectSoundToMap(uint32 soundId);
  158.  
  159. + // Attacker per-map storage operations
  160. + void AddAttackerFor(ObjectGuid targetGuid, ObjectGuid attackerGuid);
  161. + void RemoveAttackerFor(ObjectGuid targetGuid, ObjectGuid attackerGuid);
  162. + void RemoveAllAttackerFor(ObjectGuid targetGuid);
  163. + ObjectGuidSet const& GetAttackersFor(ObjectGuid targetGuid);
  164. + void CreateAttackersStorageFor(ObjectGuid targetGuid);
  165. + void RemoveAttackersStorageFor(ObjectGuid targetGuid);
  166. +
  167. + // multithread locking
  168. + typedef ACE_RW_Thread_Mutex LockType;
  169. + typedef ACE_Read_Guard<LockType> ReadGuard;
  170. + typedef ACE_Write_Guard<LockType> WriteGuard;
  171. + LockType& GetLock() { return i_lock; }
  172. +
  173. private:
  174. void LoadMapAndVMap(int gx, int gy);
  175.  
  176. @@ -347,6 +364,10 @@ class MANGOS_DLL_SPEC Map : public GridRefManager<NGridType>
  177.  
  178. template<class T>
  179. void RemoveFromGrid(T*, NGridType *, Cell const&);
  180. +
  181. + LockType i_lock;
  182. + AttackersMap m_attackersMap;
  183. +
  184. };
  185.  
  186. class MANGOS_DLL_SPEC WorldMap : public Map
  187. diff --git a/src/game/SpellEffects.cpp b/src/game/SpellEffects.cpp
  188. index 067d992..83566e1 100644
  189. --- a/src/game/SpellEffects.cpp
  190. +++ b/src/game/SpellEffects.cpp
  191. @@ -3581,14 +3581,15 @@ void Spell::EffectDummy(SpellEffectIndex eff_idx)
  192. ihit->effectMask &= ~(1<<1);
  193.  
  194. // not empty (checked), copy
  195. - Unit::AttackerSet attackers = friendTarget->getAttackers();
  196. + ObjectGuidSet attackers = friendTarget->getAttackers();
  197.  
  198. // selected from list 3
  199. - for(uint32 i = 0; i < std::min(size_t(3),attackers.size()); ++i)
  200. + for(uint32 i = 0; i < std::min(size_t(3), attackers.size()); ++i)
  201. {
  202. - Unit::AttackerSet::iterator aItr = attackers.begin();
  203. + ObjectGuidSet::iterator aItr = attackers.begin();
  204. std::advance(aItr, rand() % attackers.size());
  205. - AddUnitTarget((*aItr), EFFECT_INDEX_1);
  206. + if (Unit* nTarget = friendTarget->GetMap()->GetUnit(*aItr))
  207. + AddUnitTarget(nTarget, EFFECT_INDEX_1);
  208. attackers.erase(aItr);
  209. }
  210.  
  211. diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp
  212. index abc2249..18aa050 100644
  213. --- a/src/game/Unit.cpp
  214. +++ b/src/game/Unit.cpp
  215. @@ -257,7 +257,7 @@ Unit::Unit() :
  216. for (int i = 0; i < MAX_STATS; ++i)
  217. m_createStats[i] = 0.0f;
  218.  
  219. - m_attacking = NULL;
  220. + m_attackingGuid.Clear();
  221. m_modMeleeHitChance = 0.0f;
  222. m_modRangedHitChance = 0.0f;
  223. m_modSpellHitChance = 0.0f;
  224. @@ -6048,14 +6048,15 @@ Unit* Unit::getAttackerForHelper()
  225. if (getVictim())
  226. return getVictim();
  227.  
  228. - if (!m_attackers.empty())
  229. + ObjectGuidSet const& attackers = GetMap()->GetAttackersFor(GetObjectGuid());
  230. + if (!attackers.empty())
  231. {
  232. - for(AttackerSet::iterator i = m_attackers.begin(); i != m_attackers.end();)
  233. + for(ObjectGuidSet::const_iterator itr = attackers.begin(); itr != attackers.end();)
  234. {
  235. - ObjectGuid guid = *i;
  236. + ObjectGuid guid = *itr++;
  237. Unit* attacker = GetMap()->GetUnit(guid);
  238. if (!attacker || !attacker->isAlive())
  239. - m_attackers.erase(guid);
  240. + GetMap()->RemoveAttackerFor(GetObjectGuid(),guid);
  241. else
  242. return attacker;
  243. }
  244. @@ -6095,9 +6096,9 @@ bool Unit::Attack(Unit *victim, bool meleeAttack)
  245. RemoveSpellsCausingAura(SPELL_AURA_MOD_UNATTACKABLE);
  246.  
  247. // in fighting already
  248. - if (m_attacking)
  249. + if (m_attackingGuid)
  250. {
  251. - if (m_attacking == victim)
  252. + if (m_attackingGuid == victim->GetObjectGuid())
  253. {
  254. // switch to melee attack from ranged/magic
  255. if ( meleeAttack && !hasUnitState(UNIT_STAT_MELEE_ATTACKING) )
  256. @@ -6126,8 +6127,9 @@ bool Unit::Attack(Unit *victim, bool meleeAttack)
  257. if (meleeAttack)
  258. addUnitState(UNIT_STAT_MELEE_ATTACKING);
  259.  
  260. - m_attacking = victim;
  261. - m_attacking->_addAttacker(GetObjectGuid());
  262. + m_attackingGuid = victim->GetObjectGuid();
  263. +
  264. + GetMap()->AddAttackerFor(m_attackingGuid,GetObjectGuid());
  265.  
  266. if (GetTypeId() == TYPEID_UNIT)
  267. {
  268. @@ -6166,13 +6168,12 @@ void Unit::AttackedBy(Unit *attacker)
  269.  
  270. bool Unit::AttackStop(bool targetSwitch /*=false*/)
  271. {
  272. - if (!m_attacking)
  273. + if (!m_attackingGuid || !GetMap())
  274. return false;
  275.  
  276. - Unit* victim = m_attacking;
  277. -
  278. - m_attacking->_removeAttacker(GetObjectGuid());
  279. - m_attacking = NULL;
  280. + Unit* victim = GetMap()->GetUnit(m_attackingGuid);
  281. + GetMap()->RemoveAttackerFor(m_attackingGuid,GetObjectGuid());
  282. + m_attackingGuid.Clear();
  283.  
  284. // Clear our target
  285. SetTargetGuid(ObjectGuid());
  286. @@ -6249,15 +6250,20 @@ void Unit::RemoveAllAttackers()
  287. if (!GetMap())
  288. return;
  289.  
  290. - while (!m_attackers.empty())
  291. + ObjectGuidSet const& attackers = GetMap()->GetAttackersFor(GetObjectGuid());
  292. +
  293. + for (ObjectGuidSet::const_iterator itr = attackers.begin(); itr != attackers.end();)
  294. {
  295. - AttackerSet::iterator iter = m_attackers.begin();
  296. - ObjectGuid guid = *iter;
  297. + ObjectGuid guid = *itr++;
  298. Unit* attacker = GetMap()->GetUnit(guid);
  299. if(!attacker || !attacker->AttackStop())
  300. {
  301. sLog.outError("WORLD: Unit has an attacker that isn't attacking it!");
  302. - m_attackers.erase(guid);
  303. + GetMap()->RemoveAttackerFor(GetObjectGuid(),guid);
  304. + }
  305. + else
  306. + {
  307. + attacker->AttackStop();
  308. }
  309. }
  310. }
  311. @@ -8811,7 +8817,7 @@ bool Unit::isVisibleForOrDetect(Unit const* u, WorldObject const* viewPoint, boo
  312. // Special cases
  313.  
  314. // If is attacked then stealth is lost, some creature can use stealth too
  315. - if ( !getAttackers().empty() )
  316. + if (IsInCombat())
  317. return true;
  318.  
  319. // If there is collision rogue is seen regardless of level difference
  320. @@ -9424,7 +9430,9 @@ bool Unit::SelectHostileTarget()
  321. // Note: creature not have targeted movement generator but have attacker in this case
  322. if (GetMotionMaster()->GetCurrentMovementGeneratorType() != CHASE_MOTION_TYPE)
  323. {
  324. - for(AttackerSet::const_iterator itr = m_attackers.begin(); itr != m_attackers.end(); ++itr)
  325. + ObjectGuidSet const& attackers = GetMap()->GetAttackersFor(GetObjectGuid());
  326. +
  327. + for (ObjectGuidSet::const_iterator itr = attackers.begin(); itr != attackers.end(); ++itr)
  328. {
  329. Unit* attacker = GetMap()->GetUnit(*itr);
  330. if (attacker && attacker->IsInMap(this) && attacker->isTargetableForAttack() && attacker->isInAccessablePlaceFor((Creature*)this))
  331. @@ -11993,10 +12001,11 @@ void Unit::StopAttackFaction(uint32 faction_id)
  332. }
  333. }
  334.  
  335. - AttackerSet const& attackers = getAttackers();
  336. - for(AttackerSet::const_iterator itr = attackers.begin(); itr != attackers.end();)
  337. + ObjectGuidSet const& attackers = GetMap()->GetAttackersFor(GetObjectGuid());
  338. + for(ObjectGuidSet::const_iterator itr = attackers.begin(); itr != attackers.end();)
  339. {
  340. Unit* attacker = GetMap()->GetUnit(*itr);
  341. +
  342. if (attacker && attacker->getFactionTemplateEntry()->faction==faction_id)
  343. {
  344. attacker->AttackStop();
  345. diff --git a/src/game/Unit.h b/src/game/Unit.h
  346. index a03b7cf..eb07253 100644
  347. --- a/src/game/Unit.h
  348. +++ b/src/game/Unit.h
  349. @@ -1152,7 +1152,6 @@ class VehicleKit;
  350. class MANGOS_DLL_SPEC Unit : public WorldObject
  351. {
  352. public:
  353. - typedef std::set<ObjectGuid> AttackerSet;
  354. typedef std::multimap< uint32, SpellAuraHolder*> SpellAuraHolderMap;
  355. typedef std::pair<SpellAuraHolderMap::iterator, SpellAuraHolderMap::iterator> SpellAuraHolderBounds;
  356. typedef std::pair<SpellAuraHolderMap::const_iterator, SpellAuraHolderMap::const_iterator> SpellAuraHolderConstBounds;
  357. @@ -1208,31 +1207,16 @@ class MANGOS_DLL_SPEC Unit : public WorldObject
  358. bool CanReachWithMeleeAttack(Unit* pVictim, float flat_mod = 0.0f) const;
  359. uint32 m_extraAttacks;
  360.  
  361. - void _addAttacker(ObjectGuid attackerGuid) // must be called only from Unit::Attack(Unit*)
  362. - {
  363. - if (attackerGuid.IsEmpty())
  364. - return;
  365. -
  366. - if (m_attackers.find(attackerGuid) == m_attackers.end())
  367. - m_attackers.insert(attackerGuid);
  368. - }
  369. - void _removeAttacker(ObjectGuid attackerGuid) // must be called only from Unit::AttackStop()
  370. - {
  371. - if (attackerGuid.IsEmpty())
  372. - return;
  373. -
  374. - if (m_attackers.find(attackerGuid) != m_attackers.end())
  375. - m_attackers.erase(attackerGuid);
  376. - }
  377. + ObjectGuidSet const& getAttackers() const { return GetMap() ? GetMap()->GetAttackersFor(GetObjectGuid()) : ObjectGuidSet(); }
  378. + bool const IsInCombat() const { return GetMap() ? bool(GetMap()->GetAttackersFor(GetObjectGuid()).size() > 0) : false; }
  379. Unit* getAttackerForHelper(); // If someone wants to help, who to give them
  380. bool Attack(Unit *victim, bool meleeAttack);
  381. void AttackedBy(Unit *attacker);
  382. void CastStop(uint32 except_spellid = 0);
  383. bool AttackStop(bool targetSwitch = false);
  384. void RemoveAllAttackers();
  385. - AttackerSet const& getAttackers() const { return m_attackers; }
  386. bool isAttackingPlayer() const;
  387. - Unit* getVictim() const { return m_attacking; }
  388. + Unit* getVictim() const { return GetMap() ? GetMap()->GetUnit(m_attackingGuid) : NULL; }
  389. void CombatStop(bool includingCast = false);
  390. void CombatStopWithPets(bool includingCast = false);
  391. void StopAttackFaction(uint32 faction_id);
  392. @@ -2090,8 +2074,7 @@ class MANGOS_DLL_SPEC Unit : public WorldObject
  393.  
  394. float m_createStats[MAX_STATS];
  395.  
  396. - AttackerSet m_attackers;
  397. - Unit* m_attacking;
  398. + ObjectGuid m_attackingGuid;
  399.  
  400. DeathState m_deathState;
  401.  
  402. diff --git a/src/game/WorldSession.cpp b/src/game/WorldSession.cpp
  403. index 10a759d..b162e40 100644
  404. --- a/src/game/WorldSession.cpp
  405. +++ b/src/game/WorldSession.cpp
  406. @@ -397,25 +397,27 @@ void WorldSession::LogoutPlayer(bool Save)
  407.  
  408. ///- If the player just died before logging out, make him appear as a ghost
  409. //FIXME: logout must be delayed in case lost connection with client in time of combat
  410. - if (_player->GetDeathTimer())
  411. + if (GetPlayer()->GetDeathTimer())
  412. {
  413. - _player->getHostileRefManager().deleteReferences();
  414. - _player->BuildPlayerRepop();
  415. - _player->RepopAtGraveyard();
  416. + GetPlayer()->getHostileRefManager().deleteReferences();
  417. + GetPlayer()->BuildPlayerRepop();
  418. + GetPlayer()->RepopAtGraveyard();
  419. }
  420. - else if (!_player->getAttackers().empty())
  421. + else if (GetPlayer()->IsInCombat() && GetPlayer()->GetMap())
  422. {
  423. - _player->CombatStop();
  424. - _player->getHostileRefManager().setOnlineOfflineState(false);
  425. - _player->RemoveAllAurasOnDeath();
  426. + GetPlayer()->CombatStop();
  427. + GetPlayer()->getHostileRefManager().setOnlineOfflineState(false);
  428. + GetPlayer()->RemoveAllAurasOnDeath();
  429.  
  430. // build set of player who attack _player or who have pet attacking of _player
  431. std::set<Player*> aset;
  432. - for(Unit::AttackerSet::const_iterator itr = _player->getAttackers().begin(); itr != _player->getAttackers().end(); ++itr)
  433. + ObjectGuidSet const& attackers = GetPlayer()->GetMap()->GetAttackersFor(GetPlayer()->GetObjectGuid());
  434. +
  435. + for(ObjectGuidSet::const_iterator itr = attackers.begin(); itr != attackers.end();)
  436. {
  437. - Unit* attacker = _player->GetMap()->GetUnit(*itr);
  438. - if (!attacker)
  439. - continue;
  440. + Unit* attacker = GetPlayer()->GetMap()->GetUnit(*itr++);
  441. + if (!attacker)
  442. + continue;
  443.  
  444. Unit* owner = attacker->GetOwner(); // including player controlled case
  445. if(owner)
  446. @@ -428,59 +430,59 @@ void WorldSession::LogoutPlayer(bool Save)
  447. aset.insert((Player*)(attacker));
  448. }
  449.  
  450. - _player->SetPvPDeath(!aset.empty());
  451. - _player->KillPlayer();
  452. - _player->BuildPlayerRepop();
  453. - _player->RepopAtGraveyard();
  454. + GetPlayer()->SetPvPDeath(!aset.empty());
  455. + GetPlayer()->KillPlayer();
  456. + GetPlayer()->BuildPlayerRepop();
  457. + GetPlayer()->RepopAtGraveyard();
  458.  
  459. // give honor to all attackers from set like group case
  460. for(std::set<Player*>::const_iterator itr = aset.begin(); itr != aset.end(); ++itr)
  461. - (*itr)->RewardHonor(_player,aset.size());
  462. + (*itr)->RewardHonor(GetPlayer(),aset.size());
  463.  
  464. // give bg rewards and update counters like kill by first from attackers
  465. // this can't be called for all attackers.
  466. if(!aset.empty())
  467. - if(BattleGround *bg = _player->GetBattleGround())
  468. - bg->HandleKillPlayer(_player,*aset.begin());
  469. + if(BattleGround *bg = GetPlayer()->GetBattleGround())
  470. + bg->HandleKillPlayer(GetPlayer(),*aset.begin());
  471. }
  472. - else if(_player->HasAuraType(SPELL_AURA_SPIRIT_OF_REDEMPTION))
  473. + else if(GetPlayer()->HasAuraType(SPELL_AURA_SPIRIT_OF_REDEMPTION))
  474. {
  475. // this will kill character by SPELL_AURA_SPIRIT_OF_REDEMPTION
  476. - _player->RemoveSpellsCausingAura(SPELL_AURA_MOD_SHAPESHIFT);
  477. - //_player->SetDeathPvP(*); set at SPELL_AURA_SPIRIT_OF_REDEMPTION apply time
  478. - _player->KillPlayer();
  479. - _player->BuildPlayerRepop();
  480. - _player->RepopAtGraveyard();
  481. + GetPlayer()->RemoveSpellsCausingAura(SPELL_AURA_MOD_SHAPESHIFT);
  482. + //GetPlayer()->SetDeathPvP(*); set at SPELL_AURA_SPIRIT_OF_REDEMPTION apply time
  483. + GetPlayer()->KillPlayer();
  484. + GetPlayer()->BuildPlayerRepop();
  485. + GetPlayer()->RepopAtGraveyard();
  486. }
  487. - else if (_player->HasPendingBind())
  488. + else if (GetPlayer()->HasPendingBind())
  489. {
  490. - _player->RepopAtGraveyard();
  491. - _player->SetPendingBind(NULL, 0);
  492. + GetPlayer()->RepopAtGraveyard();
  493. + GetPlayer()->SetPendingBind(NULL, 0);
  494. }
  495.  
  496. //drop a flag if player is carrying it
  497. - if(BattleGround *bg = _player->GetBattleGround())
  498. - bg->EventPlayerLoggedOut(_player);
  499. + if(BattleGround *bg = GetPlayer()->GetBattleGround())
  500. + bg->EventPlayerLoggedOut(GetPlayer());
  501.  
  502. ///- Teleport to home if the player is in an invalid instance
  503. - if(!_player->m_InstanceValid && !_player->isGameMaster())
  504. + if(!GetPlayer()->m_InstanceValid && !GetPlayer()->isGameMaster())
  505. {
  506. - _player->TeleportToHomebind();
  507. + GetPlayer()->TeleportToHomebind();
  508. //this is a bad place to call for far teleport because we need player to be in world for successful logout
  509. //maybe we should implement delayed far teleport logout?
  510. }
  511.  
  512. // FG: finish pending transfers after starting the logout
  513. // this should fix players beeing able to logout and login back with full hp at death position
  514. - while(_player->IsBeingTeleportedFar())
  515. + while(GetPlayer()->IsBeingTeleportedFar())
  516. HandleMoveWorldportAckOpcode();
  517.  
  518. for (int i=0; i < PLAYER_MAX_BATTLEGROUND_QUEUES; ++i)
  519. {
  520. - if(BattleGroundQueueTypeId bgQueueTypeId = _player->GetBattleGroundQueueTypeId(i))
  521. + if(BattleGroundQueueTypeId bgQueueTypeId = GetPlayer()->GetBattleGroundQueueTypeId(i))
  522. {
  523. - _player->RemoveBattleGroundQueueId(bgQueueTypeId);
  524. - sBattleGroundMgr.m_BattleGroundQueues[ bgQueueTypeId ].RemovePlayer(_player->GetObjectGuid(), true);
  525. + GetPlayer()->RemoveBattleGroundQueueId(bgQueueTypeId);
  526. + sBattleGroundMgr.m_BattleGroundQueues[ bgQueueTypeId ].RemovePlayer(GetPlayer()->GetObjectGuid(), true);
  527. }
  528. }
  529.  
  530. @@ -496,48 +498,48 @@ void WorldSession::LogoutPlayer(bool Save)
  531. }
  532.  
  533. ///- If the player is in a guild, update the guild roster and broadcast a logout message to other guild members
  534. - if (Guild* guild = sGuildMgr.GetGuildById(_player->GetGuildId()))
  535. + if (Guild* guild = sGuildMgr.GetGuildById(GetPlayer()->GetGuildId()))
  536. {
  537. - if (MemberSlot* slot = guild->GetMemberSlot(_player->GetObjectGuid()))
  538. + if (MemberSlot* slot = guild->GetMemberSlot(GetPlayer()->GetObjectGuid()))
  539. {
  540. - slot->SetMemberStats(_player);
  541. + slot->SetMemberStats(GetPlayer());
  542. slot->UpdateLogoutTime();
  543. }
  544.  
  545. - guild->BroadcastEvent(GE_SIGNED_OFF, _player->GetObjectGuid(), _player->GetName());
  546. + guild->BroadcastEvent(GE_SIGNED_OFF, GetPlayer()->GetObjectGuid(), GetPlayer()->GetName());
  547. }
  548.  
  549. ///- Remove pet
  550. - _player->RemovePet(PET_SAVE_AS_CURRENT);
  551. + GetPlayer()->RemovePet(PET_SAVE_AS_CURRENT);
  552.  
  553. - _player->InterruptNonMeleeSpells(true);
  554. + GetPlayer()->InterruptNonMeleeSpells(true);
  555.  
  556. ///- empty buyback items and save the player in the database
  557. // some save parts only correctly work in case player present in map/player_lists (pets, etc)
  558. if(Save)
  559. - _player->SaveToDB();
  560. + GetPlayer()->SaveToDB();
  561.  
  562. ///- Leave all channels before player delete...
  563. - _player->CleanupChannels();
  564. + GetPlayer()->CleanupChannels();
  565.  
  566. // LFG cleanup
  567. - sLFGMgr.Leave(_player);
  568. + sLFGMgr.Leave(GetPlayer());
  569.  
  570. ///- If the player is in a group (or invited), remove him. If the group if then only 1 person, disband the group.
  571. - _player->UninviteFromGroup();
  572. + GetPlayer()->UninviteFromGroup();
  573.  
  574. // remove player from the group if he is:
  575. // a) in group; b) not in raid group; c) logging out normally (not being kicked or disconnected)
  576. - if(_player->GetGroup() && !_player->GetGroup()->isRaidGroup() && m_Socket)
  577. - _player->RemoveFromGroup();
  578. + if(GetPlayer()->GetGroup() && !GetPlayer()->GetGroup()->isRaidGroup() && m_Socket)
  579. + GetPlayer()->RemoveFromGroup();
  580.  
  581. ///- Send update to group
  582. - if(_player->GetGroup())
  583. - _player->GetGroup()->SendUpdate();
  584. + if(GetPlayer()->GetGroup())
  585. + GetPlayer()->GetGroup()->SendUpdate();
  586.  
  587. ///- Broadcast a logout message to the player's friends
  588. - sSocialMgr.SendFriendStatus(_player, FRIEND_OFFLINE, _player->GetObjectGuid(), true);
  589. - sSocialMgr.RemovePlayerSocial (_player->GetGUIDLow ());
  590. + sSocialMgr.SendFriendStatus(GetPlayer(), FRIEND_OFFLINE, GetPlayer()->GetObjectGuid(), true);
  591. + sSocialMgr.RemovePlayerSocial (GetPlayer()->GetGUIDLow ());
  592.  
  593. // Playerbot - remember player GUID for update SQL below
  594. uint32 guid = GetPlayer()->GetGUIDLow();
  595. @@ -546,15 +548,15 @@ void WorldSession::LogoutPlayer(bool Save)
  596. // the player may not be in the world when logging out
  597. // e.g if he got disconnected during a transfer to another map
  598. // calls to GetMap in this case may cause crashes
  599. - if (_player->IsInWorld())
  600. + if (GetPlayer()->IsInWorld())
  601. {
  602. - Map* _map = _player->GetMap();
  603. - _map->Remove(_player, true);
  604. + Map* _map = GetPlayer()->GetMap();
  605. + _map->Remove(GetPlayer(), true);
  606. }
  607. else
  608. {
  609. - _player->CleanupsBeforeDelete();
  610. - Map::DeleteFromWorld(_player);
  611. + GetPlayer()->CleanupsBeforeDelete();
  612. + Map::DeleteFromWorld(GetPlayer());
  613. }
  614.  
  615. SetPlayer(NULL); // deleted in Remove/DeleteFromWorld call
Add Comment
Please, Sign In to add comment