bool MissionManager::checkCraftingMission(PlayerObject* player,NPCObject* npc) { Datapad* datapad = dynamic_cast<Datapad*>(player->getEquipManager()->getEquippedObject(CreatureEquipSlot_Datapad)); if(datapad->hasMission()) //player has a mission { MissionList::iterator it = datapad->getMissions()->begin(); while(it != datapad->getMissions()->end()) { MissionObject* mission = dynamic_cast<MissionObject*>(*it); if(mission->getMissionType() == crafting) { if(mission->getStartNPC() == npc) { //This is the start npc for the deliver mission char mp[10]; sprintf(mp,"m%dp",mission->getNum()); gMessageLib->sendSpatialChat(npc,player,L"",mission->getTitleFile(),mp); mission->setStartNPC(NULL); gMessageLib->sendSystemMessage(player,L"","mission/mission_generic","deliver_received_data"); MissionObject* updater = new MissionObject(); updater->clear(); updater->setId(mission->getId()); updater->getWaypoint()->setId(mission->getId()+1); updater->getWaypoint()->setCoords(mission->getDestination().Coordinates); updater->getWaypoint()->setPlanetCRC(mission->getDestination().PlanetCRC); char name[150]; sprintf(name, "@%s:%s",mission->getTitleFile().getRawData(),mission->getTitle().getRawData()); updater->getWaypoint()->setName(name); updater->getWaypoint()->setActive(true); gMessageLib->sendMISO_Delta(updater,player); delete updater; return true; } else if(mission->getDestinationNPC() == npc && mission->getStartNPC() == NULL) { //This is the end npc for the deliver mission. char mr[10]; sprintf(mr,"m%dr",mission->getNum()); gMessageLib->sendSpatialChat(npc,player,L"",mission->getTitleFile(),mr); missionComplete(player,mission); mission->setDestinationNPC(NULL); it = datapad->removeMission(it); delete mission; return true; } } ++it; } } return false; }
void MissionManager::checkDancerMission(PlayerObject* player) { Datapad* datapad = dynamic_cast<Datapad*>(player->getEquipManager()->getEquippedObject(CreatureEquipSlot_Datapad)); if(datapad->hasMission()) //player has a mission { MissionList::iterator it = datapad->getMissions()->begin(); while(it != datapad->getMissions()->end()) { MissionObject* mission = dynamic_cast<MissionObject*>(*it); if(mission->getMissionType() == dancer) { if(mission->getInProgress()) { ++it; continue; } if(glm::distance(player->mPosition, mission->getDestination().Coordinates) < 20) { BuffAttribute* performance_timer = new BuffAttribute(Mission_Timer, 0,0,0); Buff* timer = Buff::SimpleBuff(player, player, 600000, 0, gWorldManager->GetCurrentGlobalTick()); timer->AddAttribute(performance_timer); player->AddBuff(timer); mission->setInProgress(true); } } ++it; } } return; }
void MissionManager::missionFailedEntertainer(PlayerObject* player) { Datapad* datapad = dynamic_cast<Datapad*>(player->getEquipManager()->getEquippedObject(CreatureEquipSlot_Datapad)); if(datapad->hasMission()) //player has a mission { MissionList::iterator it = datapad->getMissions()->begin(); while(it != datapad->getMissions()->end()) { MissionObject* mission = dynamic_cast<MissionObject*>(*it); if(mission->getMissionType() == dancer || mission->getMissionType() == musician) { if(!mission->getInProgress()) { ++it; continue; } if(glm::distance(player->mPosition, mission->getDestination().Coordinates) < 20) { missionFailed(player,mission); it = datapad->removeMission(it); delete mission; return; } } ++it; } } }
void GroupManager::sendGroupMissionUpdate(GroupObject* group) { // this procedure ensures, that in case of a change in the mission pool of the group // all players get updated Mission waypoints // it concerns all players of the group on the zone, but not on other zones //get us the mission nearest to the most players on the Zone MissionObject* mission = getZoneGroupMission(group->getPlayerList()); if(!mission) return; //now set the GroupWaypoint for all onZone groupmembers Uint64List::iterator playerListIt = group->getPlayerList()->begin(); while(playerListIt != group->getPlayerList()->end()) { PlayerObject* player = dynamic_cast<PlayerObject*> (gWorldManager->getObjectById((*playerListIt))); Datapad* datapad = dynamic_cast<Datapad*>(player->getEquipManager()->getEquippedObject(CreatureEquipSlot_Datapad)); WaypointObject* waypoint = datapad->getWaypointByName("@group:groupwaypoint"); // remove the old one if(waypoint) { gMessageLib->sendUpdateWaypoint(waypoint,ObjectUpdateAdd,player); datapad->removeWaypoint(waypoint); gObjectFactory->deleteObjectFromDB(waypoint); } else // create a new one if(datapad->getCapacity()) { datapad->requestNewWaypoint("@group:groupwaypoint",mission->getDestination().Coordinates,static_cast<uint16>(gWorldManager->getZoneId()),Waypoint_blue); gMessageLib->sendSystemMessage(player,L"","group","groupwaypoint"); } playerListIt++; } }
/* * Player Accepted Mission */ void MissionManager::missionRequest(PlayerObject* player, uint64 mission_id) { Datapad* datapad = dynamic_cast<Datapad*>(player->getEquipManager()->getEquippedObject(CreatureEquipSlot_Datapad)); //Move the mission from the player's mission bag to his datapad. MissionBag* mission_bag = dynamic_cast<MissionBag*>(player->getEquipManager()->getEquippedObject(CreatureEquipSlot_MissionBag)); MissionObject* mission = mission_bag->getMissionById(mission_id); if(mission == NULL) { gLogger->logMsgF("ERROR: Failed to retrieve mission with id %"PRIu64". Unable to accept mission!", MSG_HIGH, mission_id); return; } //automatically checks the datapads capacity if(!datapad->addMission(mission)) { gMessageLib->sendSystemMessage(player,L"","mission/mission_generic","too_many_missions"); return; } mission_bag->removeMission(mission); gMessageLib->sendContainmentMessage(mission->getId(), datapad->getId(), 0xffffffff, player); //Replace it with a new mission. mission_bag->spawnNAdd(); //Send MissionGenericResponse to tell the client its been accepted gMessageLib->sendMissionGenericResponse(mission,player); //Update the name and mission waypoint MissionObject* updater = new MissionObject(); updater->clear(); updater->setId(mission->getId()); updater->setNameFile(mission->getTitleFile().getRawData()); updater->setName(mission->getTitle().getRawData()); if(mission->getMissionType() != survey) { updater->getWaypoint()->setId(mission->getId()+1); if(mission->getMissionType() == deliver || mission->getMissionType() == crafting) { updater->getWaypoint()->setCoords(mission->getStart().Coordinates); updater->getWaypoint()->setPlanetCRC(mission->getStart().PlanetCRC); } else { updater->getWaypoint()->setCoords(mission->getDestination().Coordinates); updater->getWaypoint()->setPlanetCRC(mission->getDestination().PlanetCRC); } char name[150]; sprintf(name, "@%s:%s",mission->getTitleFile().getRawData(),mission->getTitle().getRawData()); updater->getWaypoint()->setName(name); updater->getWaypoint()->setActive(true); } else { gMessageLib->sendSystemMessage(player,L"","mission/mission_generic","survey_start"); } //Accept the mission let the player know gMessageLib->sendPlayMusicMessage(WMSound_Mission_Accepted,player); //3887, 'sound/music_mission_accepted.snd' gMessageLib->sendMISO_Delta(updater,player); mission->sendAttributes(mission->getOwner()); delete updater; if(mission->getMissionType() == recon) mission->setTaskId(gWorldManager->addMissionToProcess(mission)); //check if we need to inform our group if((mission->getMissionType() == destroy)&&(player->getGroupId() != 0)) { // we are in a group and just accepted a destroy mission // check the missions and update the nearest waypoint GroupObject* group = gGroupManager->getGroupObject(player->getGroupId()); gGroupManager->sendGroupMissionUpdate(group); } return; }
MissionObject* GroupManager::getZoneGroupMission(std::list<uint64>* members) { // we will iterate through all onZone groupmembers and compile a list of missions // we will find the mission nearest to the most players // and set the waypoints accordingly MissionObject* chosenMission = NULL; uint32 chosenRubberPoints = 0; if(!members->size()) return NULL; MissionGroupRangeList missionRangeList; //compile the missionlist Uint64List::iterator playerListIt = members->begin(); while(playerListIt != members->end()) { PlayerObject* groupMember = dynamic_cast<PlayerObject*> (gWorldManager->getObjectById((*playerListIt))); if(!groupMember) { playerListIt++; continue; } Datapad* datapad = dynamic_cast<Datapad*>(groupMember->getEquipManager()->getEquippedObject(CreatureEquipSlot_Datapad)); MissionList* missionList = datapad->getMissions(); MissionList::iterator missionListIt = missionList->begin(); //add all Missions of the player to our List while(missionListIt != missionList->end()) { //the rubber point counter will be set to 0 initially missionRangeList.push_back(std::make_pair((*missionListIt),0)); missionListIt++; } playerListIt++; } //do we have missions in the first place ? if(!missionRangeList.size()) return NULL; //now iterate through all players and determine their nearest mission playerListIt = members->begin(); while(playerListIt != members->end()) { PlayerObject* groupMember = dynamic_cast<PlayerObject*> (gWorldManager->getObjectById((*playerListIt))); //now check for the nearest mission - increase its counter MissionGroupRangeList::iterator missionRangeListIt = missionRangeList.begin(); MissionGroupRangeList::iterator missionRangeListStorage = missionRangeList.begin(); while(missionRangeListIt != missionRangeList.end()) { MissionObject* nearestMission = NULL; float nearestDistance = 88000.0; MissionObject* currentMission = (*missionRangeListIt).first; float currentDistance = glm::distance(groupMember->mPosition, currentMission->getDestination().Coordinates); //store the nearest Mission if(currentDistance < nearestDistance) { nearestDistance = currentDistance; nearestMission = currentMission; //store the lists iterator for future reference missionRangeListStorage = missionRangeListIt; } missionRangeListIt++; } //now take the nearest Mission and give it a rubberpoint (*missionRangeListStorage).second++; //does our mission have enough rubberpoints? if((*missionRangeListStorage).second > (uint32)(members->size() /2)) { //jupp :) return (*missionRangeListStorage).first; } //remember the mission with the most rubberpoints anyway in case we dont have a clear winner if((*missionRangeListStorage).second > chosenRubberPoints) { chosenRubberPoints = (*missionRangeListStorage).second; chosenMission = (*missionRangeListStorage).first; } playerListIt++; } return chosenMission; }