aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/game/Map.cpp71
-rw-r--r--src/game/MapManager.cpp22
-rw-r--r--src/game/Player.cpp351
-rw-r--r--src/game/Unit.cpp66
4 files changed, 237 insertions, 273 deletions
diff --git a/src/game/Map.cpp b/src/game/Map.cpp
index d859b8567cb..cc47cfbf051 100644
--- a/src/game/Map.cpp
+++ b/src/game/Map.cpp
@@ -698,11 +698,9 @@ void Map::Update(const uint32 &t_diff)
{
/// update players at tick
for (m_mapRefIter = m_mapRefManager.begin(); m_mapRefIter != m_mapRefManager.end(); ++m_mapRefIter)
- {
- Player* plr = m_mapRefIter->getSource();
- if(plr && plr->IsInWorld())
- plr->Update(t_diff);
- }
+ if (Player* plr = m_mapRefIter->getSource())
+ if (plr && plr->IsInWorld())
+ plr->Update(t_diff);
m_notifyTimer.Update(t_diff);
if(m_notifyTimer.Passed())
@@ -726,7 +724,7 @@ void Map::Update(const uint32 &t_diff)
{
Player* plr = m_mapRefIter->getSource();
- if(!plr->IsInWorld())
+ if (!plr->IsInWorld())
continue;
CellPair standing_cell(Trinity::ComputeCellPair(plr->GetPositionX(), plr->GetPositionY()));
@@ -749,7 +747,7 @@ void Map::Update(const uint32 &t_diff)
// marked cells are those that have been visited
// don't visit the same cell twice
uint32 cell_id = (y * TOTAL_NUMBER_OF_CELLS_PER_MAP) + x;
- if(!isCellMarked(cell_id))
+ if (!isCellMarked(cell_id))
{
markCell(cell_id);
CellPair pair(x,y);
@@ -763,12 +761,12 @@ void Map::Update(const uint32 &t_diff)
}
}
- if(plr->m_seer != plr && !plr->GetVehicle())
+ if (plr->m_seer != plr && !plr->GetVehicle())
AddUnitToNotify(plr);
}
// non-player active objects
- if(!m_activeNonPlayers.empty())
+ if (!m_activeNonPlayers.empty())
{
for (m_activeNonPlayersIter = m_activeNonPlayers.begin(); m_activeNonPlayersIter != m_activeNonPlayers.end(); )
{
@@ -779,7 +777,7 @@ void Map::Update(const uint32 &t_diff)
// step to next-next, and if we step to end() then newly added objects can wait next update.
++m_activeNonPlayersIter;
- if(!obj->IsInWorld())
+ if (!obj->IsInWorld())
continue;
CellPair standing_cell(Trinity::ComputeCellPair(obj->GetPositionX(), obj->GetPositionY()));
@@ -2644,7 +2642,7 @@ void InstanceMap::Update(const uint32& t_diff)
{
Map::Update(t_diff);
- if(i_data)
+ if (i_data)
i_data->Update(t_diff);
}
@@ -2652,7 +2650,7 @@ void InstanceMap::Remove(Player *player, bool remove)
{
sLog.outDetail("MAP: Removing player '%s' from instance '%u' of map '%s' before relocating to other map", player->GetName(), GetInstanceId(), GetMapName());
//if last player set unload timer
- if(!m_unloadTimer && m_mapRefManager.getSize() == 1)
+ if (!m_unloadTimer && m_mapRefManager.getSize() == 1)
m_unloadTimer = m_unloadWhenEmpty ? MIN_UNLOAD_DELAY : std::max(sWorld.getConfig(CONFIG_INSTANCE_UNLOAD_DELAY), (uint32)MIN_UNLOAD_DELAY);
Map::Remove(player, remove);
// for normal instances schedule the reset after all players have left
@@ -2661,7 +2659,7 @@ void InstanceMap::Remove(Player *player, bool remove)
void InstanceMap::CreateInstanceData(bool load)
{
- if(i_data != NULL)
+ if (i_data != NULL)
return;
InstanceTemplate const* mInstance = objmgr.GetInstanceTemplate(GetId());
@@ -2671,12 +2669,12 @@ void InstanceMap::CreateInstanceData(bool load)
i_data = Script->CreateInstanceData(this);
}
- if(!i_data)
+ if (!i_data)
return;
i_data->Initialize();
- if(load)
+ if (load)
{
// TODO: make a global storage for this
QueryResult* result = CharacterDatabase.PQuery("SELECT data FROM instance WHERE map = '%u' AND id = '%u'", GetId(), i_InstanceId);
@@ -2684,7 +2682,7 @@ void InstanceMap::CreateInstanceData(bool load)
{
Field* fields = result->Fetch();
const char* data = fields[0].GetString();
- if(data && data != "")
+ if (data && data != "")
{
sLog.outDebug("Loading instance data for `%s` with id %u", objmgr.GetScriptName(i_script_id), i_InstanceId);
i_data->Load(data);
@@ -2702,9 +2700,9 @@ bool InstanceMap::Reset(uint8 method)
// note: since the map may not be loaded when the instance needs to be reset
// the instance must be deleted from the DB by InstanceSaveManager
- if(HavePlayers())
+ if (HavePlayers())
{
- if(method == INSTANCE_RESET_ALL)
+ if (method == INSTANCE_RESET_ALL)
{
// notify the players to leave the instance so it can be reset
for (MapRefManager::iterator itr = m_mapRefManager.begin(); itr != m_mapRefManager.end(); ++itr)
@@ -2712,12 +2710,10 @@ bool InstanceMap::Reset(uint8 method)
}
else
{
- if(method == INSTANCE_RESET_GLOBAL)
- {
+ if (method == INSTANCE_RESET_GLOBAL)
// set the homebind timer for players inside (1 minute)
for (MapRefManager::iterator itr = m_mapRefManager.begin(); itr != m_mapRefManager.end(); ++itr)
itr->getSource()->m_InstanceValid = false;
- }
// the unload timer is not started
// instead the map will unload immediately after the players have left
@@ -2737,11 +2733,11 @@ bool InstanceMap::Reset(uint8 method)
void InstanceMap::PermBindAllPlayers(Player *player)
{
- if(!IsDungeon())
+ if (!IsDungeon())
return;
InstanceSave *save = sInstanceSaveManager.GetInstanceSave(GetInstanceId());
- if(!save)
+ if (!save)
{
sLog.outError("Cannot bind players, no instance save available for map!");
return;
@@ -2755,7 +2751,7 @@ void InstanceMap::PermBindAllPlayers(Player *player)
// players inside an instance cannot be bound to other instances
// some players may already be permanently bound, in this case nothing happens
InstancePlayerBind *bind = plr->GetBoundInstance(save->GetMapId(), save->GetDifficulty());
- if(!bind || !bind->perm)
+ if (!bind || !bind->perm)
{
plr->BindToInstance(save, true);
WorldPacket data(SMSG_INSTANCE_SAVE_CREATED, 4);
@@ -2764,7 +2760,7 @@ void InstanceMap::PermBindAllPlayers(Player *player)
}
// if the leader is not in the instance the group will not get a perm bind
- if(group && group->GetLeaderGUID() == plr->GetGUID())
+ if (group && group->GetLeaderGUID() == plr->GetGUID())
group->BindToInstance(save, true);
}
}
@@ -2773,7 +2769,7 @@ void InstanceMap::UnloadAll()
{
assert(!HavePlayers());
- if(m_resetAfterUnload == true)
+ if (m_resetAfterUnload == true)
objmgr.DeleteRespawnTimeForInstance(GetInstanceId());
Map::UnloadAll();
@@ -2790,10 +2786,10 @@ void InstanceMap::SetResetSchedule(bool on)
// only for normal instances
// the reset time is only scheduled when there are no payers inside
// it is assumed that the reset time will rarely (if ever) change while the reset is scheduled
- if(IsDungeon() && !HavePlayers() && !IsRaid() && !IsHeroic())
+ if (IsDungeon() && !HavePlayers() && !IsRaid() && !IsHeroic())
{
InstanceSave *save = sInstanceSaveManager.GetInstanceSave(GetInstanceId());
- if(!save) sLog.outError("InstanceMap::SetResetSchedule: cannot turn schedule %s, no save available for instance %d of %d", on ? "on" : "off", GetInstanceId(), GetId());
+ if (!save) sLog.outError("InstanceMap::SetResetSchedule: cannot turn schedule %s, no save available for instance %d of %d", on ? "on" : "off", GetInstanceId(), GetId());
else sInstanceSaveManager.ScheduleReset(on, save->GetResetTime(), InstanceSaveManager::InstResetEvent(0, GetId(), GetInstanceId()));
}
}
@@ -2801,7 +2797,7 @@ void InstanceMap::SetResetSchedule(bool on)
uint32 InstanceMap::GetMaxPlayers() const
{
InstanceTemplate const* iTemplate = objmgr.GetInstanceTemplate(GetId());
- if(!iTemplate)
+ if (!iTemplate)
return 0;
return IsHeroic() ? iTemplate->maxPlayersHeroic : iTemplate->maxPlayers;
}
@@ -2827,14 +2823,14 @@ void BattleGroundMap::InitVisibilityDistance()
bool BattleGroundMap::CanEnter(Player * player)
{
- if(player->GetMapRef().getTarget() == this)
+ if (player->GetMapRef().getTarget() == this)
{
sLog.outError("BGMap::CanEnter - player %u already in map!", player->GetGUIDLow());
assert(false);
return false;
}
- if(player->GetBattleGroundId() != GetInstanceId())
+ if (player->GetBattleGroundId() != GetInstanceId())
return false;
// player number limit is checked in bgmgr, no need to do it here
@@ -2868,15 +2864,12 @@ void BattleGroundMap::SetUnload()
void BattleGroundMap::RemoveAllPlayers()
{
- if(HavePlayers())
- {
+ if (HavePlayers())
for (MapRefManager::iterator itr = m_mapRefManager.begin(); itr != m_mapRefManager.end(); ++itr)
- {
- Player* plr = itr->getSource();
- if(!plr->IsBeingTeleportedFar())
- plr->TeleportTo(plr->GetBattleGroundEntryPoint());
- }
- }
+ if (Player* plr = itr->getSource())
+ if (!plr->IsBeingTeleportedFar())
+ plr->TeleportTo(plr->GetBattleGroundEntryPoint());
+
}
/// Put scripts in the execution queue
diff --git a/src/game/MapManager.cpp b/src/game/MapManager.cpp
index 7947c8d0089..68953556aa0 100644
--- a/src/game/MapManager.cpp
+++ b/src/game/MapManager.cpp
@@ -295,22 +295,22 @@ void
MapManager::Update(uint32 diff)
{
i_timer.Update(diff);
- if( !i_timer.Passed() )
+ if (!i_timer.Passed())
return;
+ MapMapType::iterator iter = i_maps.begin();
#ifdef MULTI_THREAD_MAP
- uint32 i=0;
- MapMapType::iterator iter;
+ uint32 i;
std::vector<Map*> update_queue(i_maps.size());
int omp_set_num_threads(sWorld.getConfig(CONFIG_NUMTHREADS));
- for (iter = i_maps.begin(), i=0; iter != i_maps.end(); ++iter, i++)
- update_queue[i]=iter->second;
+ for (i = 0; iter != i_maps.end(); ++iter, ++i)
+ update_queue[i] = iter->second;
/*
gomp in gcc <4.4 version cannot parallelise loops using random access iterators
so until gcc 4.4 isnt standard, we need the update_queue workaround
*/
#pragma omp parallel for schedule(dynamic) private(i) shared(update_queue)
- for (int32 i = 0; i < i_maps.size(); ++i)
+ for (; i > 0; --i)
{
checkAndCorrectGridStatesArray(); // debugging code, should be deleted some day
update_queue[i]->Update(i_timer.GetCurrent());
@@ -318,7 +318,7 @@ MapManager::Update(uint32 diff)
// sLog.outError("This is thread %d out of %d threads,updating map %u",omp_get_thread_num(),omp_get_num_threads(),iter->second->GetId());
}
#else
- for (MapMapType::iterator iter=i_maps.begin(); iter != i_maps.end(); ++iter)
+ for (MapMapType::iterator iter = i_maps.begin(); iter != i_maps.end(); ++iter)
{
iter->second->Update(i_timer.GetCurrent());
sWorld.RecordTimeDiff("UpdateMap %u", iter->second->GetId());
@@ -340,17 +340,15 @@ MapManager::Update(uint32 diff)
void MapManager::DoDelayedMovesAndRemoves()
{
/*
- int i =0;
std::vector<Map*> update_queue(i_maps.size());
- MapMapType::iterator iter;
- for (iter = i_maps.begin(); iter != i_maps.end(); ++iter, i++)
+ for (MapMapType::iterator iter = i_maps.begin(), uint32 i = 0; iter != i_maps.end(); ++iter, ++i)
update_queue[i] = iter->second;
omp_set_num_threads(sWorld.getConfig(CONFIG_NUMTHREADS));
#pragma omp parallel for schedule(dynamic) private(i) shared(update_queue)
- for (i=0; i<i_maps.size(); i++)
- update_queue[i]->DoDelayedMovesAndRemoves();
+ for (uint32 i = 0; i < i_maps.size(); ++i)
+ update_queue[i]->DoDelayedMovesAndRemoves();
*/
}
diff --git a/src/game/Player.cpp b/src/game/Player.cpp
index d9e2f139880..a9254c15fe6 100644
--- a/src/game/Player.cpp
+++ b/src/game/Player.cpp
@@ -1121,11 +1121,17 @@ void Player::SetDrunkValue(uint16 newDrunkenValue, uint32 itemId)
void Player::Update( uint32 p_time )
{
- if(!IsInWorld())
+ // Until Trinity is thread safe, anything that could result in a
+ // map, zone, or area change in this Update should be preceded by:
+ // #pragma omp critical(UpdateThreadSafety)
+ // This will only allow one thread at a time to process a "UpdateThreadSafety" block.
+ // NOTE: I'm only certain about the map change part. The zone and area #pragma is just a precaution.
+
+ if (!IsInWorld())
return;
// undelivered mail
- if(m_nextMailDelivereTime && m_nextMailDelivereTime <= time(NULL))
+ if (m_nextMailDelivereTime && m_nextMailDelivereTime <= time(NULL))
{
SendNewMail();
++unReadMails;
@@ -1137,7 +1143,7 @@ void Player::Update( uint32 p_time )
// If this is set during update SetSpellModTakingSpell call is missing somewhere in the code
// Having this would prevent more aura charges to be dropped, so let's crash
//assert (!m_spellModTakingSpell);
- if(/*m_pad ||*/ m_spellModTakingSpell)
+ if (/*m_pad ||*/ m_spellModTakingSpell)
{
//sLog.outCrash("Player has m_pad %u during update!", m_pad);
//if(m_spellModTakingSpell)
@@ -1148,10 +1154,10 @@ void Player::Update( uint32 p_time )
//used to implement delayed far teleports
SetCanDelayTeleport(true);
- Unit::Update( p_time );
+ Unit::Update(p_time);
SetCanDelayTeleport(false);
- time_t now = time (NULL);
+ time_t now = time(NULL);
UpdatePvPFlag(now);
@@ -1163,16 +1169,14 @@ void Player::Update( uint32 p_time )
UpdateAfkReport(now);
- if(isCharmed())
- {
- if(Unit *charmer = GetCharmer())
- if(charmer->GetTypeId() == TYPEID_UNIT && charmer->isAlive())
+ if (isCharmed())
+ if (Unit *charmer = GetCharmer())
+ if (charmer->GetTypeId() == TYPEID_UNIT && charmer->isAlive())
UpdateCharmedAI();
- }
// Update items that have just a limited lifetime
- if (now>m_Last_tick)
- UpdateItemDuration(uint32(now- m_Last_tick));
+ if (now > m_Last_tick)
+ UpdateItemDuration(uint32(now - m_Last_tick));
if (!m_timedquests.empty())
{
@@ -1180,7 +1184,7 @@ void Player::Update( uint32 p_time )
while (iter != m_timedquests.end())
{
QuestStatusData& q_status = mQuestStatus[*iter];
- if( q_status.m_timer <= p_time )
+ if (q_status.m_timer <= p_time)
{
uint32 quest_id = *iter;
++iter; // current iter will be removed in FailQuest
@@ -1189,7 +1193,8 @@ void Player::Update( uint32 p_time )
else
{
q_status.m_timer -= p_time;
- if (q_status.uState != QUEST_NEW) q_status.uState = QUEST_CHANGED;
+ if (q_status.uState != QUEST_NEW)
+ q_status.uState = QUEST_CHANGED;
++iter;
}
}
@@ -1197,27 +1202,27 @@ void Player::Update( uint32 p_time )
if (hasUnitState(UNIT_STAT_MELEE_ATTACKING) && !hasUnitState(UNIT_STAT_CASTING))
{
- if(Unit *pVictim = getVictim())
+ if (Unit *pVictim = getVictim())
{
// default combat reach 10
// TODO add weapon,skill check
if (isAttackReady(BASE_ATTACK))
{
- if(!IsWithinMeleeRange(pVictim))
+ if (!IsWithinMeleeRange(pVictim))
{
setAttackTimer(BASE_ATTACK,100);
- if(m_swingErrorMsg != 1) // send single time (client auto repeat)
+ if (m_swingErrorMsg != 1) // send single time (client auto repeat)
{
SendAttackSwingNotInRange();
m_swingErrorMsg = 1;
}
}
//120 degrees of radiant range
- else if( !HasInArc( 2*M_PI/3, pVictim ))
+ else if (!HasInArc(2*M_PI/3, pVictim))
{
setAttackTimer(BASE_ATTACK,100);
- if(m_swingErrorMsg != 2) // send single time (client auto repeat)
+ if (m_swingErrorMsg != 2) // send single time (client auto repeat)
{
SendAttackSwingBadFacingAttack();
m_swingErrorMsg = 2;
@@ -1228,33 +1233,28 @@ void Player::Update( uint32 p_time )
m_swingErrorMsg = 0; // reset swing error state
// prevent base and off attack in same time, delay attack at 0.2 sec
- if(haveOffhandWeapon())
- {
- uint32 off_att = getAttackTimer(OFF_ATTACK);
- if(off_att < ATTACK_DISPLAY_DELAY)
+ if (haveOffhandWeapon())
+ if (getAttackTimer(OFF_ATTACK) < ATTACK_DISPLAY_DELAY)
setAttackTimer(OFF_ATTACK,ATTACK_DISPLAY_DELAY);
- }
+
+ // do attack
AttackerStateUpdate(pVictim, BASE_ATTACK);
resetAttackTimer(BASE_ATTACK);
}
}
- if ( haveOffhandWeapon() && isAttackReady(OFF_ATTACK))
+ if (haveOffhandWeapon() && isAttackReady(OFF_ATTACK))
{
- if(!IsWithinMeleeRange(pVictim))
- {
+ if (!IsWithinMeleeRange(pVictim))
setAttackTimer(OFF_ATTACK,100);
- }
- else if( !HasInArc( 2*M_PI/3, pVictim ))
- {
+ else if (!HasInArc(2*M_PI/3, pVictim))
setAttackTimer(OFF_ATTACK,100);
- }
else
{
// prevent base and off attack in same time, delay attack at 0.2 sec
- uint32 base_att = getAttackTimer(BASE_ATTACK);
- if(base_att < ATTACK_DISPLAY_DELAY)
+ if(getAttackTimer(BASE_ATTACK) < ATTACK_DISPLAY_DELAY)
setAttackTimer(BASE_ATTACK,ATTACK_DISPLAY_DELAY);
+
// do attack
AttackerStateUpdate(pVictim, OFF_ATTACK);
resetAttackTimer(OFF_ATTACK);
@@ -1271,16 +1271,16 @@ void Player::Update( uint32 p_time )
}
}
- if(HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING))
+ if (HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING))
{
- if(roll_chance_i(3) && GetTimeInnEnter() > 0) //freeze update
+ if (roll_chance_i(3) && GetTimeInnEnter() > 0) // freeze update
{
int time_inn = time(NULL)-GetTimeInnEnter();
- if (time_inn >= 10) //freeze update
+ if (time_inn >= 10) // freeze update
{
float bubble = 0.125*sWorld.getRate(RATE_REST_INGAME);
- //speed collect rest bonus (section/in hour)
- SetRestBonus( GetRestBonus()+ time_inn*((float)GetUInt32Value(PLAYER_NEXT_LEVEL_XP)/72000)*bubble );
+ // speed collect rest bonus (section/in hour)
+ SetRestBonus(GetRestBonus()+ time_inn*((float)GetUInt32Value(PLAYER_NEXT_LEVEL_XP)/72000)*bubble);
UpdateInnerTime(time(NULL));
}
}
@@ -1288,26 +1288,27 @@ void Player::Update( uint32 p_time )
if (m_weaponChangeTimer > 0)
{
- if(p_time >= m_weaponChangeTimer)
+ if (p_time >= m_weaponChangeTimer)
m_weaponChangeTimer = 0;
else
m_weaponChangeTimer -= p_time;
}
+ #pragma omp critical(UpdateThreadSafety)
if (m_zoneUpdateTimer > 0)
{
- if(p_time >= m_zoneUpdateTimer)
+ if (p_time >= m_zoneUpdateTimer)
{
uint32 newzone, newarea;
GetZoneAndAreaId(newzone,newarea);
- if( m_zoneUpdateId != newzone )
+ if (m_zoneUpdateId != newzone)
UpdateZone(newzone,newarea); // also update area
else
{
// use area updates as well
// needed for free far all arenas for example
- if( m_areaUpdateId != newarea )
+ if (m_areaUpdateId != newarea)
UpdateArea(newarea);
m_zoneUpdateTimer = ZONE_UPDATE_INTERVAL;
@@ -1324,22 +1325,18 @@ void Player::Update( uint32 p_time )
}
if (m_deathState == JUST_DIED)
- {
KillPlayer();
- }
- if(m_nextSave > 0)
+ if (m_nextSave > 0)
{
- if(p_time >= m_nextSave)
+ if (p_time >= m_nextSave)
{
// m_nextSave reseted in SaveToDB call
SaveToDB();
sLog.outDetail("Player '%s' (GUID: %u) saved", GetName(), GetGUIDLow());
}
else
- {
m_nextSave -= p_time;
- }
}
//Handle Water/drowning
@@ -1375,7 +1372,8 @@ void Player::Update( uint32 p_time )
}
// not auto-free ghost from body in instances
- if(m_deathTimer > 0 && !GetBaseMap()->Instanceable())
+ #pragma omp critical(UpdateThreadSafety)
+ if(m_deathTimer > 0 && !GetBaseMap()->Instanceable())
{
if(p_time >= m_deathTimer)
{
@@ -1396,13 +1394,12 @@ void Player::Update( uint32 p_time )
Pet* pet = GetPet();
if(pet && !IsWithinDistInMap(pet, OWNER_MAX_DISTANCE) && !pet->isPossessed())
//if(pet && !IsWithinDistInMap(pet, OWNER_MAX_DISTANCE) && (GetCharmGUID() && (pet->GetGUID() != GetCharmGUID())))
- {
RemovePet(pet, PET_SAVE_NOT_IN_SLOT, true);
- }
//we should execute delayed teleports only for alive(!) players
//because we don't want player's ghost teleported from graveyard
- if(IsHasDelayedTeleport() && isAlive())
+ #pragma omp critical(UpdateThreadSafety)
+ if (IsHasDelayedTeleport() && isAlive())
TeleportTo(m_teleport_dest, m_teleport_options);
}
@@ -1412,9 +1409,9 @@ void Player::setDeathState(DeathState s)
bool cur = isAlive();
- if(s == JUST_DIED)
+ if (s == JUST_DIED)
{
- if(!cur)
+ if (!cur)
{
sLog.outError("setDeathState: attempt to kill a dead player %s(%d)", GetName(), GetGUIDLow());
return;
@@ -1446,16 +1443,16 @@ void Player::setDeathState(DeathState s)
Unit::setDeathState(s);
// restore resurrection spell id for player after aura remove
- if(s == JUST_DIED && cur && ressSpellId)
+ if (s == JUST_DIED && cur && ressSpellId)
SetUInt32Value(PLAYER_SELF_RES_SPELL, ressSpellId);
- if(isAlive() && !cur)
+ if (isAlive() && !cur)
{
//clear aura case after resurrection by another way (spells will be applied before next death)
SetUInt32Value(PLAYER_SELF_RES_SPELL, 0);
// restore default warrior stance
- if(getClass()== CLASS_WARRIOR)
+ if (getClass() == CLASS_WARRIOR)
CastSpell(this,SPELL_ID_PASSIVE_BATTLE_STANCE,true);
}
}
@@ -1476,7 +1473,7 @@ bool Player::BuildEnumData( QueryResult * result, WorldPacket * p_data )
uint8 pClass = fields[3].GetUInt8();
PlayerInfo const *info = objmgr.GetPlayerInfo(pRace, pClass);
- if(!info)
+ if (!info)
{
sLog.outError("Player %u has incorrect race/class pair. Don't build enum.", guid);
return false;
@@ -1510,17 +1507,17 @@ bool Player::BuildEnumData( QueryResult * result, WorldPacket * p_data )
uint32 char_flags = 0;
uint32 playerFlags = fields[14].GetUInt32();
uint32 atLoginFlags = fields[15].GetUInt32();
- if(playerFlags & PLAYER_FLAGS_HIDE_HELM)
+ if (playerFlags & PLAYER_FLAGS_HIDE_HELM)
char_flags |= CHARACTER_FLAG_HIDE_HELM;
- if(playerFlags & PLAYER_FLAGS_HIDE_CLOAK)
+ if (playerFlags & PLAYER_FLAGS_HIDE_CLOAK)
char_flags |= CHARACTER_FLAG_HIDE_CLOAK;
- if(playerFlags & PLAYER_FLAGS_GHOST)
+ if (playerFlags & PLAYER_FLAGS_GHOST)
char_flags |= CHARACTER_FLAG_GHOST;
- if(atLoginFlags & AT_LOGIN_RENAME)
+ if (atLoginFlags & AT_LOGIN_RENAME)
char_flags |= CHARACTER_FLAG_RENAME;
- if(sWorld.getConfig(CONFIG_DECLINED_NAMES_USED))
+ if (sWorld.getConfig(CONFIG_DECLINED_NAMES_USED))
{
- if(!fields[20].GetCppString().empty())
+ if (!fields[20].GetCppString().empty())
char_flags |= CHARACTER_FLAG_DECLINED;
}
else
@@ -1542,7 +1539,7 @@ bool Player::BuildEnumData( QueryResult * result, WorldPacket * p_data )
{
uint32 entry = fields[16].GetUInt32();
CreatureInfo const* cInfo = sCreatureStorage.LookupEntry<CreatureInfo>(entry);
- if(cInfo)
+ if (cInfo)
{
petDisplayId = fields[17].GetUInt32();
petLevel = fields[18].GetUInt32();
@@ -1558,12 +1555,12 @@ bool Player::BuildEnumData( QueryResult * result, WorldPacket * p_data )
// TODO: do not access data field here
Tokens data = StrSplit(fields[19].GetCppString(), " ");
- for (uint8 slot = 0; slot < EQUIPMENT_SLOT_END; slot++)
+ for (uint8 slot = 0; slot < EQUIPMENT_SLOT_END; ++slot)
{
uint32 visualbase = PLAYER_VISIBLE_ITEM_1_ENTRYID + (slot * 2);
uint32 item_id = GetUInt32ValueFromArray(data, visualbase);
const ItemPrototype * proto = objmgr.GetItemPrototype(item_id);
- if(!proto)
+ if (!proto)
{
*p_data << uint32(0);
*p_data << uint8(0);
@@ -1578,7 +1575,7 @@ bool Player::BuildEnumData( QueryResult * result, WorldPacket * p_data )
{
// values stored in 2 uint16
uint32 enchantId = 0x0000FFFF & (enchants >> enchantSlot*16);
- if(!enchantId)
+ if (!enchantId)
continue;
if ((enchant = sSpellItemEnchantmentStore.LookupEntry(enchantId)))
@@ -1603,7 +1600,7 @@ bool Player::ToggleAFK()
bool state = HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_AFK);
// afk player not allowed in battleground
- if(state && InBattleGround())
+ if (state && InBattleGround())
LeaveBattleground();
return state;
@@ -1623,11 +1620,11 @@ uint8 Player::chatTag() const
// 0x4 - gm
// 0x2 - dnd
// 0x1 - afk
- if(isGMChat())
+ if (isGMChat())
return 4;
- else if(isDND())
+ else if (isDND())
return 3;
- if(isAFK())
+ if (isAFK())
return 1;
else
return 0;
@@ -1645,18 +1642,18 @@ void Player::SendTeleportAckMsg()
// this is not used anywhere
void Player::TeleportOutOfMap(Map *oldMap)
{
- while(IsBeingTeleportedFar())
+ while (IsBeingTeleportedFar())
GetSession()->HandleMoveWorldportAckOpcode();
- if(GetMap() != oldMap)
+ if (GetMap() != oldMap)
return;
TeleportTo(m_homebindMapId, m_homebindX, m_homebindY, m_homebindZ, GetOrientation());
- while(IsBeingTeleportedFar())
+ while (IsBeingTeleportedFar())
GetSession()->HandleMoveWorldportAckOpcode();
- if(GetMap() == oldMap)
+ if (GetMap() == oldMap)
{
sLog.outCrash("Cannot teleport player out of map!");
ResetMap();
@@ -1685,15 +1682,15 @@ bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientati
// don't let enter battlegrounds without assigned battleground id (for example through areatrigger)...
// don't let gm level > 1 either
- if(!InBattleGround() && mEntry->IsBattleGroundOrArena())
+ if (!InBattleGround() && mEntry->IsBattleGroundOrArena())
return false;
// client without expansion support
- if(GetSession()->Expansion() < mEntry->Expansion())
+ if (GetSession()->Expansion() < mEntry->Expansion())
{
sLog.outDebug("Player %s using client without required expansion tried teleport to non accessible map %u", GetName(), mapid);
- if(GetTransport())
+ if (GetTransport())
RepopAtGraveyard(); // teleport to near graveyard if on transport, looks blizz like :)
SendTransferAborted(mapid, TRANSFER_ABORT_INSUF_EXPAN_LVL, mEntry->Expansion());
@@ -1701,9 +1698,7 @@ bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientati
return false; // normal client can't teleport to this map...
}
else
- {
sLog.outDebug("Player %s is being teleported to map %u", GetName(), mapid);
- }
// reset movement flags at teleport, because player will continue move with these flags after teleport
SetUnitMovementFlags(0);
@@ -1727,14 +1722,11 @@ bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientati
// The player was ported to another map and looses the duel immediately.
// We have to perform this check before the teleport, otherwise the
// ObjectAccessor won't find the flag.
- if (duel && GetMapId()!=mapid)
- {
- GameObject* obj = GetMap()->GetGameObject(GetUInt64Value(PLAYER_DUEL_ARBITER));
- if (obj)
+ if (duel && GetMapId() != mapid)
+ if (GameObject* obj = GetMap()->GetGameObject(GetUInt64Value(PLAYER_DUEL_ARBITER)))
DuelComplete(DUEL_FLED);
- }
- if ((GetMapId() == mapid) && (!m_transport))
+ if (GetMapId() == mapid && !m_transport)
{
//lets reset far teleport flag if it wasn't reset during chained teleports
SetSemaphoreTeleportFar(false);
@@ -1758,7 +1750,7 @@ bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientati
UnsummonPetTemporaryIfAny();
}
- if(!(options & TELE_TO_NOT_LEAVE_COMBAT))
+ if (!(options & TELE_TO_NOT_LEAVE_COMBAT))
CombatStop();
// this will be used instead of the current location in SaveToDB
@@ -1780,7 +1772,7 @@ bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientati
}
else
{
- if(getClass() == CLASS_DEATH_KNIGHT && GetMapId() == 609 && !isGameMaster()
+ if (getClass() == CLASS_DEATH_KNIGHT && GetMapId() == 609 && !isGameMaster()
&& !HasSpell(SPELL_ID_DEATH_GATE))
return false;
@@ -1825,7 +1817,7 @@ bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientati
// Note: at battleground join battleground id set before teleport
// and we already will found "current" battleground
// just need check that this is targeted map or leave
- if(bg->GetMapId() != mapid)
+ if (bg->GetMapId() != mapid)
LeaveBattleground(false); // don't teleport to entry point
}
@@ -1845,7 +1837,7 @@ bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientati
//remove auras before removing from map...
RemoveAurasWithInterruptFlags(AURA_INTERRUPT_FLAG_CHANGE_MAP | AURA_INTERRUPT_FLAG_MOVE | AURA_INTERRUPT_FLAG_TURNING);
- if(!GetSession()->PlayerLogout())
+ if (!GetSession()->PlayerLogout())
{
// send transfer packets
WorldPacket data(SMSG_TRANSFER_PENDING, (4+4+4));
@@ -1858,19 +1850,17 @@ bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientati
data.Initialize(SMSG_NEW_WORLD, (20));
if (m_transport)
- {
data << (uint32)mapid << m_movementInfo.t_x << m_movementInfo.t_y << m_movementInfo.t_z << m_movementInfo.t_o;
- }
else
- {
data << (uint32)mapid << (float)x << (float)y << (float)z << (float)orientation;
- }
+
GetSession()->SendPacket( &data );
SendSavedInstances();
}
// remove from old map now
- if(oldmap) oldmap->Remove(this, false);
+ if(oldmap)
+ oldmap->Remove(this, false);
// new final coordinates
float final_x = x;
@@ -1878,7 +1868,7 @@ bool Player::TeleportTo(uint32 mapid, float x, float y, float z, float orientati
float final_z = z;
float final_o = orientation;
- if(m_transport)
+ if (m_transport)
{
final_x += m_movementInfo.t_x;
final_y += m_movementInfo.t_y;
@@ -1910,38 +1900,34 @@ bool Player::TeleportToBGEntryPoint()
void Player::ProcessDelayedOperations()
{
- if(m_DelayedOperations == 0)
+ if (m_DelayedOperations == 0)
return;
- if(m_DelayedOperations & DELAYED_RESURRECT_PLAYER)
+ if (m_DelayedOperations & DELAYED_RESURRECT_PLAYER)
{
ResurrectPlayer(0.0f, false);
- if(GetMaxHealth() > m_resurrectHealth)
- SetHealth( m_resurrectHealth );
+ if (GetMaxHealth() > m_resurrectHealth)
+ SetHealth(m_resurrectHealth);
else
- SetHealth( GetMaxHealth() );
+ SetHealth(GetMaxHealth());
- if(GetMaxPower(POWER_MANA) > m_resurrectMana)
- SetPower(POWER_MANA, m_resurrectMana );
+ if (GetMaxPower(POWER_MANA) > m_resurrectMana)
+ SetPower(POWER_MANA, m_resurrectMana);
else
- SetPower(POWER_MANA, GetMaxPower(POWER_MANA) );
+ SetPower(POWER_MANA, GetMaxPower(POWER_MANA));
- SetPower(POWER_RAGE, 0 );
- SetPower(POWER_ENERGY, GetMaxPower(POWER_ENERGY) );
+ SetPower(POWER_RAGE, 0);
+ SetPower(POWER_ENERGY, GetMaxPower(POWER_ENERGY));
SpawnCorpseBones();
}
- if(m_DelayedOperations & DELAYED_SAVE_PLAYER)
- {
+ if (m_DelayedOperations & DELAYED_SAVE_PLAYER)
SaveToDB();
- }
- if(m_DelayedOperations & DELAYED_SPELL_CAST_DESERTER)
- {
+ if (m_DelayedOperations & DELAYED_SPELL_CAST_DESERTER)
CastSpell(this, SPELL_ID_DESERTER, true); // Deserter
- }
if (m_DelayedOperations & DELAYED_BG_MOUNT_RESTORE)
{
@@ -1976,10 +1962,8 @@ void Player::AddToWorld()
Unit::AddToWorld();
for (uint8 i = PLAYER_SLOT_START; i < PLAYER_SLOT_END; ++i)
- {
if(m_items[i])
m_items[i]->AddToWorld();
- }
}
void Player::RemoveFromWorld()
@@ -2001,16 +1985,16 @@ void Player::RemoveFromWorld()
for (uint8 i = PLAYER_SLOT_START; i < PLAYER_SLOT_END; ++i)
{
- if(m_items[i])
+ if (m_items[i])
m_items[i]->RemoveFromWorld();
}
for (ItemMap::iterator iter = mMitems.begin(); iter != mMitems.end(); ++iter)
iter->second->RemoveFromWorld();
- if(m_uint32Values)
+ if (m_uint32Values)
{
- if(WorldObject *viewpoint = GetViewpoint())
+ if (WorldObject *viewpoint = GetViewpoint())
{
sLog.outCrash("Player %s has viewpoint %u %u when removed from world", GetName(), viewpoint->GetEntry(), viewpoint->GetTypeId());
SetViewpoint(viewpoint, false);
@@ -2025,11 +2009,11 @@ void Player::RegenerateAll()
m_regenTimerCount += m_regenTimer;
- Regenerate( POWER_ENERGY );
+ Regenerate(POWER_ENERGY);
- Regenerate( POWER_MANA );
+ Regenerate(POWER_MANA);
- if(m_regenTimerCount >= 2000)
+ if (m_regenTimerCount >= 2000)
{
// Not in combat or they have regeneration
if( !isInCombat() || HasAuraType(SPELL_AURA_MOD_REGEN_DURING_COMBAT) ||
@@ -2039,13 +2023,13 @@ void Player::RegenerateAll()
if (!isInCombat() && !HasAuraType(SPELL_AURA_INTERRUPT_REGEN))
{
Regenerate(POWER_RAGE);
- if(getClass() == CLASS_DEATH_KNIGHT)
+ if (getClass() == CLASS_DEATH_KNIGHT)
Regenerate(POWER_RUNIC_POWER);
}
}
if(getClass() == CLASS_DEATH_KNIGHT)
- Regenerate( POWER_RUNE );
+ Regenerate(POWER_RUNE);
m_regenTimerCount -= 2000;
}
@@ -2055,19 +2039,17 @@ void Player::RegenerateAll()
void Player::Regenerate(Powers power)
{
- if(power == POWER_RUNE)
- {
+ if (power == POWER_RUNE)
for (uint32 i = 0; i < MAX_RUNES; ++i)
- if(uint8 cd = GetRuneCooldown(i)) // if we have cooldown, reduce it...
- SetRuneCooldown(i, cd - 1); // ... by 2 sec (because update is every 2 sec)
- }
+ if (uint8 cd = GetRuneCooldown(i)) // if we have cooldown, reduce it...
+ SetRuneCooldown(i, cd - 1); // ... by 2 sec (because update is every 2 sec)
uint32 maxValue = GetMaxPower(power);
- if(!maxValue)
+ if (!maxValue)
return;
uint32 curValue = GetPower(power);
- if(curValue == maxValue)
+ if (curValue == maxValue)
return;
// TODO: possible use of miscvalueb instead of amount
@@ -2168,10 +2150,10 @@ void Player::RegenerateHealth()
float addvalue = 0.0f;
// polymorphed case
- if ( IsPolymorphed() )
+ if (IsPolymorphed())
addvalue = GetMaxHealth()/3;
// normal regen case (maybe partly in combat case)
- else if (!isInCombat() || HasAuraType(SPELL_AURA_MOD_REGEN_DURING_COMBAT) )
+ else if (!isInCombat() || HasAuraType(SPELL_AURA_MOD_REGEN_DURING_COMBAT))
{
addvalue = OCTRegenHPPerSpirit()* HealthIncreaseRate;
if (!isInCombat())
@@ -2180,17 +2162,17 @@ void Player::RegenerateHealth()
for (AuraEffectList::const_iterator i = mModHealthRegenPct.begin(); i != mModHealthRegenPct.end(); ++i)
addvalue *= (100.0f + (*i)->GetAmount()) / 100.0f;
}
- else if(HasAuraType(SPELL_AURA_MOD_REGEN_DURING_COMBAT))
+ else if (HasAuraType(SPELL_AURA_MOD_REGEN_DURING_COMBAT))
addvalue *= GetTotalAuraModifier(SPELL_AURA_MOD_REGEN_DURING_COMBAT) / 100.0f;
- if(!IsStandState())
+ if (!IsStandState())
addvalue *= 1.5;
}
// always regeneration bonus (including combat)
addvalue += GetTotalAuraModifier(SPELL_AURA_MOD_HEALTH_REGEN_IN_COMBAT);
- if(addvalue < 0)
+ if (addvalue < 0)
addvalue = 0;
ModifyHealth(int32(addvalue));
@@ -2198,9 +2180,9 @@ void Player::RegenerateHealth()
bool Player::CanInteractWithNPCs(bool alive) const
{
- if(alive && !isAlive())
+ if (alive && !isAlive())
return false;
- if(isInFlight())
+ if (isInFlight())
return false;
return true;
@@ -2213,7 +2195,7 @@ Player::GetNPCIfCanInteractWith(uint64 guid, uint32 npcflagmask)
if (!guid)
return NULL;
- if(!IsInWorld())
+ if (!IsInWorld())
return NULL;
// exist (we need look pets also for some interaction (quest/etc)
@@ -2222,34 +2204,34 @@ Player::GetNPCIfCanInteractWith(uint64 guid, uint32 npcflagmask)
return NULL;
// player check
- if(!CanInteractWithNPCs(!unit->isSpiritService()))
+ if (!CanInteractWithNPCs(!unit->isSpiritService()))
return NULL;
// appropriate npc type
- if(npcflagmask && !unit->HasFlag( UNIT_NPC_FLAGS, npcflagmask ))
+ if (npcflagmask && !unit->HasFlag(UNIT_NPC_FLAGS, npcflagmask))
return NULL;
// alive or spirit healer
- if(!unit->isAlive() && (!unit->isSpiritService() || isAlive() ))
+ if (!unit->isAlive() && (!unit->isSpiritService() || isAlive()))
return NULL;
// not allow interaction under control, but allow with own pets
- if(unit->GetCharmerGUID())
+ if (unit->GetCharmerGUID())
return NULL;
// not enemy
- if( unit->IsHostileTo(this))
+ if (unit->IsHostileTo(this))
return NULL;
// not unfriendly
- if(FactionTemplateEntry const* factionTemplate = sFactionTemplateStore.LookupEntry(unit->getFaction()))
- if(factionTemplate->faction)
- if(FactionEntry const* faction = sFactionStore.LookupEntry(factionTemplate->faction))
- if(faction->reputationListID >= 0 && GetReputationMgr().GetRank(faction) <= REP_UNFRIENDLY)
+ if (FactionTemplateEntry const* factionTemplate = sFactionTemplateStore.LookupEntry(unit->getFaction()))
+ if (factionTemplate->faction)
+ if (FactionEntry const* faction = sFactionStore.LookupEntry(factionTemplate->faction))
+ if (faction->reputationListID >= 0 && GetReputationMgr().GetRank(faction) <= REP_UNFRIENDLY)
return NULL;
// not too far
- if(!unit->IsWithinDistInMap(this,INTERACTION_DISTANCE))
+ if (!unit->IsWithinDistInMap(this,INTERACTION_DISTANCE))
return NULL;
return unit;
@@ -2257,12 +2239,12 @@ Player::GetNPCIfCanInteractWith(uint64 guid, uint32 npcflagmask)
GameObject* Player::GetGameObjectIfCanInteractWith(uint64 guid, GameobjectTypes type) const
{
- if(GameObject *go = GetMap()->GetGameObject(guid))
+ if (GameObject *go = GetMap()->GetGameObject(guid))
{
- if(go->GetGoType() == type)
+ if (go->GetGoType() == type)
{
float maxdist;
- switch(type)
+ switch (type)
{
// TODO: find out how the client calculates the maximal usage distance to spellless working
// gameobjects like guildbanks and mailboxes - 10.0 is a just an abitrary choosen number
@@ -6616,7 +6598,7 @@ void Player::UpdateArea(uint32 newArea)
void Player::UpdateZone(uint32 newZone, uint32 newArea)
{
- if(m_zoneUpdateId != newZone)
+ if (m_zoneUpdateId != newZone)
{
sOutdoorPvPMgr.HandlePlayerLeaveZone(this, m_zoneUpdateId);
sOutdoorPvPMgr.HandlePlayerEnterZone(this, newZone);
@@ -6630,19 +6612,17 @@ void Player::UpdateZone(uint32 newZone, uint32 newArea)
UpdateArea(newArea);
AreaTableEntry const* zone = GetAreaEntryByAreaID(newZone);
- if(!zone)
+ if (!zone)
return;
if (sWorld.getConfig(CONFIG_WEATHER))
{
Weather *wth = sWorld.FindWeather(zone->ID);
- if(wth)
- {
+ if (wth)
wth->SendWeatherUpdateToPlayer(this);
- }
else
{
- if(!sWorld.AddWeather(zone->ID))
+ if (!sWorld.AddWeather(zone->ID))
{
// send fine weather packet to remove old zone's weather
Weather::SendFineWeatherUpdateToPlayer(this);
@@ -6652,7 +6632,7 @@ void Player::UpdateZone(uint32 newZone, uint32 newArea)
// in PvP, any not controlled zone (except zone->team == 6, default case)
// in PvE, only opposition team capital
- switch(zone->team)
+ switch (zone->team)
{
case AREATEAM_ALLY:
pvpInfo.inHostileArea = GetTeam() != ALLIANCE && (sWorld.IsPvPRealm() || zone->flags & AREA_FLAG_CAPITAL);
@@ -6662,7 +6642,7 @@ void Player::UpdateZone(uint32 newZone, uint32 newArea)
break;
case AREATEAM_NONE:
// overwrite for battlegrounds, maybe batter some zone flags but current known not 100% fit to this
- pvpInfo.inHostileArea = sWorld.IsPvPRealm() || InBattleGround() || (zone->flags & AREA_FLAG_OUTDOOR_PVP);
+ pvpInfo.inHostileArea = sWorld.IsPvPRealm() || InBattleGround() || zone->flags & AREA_FLAG_OUTDOOR_PVP;
break;
default: // 6 in fact
pvpInfo.inHostileArea = false;
@@ -6677,9 +6657,7 @@ void Player::UpdateZone(uint32 newZone, uint32 newArea)
CombatStopWithPets();
}
else
- {
RemoveByteFlag(UNIT_FIELD_BYTES_2, 1, UNIT_BYTE2_FLAG_SANCTUARY);
- }
if(zone->flags & AREA_FLAG_CAPITAL) // in capital city
{
@@ -6692,9 +6670,9 @@ void Player::UpdateZone(uint32 newZone, uint32 newArea)
{
if(HasFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING)) // but resting (walk from city or maybe in tavern or leave tavern recently)
{
- if(GetRestType()==REST_TYPE_IN_TAVERN) // has been in tavern. Is still in?
+ if(GetRestType() == REST_TYPE_IN_TAVERN) // has been in tavern. Is still in?
{
- if(GetMapId()!=GetInnPosMapId() || sqrt((GetPositionX()-GetInnPosX())*(GetPositionX()-GetInnPosX())+(GetPositionY()-GetInnPosY())*(GetPositionY()-GetInnPosY())+(GetPositionZ()-GetInnPosZ())*(GetPositionZ()-GetInnPosZ()))>40)
+ if(GetMapId() != GetInnPosMapId() || sqrt((GetPositionX()-GetInnPosX())*(GetPositionX()-GetInnPosX())+(GetPositionY()-GetInnPosY())*(GetPositionY()-GetInnPosY())+(GetPositionZ()-GetInnPosZ())*(GetPositionZ()-GetInnPosZ()))>40)
{
RemoveFlag(PLAYER_FLAGS, PLAYER_FLAGS_RESTING);
SetRestType(REST_TYPE_NO);
@@ -6712,17 +6690,17 @@ void Player::UpdateZone(uint32 newZone, uint32 newArea)
// remove items with area/map limitations (delete only for alive player to allow back in ghost mode)
// if player resurrected at teleport this will be applied in resurrect code
- if(isAlive())
- DestroyZoneLimitedItem( true, newZone );
+ if (isAlive())
+ DestroyZoneLimitedItem(true, newZone);
// check some item equip limitations (in result lost CanTitanGrip at talent reset, for example)
AutoUnequipOffhandIfNeed();
// recent client version not send leave/join channel packets for built-in local channels
- UpdateLocalChannels( newZone );
+ UpdateLocalChannels(newZone);
// group update
- if(GetGroup())
+ if (GetGroup())
SetGroupUpdateFlag(GROUP_UPDATE_FLAG_ZONE);
UpdateZoneDependentAuras(newZone);
@@ -6731,17 +6709,17 @@ void Player::UpdateZone(uint32 newZone, uint32 newArea)
//If players are too far way of duel flag... then player loose the duel
void Player::CheckDuelDistance(time_t currTime)
{
- if(!duel)
+ if (!duel)
return;
uint64 duelFlagGUID = GetUInt64Value(PLAYER_DUEL_ARBITER);
GameObject* obj = GetMap()->GetGameObject(duelFlagGUID);
- if(!obj)
+ if (!obj)
return;
- if(duel->outOfBound == 0)
+ if (duel->outOfBound == 0)
{
- if(!IsWithinDistInMap(obj, 50))
+ if (!IsWithinDistInMap(obj, 50))
{
duel->outOfBound = currTime;
@@ -6751,29 +6729,27 @@ void Player::CheckDuelDistance(time_t currTime)
}
else
{
- if(IsWithinDistInMap(obj, 40))
+ if (IsWithinDistInMap(obj, 40))
{
duel->outOfBound = 0;
WorldPacket data(SMSG_DUEL_INBOUNDS, 0);
GetSession()->SendPacket(&data);
}
- else if(currTime >= (duel->outOfBound+10))
- {
+ else if (currTime >= (duel->outOfBound+10))
DuelComplete(DUEL_FLED);
- }
}
}
bool Player::IsOutdoorPvPActive()
{
- return (isAlive() && !HasInvisibilityAura() && !HasStealthAura() && (IsPvP() || sWorld.IsPvPRealm()) && !HasUnitMovementFlag(MOVEMENTFLAG_FLYING) && !isInFlight());
+ return isAlive() && !HasInvisibilityAura() && !HasStealthAura() && (IsPvP() || sWorld.IsPvPRealm()) && !HasUnitMovementFlag(MOVEMENTFLAG_FLYING) && !isInFlight();
}
void Player::DuelComplete(DuelCompleteType type)
{
// duel not requested
- if(!duel)
+ if (!duel)
return;
sLog.outDebug("Duel Complete %s %s", GetName(), duel->opponent->GetName());
@@ -22012,10 +21988,10 @@ void Player::_SaveTalents()
void Player::UpdateSpecCount(uint8 count)
{
- if(GetSpecsCount() == count)
+ if (GetSpecsCount() == count)
return;
- if(count == MIN_TALENT_SPECS)
+ if (count == MIN_TALENT_SPECS)
{
_SaveActions(); // make sure the button list is cleaned up
// active spec becomes only spec?
@@ -22026,15 +22002,11 @@ void Player::UpdateSpecCount(uint8 count)
{
_SaveActions(); // make sure the button list is cleaned up
for (ActionButtonList::iterator itr = m_actionButtons.begin(); itr != m_actionButtons.end(); ++itr)
- {
CharacterDatabase.PExecute("INSERT INTO character_action (guid,button,action,type,spec) VALUES ('%u', '%u', '%u', '%u', '%u')",
- GetGUIDLow(), (uint32)itr->first, (uint32)itr->second.GetAction(), (uint32)itr->second.GetType(), 1 );
- }
+ GetGUIDLow(), uint32(itr->first), uint32(itr->second.GetAction()), uint32(itr->second.GetType()), 1);
}
else
- {
return;
- }
SetSpecsCount(count);
@@ -22052,11 +22024,18 @@ void Player::ActivateSpec(uint8 spec)
if (GetMap()->IsBattleGround() && !HasAura(44521)) // In BattleGround with no Preparation buff
return;
- RemoveAllAuras(this->GetGUID(), NULL, false, true); // remove all positive auras (ie: buffs from another spec)
-
_SaveActions();
+ if (IsNonMeleeSpellCasted(false))
+ InterruptNonMeleeSpells(false);
+
UnsummonPetTemporaryIfAny();
+ ClearComboPointHolders();
+ UnsummonAllTotems();
+ RemoveAllControlled();
+ RemoveAllAurasOnDeath();
+ //RemoveAllAuras(this->GetGUID(), NULL, false, true); // removes too many auras
+ //ExitVehicle(); // should be impossible to switch specs from inside a vehicle..
uint32 const* talentTabIds = GetTalentTabPages(getClass());
diff --git a/src/game/Unit.cpp b/src/game/Unit.cpp
index 9f2e3852a9d..8e0c1fcfe03 100644
--- a/src/game/Unit.cpp
+++ b/src/game/Unit.cpp
@@ -223,8 +223,11 @@ void Unit::Update( uint32 p_time )
// WARNING! Order of execution here is important, do not change.
// Spells must be processed with event system BEFORE they go to _UpdateSpells.
// Or else we may have some SPELL_STATE_FINISHED spells stalled in pointers, that is bad.
- m_Events.Update( p_time );
- _UpdateSpells( p_time );
+ #pragma omp critical(UpdateThreadSafety)
+ {
+ m_Events.Update( p_time );
+ _UpdateSpells( p_time );
+ }
// If this is set during update SetCantProc(false) call is missing somewhere in the code
// Having this would prevent spells from being proced, so let's crash
@@ -253,11 +256,11 @@ void Unit::Update( uint32 p_time )
//if(!hasUnitState(UNIT_STAT_CASTING))
{
if(uint32 base_att = getAttackTimer(BASE_ATTACK))
- setAttackTimer(BASE_ATTACK, (p_time >= base_att ? 0 : base_att - p_time) );
+ setAttackTimer(BASE_ATTACK, (p_time >= base_att ? 0 : base_att - p_time));
if(uint32 ranged_att = getAttackTimer(RANGED_ATTACK))
- setAttackTimer(RANGED_ATTACK, (p_time >= ranged_att ? 0 : ranged_att - p_time) );
+ setAttackTimer(RANGED_ATTACK, (p_time >= ranged_att ? 0 : ranged_att - p_time));
if(uint32 off_att = getAttackTimer(OFF_ATTACK))
- setAttackTimer(OFF_ATTACK, (p_time >= off_att ? 0 : off_att - p_time) );
+ setAttackTimer(OFF_ATTACK, (p_time >= off_att ? 0 : off_att - p_time));
}
// update abilities available only for fraction of time
@@ -4131,7 +4134,7 @@ void Unit::RemoveAllAuras()
void Unit::RemoveAllAuras(uint64 casterGUID, Aura * except /*=NULL*/, bool negative /*=true*/, bool positive /*=true*/)
{
- for (AuraMap::iterator iter = m_Auras.begin(); iter != m_Auras.end(); )
+ for (AuraMap::iterator iter = m_Auras.begin(); iter != m_Auras.end();)
{
if (iter->second != except && (!casterGUID || iter->second->GetCasterGUID()==casterGUID)
&& ((negative && !iter->second->IsPositive()) || (positive && iter->second->IsPositive())))
@@ -8865,20 +8868,20 @@ int32 Unit::DealHeal(Unit *pVictim, uint32 addhealth, SpellEntry const *spellPro
Unit* Unit::SelectMagnetTarget(Unit *victim, SpellEntry const *spellInfo)
{
- if(!victim)
+ if (!victim)
return NULL;
// Magic case
- if(spellInfo && (spellInfo->DmgClass == SPELL_DAMAGE_CLASS_NONE || spellInfo->DmgClass == SPELL_DAMAGE_CLASS_MAGIC))
+ if (spellInfo && (spellInfo->DmgClass == SPELL_DAMAGE_CLASS_NONE || spellInfo->DmgClass == SPELL_DAMAGE_CLASS_MAGIC))
{
//I am not sure if this should be redirected.
- if(spellInfo->DmgClass == SPELL_DAMAGE_CLASS_NONE)
+ if (spellInfo->DmgClass == SPELL_DAMAGE_CLASS_NONE)
return victim;
Unit::AuraEffectList const& magnetAuras = victim->GetAurasByType(SPELL_AURA_SPELL_MAGNET);
for (Unit::AuraEffectList::const_iterator itr = magnetAuras.begin(); itr != magnetAuras.end(); ++itr)
- if(Unit* magnet = (*itr)->GetParentAura()->GetUnitSource())
- if(magnet->isAlive())
+ if (Unit* magnet = (*itr)->GetParentAura()->GetUnitSource())
+ if (magnet->isAlive())
{
(*itr)->GetParentAura()->DropAuraCharge();
return magnet;
@@ -8889,9 +8892,9 @@ Unit* Unit::SelectMagnetTarget(Unit *victim, SpellEntry const *spellInfo)
{
AuraEffectList const& hitTriggerAuras = victim->GetAurasByType(SPELL_AURA_ADD_CASTER_HIT_TRIGGER);
for (AuraEffectList::const_iterator i = hitTriggerAuras.begin(); i != hitTriggerAuras.end(); ++i)
- if(Unit* magnet = (*i)->GetParentAura()->GetUnitSource())
- if(magnet->isAlive() && magnet->IsWithinLOSInMap(this))
- if(roll_chance_i((*i)->GetAmount()))
+ if (Unit* magnet = (*i)->GetParentAura()->GetUnitSource())
+ if (magnet->isAlive() && magnet->IsWithinLOSInMap(this))
+ if (roll_chance_i((*i)->GetAmount()))
{
(*i)->GetParentAura()->DropAuraCharge();
return magnet;
@@ -8905,42 +8908,35 @@ Unit* Unit::GetFirstControlled() const
{
//Sequence: charmed, pet, other guardians
Unit *unit = GetCharm();
- if(!unit)
- {
- if(uint64 guid = GetUInt64Value(UNIT_FIELD_SUMMON))
+ if (!unit)
+ if (uint64 guid = GetUInt64Value(UNIT_FIELD_SUMMON))
unit = ObjectAccessor::GetUnit(*this, guid);
- }
+
return unit;
}
void Unit::RemoveAllControlled()
{
//possessed pet and vehicle
- if(GetTypeId() == TYPEID_PLAYER)
+ if (GetTypeId() == TYPEID_PLAYER)
((Player*)this)->StopCastingCharm();
- while(!m_Controlled.empty())
+ while (!m_Controlled.empty())
{
Unit *target = *m_Controlled.begin();
m_Controlled.erase(m_Controlled.begin());
if(target->GetCharmerGUID() == GetGUID())
- {
target->RemoveCharmAuras();
- }
- else if(target->GetOwnerGUID() == GetGUID() && target->isSummon())
- {
+ else if (target->GetOwnerGUID() == GetGUID() && target->isSummon())
((TempSummon*)target)->UnSummon();
- }
else
- {
sLog.outError("Unit %u is trying to release unit %u which is neither charmed nor owned by it", GetEntry(), target->GetEntry());
- }
}
- if(GetPetGUID())
+ if (GetPetGUID())
sLog.outCrash("Unit %u is not able to release its pet " I64FMT, GetEntry(), GetPetGUID());
- if(GetMinionGUID())
+ if (GetMinionGUID())
sLog.outCrash("Unit %u is not able to release its minion " I64FMT, GetEntry(), GetMinionGUID());
- if(GetCharmGUID())
+ if (GetCharmGUID())
sLog.outCrash("Unit %u is not able to release its charm " I64FMT, GetEntry(), GetCharmGUID());
}
@@ -8951,7 +8947,7 @@ Unit* Unit::GetNextRandomRaidMemberOrPet(float radius)
player = (Player*)this;
// Should we enable this also for charmed units?
else if (GetTypeId() == TYPEID_UNIT && ((Creature*)this)->isPet())
- player=(Player*)GetOwner();
+ player = (Player*)GetOwner();
if (!player)
return NULL;
@@ -11154,14 +11150,14 @@ void Unit::SetHover(bool on)
void Unit::setDeathState(DeathState s)
{
- if (s != ALIVE && s!= JUST_ALIVED)
+ if (s != ALIVE && s != JUST_ALIVED)
{
CombatStop();
DeleteThreatList();
getHostilRefManager().deleteReferences();
ClearComboPointHolders(); // any combo points pointed to unit lost at it death
- if(IsNonMeleeSpellCasted(false))
+ if (IsNonMeleeSpellCasted(false))
InterruptNonMeleeSpells(false);
UnsummonAllTotems();
@@ -11184,10 +11180,8 @@ void Unit::setDeathState(DeathState s)
//do not why since in IncreaseMaxHealth currenthealth is checked
SetHealth(0);
}
- else if(s == JUST_ALIVED)
- {
+ else if (s == JUST_ALIVED)
RemoveFlag (UNIT_FIELD_FLAGS, UNIT_FLAG_SKINNABLE); // clear skinnable for creature and player (at battleground)
- }
if (m_deathState != ALIVE && s == ALIVE)
{