From e9065c480f3a94b5a8722473597eddc2ea1d9d58 Mon Sep 17 00:00:00 2001 From: Waverunner Date: Mon, 21 Apr 2014 16:14:29 -0400 Subject: [PATCH] Randomize mission strings, foundation for objectives --- src/main/NGECore.java | 2 +- .../objectives/DeliveryMissionObjective.java | 53 +++++++ .../objects/mission/MissionObject.java | 15 +- src/services/mission/MissionObjective.java | 45 ++++++ .../{ => mission}/MissionService.java | 147 ++++++++++++------ 5 files changed, 212 insertions(+), 50 deletions(-) create mode 100644 src/resources/objectives/DeliveryMissionObjective.java create mode 100644 src/services/mission/MissionObjective.java rename src/services/{ => mission}/MissionService.java (55%) diff --git a/src/main/NGECore.java b/src/main/NGECore.java index f67ac8b0..8c813812 100644 --- a/src/main/NGECore.java +++ b/src/main/NGECore.java @@ -61,7 +61,6 @@ import services.housing.HousingService; import services.InstanceService; import services.LoginService; import services.LootService; -import services.MissionService; import services.PlayerService; import services.ScriptService; import services.SimulationService; @@ -83,6 +82,7 @@ import services.gcw.GCWService; import services.guild.GuildService; import services.LoginService; import services.map.MapService; +import services.mission.MissionService; import services.object.ObjectService; import services.object.UpdateService; import services.pet.MountService; diff --git a/src/resources/objectives/DeliveryMissionObjective.java b/src/resources/objectives/DeliveryMissionObjective.java new file mode 100644 index 00000000..31b1ed78 --- /dev/null +++ b/src/resources/objectives/DeliveryMissionObjective.java @@ -0,0 +1,53 @@ +/******************************************************************************* + * 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 resources.objectives; + +import resources.objects.mission.MissionObject; +import resources.objects.tangible.TangibleObject; +import services.mission.MissionObjective; + +public class DeliveryMissionObjective extends MissionObjective { + + private TangibleObject deliveryObject; + private int objectivePhase; + + public DeliveryMissionObjective(MissionObject parent) { + super(parent); + this.objectivePhase = 0; + } + + @Override + public void activate() { + } + + @Override + public void complete() { + } + + @Override + public void drop() { + } + + public TangibleObject getDeliveryObject() { return deliveryObject; } + + public int getObjectivePhase() { return objectivePhase; } +} diff --git a/src/resources/objects/mission/MissionObject.java b/src/resources/objects/mission/MissionObject.java index c5d69f0a..249d8869 100644 --- a/src/resources/objects/mission/MissionObject.java +++ b/src/resources/objects/mission/MissionObject.java @@ -28,6 +28,7 @@ import com.sleepycat.persist.model.Persistent; import resources.objects.intangible.IntangibleObject; import resources.objects.waypoint.WaypointObject; +import services.mission.MissionObjective; import engine.clients.Client; import engine.resources.objects.IPersistent; import engine.resources.scene.Planet; @@ -57,7 +58,7 @@ public class MissionObject extends IntangibleObject implements IPersistent { private String type = ""; private int missionTemplateObject = 0; private WaypointObject attachedWaypoint; - + private MissionObjective objective; @NotPersistent MissionMessageBuilder messageBuilder = new MissionMessageBuilder(this); @@ -307,6 +308,18 @@ public class MissionObject extends IntangibleObject implements IPersistent { } } + public MissionObjective getObjective() { + synchronized(objectMutex) { + return objective; + } + } + + public void setObjective(MissionObjective objective) { + synchronized(objectMutex) { + this.objective = objective; + } + } + public Transaction getTransaction() { return txn; } diff --git a/src/services/mission/MissionObjective.java b/src/services/mission/MissionObjective.java new file mode 100644 index 00000000..aa69ed08 --- /dev/null +++ b/src/services/mission/MissionObjective.java @@ -0,0 +1,45 @@ +/******************************************************************************* + * 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 resources.objects.mission.MissionObject; + +public abstract class MissionObjective { + + protected long startTime; + protected boolean activated; + protected MissionObject parent; + + public MissionObjective(MissionObject parent) { + this.startTime = System.currentTimeMillis(); + this.activated = false; + this.parent = parent; + } + + public abstract void activate(); + public abstract void complete(); + public abstract void drop(); + + public long getStartTime() { return startTime; } + public boolean isActivated() { return activated; } + public MissionObject getParent() { return parent; } +} diff --git a/src/services/MissionService.java b/src/services/mission/MissionService.java similarity index 55% rename from src/services/MissionService.java rename to src/services/mission/MissionService.java index 02b4c929..488f7d52 100644 --- a/src/services/MissionService.java +++ b/src/services/mission/MissionService.java @@ -19,11 +19,14 @@ * 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; +package services.mission; +import java.io.File; +import java.io.IOException; import java.nio.ByteOrder; import java.util.Map; import java.util.Random; +import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicInteger; import main.NGECore; @@ -35,14 +38,17 @@ import protocol.swg.objectControllerObjects.MissionListRequest; import resources.common.Console; import resources.common.TerminalType; import resources.common.ObjControllerOpcodes; +import resources.objectives.DeliveryMissionObjective; import resources.objects.creature.CreatureObject; import resources.objects.mission.MissionObject; import resources.objects.tangible.TangibleObject; import resources.objects.waypoint.WaypointObject; import engine.clientdata.ClientFileManager; +import engine.clientdata.StfTable; import engine.clientdata.visitors.DatatableVisitor; import engine.clients.Client; import engine.resources.common.CRC; +import engine.resources.common.NameGen; import engine.resources.container.Traverser; import engine.resources.objects.SWGObject; import engine.resources.scene.Planet; @@ -53,11 +59,20 @@ import engine.resources.service.INetworkRemoteEvent; public class MissionService implements INetworkDispatch { private NGECore core; + private NameGen nameGenerator; + // Use a HashMap for obtaining number of entries so we aren't using a visitor all the time. + private ConcurrentHashMap entryCounts = new ConcurrentHashMap(); + private Random ran = new Random(); public MissionService(NGECore core) { this.core = core; + + try { nameGenerator = new NameGen("names.txt"); } + catch (IOException e) { e.printStackTrace(); } + + populateMissionEntryCount(); } - + @Override public void insertOpcodes(Map swgOpcodes, Map objControllerOpcodes) { objControllerOpcodes.put(ObjControllerOpcodes.MISSION_LIST_REQUEST, new INetworkRemoteEvent() { @@ -105,79 +120,115 @@ public class MissionService implements INetworkDispatch { debugMissionDelta(creature); } - // May want to create a map for the server with needed info - public int getNumberOfEntries(String stf) { - try { - DatatableVisitor stfFile = ClientFileManager.loadFile(stf, DatatableVisitor.class); + private void populateMissionEntryCount() { + File missionFolder = new File("./clientdata/string/en/mission"); + File[] missionFiles = missionFolder.listFiles(); + + int missionStrings = 0; + for (int i = 0; i < missionFiles.length; i++) { + if (missionFiles[i].getName().contains("_easy") || missionFiles[i].getName().contains("_medium") || missionFiles[i].getName().contains("_hard")) { - for (int s = 0; s < stfFile.getRowCount(); s++) { - String name = ((String) stfFile.getObject(s, 3)); - Console.println("Name: " + name); - if (name.equals("number_of_entries")) { - int entryCount = ((int) stfFile.getObject(s, 4)); - Console.println("Entry Count: " + entryCount); - return entryCount; - } + String missionStf = "clientdata" + missionFiles[i].getAbsolutePath().split("clientdata")[1].replace("\\", "/"); + try { + StfTable stf = new StfTable(missionStf); + boolean gotCount = false; + + for (int s = 1; s < stf.getRowCount(); s++) { + + if (stf.getStringById(s).getKey() != null && stf.getStringById(s).getKey().equals("number_of_entries")) { + String finalStr = missionStf.split("clientdata/string/en/")[1].replace(".stf", ""); + entryCounts.put(finalStr, Integer.parseInt(stf.getStringById(s).getValue())); + gotCount = true; + } + } + if (gotCount == false) { + System.out.println("!NO ENTRY COUNT FOR " + missionStf); + continue; + } + } catch (Exception e) { e.printStackTrace(); } + missionStrings++; } } - catch (InstantiationException | IllegalAccessException e) { - e.printStackTrace(); - } - - return 0; + System.out.println("Loaded " + missionStrings + " mission entry counts."); } public void debugMissionDelta(CreatureObject creature) { TangibleObject missionBag = (TangibleObject) creature.getSlottedObject("mission_bag"); - final AtomicInteger count = new AtomicInteger(); - final AtomicInteger deCount = new AtomicInteger(); - final AtomicInteger dCount = new AtomicInteger(); - count.getAndSet(1); + final AtomicInteger destroyCount = new AtomicInteger(); + final AtomicInteger deliverCount = new AtomicInteger(); + missionBag.viewChildren(creature, true, false, new Traverser() { @Override public void process(SWGObject child) { - //if (count.get() > 1) - //return; - - if (child instanceof MissionObject == true) { - System.out.println(count.get() + " is a MissionObject"); - } else { - System.out.println(count.get() + " is not a MissionObject!!"); - } - - MissionObject mission = (MissionObject) child; - if (deCount.get() < 5) { - mission.setMissionType("destroy"); - deCount.getAndIncrement(); - Console.println("Destroy missions: " + String.valueOf(deCount.get())); - } - else if (dCount.get() < 5) { - mission.setMissionType("deliver"); - dCount.getAndIncrement(); - Console.println("Deliver missions: " + String.valueOf(dCount.get())); - } else { + if (child instanceof MissionObject == false) return; + + MissionObject mission = (MissionObject) child; + if (destroyCount.get() < 5) { + mission.setMissionType("destroy"); + + String missionStf = "mission/mission_destroy_neutral_easy_creature"; + int strId = getRandomStringEntry(missionStf); + + mission.setMissionDescription(missionStf, "m" + String.valueOf(strId) + "d"); + mission.setMissionTitle(missionStf, "m" + String.valueOf(strId) + "t"); + + destroyCount.getAndIncrement(); } + else if (deliverCount.get() < 5) { + mission.setMissionType("deliver"); + + String missionStf = "mission/mission_deliver_neutral_easy"; + int strId = getRandomStringEntry(missionStf); + + mission.setMissionDescription(missionStf, "m" + String.valueOf(strId) + "d"); + mission.setMissionTitle(missionStf, "m" + String.valueOf(strId) + "t"); + + deliverCount.getAndIncrement(); + } + else { return; } + + mission.setCreator(nameGenerator.compose(2) + " " + nameGenerator.compose(3)); - mission.setMissionDescription("mission/mission_deliver_neutral_easy", "m9d"); mission.setMissionLevel(1); mission.setMissionStart((float) 3377.148, (float) -4753.221, (float) 0, "tatooine"); - mission.setCreator("Waverunner"); mission.setCreditReward(69); mission.setMissionDestination((float) 3447.129, (float) -5070.057, (float) 0, "tatooine"); mission.setMissionTemplateObject(CRC.StringtoCRC("object/tangible/mission/shared_mission_datadisk.iff")); - mission.setMissionTitle("mission/mission_deliver_neutral_easy", "m9t"); mission.setRepeatCount(1); - //mission.sendMissionDelta(); - System.out.println("Object: " + count.getAndIncrement()); } }); } + + private int getRandomStringEntry(String missionStf) { + int ranEntryNum = 1; + + if (entryCounts.get(missionStf) != null) { ranEntryNum = ran.nextInt(entryCounts.get(missionStf)); } + else { System.out.println(missionStf + " was not found in entryCount and is using entry #1"); } + + if (ranEntryNum == 0) + return 1; + else + return ranEntryNum; + } + + private void randomDeliveryMission(MissionObject mission) { + mission.setMissionType("deliver"); + + String missionStf = "mission/mission_deliver_neutral_easy"; + int strId = getRandomStringEntry(missionStf); + + mission.setMissionDescription(missionStf, "m" + String.valueOf(strId) + "d"); + mission.setMissionTitle(missionStf, "m" + String.valueOf(strId) + "t"); + + //mission.setObjective(new DeliveryMissionObjective(mission)); + } + @Override public void shutdown() {