diff options
| author | Wyrserth <43747507+Wyrserth@users.noreply.github.com> | 2019-06-15 14:19:58 +0200 |
|---|---|---|
| committer | Shauren <shauren.trinity@gmail.com> | 2021-12-11 13:06:25 +0100 |
| commit | cc141e9bad5dc06a56179f820670bd6944651804 (patch) | |
| tree | 69510c12aaa38720886320906f24339a7841b71d /src/server/game/Groups/Group.cpp | |
| parent | 7b346bcf8d4c4b39685a46ef09f389c8a317b566 (diff) | |
Core/Group: implement automatic party/raid leader change when the leader has been offline for two minutes (#23398)
* Core/Group: implement automatic party/raid leader change when the leader has been offline for two minutes.
* Add #23396 to make testing easier.
* Prioritize assistants in raids.
* Fix dumb mistake and apply suggested change, thanks VincentVanclef and jackpoz!
(cherry picked from commit e906a2fe7d71fc17de9f7ea4778970beb3f9265e)
Diffstat (limited to 'src/server/game/Groups/Group.cpp')
| -rw-r--r-- | src/server/game/Groups/Group.cpp | 69 |
1 files changed, 63 insertions, 6 deletions
diff --git a/src/server/game/Groups/Group.cpp b/src/server/game/Groups/Group.cpp index b69beb76ebe..7cbcbecc934 100644 --- a/src/server/game/Groups/Group.cpp +++ b/src/server/game/Groups/Group.cpp @@ -62,7 +62,7 @@ Loot* Roll::getLoot() Group::Group() : m_leaderGuid(), m_leaderName(""), m_groupFlags(GROUP_FLAG_NONE), m_groupCategory(GROUP_CATEGORY_HOME), m_dungeonDifficulty(DIFFICULTY_NORMAL), m_raidDifficulty(DIFFICULTY_NORMAL_RAID), m_legacyRaidDifficulty(DIFFICULTY_10_N), m_bgGroup(nullptr), m_bfGroup(nullptr), m_lootMethod(FREE_FOR_ALL), m_lootThreshold(ITEM_QUALITY_UNCOMMON), m_looterGuid(), -m_masterLooterGuid(), m_subGroupsCounts(nullptr), m_guid(), m_maxEnchantingLevel(0), m_dbStoreId(0), +m_masterLooterGuid(), m_subGroupsCounts(nullptr), m_guid(), m_maxEnchantingLevel(0), m_dbStoreId(0), m_isLeaderOffline(false), m_readyCheckStarted(false), m_readyCheckTimer(Milliseconds::zero()), m_activeMarkers(0) { for (uint8 i = 0; i < TARGET_ICONS_COUNT; ++i) @@ -102,6 +102,57 @@ Group::~Group() delete[] m_subGroupsCounts; } +void Group::Update(uint32 diff) +{ + if (m_isLeaderOffline) + { + m_leaderOfflineTimer.Update(diff); + if (m_leaderOfflineTimer.Passed()) + { + SelectNewPartyOrRaidLeader(); + m_isLeaderOffline = false; + } + } + + UpdateReadyCheck(diff); +} + +void Group::SelectNewPartyOrRaidLeader() +{ + Player* newLeader = nullptr; + + // Attempt to give leadership to main assistant first + if (isRaidGroup()) + { + for (Group::MemberSlot const& memberSlot : m_memberSlots) + { + if ((memberSlot.flags & MEMBER_FLAG_ASSISTANT) == MEMBER_FLAG_ASSISTANT) + if (Player* player = ObjectAccessor::FindPlayer(memberSlot.guid)) + { + newLeader = player; + break; + } + } + } + + // If there aren't assistants in raid, or if the group is not a raid, pick the first available member + if (!newLeader) + { + for (Group::MemberSlot const& memberSlot : m_memberSlots) + if (Player* player = ObjectAccessor::FindPlayer(memberSlot.guid)) + { + newLeader = player; + break; + } + } + + if (newLeader) + { + ChangeLeader(newLeader->GetGUID()); + SendUpdate(); + } +} + bool Group::Create(Player* leader) { ObjectGuid leaderGuid = leader->GetGUID(); @@ -2265,11 +2316,6 @@ uint8 Group::GetLfgRoles(ObjectGuid guid) return slot->roles; } -void Group::Update(uint32 diff) -{ - UpdateReadyCheck(diff); -} - void Group::UpdateReadyCheck(uint32 diff) { if (!m_readyCheckStarted) @@ -2681,6 +2727,17 @@ void Group::ToggleGroupMemberFlag(member_witerator slot, uint8 flag, bool apply) slot->flags &= ~flag; } +void Group::StartLeaderOfflineTimer() +{ + m_isLeaderOffline = true; + m_leaderOfflineTimer.Reset(2 * MINUTE * IN_MILLISECONDS); +} + +void Group::StopLeaderOfflineTimer() +{ + m_isLeaderOffline = false; +} + void Group::SetEveryoneIsAssistant(bool apply) { if (apply) |
