From ac9d0e41bf060474199243022fa5f1595f881b3a Mon Sep 17 00:00:00 2001 From: Waverunner Date: Wed, 18 Jun 2014 13:57:29 -0400 Subject: [PATCH] Refactored delivery missions to use pre-spawned commoners Scripters should change any commoners being spawned to use core.staticService.spawnCommoner instead of spawnObject (see mos_eisley.py in static_spawns\tatooine for an example). The spawnCommoner method will add required attachments and set the proper options bitmask in order for the missions to function properly. Note that delivery missions won't work unless you have spawned buildouts on the planet you are requesting the missions on due to this change. --- odb/cities/je.info.0.8 | 1 - scripts/conversation/missions/deliver.py | 41 +++++++--- scripts/static_spawns/tatooine/mos_eisley.py | 27 +++---- .../objectives/DeliveryMissionObjective.java | 75 ++++++------------- .../objects/mission/MissionObject.java | 18 +++-- .../objects/player/PlayerObject.java | 14 ++++ src/services/StaticService.java | 22 ++++++ src/services/mission/CommonerSpawn.java | 51 +++++++++++++ src/services/mission/MissionService.java | 70 ++++++++++++++--- 9 files changed, 216 insertions(+), 103 deletions(-) delete mode 100644 odb/cities/je.info.0.8 create mode 100644 src/services/mission/CommonerSpawn.java diff --git a/odb/cities/je.info.0.8 b/odb/cities/je.info.0.8 deleted file mode 100644 index c6a20587..00000000 --- a/odb/cities/je.info.0.8 +++ /dev/null @@ -1 +0,0 @@ -140613 19:57:33:302 INFO [.\odb\cities]Chose lowest utilized file for cleaning. totalUtilization: 14 bestFileUtilization: 101 lnSizeCorrectionFactor: NaN isProbe: false diff --git a/scripts/conversation/missions/deliver.py b/scripts/conversation/missions/deliver.py index 126665a7..f199410e 100644 --- a/scripts/conversation/missions/deliver.py +++ b/scripts/conversation/missions/deliver.py @@ -4,9 +4,18 @@ from resources.objectives import DeliveryMissionObjective import sys def startConversation(core, actor, npc): - missionId = npc.getAttachment('assignedMission') + + player = actor.getPlayerObject() - if missionId is None: + if player is None: + return + + activeMissions = player.getActiveMissions() + + missionId = checkMissions(core, actor, npc, activeMissions) + + if missionId == 0: + core.conversationService.sendStopConversation(actor, npc, 'mission/mission_generic', 'npc_job_request_no_job') return mission = core.objectService.getObject(missionId) @@ -16,7 +25,7 @@ def startConversation(core, actor, npc): objective = mission.getObjective() - if mission.getGrandparent().getObjectId() != actor.getObjectId() or objective is None: + if objective is None: core.conversationService.sendStopConversation(actor, npc, 'mission/mission_generic', 'npc_job_request_no_job') return @@ -38,33 +47,43 @@ def endConversation(core, actor, npc): return def handlePickupStage(core, actor, npc, objective, mission): - - if objective.getMissionGiver().getObjectId() != npc.getObjectId(): + if objective.getMissionGiver() != npc.getObjectId(): endConversation(core, actor, npc) return - core.conversationService.sendStopConversation(actor, npc, mission.getMissionStf(), 'm' + str(mission.getMissionId()) + 'p') + core.conversationService.sendStopConversation(actor, npc, mission.getTitle().getStfFilename(), 'm' + str(mission.getMissionId()) + 'p') objective.createDeliveryItem(core, actor) objective.update(core, actor) return def handleDeliveryStage(core, actor, npc, objective, mission): - if objective.getDropOffNpc().getObjectId() != npc.getObjectId(): + if objective.getDropOffNpc() != npc.getObjectId(): endConversation(core, actor, npc) return - core.conversationService.sendStopConversation(actor, npc, mission.getMissionStf(), 'm' + str(mission.getMissionId()) + 'r') + core.conversationService.sendStopConversation(actor, npc, mission.getTitle().getStfFilename(), 'm' + str(mission.getMissionId()) + 'r') core.objectService.destroyObject(objective.getDeliveryObject()) objective.update(core, actor) return def handleCompletionStage(core, actor, npc, objective, mission): - if objective.getMissionGiver().getObjectId() != npc.getObjectId(): + if objective.getMissionGiver() != npc.getObjectId(): endConversation(core, actor, npc) return - core.conversationService.sendStopConversation(actor, npc, mission.getMissionStf(), 'm' + str(mission.getMissionId()) + 's') + core.conversationService.sendStopConversation(actor, npc, mission.getTitle().getStfFilename(), 'm' + str(mission.getMissionId()) + 's') core.missionService.handleMissionComplete(actor, mission) - return \ No newline at end of file + return + +def checkMissions(core, actor, npc, activeMissions): + for objId in activeMissions: + missionObj = core.objectService.getObject(objId) + + if (missionObj != None): + if (missionObj.getStartLocation() is not None and missionObj.getStartLocation().getObjectId() == npc.getObjectID()): + return missionObj.getObjectID() + elif (missionObj.getDestinationLocation() is not None and missionObj.getDestinationLocation().getObjectId() == npc.getObjectID()): + return missionObj.getObjectID() + return 0 \ No newline at end of file diff --git a/scripts/static_spawns/tatooine/mos_eisley.py b/scripts/static_spawns/tatooine/mos_eisley.py index 90c02333..d4c7ee3d 100644 --- a/scripts/static_spawns/tatooine/mos_eisley.py +++ b/scripts/static_spawns/tatooine/mos_eisley.py @@ -140,8 +140,8 @@ def addPlanetSpawns(core, planet): #City Hall Interior #Lucky Despot Interior TODO: Check Cell IDs for Spawned NPCS inside once Lucky Despot is spawning properly again. - building = core.objectService.getObject(long(-466404040703447347)) - stcSvc.spawnObject('object/mobile/shared_han_solo.iff', 'tatooine', building.getCellByCellNumber(9), float(32.3), float(7.0), float(1.6), float(0), float(0), float(0), float(0)) + #building = core.objectService.getObject(long(-466404040703447347)) + #stcSvc.spawnObject('object/mobile/shared_han_solo.iff', 'tatooine', building.getCellByCellNumber(9), float(32.3), float(7.0), float(1.6), float(0), float(0), float(0), float(0)) valarian = stcSvc.spawnObject('object/mobile/shared_lady_valarian.iff', 'tatooine', building.getCellByCellNumber(4), float(-21.5), float(9.0), float(0.5), float(0), float(0.70), float(0), float(-0.71)) valarian.setCustomName('Lady Valarian') @@ -162,9 +162,8 @@ def addPlanetSpawns(core, planet): noble2.setCustomName('a Noble') noble2.setOptionsBitmask(256) - commoner11 = stcSvc.spawnObject('object/mobile/shared_dressed_commoner_naboo_human_male_06.iff', 'tatooine', long(0), float(3529.1), float(5.0), float(-4900.4), float(0.42), float(0.91)) + commoner11 = stcSvc.spawnCommoner('object/mobile/shared_dressed_commoner_naboo_human_male_06.iff', 'tatooine', long(0), float(3529.1), float(5.0), float(-4900.4), float(0.42), float(0.91)) commoner11.setCustomName('a Commoner') - commoner11.setOptionsBitmask(256) businessman3 = stcSvc.spawnObject('object/mobile/shared_dressed_commoner_tatooine_trandoshan_male_02.iff', 'tatooine', long(0), float(3595.7), float(5.0), float(-4740.1), float(0), float(0)) businessman3.setCustomName('a Businessman') @@ -174,21 +173,17 @@ def addPlanetSpawns(core, planet): jawa1.setCustomName('a Jawa') jawa1.setOptionsBitmask(256) - commoner12 = stcSvc.spawnObject('object/mobile/shared_dressed_commoner_naboo_moncal_male_01.iff', 'tatooine', long(0), float(3490.3), float(5.0), float(-4799.4), float(0), float(0)) + commoner12 = stcSvc.spawnCommoner('object/mobile/shared_dressed_commoner_naboo_moncal_male_01.iff', 'tatooine', long(0), float(3490.3), float(5.0), float(-4799.4), float(0), float(0)) commoner12.setCustomName('a Scientist') - commoner12.setOptionsBitmask(256) - commoner13 = stcSvc.spawnObject('object/mobile/shared_dressed_commoner_naboo_zabrak_female_02.iff', 'tatooine', long(0), float(3559.7), float(5.0), float(-4725.9), float(0), float(0)) + commoner13 = stcSvc.spawnCommoner('object/mobile/shared_dressed_commoner_naboo_zabrak_female_02.iff', 'tatooine', long(0), float(3559.7), float(5.0), float(-4725.9), float(0), float(0)) commoner13.setCustomName('a Commoner') - commoner13.setOptionsBitmask(256) - commoner14 = stcSvc.spawnObject('object/mobile/shared_dressed_commoner_tatooine_devaronian_male_01.iff', 'tatooine', long(0), float(3527.7), float(5.0), float(-4721.1), float(0.71), float(0.71)) + commoner14 = stcSvc.spawnCommoner('object/mobile/shared_dressed_commoner_tatooine_devaronian_male_01.iff', 'tatooine', long(0), float(3527.7), float(5.0), float(-4721.1), float(0.71), float(0.71)) commoner14.setCustomName('a Commoner') - commoner14.setOptionsBitmask(256) - commoner15 = stcSvc.spawnObject('object/mobile/shared_dressed_commoner_tatooine_aqualish_female_01.iff', 'tatooine', long(0), float(3514.9), float(5.0), float(-4737.8), float(0), float(0)) + commoner15 = stcSvc.spawnCommoner('object/mobile/shared_dressed_commoner_tatooine_aqualish_female_01.iff', 'tatooine', long(0), float(3514.9), float(5.0), float(-4737.8), float(0), float(0)) commoner15.setCustomName('a Commoner') - commoner15.setOptionsBitmask(256) jawa2 = stcSvc.spawnObject('object/mobile/shared_jawa.iff', 'tatooine', long(0), float(3485.2), float(4.9), float(-4859.2), float(0), float(0)) jawa2.setCustomName('a Jawa') @@ -226,10 +221,9 @@ def addPlanetSpawns(core, planet): bib.setCustomName('Bib Fortuna') bib.setOptionsBitmask(256) - commoner16 = stcSvc.spawnObject('object/mobile/shared_dressed_commoner_naboo_human_male_06.iff', 'tatooine', long(0), float(3398.2), float(4.0), float(-4654.2), float(0.42), float(0.91)) + commoner16 = stcSvc.spawnCommoner('object/mobile/shared_dressed_commoner_naboo_human_male_06.iff', 'tatooine', long(0), float(3398.2), float(4.0), float(-4654.2), float(0.42), float(0.91)) commoner16.setCustomName('a Commoner') - commoner16.setOptionsBitmask(256) - + noble3 = stcSvc.spawnObject('object/mobile/shared_dressed_noble_human_female_01.iff', 'tatooine', long(0), float(3396.3), float(4.0), float(-4774.1), float(0.42), float(0.91)) noble3.setCustomName('a Noble') noble3.setOptionsBitmask(256) @@ -246,9 +240,8 @@ def addPlanetSpawns(core, planet): eg1.setCustomName('an EG-6 Power Droid') eg1.setOptionsBitmask(256) - commoner17 = stcSvc.spawnObject('object/mobile/shared_dressed_commoner_naboo_zabrak_female_02.iff', 'tatooine', long(0), float(3452.6), float(4.0), float(-4937.1), float(0), float(0)) + commoner17 = stcSvc.spawnCommoner('object/mobile/shared_dressed_commoner_naboo_zabrak_female_02.iff', 'tatooine', long(0), float(3452.6), float(4.0), float(-4937.1), float(0), float(0)) commoner17.setCustomName('a Commoner') - commoner17.setOptionsBitmask(256) lifter1 = stcSvc.spawnObject('object/mobile/shared_cll8_binary_load_lifter.iff', 'tatooine', long(0), float(3547), float(5.0), float(-4768.9), float(0), float(0)) lifter1.setCustomName('a CLL-8 Binary Load Lifter') diff --git a/src/resources/objectives/DeliveryMissionObjective.java b/src/resources/objectives/DeliveryMissionObjective.java index b2ae62a6..c4eef253 100644 --- a/src/resources/objectives/DeliveryMissionObjective.java +++ b/src/resources/objectives/DeliveryMissionObjective.java @@ -22,7 +22,6 @@ package resources.objectives; import engine.resources.common.CRC; -import engine.resources.scene.Point3D; import main.NGECore; import resources.common.OutOfBand; import resources.datatables.DisplayType; @@ -36,9 +35,9 @@ public class DeliveryMissionObjective extends MissionObjective { private static final long serialVersionUID = 1L; - private TangibleObject deliveryObject; - private CreatureObject missionGiver; - private CreatureObject dropOffNpc; + private long deliveryObjectId; + private long missionGiverId; + private long dropOffNpcId; public DeliveryMissionObjective(MissionObject parent) { super(parent); @@ -50,47 +49,22 @@ public class DeliveryMissionObjective extends MissionObjective { if (isActivated()) return; - String template = "object/mobile/shared_dressed_commoner_tatooine_sullustan_male_06.iff"; - - Point3D startLoc = parent.getStartLocation().getLocation(); - Point3D destination = parent.getDestinationLocation().getLocation(); - - // TODO: Randomize this process. - CreatureObject missionGiver = (CreatureObject) core.staticService.spawnObject(template, parent.getPlanet().name, 0, startLoc.x, startLoc.y, startLoc.z, 0, 1); - if (missionGiver == null) - return; - - missionGiver.setCustomName("a commoner"); - missionGiver.setAttachment("conversationFile", "missions/deliver"); - missionGiver.setAttachment("radial_filename", "object/conversation"); - missionGiver.setAttachment("assignedMission", getMissionObject().getObjectId()); - missionGiver.setOptionsBitmask(264); - setMissionGiver(missionGiver); - - CreatureObject dropOffNpc = (CreatureObject) core.staticService.spawnObject(template, parent.getPlanet().name, 0, destination.x, destination.y, destination.z, 0, 1); - if (dropOffNpc == null) - return; - - dropOffNpc.setCustomName("a commoner"); - dropOffNpc.setAttachment("conversationFile", "missions/deliver"); - dropOffNpc.setAttachment("radial_filename", "object/conversation"); - dropOffNpc.setAttachment("assignedMission", getMissionObject().getObjectId()); - dropOffNpc.setOptionsBitmask(264); - setDropOffNpc(dropOffNpc); + this.missionGiverId = parent.getStartLocation().getObjectId(); + this.dropOffNpcId = parent.getDestinationLocation().getObjectId(); if (getObjectivePhase() == 0) { WaypointObject waypoint = getMissionObject().getWaypoint(); - //waypoint.setPlanet(missionGiver.getPlanet()); - waypoint.setPlanetCRC(CRC.StringtoCRC(missionGiver.getPlanet().name)); - waypoint.setPosition(startLoc); + waypoint.setPlanetCRC(CRC.StringtoCRC(player.getPlanet().name)); + waypoint.setPosition(parent.getStartLocation().getLocation()); waypoint.setName("@" + parent.getTitle().getStfFilename() + ":" + "m" + parent.getMissionId() + "t"); waypoint.setColor(WaypointObject.ORANGE); waypoint.setActive(true); getMissionObject().setWaypoint(waypoint); + } else if (getObjectivePhase() == 1) { WaypointObject waypoint = getMissionObject().getWaypoint(); - waypoint.setPlanetCRC(CRC.StringtoCRC(dropOffNpc.getPlanet().name)); - waypoint.setPosition(destination); + waypoint.setPlanetCRC(CRC.StringtoCRC(player.getPlanet().name)); + waypoint.setPosition(parent.getDestinationLocation().getLocation()); waypoint.setName("@" + parent.getTitle().getStfFilename() + ":" + "m" + parent.getMissionId() + "t"); waypoint.setColor(WaypointObject.ORANGE); waypoint.setActive(true); @@ -108,22 +82,13 @@ public class DeliveryMissionObjective extends MissionObjective { player.addBankCredits(reward); player.sendSystemMessage(OutOfBand.ProsePackage("@mission/mission_generic:success_w_amount", reward), DisplayType.Broadcast); - - abort(core, player); - - core.objectService.destroyObject(getMissionObject()); } @Override public void abort(NGECore core, CreatureObject player) { + TangibleObject deliveryObject = (TangibleObject) core.objectService.getObject(deliveryObjectId); if (deliveryObject != null) - core.objectService.destroyObject(deliveryObject.getObjectId()); - - if (missionGiver != null) - core.objectService.destroyObject(missionGiver, 360); - - if (dropOffNpc != null) - core.objectService.destroyObject(dropOffNpc, 360); + core.objectService.destroyObject(deliveryObject); } @Override @@ -138,6 +103,7 @@ public class DeliveryMissionObjective extends MissionObjective { waypoint.setName("@" + parent.getTitle().getStfFilename() + ":" + "m" + parent.getMissionId() + "t"); waypoint.setColor(WaypointObject.ORANGE); waypoint.setActive(true); + waypoint.setPlanetCRC(CRC.StringtoCRC(player.getPlanet().name)); getMissionObject().setTargetName("Dropoff Location"); getMissionObject().setWaypoint(waypoint); break; @@ -147,6 +113,7 @@ public class DeliveryMissionObjective extends MissionObjective { returnWp.setName("@" + parent.getTitle().getStfFilename() + ":" + "m" + parent.getMissionId() + "t"); returnWp.setColor(WaypointObject.ORANGE); returnWp.setActive(true); + returnWp.setPlanetCRC(CRC.StringtoCRC(player.getPlanet().name)); getMissionObject().setTargetName("Return"); getMissionObject().setWaypoint(returnWp); break; @@ -166,23 +133,23 @@ public class DeliveryMissionObjective extends MissionObjective { TangibleObject deliveryObject = (TangibleObject) core.objectService.createObject("object/tangible/mission/shared_mission_datadisk.iff", player.getPlanet()); if (deliveryObject != null && inventory.add(deliveryObject)) { - setDeliveryObject(deliveryObject); + setDeliveryObject(deliveryObject.getObjectID()); return true; } else return false; } - public TangibleObject getDeliveryObject() { return deliveryObject; } + public long getDeliveryObject() { return deliveryObjectId; } - public void setDeliveryObject(TangibleObject object) { this.deliveryObject = object; } + public void setDeliveryObject(long object) { this.deliveryObjectId = object; } - public CreatureObject getMissionGiver() { return missionGiver; } + public long getMissionGiver() { return missionGiverId; } - public void setMissionGiver(CreatureObject missionGiver) { this.missionGiver = missionGiver; } + public void setMissionGiver(long missionGiver) { this.missionGiverId = missionGiver; } - public CreatureObject getDropOffNpc() { return dropOffNpc; } + public long getDropOffNpc() { return dropOffNpcId; } - public void setDropOffNpc(CreatureObject dropOffNpc) { this.dropOffNpc = dropOffNpc; } + public void setDropOffNpc(long dropOffNpc) { this.dropOffNpcId = dropOffNpc; } } diff --git a/src/resources/objects/mission/MissionObject.java b/src/resources/objects/mission/MissionObject.java index be116933..d357ab01 100644 --- a/src/resources/objects/mission/MissionObject.java +++ b/src/resources/objects/mission/MissionObject.java @@ -47,6 +47,8 @@ public class MissionObject extends IntangibleObject implements Serializable { private transient MissionMessageBuilder messageBuilder = new MissionMessageBuilder(this); + private MissionObjective objective; + public MissionObject() { super(); } @@ -58,7 +60,7 @@ public class MissionObject extends IntangibleObject implements Serializable { @Override public Baseline getOtherVariables() { Baseline baseline = super.getOtherVariables(); - baseline.put("objective", new DefaultMissionObjective(this)); + //baseline.put("objective", new DefaultMissionObjective(this)); baseline.put("bountyMarkId", (long) 0); baseline.put("missionId", 0); baseline.put("missionType", ""); @@ -118,9 +120,8 @@ public class MissionObject extends IntangibleObject implements Serializable { return (MissionLocation) getBaseline(3).get("startLocation"); } - public void setStartLocation(Point3D location, long objId, String planet) { + public void setStartLocation(MissionLocation startLocation) { if (getGrandparent() != null && getGrandparent().getClient() != null) { - MissionLocation startLocation = new MissionLocation(location.clone(), objId, planet); getGrandparent().getClient().getSession().write(getBaseline(3).set("startLocation", startLocation)); } } @@ -149,9 +150,8 @@ public class MissionObject extends IntangibleObject implements Serializable { return (MissionLocation) getBaseline(3).get("destinationLocation"); } - public void setDestinationLocation(Point3D location, long objId, String planet) { + public void setDestinationLocation(MissionLocation destinationLocation) { if (getGrandparent() != null && getGrandparent().getClient() != null) { - MissionLocation destinationLocation = new MissionLocation(location.clone(), objId, planet); getGrandparent().getClient().getSession().write(getBaseline(3).set("destinationLocation", destinationLocation)); } } @@ -241,15 +241,17 @@ public class MissionObject extends IntangibleObject implements Serializable { } public MissionObjective getObjective() { - if (otherVariables.get("objective") instanceof DefaultMissionObjective) { + /*if (otherVariables.get("objective") instanceof DefaultMissionObjective) { return null; } else { return (MissionObjective) otherVariables.get("objective"); - } + }*/ + return objective; } public void setObjective(MissionObjective objective) { - otherVariables.set("objective", objective); + //otherVariables.set("objective", objective); + this.objective = objective; } public long getBountyMarkId() { diff --git a/src/resources/objects/player/PlayerObject.java b/src/resources/objects/player/PlayerObject.java index 68080ea0..eea76495 100644 --- a/src/resources/objects/player/PlayerObject.java +++ b/src/resources/objects/player/PlayerObject.java @@ -92,6 +92,7 @@ public class PlayerObject extends IntangibleObject implements Serializable { baseline.put("lotsRemaining", 10); baseline.put("holoEmote", ""); baseline.put("holoEmoteUses", 0); + baseline.put("activeMissions", new ArrayList()); // TODO: Look at MissionCriticalObject in CREO4, could use that instead of this return baseline; } @@ -927,6 +928,19 @@ public class PlayerObject extends IntangibleObject implements Serializable { return false; } + public void addActiveMission(long missionObjId) { + getActiveMissions().add(missionObjId); + } + + public void removeActiveMission(long missionObjId) { + getActiveMissions().remove(missionObjId); + } + + @SuppressWarnings("unchecked") + public List getActiveMissions() { + return (List) otherVariables.get("activeMissions"); + } + public boolean isCallingCompanion() { synchronized(objectMutex) { return callingCompanion; diff --git a/src/services/StaticService.java b/src/services/StaticService.java index d0c93c5a..e943ffb1 100644 --- a/src/services/StaticService.java +++ b/src/services/StaticService.java @@ -36,6 +36,7 @@ import java.util.Map; import resources.common.FileUtilities; import resources.objects.building.BuildingObject; import resources.objects.cell.CellObject; +import resources.objects.creature.CreatureObject; import services.ai.AIActor; import services.spawn.MobileTemplate; import main.NGECore; @@ -214,6 +215,27 @@ public class StaticService implements INetworkDispatch { return object; } + /** + * Used for spawning a commoner that can be used for a variety of mission types, like delivery and crafting missions. + */ + public CreatureObject spawnCommoner(String template, String planetName, long cellId, float x, float y, float z, float qW, float qX, float qY, float qZ) { + CreatureObject commoner = (CreatureObject) spawnObject(template, planetName, cellId, x, y, z, qW, qX, qY, qZ); + + if (commoner == null) + return null; + + commoner.setAttachment("conversationFile", "missions/deliver"); + commoner.setAttachment("radial_filename", "object/conversation"); + commoner.setOptionsBitmask(264); + + core.missionService.addCommoner(commoner); + return commoner; + } + + public CreatureObject spawnCommoner(String template, String planetName, long cellId, float x, float y, float z, float qY, float qW) { + return spawnCommoner(template, planetName, cellId, x, y, z, qW, 0, qY, 0); + } + public List getCloningFacilitiesByPlanet(Planet planet) { List objects = core.simulationService.get(planet, 0, 0, 8300); List cloners = new ArrayList(); diff --git a/src/services/mission/CommonerSpawn.java b/src/services/mission/CommonerSpawn.java new file mode 100644 index 00000000..f49999f8 --- /dev/null +++ b/src/services/mission/CommonerSpawn.java @@ -0,0 +1,51 @@ +/******************************************************************************* + * Copyright (c) 2013 + * + * This File is part of NGECore2. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program. If not, see . + * + * Using NGEngine to work with NGECore2 is making a combined work based on NGEngine. + * Therefore all terms and conditions of the GNU Lesser General Public License cover the combination. + ******************************************************************************/ +package services.mission; + +import engine.resources.scene.Point3D; + +public class CommonerSpawn { + private long objectId; + private Point3D position; + + public CommonerSpawn(long objectId, Point3D position) { + this.objectId = objectId; + this.position = position; + } + + public long getObjectId() { + return objectId; + } + + public void setObjectId(long objectId) { + this.objectId = objectId; + } + + public Point3D getLocation() { + return position; + } + + public void setLocation(Point3D position) { + this.position = position; + } + +} diff --git a/src/services/mission/MissionService.java b/src/services/mission/MissionService.java index 9db4b42a..f5fcfa09 100644 --- a/src/services/mission/MissionService.java +++ b/src/services/mission/MissionService.java @@ -46,6 +46,7 @@ import protocol.swg.objectControllerObjects.MissionListRequest; import resources.common.BountyListItem; import resources.common.SpawnPoint; import resources.common.ObjControllerOpcodes; +import services.mission.CommonerSpawn; import resources.objectives.BountyMissionObjective; import resources.objectives.DeliveryMissionObjective; import resources.objectives.DestroyMissionObjective; @@ -75,12 +76,12 @@ public class MissionService implements INetworkDispatch { // Use a HashMap for obtaining number of entries so we aren't using a visitor all the time. private Map entryCounts = new ConcurrentHashMap(); private Map bountyMap = new ConcurrentHashMap(); + private Map> commonerMap = new ConcurrentHashMap>(); private ObjectDatabase bountiesODB; private Random ran = new Random(); public MissionService(NGECore core) { this.core = core; - try { nameGenerator = new NameGen("names.txt"); } catch (IOException e) { e.printStackTrace(); } @@ -223,6 +224,9 @@ public class MissionService implements INetworkDispatch { * @param silent If true, called the MissionObjective.abort() method, otherwise it simply destroys the mission (false) */ public void handleMissionAbort(CreatureObject creature, MissionObject mission, boolean silent) { + + creature.getPlayerObject().removeActiveMission(mission.getObjectID()); + MissionObjective objective = mission.getObjective(); if (objective != null && !silent) @@ -307,7 +311,8 @@ public class MissionService implements INetworkDispatch { randomBountyMission(player, mission); else if (type == TerminalType.ARTISAN) - randomSurveyMission(player, mission); + return; + //randomSurveyMission(player, mission); else return; @@ -337,12 +342,17 @@ public class MissionService implements INetworkDispatch { } public void handleMissionComplete(CreatureObject creature, MissionObject mission) { + + creature.getPlayerObject().removeActiveMission(mission.getObjectID()); + MissionObjective objective = mission.getObjective(); if (objective == null) return; objective.complete(core, creature); + + core.objectService.destroyObject(mission.getObjectId()); } private boolean handleMissionAccept(CreatureObject creature, MissionObject mission) { @@ -388,6 +398,7 @@ public class MissionService implements INetworkDispatch { mission.setPlanetId(creature.getPlanetId()); } + creature.getPlayerObject().addActiveMission(mission.getObjectID()); missionBag.transferTo(creature, datapad, mission); createMissionObjective(creature, mission); return true; @@ -443,7 +454,7 @@ public class MissionService implements INetworkDispatch { return null; } } - private void randomSurveyMission(SWGObject player, MissionObject mission) { + /*private void randomSurveyMission(SWGObject player, MissionObject mission) { byte generalType = (byte) (ran.nextInt(3) == 0 ? 1 : 0); @@ -496,9 +507,38 @@ public class MissionService implements INetworkDispatch { mission.setTemplateObject(CRC.StringtoCRC(ResourceRoot.CONTAINER_TYPE_IFF_SIGNIFIER[family.getContainerType()])); // This should be the resource container obj mission.setTargetName(family.getResourceType() + family.getResourceClass()); - } + }*/ private void randomDeliveryMission(SWGObject player, MissionObject mission) { + if (!commonerMap.containsKey(player.getPlanet().name)) + return; + + Vector spawns = commonerMap.get(player.getPlanet().name); + Point3D playerLocation = player.getWorldPosition(); + MissionLocation startLocation = null; + MissionLocation destinationLocation = null; + + Random randomSpawn = new Random(10); + // TODO: There is probably a much better way of doing this. + for (CommonerSpawn spawn : spawns) { + if (randomSpawn.nextInt() >= 5) { + continue; + } + + float distance = playerLocation.getDistance2D(spawn.getLocation()); + if (distance <= 500 && startLocation == null) { + startLocation = new MissionLocation(spawn.getLocation(), spawn.getObjectId(), player.getPlanet().name); + } else if (distance <= 2500 && destinationLocation == null) { + destinationLocation = new MissionLocation(spawn.getLocation(), spawn.getObjectId(), player.getPlanet().name); + } + + if (destinationLocation != null && startLocation != null) + break; + } + + if (startLocation == null || destinationLocation == null) + return; + mission.setMissionType("deliver"); String[] difficulties = { "easy", "medium", "hard" }; @@ -513,14 +553,9 @@ public class MissionService implements INetworkDispatch { mission.setDifficultyLevel(5); - // TODO: Use pre-defined commoner locations - Point3D startLocation = SpawnPoint.getRandomPosition(player.getPosition(), (float) 50, (float) 300, player.getPlanetId()); - Point3D destination = SpawnPoint.getRandomPosition(startLocation, (float) 50, (float) 500, player.getPlanetId()); - - mission.setStartLocation(startLocation, 0, player.getPlanet().name); - mission.setDestinationLocation(destination, 0, player.getPlanet().name); - - mission.setCreditReward((int) (200 + ((startLocation.getDistance2D(destination) / 10)))); + mission.setStartLocation(startLocation); + mission.setDestinationLocation(destinationLocation); + mission.setCreditReward((int) (200 + ((startLocation.getLocation().getDistance2D(destinationLocation.getLocation()) / 10)))); mission.setTemplateObject(CRC.StringtoCRC("object/tangible/mission/shared_mission_datadisk.iff")); mission.setTargetName("Datadisk"); @@ -654,6 +689,17 @@ public class MissionService implements INetworkDispatch { return true; } + public void addCommoner(SWGObject commoner) { + CommonerSpawn commonerSpawn = new CommonerSpawn(commoner.getObjectId(), commoner.getPosition()); + if (commonerMap.containsKey(commoner.getPlanet().name)) + commonerMap.get(commoner.getPlanet().name).add(commonerSpawn); + else { + commonerMap.put(commoner.getPlanet().name, new Vector()); + commonerMap.get(commoner.getPlanet().name).add(commonerSpawn); + } + + } + public boolean removeBounty(long bountyTarget, boolean listRemove) { if (listRemove) bountyMap.remove(bountyTarget);