void BountyMissionObjectiveImplementation::handleNpcTargetKilled(Observable* observable) { CreatureObject* target = cast<CreatureObject*>(observable); ManagedReference<CreatureObject*> owner = getPlayerOwner(); if (owner == NULL || target == NULL) return; SceneObject* targetInventory = target->getSlottedObject("inventory"); if (targetInventory == NULL) return; uint64 lootOwnerID = targetInventory->getContainerPermissions()->getOwnerID(); GroupObject* group = owner->getGroup(); if (lootOwnerID == owner->getObjectID() || (group != NULL && lootOwnerID == group->getObjectID())) { //Target killed by player, complete mission. complete(); } else { //Target killed by other player, fail mission. owner->sendSystemMessage("@mission/mission_generic:failed"); // Mission failed abort(); removeMissionFromPlayer(); } }
String BountyMissionObjectiveImplementation::getTargetZoneName() { Locker locker(&syncMutex); ManagedReference<MissionObject* > mission = this->mission.get(); if (isPlayerTarget()) { uint64 targetId = mission->getTargetObjectId(); ZoneServer* zoneServer = getPlayerOwner().get()->getZoneServer(); if (zoneServer != NULL) { ManagedReference<CreatureObject*> creature = zoneServer->getObject(targetId).castTo<CreatureObject*>(); if (creature != NULL && creature->getZone() != NULL) { return creature->getZone()->getZoneName(); } } } else { if (targetTask != NULL) { return targetTask->getTargetZoneName(); } } //No target task, return dungeon1 which is not able to find. return "dungeon1"; }
void MissionObjectiveImplementation::complete() { Locker _lock(_this.get()); ManagedReference<CreatureObject*> player = getPlayerOwner(); if (player == NULL) return; _lock.release(); Reference<CompleteMissionObjectiveTask*> task = new CompleteMissionObjectiveTask(_this.get()); task->execute(); if (player->isGrouped() && player->getGroup() != NULL) { GroupObject* group = player->getGroup(); Locker locker(group); group->scheduleUpdateNearestMissionForGroup(player->getPlanetCRC()); } /*awardReward(); awardFactionPoints(); removeMissionFromPlayer();*/ }
void BountyMissionObjectiveImplementation::updateWaypoint() { Locker locker(&syncMutex); ManagedReference<MissionObject* > mission = this->mission.get(); WaypointObject* waypoint = mission->getWaypointToMission(); if (waypoint == NULL) { Locker mlocker(mission); waypoint = mission->createWaypoint(); } Locker wplocker(waypoint); waypoint->setPlanetCRC(getTargetZoneName().hashCode()); Vector3 position = getTargetPosition(); waypoint->setPosition(position.getX(), 0, position.getY()); waypoint->setActive(true); mission->updateMissionLocation(); if (mission->getMissionLevel() == 1) { getPlayerOwner().get()->sendSystemMessage("@mission/mission_bounty_informant:target_location_received"); // Target Waypoint Received. } }
void BountyMissionObjectiveImplementation::handleNpcTargetKilled(ManagedObject* arg1) { CreatureObject* attacker = NULL; attacker = cast<CreatureObject*>(arg1); ManagedReference<MissionObject* > mission = this->mission.get(); ManagedReference<CreatureObject*> owner = getPlayerOwner(); if (owner == NULL) return; if (attacker != NULL && attacker->getObjectID() == owner->getObjectID() && attacker->isPlayerCreature()) { //Target killed by player, complete mission. complete(); } else if (attacker != NULL && attacker->isPet()) { // Target killed by pet ManagedReference<CreatureObject*> petOwner = attacker->getLinkedCreature().get(); if (petOwner != NULL && petOwner->getObjectID() == owner->getObjectID()) { // Pet is owned by mission owner, complete mission. complete(); } } else { //Target killed by other player, fail mission. owner->sendSystemMessage("@mission/mission_generic:failed"); // Mission failed abort(); removeMissionFromPlayer(); } }
void DestroyMissionObjectiveImplementation::abort() { MissionObjectiveImplementation::abort(); if (hasObservers()) { ManagedReference<MissionObserver*> observer = getObserver(0); ManagedReference<CreatureObject*> player = getPlayerOwner(); ManagedReference<LairObject*> lair = lairObject; if (lair != NULL) { Locker locker(lair); lair->dropObserver(ObserverEventType::OBJECTDESTRUCTION, observer); lair->destroyObjectFromWorld(true); lair = NULL; dropObserver(observer, true); } //spawnActiveArea->destroyObjectFromDatabase(true); } ManagedReference<MissionSpawnActiveArea* > spawnActiveArea = this->spawnActiveArea; if (spawnActiveArea != NULL) { Locker locker(spawnActiveArea); spawnActiveArea->destroyObjectFromWorld(true); } }
bool BountyMissionObjectiveImplementation::addPlayerTargetObservers() { Locker locker(&syncMutex); ManagedReference<MissionObject* > mission = this->mission.get(); ManagedReference<CreatureObject*> owner = getPlayerOwner(); ZoneServer* zoneServer = owner->getZoneServer(); if (zoneServer != NULL) { ManagedReference<CreatureObject*> target = zoneServer->getObject(mission->getTargetObjectId()).castTo<CreatureObject*>(); if (target != NULL) { addObserverToCreature(ObserverEventType::PLAYERKILLED, target); addObserverToCreature(ObserverEventType::DEFENDERADDED, target); addObserverToCreature(ObserverEventType::DEFENDERDROPPED, target); addObserverToCreature(ObserverEventType::PLAYERKILLED, owner); addObserverToCreature(ObserverEventType::DEFENDERADDED, owner); addObserverToCreature(ObserverEventType::DEFENDERDROPPED, owner); owner->getZoneServer()->getMissionManager()->addBountyHunterToPlayerBounty(mission->getTargetObjectId(), owner->getObjectID()); //Update aggressive status on target for bh. target->sendPvpStatusTo(owner); return true; } } return false; }
void BountyMissionObjectiveImplementation::handlePlayerKilled(ManagedObject* arg1) { CreatureObject* killer = NULL; killer = cast<CreatureObject*>(arg1); ManagedReference<MissionObject* > mission = this->mission.get(); ManagedReference<CreatureObject*> owner = getPlayerOwner(); if (owner != NULL && killer != NULL) { if (owner->getObjectID() == killer->getObjectID()) { //Target killed by player, complete mission. ZoneServer* zoneServer = owner->getZoneServer(); if (zoneServer != NULL) { ManagedReference<CreatureObject*> target = zoneServer->getObject(mission->getTargetObjectId()).castTo<CreatureObject*>(); if (target != NULL) { VisibilityManager::instance()->clearVisibility(target); owner->getZoneServer()->getPlayerManager()->awardExperience(target, "jedi_general", -30000, true); } } complete(); } else if (mission->getTargetObjectId() == killer->getObjectID() || (npcTarget != NULL && npcTarget->getObjectID() == killer->getObjectID())) { //Player killed by target, fail mission. owner->sendSystemMessage("@mission/mission_generic:failed"); // Mission failed killer->sendSystemMessage("You have defeated a bounty hunter, ruining his mission against you!"); fail(); } } }
Vector3 BountyMissionObjectiveImplementation::getTargetPosition() { Locker locker(&syncMutex); ManagedReference<MissionObject* > mission = this->mission.get(); if (isPlayerTarget()) { uint64 targetId = mission->getTargetObjectId(); ZoneServer* zoneServer = getPlayerOwner().get()->getZoneServer(); if (zoneServer != NULL) { ManagedReference<CreatureObject*> creature = zoneServer->getObject(targetId).castTo<CreatureObject*>(); if (creature != NULL) { return creature->getWorldPosition(); } } } else { if (targetTask != NULL) { return targetTask->getTargetPosition(); } } Vector3 empty; return empty; }
void BountyMissionObjectiveImplementation::abort() { Locker locker(&syncMutex); ManagedReference<CreatureObject*> owner = getPlayerOwner(); ManagedReference<MissionObject*> strongRef = mission.get(); MissionObjectiveImplementation::abort(); cancelAllTasks(); if (strongRef == NULL || owner == NULL) return; owner->getZoneServer()->getMissionManager()->removeBountyHunterFromPlayerBounty(strongRef->getTargetObjectId(), owner->getObjectID()); removeFromBountyLock(true); WaypointObject* waypoint = strongRef->getWaypointToMission(); if (waypoint != NULL && waypoint->isActive()) { Locker wplocker(waypoint); waypoint->setActive(false); } //Remove observers if (hasObservers()) { if (isPlayerTarget()) { removePlayerTargetObservers(); } else { removeNpcTargetObservers(); } } }
int BountyMissionObjectiveImplementation::handleNpcTargetReceivesDamage(ManagedObject* arg1) { CreatureObject* target = NULL; target = cast<CreatureObject*>(arg1); ManagedReference<MissionObject* > mission = this->mission.get(); ManagedReference<CreatureObject*> owner = getPlayerOwner(); if (owner != NULL && target != NULL && target->getFirstName() == owner->getFirstName() && target->isPlayerCreature() && objectiveStatus == HASBIOSIGNATURESTATUS) { updateMissionStatus(mission->getMissionLevel()); String diffString = "easy"; if (mission->getMissionLevel() == 3) { diffString = "hard"; } else if (mission->getMissionLevel() == 2) { diffString = "medium"; } target->getZoneServer()->getChatManager()->broadcastMessage(npcTarget, "@mission/mission_bounty_neutral_" + diffString + ":m" + String::valueOf(mission->getMissionNumber()) + "v", 0, 0, 0); return 1; } return 0; }
void BountyMissionObjectiveImplementation::activate() { Locker locker(&syncMutex); MissionObjectiveImplementation::activate(); bool failMission = false; //Start NPC task or add observers to player target. if (getObserverCount() == 2) { removeNpcTargetObservers(); startNpcTargetTask(); } else if (getObserverCount() != 6) { if (isPlayerTarget()) { failMission = !addPlayerTargetObservers(); } else { startNpcTargetTask(); } } if (failMission) { getPlayerOwner().get()->sendSystemMessage("@mission/mission_generic:failed"); // Mission failed abort(); removeMissionFromPlayer(); } }
int EntertainerMissionObjectiveImplementation::notifyObserverEvent(MissionObserver* observer, unsigned int eventType, Observable* observable, ManagedObject* arg1, long long arg2) { if (eventType != ObserverEventType::ENTEREDAREA && eventType != ObserverEventType::EXITEDAREA) { return 0; } if (cast<ActiveArea*>(observable) != locationActiveArea) { return 0; } if (cast<CreatureObject*>(arg1) != getPlayerOwner().get()) { return 0; } Locker _lock(_this.getReferenceUnsafeStaticCast()); if (eventType == ObserverEventType::ENTEREDAREA) { inMissionArea = true; } else { inMissionArea = false; } startCompleteTask(); return 0; }
void BountyMissionObjectiveImplementation::updateMissionStatus(int informantLevel) { Locker locker(&syncMutex); ManagedReference<MissionObject* > mission = this->mission.get(); if (getPlayerOwner() == NULL) { return; } switch (objectiveStatus) { case INITSTATUS: if (mission->getTargetOptionalTemplate() != "") { startNpcTargetTask(); } if (informantLevel == 1) { updateWaypoint(); } objectiveStatus = HASBIOSIGNATURESTATUS; break; case HASBIOSIGNATURESTATUS: if (informantLevel > 1) { updateWaypoint(); } objectiveStatus = HASTALKED; break; case HASTALKED: if (informantLevel > 1) { updateWaypoint(); } break; default: break; } }
void EntertainerMissionObjectiveImplementation::startCompleteTask() { //Is entertaining in mission area inside a building. Locker _lock(_this.getReferenceUnsafeStaticCast()); ManagedReference<CreatureObject*> object = getPlayerOwner(); if (object == NULL) return; if (isEntertaining && inMissionArea && object != NULL && object->getParentID() != 0) { if (completeTask == NULL) { completeTask = new CompleteMissionAfterCertainTimeTask(_this.getReferenceUnsafeStaticCast()); } if (completeTask->isScheduled()) { completeTask->reschedule(10 * 60 * 1000); } else { completeTask->schedule(10 * 60 * 1000); } } else { if (completeTask != NULL && completeTask->isScheduled()) { completeTask->cancel(); } } }
void BountyMissionObjectiveImplementation::startNpcTargetTask() { Locker locker(&syncMutex); ManagedReference<MissionObject* > mission = this->mission.get(); targetTask = new BountyHunterTargetTask(mission, getPlayerOwner().get(), mission->getEndPlanet()); if (targetTask != NULL && !targetTask->isScheduled()) { targetTask->schedule(10 * 1000); } }
void MissionObjectiveImplementation::removeMissionFromPlayer() { ManagedReference<CreatureObject*> player = getPlayerOwner(); ManagedReference<MissionObject* > mission = this->mission.get(); if (player != NULL) { ZoneServer* zoneServer = player->getZoneServer(); MissionManager* missionManager = zoneServer->getMissionManager(); missionManager->removeMission(mission, player); } }
void BountyMissionObjectiveImplementation::spawnTarget(const String& zoneName) { Locker locker(&syncMutex); ManagedReference<MissionObject* > mission = this->mission.get(); if ((npcTarget != NULL && npcTarget->isInQuadTree()) || isPlayerTarget()) { return; } ZoneServer* zoneServer = getPlayerOwner().get()->getZoneServer(); Zone* zone = zoneServer->getZone(zoneName); CreatureManager* cmng = zone->getCreatureManager(); if (npcTarget == NULL) { Vector3 position = getTargetPosition(); try { npcTarget = cast<AiAgent*>(zone->getCreatureManager()->spawnCreatureWithAi(mission->getTargetOptionalTemplate().hashCode(), position.getX(), zone->getHeight(position.getX(), position.getY()), position.getY(), 0)); } catch (Exception& e) { fail(); ManagedReference<CreatureObject*> player = getPlayerOwner(); if (player != NULL) { player->sendSystemMessage("ERROR: could not find template for target. Please report this on Mantis to help us track down the root cause."); } error("Template error: " + e.getMessage() + " Template = '" + mission->getTargetOptionalTemplate() +"'"); } if (npcTarget != NULL) { npcTarget->setCustomObjectName(mission->getTargetName(), true); //TODO add observer to catch player kill and fail mission in that case. addObserverToCreature(ObserverEventType::OBJECTDESTRUCTION, npcTarget); addObserverToCreature(ObserverEventType::DAMAGERECEIVED, npcTarget); } else { fail(); ManagedReference<CreatureObject*> player = getPlayerOwner(); if (player != NULL) { player->sendSystemMessage("ERROR: could not find template for target. Please report this on Mantis to help us track down the root cause."); } error("Could not spawn template: '" + mission->getTargetOptionalTemplate() + "'"); } } }
void MissionObjectiveImplementation::awardReward() { Vector<ManagedReference<CreatureObject*> > players; PlayMusicMessage* pmm = new PlayMusicMessage("sound/music_mission_complete.snd"); Vector3 missionEndPoint = getEndPosition(); ManagedReference<CreatureObject*> owner = getPlayerOwner(); ManagedReference<GroupObject*> group = owner->getGroup(); if (group != NULL) { Locker lockerGroup(group, _this.get()); for(int i = 0; i < group->getGroupSize(); i++) { Reference<CreatureObject*> groupMember = group->getGroupMember(i)->isPlayerCreature() ? (group->getGroupMember(i)).castTo<CreatureObject*>() : NULL; if (groupMember != NULL) { //Play mission complete sound. groupMember->sendMessage(pmm->clone()); if (groupMember->getWorldPosition().distanceTo(missionEndPoint) < 128) { players.add(groupMember); } } } delete pmm; } else { //Play mission complete sound. owner->sendMessage(pmm); players.add(owner); } if (players.size() == 0) { players.add(owner); } ManagedReference<MissionObject* > mission = this->mission.get(); int dividedReward = mission->getRewardCredits() / players.size(); for (int i = 0; i < players.size(); i++) { ManagedReference<CreatureObject*> player = players.get(i); StringIdChatParameter stringId("mission/mission_generic", "success_w_amount"); stringId.setDI(dividedReward); player->sendSystemMessage(stringId); Locker lockerPl(player, _this.get()); player->addBankCredits(dividedReward, true); } StatisticsManager::instance()->completeMission(mission->getTypeCRC() ,mission->getRewardCredits()); }
Vector3 MissionObjectiveImplementation::getEndPosition() { ManagedReference<MissionObject* > mission = this->mission.get(); Vector3 missionEndPoint; missionEndPoint.setX(mission->getEndPositionX()); missionEndPoint.setY(mission->getEndPositionY()); TerrainManager* terrain = getPlayerOwner().get()->getZone()->getPlanetManager()->getTerrainManager(); missionEndPoint.setZ(terrain->getHeight(missionEndPoint.getX(), missionEndPoint.getY())); return missionEndPoint; }
void BountyMissionObjectiveImplementation::removeFromBountyLock(bool immediately) { Locker locker(&syncMutex); ManagedReference<MissionObject* > mission = this->mission.get(); ManagedReference<PlayerObject*> ghost = getPlayerOwner().get()->getPlayerObject(); if (ghost == NULL) { return; } ghost->removeFromBountyLockList(mission->getTargetObjectId(), immediately); }
void BountyMissionObjectiveImplementation::addToBountyLock() { Locker locker(&syncMutex); ManagedReference<MissionObject* > mission = this->mission.get(); ManagedReference<PlayerObject*> ghost = getPlayerOwner().get()->getPlayerObject(); if (ghost == NULL) { return; } ghost->addToBountyLockList(mission->getTargetObjectId()); }
int HuntingMissionObjectiveImplementation::notifyObserverEvent(MissionObserver* observer, uint32 eventType, Observable* observable, ManagedObject* arg1, int64 arg2) { ManagedReference<MissionObject* > mission = this->mission.get(); if (eventType == ObserverEventType::KILLEDCREATURE) { if (cast<CreatureObject*>(observable) != getPlayerOwner().get()) return 0; CreatureObject* creature = cast<CreatureObject*>(arg1); AiAgent* agent = cast<AiAgent*>(creature); if (agent == NULL) return 0; CreatureTemplate* creatureTemplate = agent->getCreatureTemplate(); if (creatureTemplate == NULL) return 0; String temp1 = mission->getTemplateString1(); String temp2 = mission->getTemplateString2(); if (creatureTemplate->getTemplateName() == temp1 || creatureTemplate->getTemplateName() == temp2) { targetsKilled--; if (targetsKilled <= 0) { complete(); return 1; } StringIdChatParameter message("mission/mission_generic", "hunting_kills_remaining"); message.setDI(targetsKilled); message.setTO(mission->getTargetName()); getPlayerOwner().get()->sendSystemMessage(message); } } return 0; }
void SurveyMissionObjectiveImplementation::activate() { MissionObjectiveImplementation::activate(); if (hasObservers()) { return; } ManagedReference<CreatureObject*> player = getPlayerOwner(); if (player != NULL) { ManagedReference<MissionObserver*> observer = new MissionObserver(_this.getReferenceUnsafeStaticCast()); addObserver(observer, true); player->registerObserver(ObserverEventType::SURVEY, observer); } }
void SurveyMissionObjectiveImplementation::abort() { MissionObjectiveImplementation::abort(); if (!hasObservers()) return; ManagedReference<MissionObserver*> observer = getObserver(0); ManagedReference<CreatureObject*> player = getPlayerOwner(); if (player != NULL) { player->dropObserver(ObserverEventType::SURVEY, observer); dropObserver(observer, true); } }
void BountyMissionObjectiveImplementation::handleDefenderDropped(ManagedObject* arg1) { CreatureObject* defender = NULL; defender = cast<CreatureObject*>(arg1); ManagedReference<MissionObject* > mission = this->mission.get(); ManagedReference<CreatureObject*> owner = getPlayerOwner(); if (owner != NULL && defender != NULL) { if (owner->getObjectID() == defender->getObjectID() || mission->getTargetObjectId() == defender->getObjectID()) { removeFromBountyLock(false); } } }
void BountyMissionObjectiveImplementation::complete() { Locker locker(&syncMutex); cancelAllTasks(); ManagedReference<MissionObject* > mission = this->mission.get(); ManagedReference<CreatureObject*> owner = getPlayerOwner(); //Award bountyhunter xp. owner->getZoneServer()->getPlayerManager()->awardExperience(owner, "bountyhunter", mission->getRewardCredits() / 100, true, 1); owner->getZoneServer()->getMissionManager()->completePlayerBounty(mission->getTargetObjectId(), owner->getObjectID()); removeFromBountyLock(true); MissionObjectiveImplementation::complete(); }
void HuntingMissionObjectiveImplementation::activate() { MissionObjectiveImplementation::activate(); if (hasObservers()) return; targetsKilled = 15 * getMissionObject().get()->getDifficultyLevel(); ManagedReference<CreatureObject*> player = getPlayerOwner(); ManagedReference<MissionObserver*> observer = new MissionObserver(_this.getReferenceUnsafeStaticCast()); addObserver(observer, true); Locker locker(player); player->registerObserver(ObserverEventType::KILLEDCREATURE, observer); }
Vector3 DestroyMissionObjectiveImplementation::getEndPosition() { ManagedReference<MissionObject* > mission = this->mission.get(); Vector3 missionEndPoint; missionEndPoint.setX(mission->getStartPositionX()); missionEndPoint.setY(mission->getStartPositionY()); Zone* zone = getPlayerOwner().get()->getZone(); if (zone != NULL) { missionEndPoint.setZ(zone->getHeight(missionEndPoint.getX(), missionEndPoint.getY())); } return missionEndPoint; }
void BountyMissionObjectiveImplementation::handlePlayerKilled(ManagedObject* arg1) { CreatureObject* killer = NULL; killer = cast<CreatureObject*>(arg1); ManagedReference<MissionObject* > mission = this->mission.get(); ManagedReference<CreatureObject*> owner = getPlayerOwner(); if(mission == NULL) return; if (owner != NULL && killer != NULL) { if (owner->getObjectID() == killer->getObjectID()) { //Target killed by player, complete mission. ZoneServer* zoneServer = owner->getZoneServer(); if (zoneServer != NULL) { ManagedReference<CreatureObject*> target = zoneServer->getObject(mission->getTargetObjectId()).castTo<CreatureObject*>(); if (target != NULL) { int minXpLoss = -50000; int maxXpLoss = -500000; VisibilityManager::instance()->clearVisibility(target); int xpLoss = mission->getRewardCredits() * -2; if (xpLoss > minXpLoss) xpLoss = minXpLoss; else if (xpLoss < maxXpLoss) xpLoss = maxXpLoss; owner->getZoneServer()->getPlayerManager()->awardExperience(target, "jedi_general", xpLoss, true); StringIdChatParameter message("base_player","prose_revoke_xp"); message.setDI(xpLoss * -1); message.setTO("exp_n", "jedi_general"); target->sendSystemMessage(message); } } complete(); } else if (mission->getTargetObjectId() == killer->getObjectID() || (npcTarget != NULL && npcTarget->getObjectID() == killer->getObjectID())) { //Player killed by target, fail mission. owner->sendSystemMessage("@mission/mission_generic:failed"); // Mission failed killer->sendSystemMessage("You have defeated a bounty hunter, ruining his mission against you!"); fail(); } } }