bool Group::AddMember(PlayerInfo * info, int32 subgroupid/* =-1 */) { m_groupLock.Acquire(); Player * pPlayer = info->m_loggedInPlayer; if( m_isqueued ) { m_isqueued = false; BattlegroundManager.RemoveGroupFromQueues(this); } if( !IsFull() ) { SubGroup* subgroup = (subgroupid>0) ? m_SubGroups[subgroupid] : FindFreeSubGroup(); if(subgroup == NULL) { m_groupLock.Release(); return false; } if( subgroup->AddPlayer( info ) ) { if( pPlayer != NULL ) sEventMgr.AddEvent( pPlayer,&Player::EventGroupFullUpdate, EVENT_PLAYER_UPDATE, 1500, 1, EVENT_FLAG_DO_NOT_EXECUTE_IN_WORLD_CONTEXT ); if( info->m_Group && info->m_Group != this ) info->m_Group->RemovePlayer( info ); if( m_Leader == NULL && info->m_loggedInPlayer ) m_Leader = info; info->m_Group = this; info->subGroup = (int8)subgroup->GetID(); ++m_MemberCount; m_dirty = true; Update(); // Send group update m_groupLock.Release(); return true; } else { m_groupLock.Release(); info->m_Group = NULL; info->subGroup = -1; return false; } } else { info->m_Group = NULL; info->subGroup = -1; m_groupLock.Release(); return false; } }
void Group::MovePlayer(PlayerInfo *info, uint8 subgroup) { if( subgroup >= m_SubGroupCount ) return; if( m_SubGroups[subgroup]->IsFull() ) return; m_groupLock.Acquire(); SubGroup *sg = NULL; if( info->subGroup > 0 && info->subGroup <= 8 ) sg = m_SubGroups[info->subGroup]; if( sg == NULL || sg->m_GroupMembers.find(info) == sg->m_GroupMembers.end() ) { for( uint8 i = 0; i < m_SubGroupCount; ++i ) { if( m_SubGroups[i] != NULL ) { if( m_SubGroups[i]->m_GroupMembers.find(info) != m_SubGroups[i]->m_GroupMembers.end() ) { sg = m_SubGroups[i]; break; } } } } if( sg == NULL ) { m_groupLock.Release(); return; } sg->RemovePlayer( info ); // Grab the new group, and insert sg = m_SubGroups[subgroup]; if( !sg->AddPlayer( info ) ) { RemovePlayer( info ); } else { info->subGroup = (int8)sg->GetID(); } Update(); m_groupLock.Release(); }
void Group::SetSubGroupLeader(Player *pPlayer, uint8 subgroup) { sLog.outString("Set subgroup %d leader to %s", (uint32)subgroup, pPlayer->GetName()); ASSERT(subgroup < m_SubGroupCount); SubGroup *group = m_SubGroups[subgroup]; if(group->GetID() != pPlayer->GetSubGroup()) { sLog.outString("GROUP: Tried to set leader of subgroup %d and player %s is not in that group", group->GetID(), pPlayer->GetName()); return; } group->m_SubGroupLeader = pPlayer; Update(); }