diff options
author | Shauren <shauren.trinity@gmail.com> | 2019-12-26 13:30:32 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2022-10-04 00:19:38 +0200 |
commit | a131542855d23022714a97640be1c8d68a741c31 (patch) | |
tree | 8248d868b1af0e3a32ec5c261d25a496275353e2 /src/server/game/Groups/Group.cpp | |
parent | 17665c929c3a9fb7fe75dd680648129bc1c1f874 (diff) |
Core/Maps: Check group that owns instance (first group to enter a given instance id owns it)
Diffstat (limited to 'src/server/game/Groups/Group.cpp')
-rw-r--r-- | src/server/game/Groups/Group.cpp | 75 |
1 files changed, 4 insertions, 71 deletions
diff --git a/src/server/game/Groups/Group.cpp b/src/server/game/Groups/Group.cpp index 127b0dab275..f8929654908 100644 --- a/src/server/game/Groups/Group.cpp +++ b/src/server/game/Groups/Group.cpp @@ -193,7 +193,8 @@ bool Group::Create(Player* leader) CharacterDatabase.Execute(stmt); - Group::ConvertLeaderInstancesToGroup(leader, this, false); + if (InstanceMap* leaderInstance = leader->GetMap()->ToInstanceMap()) + leaderInstance->TrySetOwningGroup(this); bool addMemberResult = AddMember(leader); ASSERT(addMemberResult); // If the leader can't be added to a new group because it appears full, something is clearly wrong. @@ -715,9 +716,6 @@ void Group::ChangeLeader(ObjectGuid newLeaderGuid, int8 partyIndex) } } - // Copy the permanent binds from the new leader to the group - Group::ConvertLeaderInstancesToGroup(newLeader, this, true); - // Update the group leader CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_UPD_GROUP_LEADER); @@ -744,43 +742,6 @@ void Group::ChangeLeader(ObjectGuid newLeaderGuid, int8 partyIndex) BroadcastPacket(groupNewLeader.Write(), true); } -/// convert the player's binds to the group -void Group::ConvertLeaderInstancesToGroup(Player* player, Group* group, bool switchLeader) -{ - // copy all binds to the group, when changing leader it's assumed the character - // will not have any solo binds - for (auto difficultyItr = player->m_boundInstances.begin(); difficultyItr != player->m_boundInstances.end(); ++difficultyItr) - { - for (auto itr = difficultyItr->second.begin(); itr != difficultyItr->second.end();) - { - if (!switchLeader || !group->GetBoundInstance(itr->second.save->GetDifficultyID(), itr->first)) - if (itr->second.extendState) // not expired - group->BindToInstance(itr->second.save, itr->second.perm, false); - - // permanent binds are not removed - if (switchLeader && !itr->second.perm) - { - // increments itr in call - player->UnbindInstance(itr, difficultyItr, false); - } - else - ++itr; - } - } - - /* if group leader is in a non-raid dungeon map and nobody is actually bound to this map then the group can "take over" the instance * - * (example: two-player group disbanded by disconnect where the player reconnects within 60 seconds and the group is reformed) */ - if (Map* playerMap = player->FindMap()) - if (!switchLeader && playerMap->IsNonRaidDungeon()) - if (InstanceSave* save = sInstanceSaveMgr->GetInstanceSave(playerMap->GetInstanceId())) - if (save->GetGroupCount() == 0 && save->GetPlayerCount() == 0) - { - TC_LOG_DEBUG("maps", "Group::ConvertLeaderInstancesToGroup: Group for player %s is taking over unbound instance map %d with Id %d", player->GetName().c_str(), playerMap->GetId(), playerMap->GetInstanceId()); - // if nobody is saved to this, then the save wasn't permanent - group->BindToInstance(save, false, false); - } -} - void Group::Disband(bool hideDestroy /* = false */) { sScriptMgr->OnGroupDisband(this); @@ -1596,37 +1557,9 @@ InstanceGroupBind* Group::GetBoundInstance(Difficulty difficulty, uint32 mapId) return nullptr; } -InstanceGroupBind* Group::BindToInstance(InstanceSave* save, bool permanent, bool load) +void Group::LinkOwnedInstance(GroupInstanceReference* ref) { - if (!save || isBGGroup() || isBFGroup()) - return nullptr; - - InstanceGroupBind& bind = m_boundInstances[save->GetDifficultyID()][save->GetMapId()]; - if (!load && (!bind.save || permanent != bind.perm || save != bind.save)) - { - CharacterDatabasePreparedStatement* stmt = CharacterDatabase.GetPreparedStatement(CHAR_REP_GROUP_INSTANCE); - - stmt->setUInt32(0, m_dbStoreId); - stmt->setUInt32(1, save->GetInstanceId()); - stmt->setBool(2, permanent); - - CharacterDatabase.Execute(stmt); - } - - if (bind.save != save) - { - if (bind.save) - bind.save->RemoveGroup(this); - save->AddGroup(this); - } - - bind.save = save; - bind.perm = permanent; - if (!load) - TC_LOG_DEBUG("maps", "Group::BindToInstance: %s, storage id: %u is now bound to map %d, instance %d, difficulty %d", - GetGUID().ToString().c_str(), m_dbStoreId, save->GetMapId(), save->GetInstanceId(), static_cast<uint32>(save->GetDifficultyID())); - - return &bind; + m_ownedInstancesMgr.insertLast(ref); } void Group::UnbindInstance(uint32 mapid, uint8 difficulty, bool unload) |