diff --git a/src/resources/objectives/BountyMissionObjective.java b/src/resources/objectives/BountyMissionObjective.java index a2d81812..bd5d7a87 100644 --- a/src/resources/objectives/BountyMissionObjective.java +++ b/src/resources/objectives/BountyMissionObjective.java @@ -298,20 +298,20 @@ public class BountyMissionObjective extends MissionObjective { return; } - WaypointObject missionWp = mission.getAttachedWaypoint(); + WaypointObject missionWp = mission.getWaypoint(); - if (missionWp == null) { - WaypointObject waypoint = (WaypointObject) NGECore.getInstance().objectService.createObject("object/waypoint/shared_waypoint.iff", target.getPlanet(), - target.getWorldPosition().x, target.getWorldPosition().z, target.getWorldPosition().y); + if (missionWp.getPlanetCRC() != CRC.StringtoCRC(target.getPlanet().name)) { + WaypointObject waypoint = (WaypointObject) getMissionObject().getWaypoint(); waypoint.setActive(true); waypoint.setColor(WaypointObject.ORANGE); - waypoint.setName(getMissionObject().getMissionTargetName()); + waypoint.setName(getMissionObject().getTargetName()); waypoint.setPlanetCRC(CRC.StringtoCRC(target.getPlanet().getName())); waypoint.setStringAttribute("", ""); - getMissionObject().setAttachedWaypoint(waypoint); + getMissionObject().setWaypoint(waypoint); } else { missionWp.setPosition(target.getWorldPosition()); - mission.setAttachedWaypoint(missionWp); + mission.setWaypoint(missionWp); + getMissionObject().setWaypoint(missionWp); } actor.sendSystemMessage("@mission/mission_generic:target_location_updated_ground", DisplayType.Broadcast); actor.sendSystemMessage("@mission/mission_generic:target_continue_tracking", DisplayType.Broadcast); @@ -327,7 +327,7 @@ public class BountyMissionObjective extends MissionObjective { public void beginArakydUpdate(final CreatureObject actor) { arakydActive = true; Executors.newScheduledThreadPool(1).schedule(() -> { - + int number = new Random().nextInt(100); // Effectively a 16% chance of failing. The failure type is calculated by subtracting 10 from the number received. @@ -340,14 +340,15 @@ public class BountyMissionObjective extends MissionObjective { target.getWorldPosition().x, target.getWorldPosition().z, target.getWorldPosition().y); waypoint.setActive(true); waypoint.setColor(WaypointObject.ORANGE); - waypoint.setName(getMissionObject().getMissionTargetName()); + waypoint.setName(getMissionObject().getTargetName()); waypoint.setPlanetCRC(CRC.StringtoCRC(target.getPlanet().getName())); waypoint.setStringAttribute("", ""); - getMissionObject().setAttachedWaypoint(waypoint); + + actor.getClient().getSession().write(getMissionObject().getBaseline3().set("waypoint", waypoint)); actor.sendSystemMessage("@mission/mission_generic:target_location_updated_ground", DisplayType.Broadcast); actor.sendSystemMessage("@mission/mission_generic:target_located_" + target.getPlanet().getName(), DisplayType.Broadcast); - + }, 180, TimeUnit.SECONDS); } diff --git a/src/resources/objectives/DeliveryMissionObjective.java b/src/resources/objectives/DeliveryMissionObjective.java index 96f9b583..b2ae62a6 100644 --- a/src/resources/objectives/DeliveryMissionObjective.java +++ b/src/resources/objectives/DeliveryMissionObjective.java @@ -21,6 +21,7 @@ ******************************************************************************/ package resources.objectives; +import engine.resources.common.CRC; import engine.resources.scene.Point3D; import main.NGECore; import resources.common.OutOfBand; @@ -51,8 +52,8 @@ public class DeliveryMissionObjective extends MissionObjective { String template = "object/mobile/shared_dressed_commoner_tatooine_sullustan_male_06.iff"; - Point3D startLoc = parent.getStartLocation(); - Point3D destination = parent.getDestination(); + 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); @@ -78,19 +79,22 @@ public class DeliveryMissionObjective extends MissionObjective { setDropOffNpc(dropOffNpc); if (getObjectivePhase() == 0) { - WaypointObject waypoint = (WaypointObject) core.objectService.createObject("object/waypoint/shared_waypoint.iff", parent.getPlanet()); + WaypointObject waypoint = getMissionObject().getWaypoint(); + //waypoint.setPlanet(missionGiver.getPlanet()); + waypoint.setPlanetCRC(CRC.StringtoCRC(missionGiver.getPlanet().name)); waypoint.setPosition(startLoc); - waypoint.setName("@mission/" + parent.getMissionTitle() + ":" + "m" + parent.getMissionId() + "t"); + waypoint.setName("@" + parent.getTitle().getStfFilename() + ":" + "m" + parent.getMissionId() + "t"); waypoint.setColor(WaypointObject.ORANGE); waypoint.setActive(true); - getMissionObject().setAttachedWaypoint(waypoint); + getMissionObject().setWaypoint(waypoint); } else if (getObjectivePhase() == 1) { - WaypointObject waypoint = (WaypointObject) core.objectService.createObject("object/waypoint/shared_waypoint.iff", parent.getPlanet()); - waypoint.setPosition(parent.getDestination()); - waypoint.setName("@mission/" + parent.getMissionTitle() + ":" + "m" + parent.getMissionId() + "t"); + WaypointObject waypoint = getMissionObject().getWaypoint(); + waypoint.setPlanetCRC(CRC.StringtoCRC(dropOffNpc.getPlanet().name)); + waypoint.setPosition(destination); + waypoint.setName("@" + parent.getTitle().getStfFilename() + ":" + "m" + parent.getMissionId() + "t"); waypoint.setColor(WaypointObject.ORANGE); waypoint.setActive(true); - getMissionObject().setAttachedWaypoint(waypoint); + getMissionObject().setWaypoint(waypoint); } setActive(true); @@ -130,22 +134,21 @@ public class DeliveryMissionObjective extends MissionObjective { switch(getObjectivePhase()) { case 1: WaypointObject waypoint = (WaypointObject) core.objectService.createObject("object/waypoint/shared_waypoint.iff", parent.getPlanet()); - waypoint.setPosition(parent.getDestination()); - waypoint.setName("@mission/" + parent.getMissionTitle() + ":" + "m" + parent.getMissionId() + "t"); + waypoint.setPosition(parent.getDestinationLocation().getLocation()); + waypoint.setName("@" + parent.getTitle().getStfFilename() + ":" + "m" + parent.getMissionId() + "t"); waypoint.setColor(WaypointObject.ORANGE); waypoint.setActive(true); - getMissionObject().setMissionTargetName("Dropoff Location"); - getMissionObject().setAttachedWaypoint(waypoint); - System.out.println("Waypoint set to " + parent.getDestination().x + " and " + parent.getDestination().z); + getMissionObject().setTargetName("Dropoff Location"); + getMissionObject().setWaypoint(waypoint); break; case 2: WaypointObject returnWp = (WaypointObject) core.objectService.createObject("object/waypoint/shared_waypoint.iff", parent.getPlanet()); - returnWp.setPosition(parent.getStartLocation()); - returnWp.setName("@mission/" + parent.getMissionTitle() + ":" + "m" + parent.getMissionId() + "t"); + returnWp.setPosition(parent.getStartLocation().getLocation()); + returnWp.setName("@" + parent.getTitle().getStfFilename() + ":" + "m" + parent.getMissionId() + "t"); returnWp.setColor(WaypointObject.ORANGE); returnWp.setActive(true); - getMissionObject().setMissionTargetName("Return"); - getMissionObject().setAttachedWaypoint(returnWp); + getMissionObject().setTargetName("Return"); + getMissionObject().setWaypoint(returnWp); break; } } @@ -160,7 +163,7 @@ public class DeliveryMissionObjective extends MissionObjective { if (inventory == null) return false; - TangibleObject deliveryObject = (TangibleObject) core.objectService.createObject("object/tangible/mission/shared_mission_datadisk.iff", getMissionObject().getGrandparent().getPlanet()); + TangibleObject deliveryObject = (TangibleObject) core.objectService.createObject("object/tangible/mission/shared_mission_datadisk.iff", player.getPlanet()); if (deliveryObject != null && inventory.add(deliveryObject)) { setDeliveryObject(deliveryObject); diff --git a/src/resources/objectives/SurveyMissionObjective.java b/src/resources/objectives/SurveyMissionObjective.java index 025b15bf..67c0c3fe 100644 --- a/src/resources/objectives/SurveyMissionObjective.java +++ b/src/resources/objectives/SurveyMissionObjective.java @@ -47,7 +47,7 @@ public class SurveyMissionObjective extends MissionObjective{ public void activate(NGECore core, CreatureObject player) { pickupPlanet = player.getPlanet().getName(); pickupLocation = player.getPosition(); - resourceFamily = getMissionObject().getMissionTargetName(); + resourceFamily = getMissionObject().getTargetName(); // This way will allow 2 survey missions at a time. AtomicInteger number = new AtomicInteger(); diff --git a/src/resources/objects/mission/MissionMessageBuilder.java b/src/resources/objects/mission/MissionMessageBuilder.java index 22431c85..4166aeca 100644 --- a/src/resources/objects/mission/MissionMessageBuilder.java +++ b/src/resources/objects/mission/MissionMessageBuilder.java @@ -21,16 +21,9 @@ ******************************************************************************/ package resources.objects.mission; -import java.nio.ByteOrder; import java.util.Map; - -import org.apache.mina.core.buffer.IoBuffer; - -import engine.resources.common.CRC; import engine.resources.objects.Builder; -import engine.resources.scene.Point3D; import resources.objects.intangible.IntangibleMessageBuilder; -import resources.objects.waypoint.WaypointObject; public class MissionMessageBuilder extends IntangibleMessageBuilder { @@ -42,363 +35,6 @@ public class MissionMessageBuilder extends IntangibleMessageBuilder { super(); } - public IoBuffer buildBaseline3() { - MissionObject mission = (MissionObject) object; - IoBuffer buffer = IoBuffer.allocate(100, false).order(ByteOrder.LITTLE_ENDIAN); - buffer.setAutoExpand(true); - - buffer.putShort((short) 16); - - buffer.putFloat(object.getComplexity()); // mission complexity ?? - - buffer.put(getAsciiString(object.getStfFilename())); - buffer.putInt(0); - buffer.put(getAsciiString(object.getStfName())); - - if (mission.getCustomName() == null) { buffer.putInt(0); } - else { buffer.put(getUnicodeString(mission.getCustomName())); } - - buffer.putInt(object.getVolume()); // volume - - buffer.putInt(0); // unused - - buffer.putInt(mission.getMissionLevel()); - - if (mission.getStartLocation() != null) { - buffer.putFloat(mission.getStartLocation().x); - buffer.putFloat(0); - buffer.putFloat(mission.getStartLocation().z); - } else { - buffer.putFloat(0); - buffer.putFloat(0); - buffer.putFloat(0); - } - buffer.putLong(0); // Start Object ID - if (mission.getMissionStartPlanet() == null) - buffer.putInt(0); - else - buffer.putInt(CRC.StringtoCRC(mission.getMissionStartPlanet())); - - if (mission.getCreator() != null) - buffer.put(getUnicodeString(mission.getCreator())); - else - buffer.putInt(0); - - buffer.putInt(mission.getCreditReward()); - - if (mission.getDestination() != null) { - buffer.putFloat(mission.getDestination().x); - buffer.putFloat(0); - buffer.putFloat(mission.getDestination().z); - } else { - buffer.putFloat(0); - buffer.putFloat(0); - buffer.putFloat(0); - } - buffer.putLong(0); // Destination Object ID - if (mission.getMissionDestinationPlanet() == null) - buffer.putInt(0); - else - buffer.putInt(CRC.StringtoCRC(mission.getMissionDestinationPlanet())); - - buffer.putInt(mission.getMissionTemplateObject()); - - buffer.put(getAsciiString(mission.getMissionStf())); - buffer.putInt(0); - buffer.put(getAsciiString(mission.getMissionDescription())); - - buffer.put(getAsciiString(mission.getMissionStf())); - buffer.putInt(0); - buffer.put(getAsciiString(mission.getMissionTitle())); - - buffer.putInt(0); // refresh counter - - if(mission.getMissionType() == null) - buffer.putInt(0); - else - buffer.putInt(CRC.StringtoCRC(mission.getMissionType())); - - buffer.put(getAsciiString(mission.getMissionTargetName())); - - WaypointObject wp = mission.getAttachedWaypoint(); - - if (wp == null) { - buffer.putInt(0); // cell - buffer.putFloat(0); // x - buffer.putFloat(0); // z - buffer.putFloat(0); // y - buffer.putLong(0); // target id - buffer.putInt(0); // planet crc - buffer.putInt(0); // name - buffer.putLong(0); // waypoint id - buffer.put((byte) 0); // color - buffer.put((byte) 0x01); //active - } else { - buffer.putInt(wp.getCellId()); - buffer.putFloat(wp.getPosition().x); - buffer.putFloat(wp.getPosition().y); - buffer.putFloat(wp.getPosition().z); - buffer.putLong(0); - buffer.putInt(CRC.StringtoCRC(wp.getPlanet().name)); - buffer.put(getUnicodeString(wp.getName())); - buffer.putLong(wp.getObjectId()); - buffer.put(wp.getColor()); - buffer.put((byte) (wp.isActive() ? 1 : 0)); - } - - int size = buffer.position(); - buffer = bufferPool.allocate(size, false).put(buffer.array(), 0, size); - - buffer.flip(); - buffer = createBaseline("MISO", (byte) 3, buffer, size); - - //Console.println("MISO3 Bytes: " + StringUtilities.bytesToHex(buffer.array())); - return buffer; - } - - public IoBuffer buildBaseline6() { - - IoBuffer buffer = IoBuffer.allocate(18, false).order(ByteOrder.LITTLE_ENDIAN); - - buffer.putShort((short) 3); - buffer.putInt(76); // server id - buffer.putLong(0); // detail stf - buffer.putInt(0xFFFFFFFF); // unknown - - int size = buffer.position(); - buffer.flip(); - buffer = createBaseline("MISO", (byte) 6, buffer, size); - - return buffer; - } - - public IoBuffer buildBaseline8() { - IoBuffer buffer = IoBuffer.allocate(2, false).order(ByteOrder.LITTLE_ENDIAN); - - buffer.putShort((short) 0); // unknown - - int size = buffer.position(); - buffer.flip(); - buffer = createBaseline("MISO", (byte) 8, buffer, size); - - return buffer; - } - - public IoBuffer buildBaseline9() { - IoBuffer buffer = IoBuffer.allocate(2, false).order(ByteOrder.LITTLE_ENDIAN); - - buffer.putShort((short) 0); // unknown - - int size = buffer.position(); - buffer.flip(); - buffer = createBaseline("MISO", (byte) 9, buffer, size); - - return buffer; - } - - public IoBuffer buildStfDelta(String stfFile, String stfName) { - - IoBuffer buffer = IoBuffer.allocate(4 + stfFile.length() + stfName.length(), false).order(ByteOrder.LITTLE_ENDIAN); - - buffer.put(getAsciiString(stfFile)); - buffer.putInt(0); - buffer.put(getAsciiString(stfName)); - - int size = buffer.position(); - buffer.flip(); - buffer = createDelta("MISO", (byte) 3, (short) 1, (short) 0x01, buffer, size + 4); - - return buffer; - } - - public IoBuffer buildDifficultyLevelDelta(int difficulty) { - - IoBuffer buffer = IoBuffer.allocate(4, false).order(ByteOrder.LITTLE_ENDIAN); - - buffer.putInt(difficulty); - - int size = buffer.position(); - buffer.flip(); - buffer = createDelta("MISO", (byte) 3, (short) 1, (short) 0x05, buffer, size + 4); - - return buffer; - } - - public IoBuffer buildStartLocationDelta(Point3D startLocation, String planet) { - - IoBuffer buffer = IoBuffer.allocate(24, false).order(ByteOrder.LITTLE_ENDIAN); - - buffer.putFloat(startLocation.x); - buffer.putFloat(0); - buffer.putFloat(startLocation.z); - - buffer.putLong(0); - - if (planet == null) { - buffer.putInt(CRC.StringtoCRC(object.getPlanet().name)); - } else { - buffer.putInt(CRC.StringtoCRC(planet)); - } - int size = buffer.position(); - buffer.flip(); - buffer = createDelta("MISO", (byte) 3, (short) 1, (short) 0x06, buffer, size + 4); - - return buffer; - } - - public IoBuffer buildCreatorNameDelta(String creator) { - - IoBuffer buffer = IoBuffer.allocate(4 + (creator.length() * 2), false).order(ByteOrder.LITTLE_ENDIAN); - - buffer.put(getUnicodeString(creator)); - - int size = buffer.position(); - buffer.flip(); - buffer = createDelta("MISO", (byte) 3, (short) 1, (short) 0x07, buffer, size + 4); - - return buffer; - } - - public IoBuffer buildCreditsRewardDelta(int creds) { - - IoBuffer buffer = IoBuffer.allocate(4, false).order(ByteOrder.LITTLE_ENDIAN); - - buffer.putInt(creds); - - int size = buffer.position(); - buffer.flip(); - buffer = createDelta("MISO", (byte) 3, (short) 1, (short) 0x08, buffer, size + 4); - - return buffer; - } - - public IoBuffer buildDestinationDelta(Point3D destination, String planet) { - - IoBuffer buffer = IoBuffer.allocate(24, false).order(ByteOrder.LITTLE_ENDIAN); - - buffer.putFloat(destination.x); - buffer.putFloat(0); - buffer.putFloat(destination.z); - - buffer.putLong(0); // Destination Object ID - - if (planet == null) { - buffer.putInt(CRC.StringtoCRC(object.getPlanet().name)); - } else { - buffer.putInt(CRC.StringtoCRC(planet)); - } - - int size = buffer.position(); - buffer.flip(); - buffer = createDelta("MISO", (byte) 3, (short) 1, (short) 0x09, buffer, size + 4); - - return buffer; - } - - public IoBuffer buildTargetObjectIffDelta(int template) { - - IoBuffer buffer = IoBuffer.allocate(4, false).order(ByteOrder.LITTLE_ENDIAN); - - buffer.putInt(template); - - int size = buffer.position(); - buffer.flip(); - buffer = createDelta("MISO", (byte) 3, (short) 1, (short) 0x0A, buffer, size + 4); - - return buffer; - } - - public IoBuffer buildMissionDescriptionDelta(String stfFile, String descId) { - - IoBuffer buffer = IoBuffer.allocate(13 + stfFile.length() + descId.length(), false).order(ByteOrder.LITTLE_ENDIAN); - - buffer.put(getAsciiString(stfFile)); - buffer.putInt(0); - buffer.put(getAsciiString(descId)); - - int size = buffer.position(); - buffer.flip(); - buffer = createDelta("MISO", (byte) 3, (short) 1, (short) 0x0B, buffer, size + 4); - - return buffer; - } - - public IoBuffer buildMissionTitleDelta(String stfFile, String titleId) { - - IoBuffer buffer = IoBuffer.allocate(12 + stfFile.length() + titleId.length(), false).order(ByteOrder.LITTLE_ENDIAN); - - buffer.put(getAsciiString(stfFile)); - buffer.putInt(0); - buffer.put(getAsciiString(titleId)); - - int size = buffer.position(); - buffer.flip(); - buffer = createDelta("MISO", (byte) 3, (short) 1, (short) 0x0C, buffer, size + 4); - - return buffer; - } - - public IoBuffer buildRepeatCounterDelta(int counter) { - - IoBuffer buffer = IoBuffer.allocate(4, false).order(ByteOrder.LITTLE_ENDIAN); - - buffer.putInt(counter); - - int size = buffer.position(); - buffer.flip(); - buffer = createDelta("MISO", (byte) 3, (short) 1, (short) 0x0D, buffer, size + 4); - - return buffer; - } - - public IoBuffer buildMissionTypeDelta(String type) { - - IoBuffer buffer = IoBuffer.allocate(4, false).order(ByteOrder.LITTLE_ENDIAN); - - buffer.putInt(CRC.StringtoCRC(type)); - - int size = buffer.position(); - buffer.flip(); - buffer = createDelta("MISO", (byte) 3, (short) 1, (short) 0x0E, buffer, size + 4); - - return buffer; - } - - public IoBuffer buildTargetNameDelta(String targetName) { - - IoBuffer buffer = IoBuffer.allocate(4 + targetName.length(), false).order(ByteOrder.LITTLE_ENDIAN); - - buffer.put(getAsciiString(targetName)); - - int size = buffer.position(); - buffer.flip(); - buffer = createDelta("MISO", (byte) 3, (short) 1, (short) 0x0F, buffer, size + 4); - - return buffer; - } - - public IoBuffer buildWaypointDelta(WaypointObject wp) { - - IoBuffer buffer = IoBuffer.allocate(44 + (2 * wp.getName().length()), false).order(ByteOrder.LITTLE_ENDIAN); - - buffer.putInt(wp.getCellId()); - buffer.putFloat(wp.getPosition().x); - buffer.putFloat(wp.getPosition().y); - buffer.putFloat(wp.getPosition().z); - buffer.putLong(0); - buffer.putInt(CRC.StringtoCRC(wp.getPlanet().name)); - buffer.put(getUnicodeString(wp.getName())); - buffer.putLong(wp.getObjectId()); - buffer.put(wp.getColor()); - buffer.put((byte) (wp.isActive() ? 1 : 0)); - - int size = buffer.position(); - buffer.flip(); - buffer = createDelta("MISO", (byte) 3, (short) 1, (short) 0x10, buffer, size + 4); - - return buffer; - } - @Override public void buildBaseline3(Map baselineBuilders, Map deltaBuilders) { super.buildBaseline3(baselineBuilders, deltaBuilders); diff --git a/src/resources/objects/mission/MissionObject.java b/src/resources/objects/mission/MissionObject.java index e6640a05..cb0918f3 100644 --- a/src/resources/objects/mission/MissionObject.java +++ b/src/resources/objects/mission/MissionObject.java @@ -22,45 +22,37 @@ package resources.objects.mission; import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; -import com.sleepycat.persist.model.NotPersistent; -import com.sleepycat.persist.model.Persistent; +import org.apache.mina.core.buffer.IoBuffer; -import resources.objects.ObjectMessageBuilder; +import main.NGECore; import resources.objects.intangible.IntangibleObject; import resources.objects.waypoint.WaypointObject; +import services.mission.MissionLocation; import services.mission.MissionObjective; import engine.clients.Client; +import engine.resources.common.CRC; +import engine.resources.common.Stf; +import engine.resources.common.StringUtilities; +import engine.resources.common.UString; +import engine.resources.objects.Baseline; import engine.resources.scene.Planet; import engine.resources.scene.Point3D; import engine.resources.scene.Quaternion; -@Persistent(version=1) public class MissionObject extends IntangibleObject implements Serializable { private static final long serialVersionUID = 1L; - private Point3D destination; - private Point3D startLocation; - private String startPlanet = ""; - private int difficultyLevel = 0; // Difficulty level displayed in details - private String destinationPlanet = ""; - private int repeatCount = 0; // increases for each player using the mission; used for redisplaying on mission term too - private int reward = 0; - private String creator = ""; - private String description = ""; - private String title = ""; - private String missionTargetName = ""; // Target object I guess? - private int missionId = 0; - private String missionStf = ""; - private String type = ""; - private int missionTemplateObject = 0; - private WaypointObject attachedWaypoint; - + // Server variables private MissionObjective objective; private long bountyObjId; + private String missionType = ""; + private int missionId; - @NotPersistent private transient MissionMessageBuilder messageBuilder = new MissionMessageBuilder(this); public MissionObject() { @@ -71,221 +63,190 @@ public class MissionObject extends IntangibleObject implements Serializable { super(objectID, planet, new Point3D(0, 0, 0), new Quaternion(1, 0, 0, 0), template); } - public String getMissionDestinationPlanet() { - synchronized(objectMutex) { - return destinationPlanet; - } + public Baseline getBaseline3() { + Baseline baseline = super.getBaseline3(); + baseline.put("difficultyLevel", 0); + baseline.put("startLocation", new MissionLocation(new Point3D(0,0,0), 0, "tatooine")); + baseline.put("creator", new UString("")); + baseline.put("creditReward", 0); + baseline.put("destinationLocation", new MissionLocation(new Point3D(0,0,0), 0, "tatooine")); + baseline.put("templateObject", 0); + baseline.put("description", new Stf("", 0, "")); + baseline.put("title", new Stf("", 0, "")); + baseline.put("repeatCounter", 0); + baseline.put("missionType", 0); + baseline.put("targetName", ""); + + WaypointObject wp = (WaypointObject) NGECore.getInstance().objectService.createObject("object/waypoint/base/shared_base_waypoint.iff", getPlanet()); + wp.setActive(true); + baseline.put("waypoint", wp); + return baseline; + } + + public Baseline getBaseline6() { + Baseline baseline = super.getBaseline6(); + baseline.put("unk", -1); + return baseline; + } + + public Baseline getBaseline8() { + Baseline baseline = super.getBaseline8(); + return baseline; + } + + public Baseline getBaseline9() { + Baseline baseline = super.getBaseline9(); + return baseline; } @Override public void initAfterDBLoad() { super.init(); messageBuilder = new MissionMessageBuilder(this); - if(attachedWaypoint != null) - attachedWaypoint.initAfterDBLoad(); } - - public int getMissionLevel() { - synchronized(objectMutex) { - return difficultyLevel; + + public int getDifficultyLevel() { + return (int) getBaseline3().get("difficultyLevel"); + } + + public void setDifficultyLevel(int level) { + if (getGrandparent() != null && getGrandparent().getClient() != null) { + getBaseline(3).set("difficultyLevel", level); } } - - public void setMissionLevel(int missionLevel) { - synchronized(objectMutex) { - this.difficultyLevel = missionLevel; - } - if (getGrandparent() != null && getGrandparent().getClient() != null && getGrandparent().getClient().getSession() != null) { - getGrandparent().getClient().getSession().write(messageBuilder.buildDifficultyLevelDelta(missionLevel)); + + public MissionLocation getStartLocation() { + return (MissionLocation) getBaseline3().get("startLocation"); + } + + public void setStartLocation(Point3D location, long objId, String planet) { + if (getGrandparent() != null && getGrandparent().getClient() != null) { + MissionLocation startLocation = new MissionLocation(location.clone(), objId, planet); + getBaseline(3).set("startLocation", startLocation); } } - - public String getMissionStartPlanet() { - synchronized(objectMutex) { - return startPlanet; - } - } - - public int getMissionRepeatCounter() { - synchronized(objectMutex) { - return repeatCount; - } - } - - public void setRepeatCount(int missionRepeatCounter) { - synchronized(objectMutex) { - this.repeatCount = missionRepeatCounter; - } - if (getGrandparent() != null && getGrandparent().getClient() != null && getGrandparent().getClient().getSession() != null) { - getGrandparent().getClient().getSession().write(messageBuilder.buildRepeatCounterDelta(missionRepeatCounter)); - } - } - - public int getCreditReward() { - synchronized(objectMutex) { - return reward; - } - } - - public void setCreditReward(int missionCredits) { - synchronized(objectMutex) { - this.reward = missionCredits; - } - if (getGrandparent() != null && getGrandparent().getClient() != null && getGrandparent().getClient().getSession() != null) { - getGrandparent().getClient().getSession().write(messageBuilder.buildCreditsRewardDelta(missionCredits)); - } - } - + public String getCreator() { - synchronized(objectMutex) { - return creator; + return ((UString)getBaseline3().get("creator")).get(); + } + + public void setCreator(String creator) { + if (getGrandparent() != null && getGrandparent().getClient() != null) { + getGrandparent().getClient().getSession().write(getBaseline3().set("creator", new UString(creator))); } } - - public void setCreator(String missionCreator) { - synchronized(objectMutex) { - this.creator = missionCreator; - } - if (getGrandparent() != null && getGrandparent().getClient() != null && getGrandparent().getClient().getSession() != null) { - getGrandparent().getClient().getSession().write(messageBuilder.buildCreatorNameDelta(missionCreator)); + + public int getCreditReward() { + return (int) getBaseline3().get("creditReward"); + } + + public void setCreditReward(int credits) { + if (getGrandparent() != null && getGrandparent().getClient() != null) { + getGrandparent().getClient().getSession().write(getBaseline3().set("creditReward", credits)); } } - - public String getMissionDescription() { - synchronized(objectMutex) { - return description; + + public MissionLocation getDestinationLocation() { + return (MissionLocation) getBaseline3().get("destinationLocation"); + } + + public void setDestinationLocation(Point3D location, long objId, String planet) { + if (getGrandparent() != null && getGrandparent().getClient() != null) { + MissionLocation destinationLocation = new MissionLocation(location.clone(), objId, planet); + getGrandparent().getClient().getSession().write(getBaseline3().set("destinationLocation", destinationLocation)); } } - - public void setMissionDescription(String missionDescription) { - synchronized(objectMutex) { - this.description = missionDescription; - } - if (getGrandparent() != null && getGrandparent().getClient() != null && getGrandparent().getClient().getSession() != null) { - getGrandparent().getClient().getSession().write(messageBuilder.buildMissionDescriptionDelta(missionStf, missionDescription)); + + public int getTemplateObject() { + return (int) getBaseline3().get("templateObject"); + } + + public void setTemplateObject(int objCRC) { + if (getGrandparent() != null && getGrandparent().getClient() != null) { + getGrandparent().getClient().getSession().write(getBaseline3().set("templateObject", objCRC)); } } - - public String getMissionTitle() { - synchronized(objectMutex) { - return title; + + public Stf getDescription() { + return (Stf) getBaseline3().get("description"); + } + + public void setDescription(String description) { + if (getGrandparent() != null && getGrandparent().getClient() != null) { + getGrandparent().getClient().getSession().write(getBaseline3().set("description", new Stf(description))); } } - - public void setMissionTitle(String missionTitle) { - synchronized(objectMutex) { - this.title = missionTitle; - } - if (getGrandparent() != null && getGrandparent().getClient() != null && getGrandparent().getClient().getSession() != null) { - getGrandparent().getClient().getSession().write(messageBuilder.buildMissionTitleDelta(missionStf, missionTitle)); + + public Stf getTitle() { + return (Stf) getBaseline3().get("title"); + } + + public void setTitle(String title) { + if (getGrandparent() != null && getGrandparent().getClient() != null) { + getGrandparent().getClient().getSession().write(getBaseline3().set("title", new Stf(title))); } } - - public String getMissionTargetName() { - synchronized(objectMutex) { - return missionTargetName; + + public int getRepeatCounter() { + return (int) getBaseline3().get("repeatCounter"); + } + + public void setRepeatCounter(int count) { + if (getGrandparent() != null && getGrandparent().getClient() != null) { + getGrandparent().getClient().getSession().write(getBaseline3().set("repeatCounter", count)); } } - - public void setMissionTargetName(String missionTargetName) { - synchronized(objectMutex) { - this.missionTargetName = missionTargetName; - } - if (getGrandparent() != null && getGrandparent().getClient() != null && getGrandparent().getClient().getSession() != null) { - getGrandparent().getClient().getSession().write(messageBuilder.buildTargetNameDelta(missionTargetName)); + + public void incrementRepeatCounter() { + setRepeatCounter(getRepeatCounter() + 1); + } + + public void decrementRepeatCounter() { + int repeatCounter = getRepeatCounter() + 1; + setRepeatCounter((repeatCounter < 0) ? 0 : repeatCounter); + } + + public int getMissionTypeCRC() { + return (int) getBaseline3().get("missionType"); + } + + public void setMissionType(String type) { + if (getGrandparent() != null && getGrandparent().getClient() != null) { + getGrandparent().getClient().getSession().write(getBaseline3().set("missionType", CRC.StringtoCRC(type))); + this.missionType = type; } } - - public WaypointObject getAttachedWaypoint() { - synchronized(objectMutex) { - return attachedWaypoint; - } - } - - public void setAttachedWaypoint(WaypointObject waypoint) { - synchronized(objectMutex) { - this.attachedWaypoint = waypoint; - } - - if (getGrandparent() != null && getGrandparent().getClient() != null && getGrandparent().getClient().getSession() != null) { - getGrandparent().getClient().getSession().write(messageBuilder.buildWaypointDelta(waypoint)); - } - } - - public int getMissionTemplateObject() { - synchronized(objectMutex) { - return missionTemplateObject; - } - } - - public void setMissionTemplateObject(int missionTemplateObject) { - synchronized(objectMutex) { - this.missionTemplateObject = missionTemplateObject; - } - if (getGrandparent() != null && getGrandparent().getClient() != null && getGrandparent().getClient().getSession() != null) { - getGrandparent().getClient().getSession().write(messageBuilder.buildTargetObjectIffDelta(missionTemplateObject)); - } - } - + public String getMissionType() { - synchronized(objectMutex) { - return type; - } + return missionType; } - - public void setMissionType(String missionType) { - synchronized(objectMutex) { - this.type = missionType; - } - if (getGrandparent() != null && getGrandparent().getClient() != null && getGrandparent().getClient().getSession() != null) { - getGrandparent().getClient().getSession().write(messageBuilder.buildMissionTypeDelta(missionType)); - } + + public String getTargetName() { + return (String) getBaseline3().get("targetName"); } - - public MissionObjective getObjective() { - synchronized(objectMutex) { - return objective; - } - } - - public void setObjective(MissionObjective objective) { - synchronized(objectMutex) { - this.objective = objective; - } - } - - public Point3D getStartLocation() { - synchronized(objectMutex) { - return startLocation; + + public void setTargetName(String targetName) { + if (getGrandparent() != null && getGrandparent().getClient() != null) { + getGrandparent().getClient().getSession().write(getBaseline3().set("targetName", targetName)); } } - public Point3D getDestination() { - synchronized(objectMutex) { - return destination; - } + public WaypointObject getWaypoint() { + return (WaypointObject) getBaseline3().get("waypoint"); } - - public void setStartLocation(Point3D startLocation, String planet) { - synchronized(objectMutex) { - this.startLocation = startLocation; - this.startPlanet = planet; - } - - if (getGrandparent() != null && getGrandparent().getClient() != null && getGrandparent().getClient().getSession() != null) { - getGrandparent().getClient().getSession().write(messageBuilder.buildStartLocationDelta(startLocation, planet)); + + public void setWaypoint(WaypointObject waypoint) { + if (getGrandparent() != null && getGrandparent().getClient() != null) { + getGrandparent().getClient().getSession().write(getBaseline3().set("waypoint", waypoint)); } } - public void setDestination(Point3D destination, String planet) { - synchronized(objectMutex) { - this.destination = destination; - this.destinationPlanet = planet; - } - - if (getGrandparent() != null && getGrandparent().getClient() != null && getGrandparent().getClient().getSession() != null) { - getGrandparent().getClient().getSession().write(messageBuilder.buildDestinationDelta(destination, planet)); - } + public long getBountyMarkId() { + return bountyObjId; + } + + public void setBountyMarkId(long bountyObjId) { + this.bountyObjId = bountyObjId; } public int getMissionId() { @@ -296,38 +257,49 @@ public class MissionObject extends IntangibleObject implements Serializable { this.missionId = missionId; } - public long getBountyMarkId() { - return bountyObjId; + public MissionObjective getObjective() { + return objective; } - public void setBountyMarkId(long bountyObjId) { - this.bountyObjId = bountyObjId; - } - - public String getMissionStf() { - return missionStf; - } - - public void setMissionStf(String missionStf) { - this.missionStf = missionStf; + public void setObjective(MissionObjective objective) { + this.objective = objective; } @Override public void sendBaselines(Client destination) { - - if(destination == null || destination.getSession() == null) { - System.out.println("NULL session"); - return; + if (destination != null && destination.getSession() != null) { + destination.getSession().write(getBaseline(3).getBaseline()); + destination.getSession().write(getBaseline(6).getBaseline()); + destination.getSession().write(getBaseline(8).getBaseline()); + destination.getSession().write(getBaseline(9).getBaseline()); } - - destination.getSession().write(messageBuilder.buildBaseline3()); - destination.getSession().write(messageBuilder.buildBaseline6()); - destination.getSession().write(messageBuilder.buildBaseline8()); - destination.getSession().write(messageBuilder.buildBaseline9()); } - public ObjectMessageBuilder getMessageBuilder() { - return messageBuilder; + @Override + public void sendListDelta(byte viewType, short updateType, IoBuffer buffer) { + switch (viewType) { + case 1: + case 4: + case 3: + case 6: + case 7: + case 8: + case 9: + if (getGrandparent().getClient() != null) { + buffer = getBaseline(viewType).createDelta(updateType, buffer.array()); + getGrandparent().getClient().getSession().write(buffer); + } + default: + return; + } + } + + public MissionMessageBuilder getMessageBuilder() { + synchronized(objectMutex) { + if (messageBuilder == null) + messageBuilder = new MissionMessageBuilder(this); + + return messageBuilder; + } } - } diff --git a/src/resources/objects/waypoint/WaypointObject.java b/src/resources/objects/waypoint/WaypointObject.java index 563ae32f..189a310e 100644 --- a/src/resources/objects/waypoint/WaypointObject.java +++ b/src/resources/objects/waypoint/WaypointObject.java @@ -43,7 +43,7 @@ public class WaypointObject extends IntangibleObject implements Serializable, ID private int cellId; // ??? private long locationNetworkId; private int planetCRC; - private String name; + private String name = ""; private byte color; private boolean isActive; private transient static SimpleBufferAllocator bufferPool = new SimpleBufferAllocator(); diff --git a/src/services/mission/MissionLocation.java b/src/services/mission/MissionLocation.java new file mode 100644 index 00000000..85141267 --- /dev/null +++ b/src/services/mission/MissionLocation.java @@ -0,0 +1,88 @@ +/******************************************************************************* + * 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 org.apache.mina.core.buffer.IoBuffer; + +import engine.resources.common.CRC; +import engine.resources.objects.Delta; +import engine.resources.scene.Point3D; + +public class MissionLocation extends Delta { + + private static final long serialVersionUID = 1L; + + private Point3D location; + private long objId; + private String planet; + + public MissionLocation() { } + + public MissionLocation(Point3D location, long objId, String planet) { + this.location = location; + this.objId = objId; + this.planet = planet; + } + + public Point3D getLocation() { + return location; + } + + public void setLocation(Point3D location) { + this.location = location; + } + + public long getObjectId() { + return objId; + } + + public void setObjectId(long objId) { + this.objId = objId; + } + + public String getPlanet() { + return planet; + } + + public void setPlanet(String planet) { + this.planet = planet; + } + + public int getPlanetCRC() { + if (planet != null) + return CRC.StringtoCRC(planet); + else + return 0; + } + + @Override + public byte[] getBytes() { + IoBuffer buffer = createBuffer(24); + + buffer.putFloat(location.x); + buffer.putFloat(location.y); + buffer.putFloat(location.z); + buffer.putLong(objId); + buffer.putInt(getPlanetCRC()); + return buffer.flip().array(); + } +} diff --git a/src/services/mission/MissionService.java b/src/services/mission/MissionService.java index 809bcca8..8c6a8f77 100644 --- a/src/services/mission/MissionService.java +++ b/src/services/mission/MissionService.java @@ -312,7 +312,7 @@ public class MissionService implements INetworkDispatch { else return; - mission.setRepeatCount(requestCounter); + mission.incrementRepeatCounter(); typeOneCount.incrementAndGet(); } else if (typeTwoCount.get() < 5) { @@ -329,7 +329,7 @@ public class MissionService implements INetworkDispatch { else return; - mission.setRepeatCount(requestCounter); + mission.incrementRepeatCounter(); typeTwoCount.incrementAndGet(); } } @@ -480,21 +480,21 @@ public class MissionService implements INetworkDispatch { mission.setMissionType("survey"); String missionStf = "mission/mission_npc_survey_neutral_easy"; - mission.setMissionStf(missionStf); + mission.setMissionId(getRandomStringEntry(missionStf)); - mission.setMissionDescription("m" + mission.getMissionId() + "d"); - mission.setMissionTitle("m" + mission.getMissionId() + "t"); + mission.setDescription("@" + missionStf + ":" + "m" + mission.getMissionId() + "d"); + mission.setTitle("@" + missionStf + ":" + "m" + mission.getMissionId() + "t"); mission.setCreator(nameGenerator.compose(2) + " " + nameGenerator.compose(3)); - mission.setMissionLevel(randLevel); + mission.setDifficultyLevel(randLevel); - mission.setStartLocation(player.getPosition(), player.getPlanet().name); + mission.setStartLocation(player.getPosition(), 0, player.getPlanet().name); mission.setCreditReward(400 + (randLevel - minLevel) * 20 + ran.nextInt(100)); - mission.setMissionTemplateObject(CRC.StringtoCRC(ResourceRoot.CONTAINER_TYPE_IFF_SIGNIFIER[family.getContainerType()])); // This should be the resource container obj - mission.setMissionTargetName(family.getResourceType() + family.getResourceClass()); + mission.setTemplateObject(CRC.StringtoCRC(ResourceRoot.CONTAINER_TYPE_IFF_SIGNIFIER[family.getContainerType()])); // This should be the resource container obj + mission.setTargetName(family.getResourceType() + family.getResourceClass()); } @@ -504,26 +504,27 @@ public class MissionService implements INetworkDispatch { String[] difficulties = { "easy", "medium", "hard" }; String missionStf = "mission/mission_deliver_neutral_" + difficulties[ran.nextInt(difficulties.length)]; - mission.setMissionStf(missionStf); + mission.setMissionId(getRandomStringEntry(missionStf)); - mission.setMissionDescription("m" + mission.getMissionId() + "d"); - mission.setMissionTitle("m" + mission.getMissionId() + "t"); + mission.setDescription("@" + missionStf + ":" + "m" + mission.getMissionId() + "d"); + mission.setTitle("@" + missionStf + ":" + "m" + mission.getMissionId() + "t"); mission.setCreator(nameGenerator.compose(2) + " " + nameGenerator.compose(3)); - mission.setMissionLevel(5); + 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, player.getPlanet().name); - mission.setDestination(destination, player.getPlanet().name); + mission.setStartLocation(startLocation, 0, player.getPlanet().name); + mission.setDestinationLocation(destination, 0, player.getPlanet().name); mission.setCreditReward((int) (200 + ((startLocation.getDistance2D(destination) / 10)))); - mission.setMissionTemplateObject(CRC.StringtoCRC("object/tangible/mission/shared_mission_datadisk.iff")); - mission.setMissionTargetName("Datadisk"); + mission.setTemplateObject(CRC.StringtoCRC("object/tangible/mission/shared_mission_datadisk.iff")); + mission.setTargetName("Datadisk"); + } private void randomBountyMission(SWGObject player, MissionObject mission) { @@ -552,19 +553,18 @@ public class MissionService implements INetworkDispatch { String missionStf = "mission/mission_bounty_jedi"; - mission.setMissionStf(missionStf); if (!bountyTarget.getProfession().equals("")) { // TODO: Smuggler mission checks. if (bountyTarget.getFaction().equals("rebel")) { - mission.setMissionTargetName("Rebel Bounty"); + mission.setTargetName("Rebel Bounty"); mission.setMissionId(2); mission.setCreator("The Galactic Empire"); } else if (bountyTarget.getFaction().equals("imperial")) { - mission.setMissionTargetName("Imperial Bounty"); + mission.setTargetName("Imperial Bounty"); mission.setMissionId(1); mission.setCreator("The Alliance"); } - mission.setMissionTitle("m" + mission.getMissionId() + "t"); - mission.setMissionDescription("m" + mission.getMissionId() + "d"); + mission.setTitle("@" + missionStf + ":" + "m" + mission.getMissionId() + "t"); + mission.setDescription("@" + missionStf + ":" + "m" + mission.getMissionId() + "d"); } else { // TODO: Dead code, but place-holder for implementation of smuggler missions. if (bountyTarget.getFaction().equals("neutral")) { @@ -576,17 +576,18 @@ public class MissionService implements INetworkDispatch { else if (bountyTarget.getFaction().equals("imperial")) { mission.setMissionId(1); } - mission.setMissionTitle("m" + mission.getMissionId() + "ts"); - mission.setMissionDescription("m" + mission.getMissionId() + "ds"); + mission.setTitle("@" + missionStf + ":" + "m" + mission.getMissionId() + "ts"); + mission.setDescription("@" + missionStf + ":" + "m" + mission.getMissionId() + "ds"); } - mission.setMissionLevel(95 + bountyTarget.getFailedAttempts()); + mission.setDifficultyLevel(95 + bountyTarget.getFailedAttempts()); mission.setCreditReward(bountyTarget.getCreditReward()); - mission.setMissionTemplateObject(CRC.StringtoCRC("object/tangible/mission/shared_mission_bounty_jedi_target.iff")); + mission.setTemplateObject(CRC.StringtoCRC("object/tangible/mission/shared_mission_bounty_jedi_target.iff")); mission.setBountyMarkId(bountyTarget.getObjectID()); + } public enum TerminalType {;