diff options
Diffstat (limited to 'src/server/game/Groups/Group.cpp')
-rw-r--r-- | src/server/game/Groups/Group.cpp | 44 |
1 files changed, 23 insertions, 21 deletions
diff --git a/src/server/game/Groups/Group.cpp b/src/server/game/Groups/Group.cpp index c21cc9210dc..59da04f3673 100644 --- a/src/server/game/Groups/Group.cpp +++ b/src/server/game/Groups/Group.cpp @@ -615,30 +615,39 @@ bool Group::RemoveMember(uint64 guid, const RemoveMethod& method /*= GROUP_REMOV } } -void Group::ChangeLeader(uint64 guid) +void Group::ChangeLeader(uint64 newLeaderGuid) { - member_witerator slot = _getMemberWSlot(guid); + member_witerator slot = _getMemberWSlot(newLeaderGuid); if (slot == m_memberSlots.end()) return; - Player* player = ObjectAccessor::FindPlayer(slot->guid); + Player* newLeader = ObjectAccessor::FindPlayer(slot->guid); // Don't allow switching leader to offline players - if (!player) + if (!newLeader) return; - sScriptMgr->OnGroupChangeLeader(this, guid, m_leaderGuid); + sScriptMgr->OnGroupChangeLeader(this, newLeaderGuid, m_leaderGuid); if (!isBGGroup() && !isBFGroup()) { + SQLTransaction trans = CharacterDatabase.BeginTransaction(); + // Remove the groups permanent instance bindings for (uint8 i = 0; i < MAX_DIFFICULTY; ++i) { for (BoundInstancesMap::iterator itr = m_boundInstances[i].begin(); itr != m_boundInstances[i].end();) { - if (itr->second.perm) + // Do not unbind saves of instances that already had map created (a newLeader entered) + // forcing a new instance with another leader requires group disbanding (confirmed on retail) + if (itr->second.perm && !sMapMgr->FindMap(itr->first, itr->second.save->GetInstanceId())) { + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GROUP_INSTANCE_PERM_BINDING); + stmt->setUInt32(0, m_dbStoreId); + stmt->setUInt32(1, itr->second.save->GetInstanceId()); + trans->Append(stmt); + itr->second.save->RemoveGroup(this); m_boundInstances[i].erase(itr++); } @@ -647,29 +656,22 @@ void Group::ChangeLeader(uint64 guid) } } - // Same in the database - - PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_DEL_GROUP_INSTANCE_PERM_BINDING); - - stmt->setUInt32(0, m_dbStoreId); - stmt->setUInt32(1, player->GetGUIDLow()); - - CharacterDatabase.Execute(stmt); - // Copy the permanent binds from the new leader to the group - Player::ConvertInstancesToGroup(player, this, true); + Player::ConvertInstancesToGroup(newLeader, this, true); // Update the group leader - stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_GROUP_LEADER); + PreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_GROUP_LEADER); - stmt->setUInt32(0, player->GetGUIDLow()); + stmt->setUInt32(0, newLeader->GetGUIDLow()); stmt->setUInt32(1, m_dbStoreId); - CharacterDatabase.Execute(stmt); + trans->Append(stmt); + + CharacterDatabase.CommitTransaction(trans); } - m_leaderGuid = player->GetGUID(); - m_leaderName = player->GetName(); + m_leaderGuid = newLeader->GetGUID(); + m_leaderName = newLeader->GetName(); ToggleGroupMemberFlag(slot, MEMBER_FLAG_ASSISTANT, false); WorldPacket data(SMSG_GROUP_SET_LEADER, m_leaderName.size()+1); |