diff options
author | Treeston <treeston.mmoc@gmail.com> | 2016-09-16 13:09:16 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-09-16 13:09:16 +0200 |
commit | cf628880d586b049fa376e4533154d78d02a8ce8 (patch) | |
tree | 661467dd04d508076a1b5c1cce536d8da04c19e2 | |
parent | cd6866c1556ac05f0a24138093dd831e751caa75 (diff) |
Map/Instances: Greatly simplify PermBindAllPlayers logic. (#17940)
-rw-r--r-- | src/server/game/Entities/Unit/Unit.cpp | 9 | ||||
-rw-r--r-- | src/server/game/Maps/Map.cpp | 31 | ||||
-rw-r--r-- | src/server/game/Maps/Map.h | 2 | ||||
-rw-r--r-- | src/server/scripts/EasternKingdoms/SunwellPlateau/boss_kalecgos.cpp | 12 |
4 files changed, 21 insertions, 33 deletions
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 631971a8c2c..d4185b0b06d 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -15206,14 +15206,7 @@ void Unit::Kill(Unit* victim, bool durabilityLoss) if (instanceMap->IsRaidOrHeroicDungeon()) { if (creature->GetCreatureTemplate()->flags_extra & CREATURE_FLAG_EXTRA_INSTANCE_BIND) - { - // if the boss killed itself we still need to bind players to the instance - if (!creditedPlayer && instanceMap->HavePlayers()) - creditedPlayer = instanceMap->GetPlayers().getFirst()->GetSource(); - - if (creditedPlayer) - ((InstanceMap*)instanceMap)->PermBindAllPlayers(creditedPlayer); - } + ((InstanceMap*)instanceMap)->PermBindAllPlayers(); } else { diff --git a/src/server/game/Maps/Map.cpp b/src/server/game/Maps/Map.cpp index 23ca8cbba1a..6285d847db3 100644 --- a/src/server/game/Maps/Map.cpp +++ b/src/server/game/Maps/Map.cpp @@ -3311,7 +3311,7 @@ bool InstanceMap::Reset(uint8 method) return m_mapRefManager.isEmpty(); } -void InstanceMap::PermBindAllPlayers(Player* source) +void InstanceMap::PermBindAllPlayers() { if (!IsDungeon()) return; @@ -3319,31 +3319,36 @@ void InstanceMap::PermBindAllPlayers(Player* source) InstanceSave* save = sInstanceSaveMgr->GetInstanceSave(GetInstanceId()); if (!save) { - TC_LOG_ERROR("maps", "Cannot bind player (GUID: %u, Name: %s), because no instance save is available for instance map (Name: %s, Entry: %u, InstanceId: %u)!", source->GetGUID().GetCounter(), source->GetName().c_str(), source->GetMap()->GetMapName(), source->GetMapId(), GetInstanceId()); + TC_LOG_ERROR("maps", "Cannot bind players to instance map (Name: %s, Entry: %u, Difficulty: %u, ID: %u) because no instance save is available!", GetMapName(), GetId(), GetDifficulty(), GetInstanceId()); return; } - Group* group = source->GetGroup(); - // group members outside the instance group don't get bound + // perm bind all players that are currently inside the instance for (MapRefManager::iterator itr = m_mapRefManager.begin(); itr != m_mapRefManager.end(); ++itr) { Player* player = itr->GetSource(); - // players inside an instance cannot be bound to other instances - // some players may already be permanently bound, in this case nothing happens + // never instance bind GMs with GM mode enabled + if (player->IsGameMaster()) + continue; + InstancePlayerBind* bind = player->GetBoundInstance(save->GetMapId(), save->GetDifficulty()); - if (!bind || !bind->perm) + if (bind && bind->perm) + { + TC_LOG_ERROR("maps", "Player (GUID: %u, Name: %s) is in instance map (Name: %s, Entry: %u, Difficulty: %u, ID: %u) that is being bound, but already has a save for the map on ID %u!", player->GetGUID().GetCounter(), player->GetName().c_str(), GetMapName(), GetId(), GetDifficulty(), GetInstanceId(), save->GetInstanceId()); + } + else { player->BindToInstance(save, true); WorldPacket data(SMSG_INSTANCE_SAVE_CREATED, 4); data << uint32(0); player->GetSession()->SendPacket(&data); - if (!player->IsGameMaster()) - player->GetSession()->SendCalendarRaidLockout(save, true); - } + player->GetSession()->SendCalendarRaidLockout(save, true); - // if the leader is not in the instance the group will not get a perm bind - if (group && group->GetLeaderGUID() == player->GetGUID()) - group->BindToInstance(save, true); + // if group leader is in instance, group also gets bound + if (Group* group = player->GetGroup()) + if (group->GetLeaderGUID() == player->GetGUID()) + group->BindToInstance(save, true); + } } } diff --git a/src/server/game/Maps/Map.h b/src/server/game/Maps/Map.h index db71b6f01fa..5fc4e68bad9 100644 --- a/src/server/game/Maps/Map.h +++ b/src/server/game/Maps/Map.h @@ -769,7 +769,7 @@ class TC_GAME_API InstanceMap : public Map uint32 GetScriptId() const { return i_script_id; } InstanceScript* GetInstanceScript() { return i_data; } InstanceScript const* GetInstanceScript() const { return i_data; } - void PermBindAllPlayers(Player* source); + void PermBindAllPlayers(); void UnloadAll() override; EnterState CannotEnter(Player* player) override; void SendResetWarnings(uint32 timeLeft) const; diff --git a/src/server/scripts/EasternKingdoms/SunwellPlateau/boss_kalecgos.cpp b/src/server/scripts/EasternKingdoms/SunwellPlateau/boss_kalecgos.cpp index e216f641936..bfd9d722de8 100644 --- a/src/server/scripts/EasternKingdoms/SunwellPlateau/boss_kalecgos.cpp +++ b/src/server/scripts/EasternKingdoms/SunwellPlateau/boss_kalecgos.cpp @@ -365,17 +365,7 @@ public: if (isFriendly) { me->setDeathState(JUST_DIED); - - Map::PlayerList const& players = me->GetMap()->GetPlayers(); - if (!players.isEmpty()) - { - for (Map::PlayerList::const_iterator itr = players.begin(); itr != players.end(); ++itr) - { - Player* player = itr->GetSource(); - if (player) - me->GetMap()->ToInstanceMap()->PermBindAllPlayers(player); - } - } + me->GetMap()->ToInstanceMap()->PermBindAllPlayers(); } else { |