std::shared_ptr<PlayerController> CreatePlayerController(int numPlayers) { const int numBills = 5; PlayerList players; for (int playerId = 0; playerId < numPlayers; ++playerId) { auto timer = std::make_unique<TimerObject>(playerId); players.push_back(std::make_unique<Player>(playerId, std::move(timer), numBills)); } return std::make_shared<PlayerController>(players); }
void GroupObject::changeLeader(Player* player) { mMasterLooter = player->getCharId(); // we create a new list containing the new hierarchy PlayerList tempList; tempList.reserve(20); tempList.push_back(player); // new leader tempList.push_back(getLeader()); // old leader // iterate trough old list PlayerList::iterator listIt = mMembers.begin() + 1; // starting at position 1 ( 0 is the old leader) while(listIt != mMembers.end()) { // if not the new leader (its in position of new list 1 already) if((*listIt) != player) { tempList.push_back((*listIt)); // add to the new list } ++listIt; } // do i need this ? =0 mMembers.empty(); // assign the new list mMembers = tempList; // recalculate member indexes resetIndexes(); // send the delta to everyone broadcastDeltaResetAll(); // send the sys message to everyone gChatMessageLib->sendGroupSystemMessage(getLeader()->getName(), BString("new_leader"), NULL, this, true); }
void instance_ahnkahet::HandleInsanitySwitch(Player* pPhasedPlayer) { // Get the phase aura id std::list<Aura*> lAuraList = pPhasedPlayer->GetAurasByType(SPELL_AURA_PHASE); if (lAuraList.empty()) return; uint32 uiPhaseAura = (*lAuraList.begin())->GetId(); PlayerList lSamePhasePlayers; std::vector<Player*> vOtherPhasePlayers; // Sort the insanity players, into those which have same phase and others for (GuidList::const_iterator itr = m_lInsanityPlayersGuidList.begin(); itr != m_lInsanityPlayersGuidList.end(); ++itr) { if (Player* pTemp = instance->GetPlayer(*itr)) { if (pTemp->HasAura(uiPhaseAura)) lSamePhasePlayers.push_back(pTemp); // Check only for alive players else if (pTemp->isAlive()) vOtherPhasePlayers.push_back(pTemp); } } // This shouldn't happen if (vOtherPhasePlayers.empty()) return; // Get the phase aura of the new selected player Player* pNewPlayer = vOtherPhasePlayers[urand(0, vOtherPhasePlayers.size() - 1)]; // Get the phase aura id std::list<Aura*> lNewAuraList = pNewPlayer->GetAurasByType(SPELL_AURA_PHASE); if (lNewAuraList.empty()) return; uint32 uiNewPhaseAura = (*lNewAuraList.begin())->GetId(); // Move the same phase players to the new phase for (PlayerList::const_iterator itr = lSamePhasePlayers.begin(); itr != lSamePhasePlayers.end(); ++itr) (*itr)->CastSpell((*itr), uiNewPhaseAura, TRIGGERED_OLD_TRIGGERED); }
void ObjectController::_handleRequestCharacterMatch(uint64 targetId,Message* message,ObjectControllerCmdProperties* cmdProperties) { PlayerObject* player = dynamic_cast<PlayerObject*>(mObject); BString dataStr; PlayerList playersMatched; PlayerList* matchReference; uint32 masksCount = 0; uint32 playerFlags = 0; uint32 mask2 = 0; uint32 mask3 = 0; uint32 mask4 = 0; uint32 factionCrc = 0; int32 raceId = 0; int8 titleStr[128]; int8 unknown[64]; uint32 elementCount = 0; Skill* skill = NULL; int8* pTitle; pTitle = titleStr; message->getStringUnicode16(dataStr); if(dataStr.getLength()) elementCount = swscanf(dataStr.getUnicode16(),L"%u %u %u %u %u %u %i %s %s",&masksCount,&playerFlags,&mask2,&mask3,&mask4,&factionCrc,&raceId,titleStr,unknown); if(elementCount != 9) { DLOG(INFO) << "ObjController::_handleRequestCharacterMatch: argument mismatch " << player->getId(); return; } if(strcmp(titleStr,"\"\"") != 0) { skill = gSkillManager->getSkillByName(titleStr); if(skill == NULL) { DLOG(INFO) << "ObjController::_handleRequestCharacterMatch: could not find matching skill for " << titleStr; return; } } // for now check players in viewing range // and ourselves =) playersMatched.push_back(player); //for our practical purpose were not sending to them but merely iterating through them gContainerManager->sendToRegisteredPlayers(player,[playerFlags, raceId, factionCrc, skill, pTitle, matchReference, this] ( PlayerObject* const inRangePlayer) { if(((playerFlags & inRangePlayer->getPlayerFlags()) == playerFlags) &&(raceId == -1 || raceId == inRangePlayer->getRaceId()) &&(factionCrc == 0 || factionCrc == 1 || factionCrc == inRangePlayer->getFaction().getCrc())) { if(skill == NULL) { matchReference->push_back(inRangePlayer); } else { if((skill->mIsProfession && strstr(inRangePlayer->getTitle().getAnsi(),pTitle)) || (strcmp(pTitle,inRangePlayer->getTitle().getAnsi()) == 0)) { matchReference->push_back(inRangePlayer); } } } } ); gMessageLib->sendCharacterMatchResults(&playersMatched,player); }