Core/Instances: Fixed a bug that caused switching group leader inside active instance to cause players not being saved when a boss was killed.

Closes #5109
This commit is contained in:
Shauren committed 2013-06-11 15:50:08 +02:00
1 parent 935a1cf607
commit ef15fe8ed2
3 files changed
+27 -23

No files matched your search

+23 -21
View File
@@ -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);