diff --git a/.gitignore b/.gitignore index 63147709..ab30f143 100644 --- a/.gitignore +++ b/.gitignore @@ -60,7 +60,8 @@ odb/chatRooms/je.info.* odb/resourcehistory/je.info.* odb/resourceroots/je.info.* odb/resources/je.info.* -odb/auction/je.info.* +odb/auction/je.info.* +odb/bounties/je.info.* # External tool builders .externalToolBuilders/ diff --git a/odb/bounties/placeholder.txt b/odb/bounties/placeholder.txt new file mode 100644 index 00000000..e69de29b diff --git a/scripts/commands/setgodmode.py b/scripts/commands/setgodmode.py index e66d7982..65b10b3f 100644 --- a/scripts/commands/setgodmode.py +++ b/scripts/commands/setgodmode.py @@ -99,11 +99,9 @@ def run(core, actor, target, commandString): if (actor.isInStealth()): actor.setInStealth(False) actor.setRadarVisible(True) - actor.sendSystemMessage('You are now visible to other players.', 0) else: actor.setInStealth(True) actor.setRadarVisible(False) - actor.sendSystemMessage('You are now hidden from players. "Stealth Effect" is not implemented, however players still won\'t be able to see you. Type /setgodmode stealth again to be visible.', 0) elif command == 'holoEmote' and arg1: playerObject.setHoloEmote('holoemote_' + arg1) @@ -114,5 +112,9 @@ def run(core, actor, target, commandString): if playerObject.getGodLevel > 0: actor.removeAbility("admin") playerObject.setGodLevel(0) - + + elif command == 'setBounty' and arg1: + core.missionService.createNewBounty(actor, int(arg1)) + return + return diff --git a/scripts/conversation/missions/deliver.py b/scripts/conversation/missions/deliver.py index 5caef3fa..f8ee5667 100644 --- a/scripts/conversation/missions/deliver.py +++ b/scripts/conversation/missions/deliver.py @@ -44,8 +44,8 @@ def handlePickupStage(core, actor, npc, objective, mission): return core.conversationService.sendStopConversation(actor, npc, mission.getMissionDescription(), 'm' + str(mission.getMissionId()) + 'p') - objective.createDeliveryItem() - objective.update() + objective.createDeliveryItem(core, actor) + objective.update(core, actor) return def handleDeliveryStage(core, actor, npc, objective, mission): @@ -56,7 +56,7 @@ def handleDeliveryStage(core, actor, npc, objective, mission): core.conversationService.sendStopConversation(actor, npc, mission.getMissionDescription(), 'm' + str(mission.getMissionId()) + 'r') core.objectService.destroyObject(objective.getDeliveryObject()) - objective.update() + objective.update(core, actor) return def handleCompletionStage(core, actor, npc, objective, mission): @@ -66,5 +66,5 @@ def handleCompletionStage(core, actor, npc, objective, mission): return core.conversationService.sendStopConversation(actor, npc, mission.getMissionDescription(), 'm' + str(mission.getMissionId()) + 's') - objective.complete() + objective.complete(core, actor) return \ No newline at end of file diff --git a/scripts/object/tangible/terminal/terminal_mission.py b/scripts/object/tangible/terminal/terminal_mission.py index ccf684c0..dd9fc3e1 100644 --- a/scripts/object/tangible/terminal/terminal_mission.py +++ b/scripts/object/tangible/terminal/terminal_mission.py @@ -1,9 +1,7 @@ -from resources.common import TerminalType import sys def setup(core, object): - core.mapService.addLocation(object.getPlanet(), 'Mission Terminal', object.getPosition().x, object.getPosition().z, 41, 44, 0) - object.setAttachment("terminalType", TerminalType.MISSION_GENERIC) + object.setAttachment("terminalType", 1) return \ No newline at end of file diff --git a/scripts/object/tangible/terminal/terminal_mission_bounty.py b/scripts/object/tangible/terminal/terminal_mission_bounty.py index ccad8904..4103f954 100644 --- a/scripts/object/tangible/terminal/terminal_mission_bounty.py +++ b/scripts/object/tangible/terminal/terminal_mission_bounty.py @@ -1,4 +1,5 @@ import sys def setup(core, object): + object.setAttachment("terminalType", 2) return \ No newline at end of file diff --git a/src/main/NGECore.java b/src/main/NGECore.java index c99d4912..5f81be51 100644 --- a/src/main/NGECore.java +++ b/src/main/NGECore.java @@ -213,6 +213,7 @@ public class NGECore { private ObjectDatabase resourcesODB; private ObjectDatabase resourceRootsODB; private ObjectDatabase resourceHistoryODB; + private ObjectDatabase bountiesODB; public static boolean PACKET_DEBUG = false; @@ -274,6 +275,7 @@ public class NGECore { resourceRootsODB = new ObjectDatabase("resourceroots", true, false, true); resourceHistoryODB = new ObjectDatabase("resourcehistory", true, false, true); auctionODB = new ObjectDatabase("auction", true, false, true); + bountiesODB = new ObjectDatabase("bounties", true, false, true); // Services loginService = new LoginService(this); @@ -626,6 +628,10 @@ public class NGECore { return chatRoomODB; } + public ObjectDatabase getBountiesODB() { + return bountiesODB; + } + public ObjectDatabase getResourcesODB() { return resourcesODB; } diff --git a/src/resources/common/BountyListItem.java b/src/resources/common/BountyListItem.java new file mode 100644 index 00000000..5581483c --- /dev/null +++ b/src/resources/common/BountyListItem.java @@ -0,0 +1,105 @@ +/******************************************************************************* + * 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.common; + +import java.util.ArrayList; +import java.util.List; + +import com.sleepycat.persist.model.Entity; +import com.sleepycat.persist.model.PrimaryKey; + +@Entity +public class BountyListItem { + @PrimaryKey + private long objectId; + private int creditReward; + private String profession; + private String faction; + private String name; + private List assignedHunters; + + public BountyListItem() { } + + public BountyListItem(long objectId, int creditReward, String profession, String faction, String name) { + this.objectId = objectId; + this.creditReward = creditReward; + this.profession = profession; + this.faction = faction; + this.setName(name); + this.setAssignedHunters(new ArrayList(3)); + } + + public long getObjectId() { + return objectId; + } + public void setObjectId(long objectId) { + this.objectId = objectId; + } + public int getCreditReward() { + return creditReward; + } + public void setCreditReward(int creditReward) { + this.creditReward = creditReward; + } + public String getProfession() { + return profession; + } + public void setProfession(String profession) { + this.profession = profession; + } + + public String getFaction() { + return faction; + } + + public void setFaction(String faction) { + this.faction = faction; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public void addBounty(int amountToAdd) { + this.creditReward =+ amountToAdd; + } + + public List getAssignedHunters() { + return assignedHunters; + } + + public void setAssignedHunters(List assignedHunters) { + this.assignedHunters = assignedHunters; + } + + public boolean addBountyHunter(long objectId) { + return assignedHunters.add(objectId); + } + + public boolean removeBountyHunter(long objectId) { + return assignedHunters.remove(objectId); + } +} diff --git a/src/resources/objectives/BountyMissionObjective.java b/src/resources/objectives/BountyMissionObjective.java new file mode 100644 index 00000000..96b90c88 --- /dev/null +++ b/src/resources/objectives/BountyMissionObjective.java @@ -0,0 +1,80 @@ +/******************************************************************************* + * 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 java.util.Random; + +import engine.resources.scene.Point3D; +import main.NGECore; +import resources.common.BountyListItem; +import resources.objects.creature.CreatureObject; +import resources.objects.mission.MissionObject; +import services.mission.MissionObjective; + +public class BountyMissionObjective extends MissionObjective { + + private Point3D lastKnownLocation; + private long markObjId; + + public BountyMissionObjective(MissionObject parent) { + super(parent); + } + + @Override + public void activate(NGECore core, CreatureObject player) { + if (isActivated()) + return; + + BountyListItem bountyTarget = core.missionService.getBountyListItem(getMissionObject().getBountyObjId()); + + setMarkObjId(bountyTarget.getObjectId()); + + // TODO: Change this to a comm message. + player.sendSystemMessage("@mission/mission_bounty_informant:target_hard_" + Integer.toString(new Random().nextInt(5)), (byte) 0); + + + } + + @Override + public void complete(NGECore core, CreatureObject player) { + + } + + @Override + public void abort(NGECore core, CreatureObject player) { + + } + + @Override + public void update(NGECore core, CreatureObject player) { + + } + + public Point3D getLastKnownLocation() { return lastKnownLocation; } + + public void setLastKnownLocation(Point3D lastKnownLocation) { this.lastKnownLocation = lastKnownLocation; } + + public long getMarkObjId() { return markObjId; } + + public void setMarkObjId(long markObjId) { this.markObjId = markObjId; } + +} diff --git a/src/resources/objectives/DeliveryMissionObjective.java b/src/resources/objectives/DeliveryMissionObjective.java index b5802390..6a116a8e 100644 --- a/src/resources/objectives/DeliveryMissionObjective.java +++ b/src/resources/objectives/DeliveryMissionObjective.java @@ -21,7 +21,6 @@ ******************************************************************************/ package resources.objectives; -import engine.resources.objects.SWGObject; import engine.resources.scene.Point3D; import main.NGECore; import resources.common.OutOfBand; @@ -37,14 +36,13 @@ public class DeliveryMissionObjective extends MissionObjective { private TangibleObject deliveryObject; private CreatureObject missionGiver; private CreatureObject dropOffNpc; - private NGECore core = NGECore.getInstance(); public DeliveryMissionObjective(MissionObject parent) { super(parent); } @Override - public void activate() { + public void activate(NGECore core, CreatureObject player) { if (isActivated()) return; @@ -97,25 +95,21 @@ public class DeliveryMissionObjective extends MissionObjective { } @Override - public void complete() { - CreatureObject completer = (CreatureObject) getMissionObject().getGrandparent(); - - if (completer == null) - return; - + public void complete(NGECore core, CreatureObject player) { + int reward = getMissionObject().getCreditReward(); - completer.addBankCredits(reward); + player.addBankCredits(reward); - completer.sendSystemMessage(new OutOfBand(new ProsePackage("@mission/mission_generic:success_w_amount", reward)), (byte) 0); + player.sendSystemMessage(new OutOfBand(new ProsePackage("@mission/mission_generic:success_w_amount", reward)), (byte) 0); - abort(); + abort(core, player); core.objectService.destroyObject(getMissionObject()); } @Override - public void abort() { + public void abort(NGECore core, CreatureObject player) { if (deliveryObject != null) core.objectService.destroyObject(deliveryObject.getObjectId()); @@ -127,7 +121,7 @@ public class DeliveryMissionObjective extends MissionObjective { } @Override - public void update() { + public void update(NGECore core, CreatureObject player) { setObjectivePhase(getObjectivePhase() + 1); @@ -154,10 +148,8 @@ public class DeliveryMissionObjective extends MissionObjective { } } - public boolean createDeliveryItem() { + public boolean createDeliveryItem(NGECore core, CreatureObject player) { - SWGObject player = getMissionObject().getGrandparent(); - if (player == null) return false; diff --git a/src/resources/objectives/DestroyMissionObjective.java b/src/resources/objectives/DestroyMissionObjective.java index e4832756..7437d46f 100644 --- a/src/resources/objectives/DestroyMissionObjective.java +++ b/src/resources/objectives/DestroyMissionObjective.java @@ -21,6 +21,8 @@ ******************************************************************************/ package resources.objectives; +import main.NGECore; +import resources.objects.creature.CreatureObject; import resources.objects.mission.MissionObject; import services.mission.MissionObjective; @@ -31,27 +33,28 @@ public class DestroyMissionObjective extends MissionObjective { } @Override - public void activate() { + public void activate(NGECore core, CreatureObject player) { // TODO Auto-generated method stub - + } @Override - public void complete() { + public void complete(NGECore core, CreatureObject player) { // TODO Auto-generated method stub - + } @Override - public void abort() { + public void abort(NGECore core, CreatureObject player) { // TODO Auto-generated method stub - + } @Override - public void update() { + public void update(NGECore core, CreatureObject player) { // TODO Auto-generated method stub - + } + } diff --git a/src/resources/objects/mission/MissionMessageBuilder.java b/src/resources/objects/mission/MissionMessageBuilder.java index 24c9aa07..071a4f58 100644 --- a/src/resources/objects/mission/MissionMessageBuilder.java +++ b/src/resources/objects/mission/MissionMessageBuilder.java @@ -304,13 +304,13 @@ public class MissionMessageBuilder extends ObjectMessageBuilder { return buffer; } - public IoBuffer buildMissionDescriptionDelta(String desc, int id) { + public IoBuffer buildMissionDescriptionDelta(String desc, int id, String additionalParam) { - IoBuffer buffer = IoBuffer.allocate(12 + desc.length(), false).order(ByteOrder.LITTLE_ENDIAN); + IoBuffer buffer = IoBuffer.allocate(13 + desc.length() + additionalParam.length(), false).order(ByteOrder.LITTLE_ENDIAN); buffer.put(getAsciiString(desc)); buffer.putInt(0); - buffer.put(getAsciiString("m" + id + "d")); + buffer.put(getAsciiString("m" + id + "d" + additionalParam)); int size = buffer.position(); buffer.flip(); @@ -318,14 +318,14 @@ public class MissionMessageBuilder extends ObjectMessageBuilder { return buffer; } - - public IoBuffer buildMissionTitleDelta(String title, int id) { - IoBuffer buffer = IoBuffer.allocate(12 + title.length(), false).order(ByteOrder.LITTLE_ENDIAN); + public IoBuffer buildMissionTitleDelta(String title, int id, String additionalParam) { + + IoBuffer buffer = IoBuffer.allocate(12 + title.length() + additionalParam.length(), false).order(ByteOrder.LITTLE_ENDIAN); buffer.put(getAsciiString(title)); buffer.putInt(0); - buffer.put(getAsciiString("m" + id + "t")); + buffer.put(getAsciiString("m" + id + "t" + additionalParam)); int size = buffer.position(); buffer.flip(); diff --git a/src/resources/objects/mission/MissionObject.java b/src/resources/objects/mission/MissionObject.java index 12ed3fa8..48f573f2 100644 --- a/src/resources/objects/mission/MissionObject.java +++ b/src/resources/objects/mission/MissionObject.java @@ -26,6 +26,7 @@ import com.sleepycat.je.Transaction; import com.sleepycat.persist.model.NotPersistent; import com.sleepycat.persist.model.Persistent; +import resources.common.BountyListItem; import resources.objects.intangible.IntangibleObject; import resources.objects.waypoint.WaypointObject; import services.mission.MissionObjective; @@ -53,8 +54,11 @@ public class MissionObject extends IntangibleObject implements IPersistent { private String type = ""; private int missionTemplateObject = 0; private WaypointObject attachedWaypoint; + + // Server variables private MissionObjective objective; - + private long bountyObjId; + @NotPersistent MissionMessageBuilder messageBuilder = new MissionMessageBuilder(this); @@ -148,11 +152,15 @@ public class MissionObject extends IntangibleObject implements IPersistent { } public void setMissionDescription(String missionDescription) { + setMissionDescription(missionDescription, ""); + } + + public void setMissionDescription(String missionDescription, String additionalParam) { synchronized(objectMutex) { this.description = missionDescription; } if (getGrandparent() != null && getGrandparent().getClient() != null && getGrandparent().getClient().getSession() != null) { - getGrandparent().getClient().getSession().write(messageBuilder.buildMissionDescriptionDelta(missionDescription, missionId)); + getGrandparent().getClient().getSession().write(messageBuilder.buildMissionDescriptionDelta(missionDescription, missionId, additionalParam)); } } @@ -163,11 +171,15 @@ public class MissionObject extends IntangibleObject implements IPersistent { } public void setMissionTitle(String missionTitle) { + setMissionTitle(missionTitle, ""); + } + + public void setMissionTitle(String missionTitle, String additionalParam) { synchronized(objectMutex) { this.title = missionTitle; } if (getGrandparent() != null && getGrandparent().getClient() != null && getGrandparent().getClient().getSession() != null) { - getGrandparent().getClient().getSession().write(messageBuilder.buildMissionTitleDelta(missionTitle, missionId)); + getGrandparent().getClient().getSession().write(messageBuilder.buildMissionTitleDelta(missionTitle, missionId, additionalParam)); } } @@ -286,6 +298,14 @@ public class MissionObject extends IntangibleObject implements IPersistent { this.missionId = missionId; } + public long getBountyObjId() { + return bountyObjId; + } + + public void setBountyObjId(long bountyObjId) { + this.bountyObjId = bountyObjId; + } + public Transaction getTransaction() { return txn; } diff --git a/src/services/CharacterService.java b/src/services/CharacterService.java index b11bd350..7807b9ec 100644 --- a/src/services/CharacterService.java +++ b/src/services/CharacterService.java @@ -323,6 +323,8 @@ public class CharacterService implements INetworkDispatch { object.addAbility("startDance"); object.addAbility("startDance+Basic"); + object.setFaction("neutral"); + object.addObjectToEquipList(datapad); object.addObjectToEquipList(inventory); object.addObjectToEquipList(bank); diff --git a/src/services/GroupService.java b/src/services/GroupService.java index fa4d9d5b..3f063a74 100644 --- a/src/services/GroupService.java +++ b/src/services/GroupService.java @@ -146,6 +146,12 @@ public class GroupService implements INetworkDispatch { group.setGroupLeader(leader); group.getMemberList().add(leader); group.getMemberList().add(invited); + + if (invited.getLevel() > leader.getLevel()) + group.setGroupLevel(invited.getLevel()); + else + group.setGroupLevel(leader.getLevel()); + leader.makeAware(group); leader.setGroupId(group.getObjectID()); invited.makeAware(group); @@ -170,6 +176,10 @@ public class GroupService implements INetworkDispatch { invited.makeAware(group); invited.setGroupId(group.getObjectID()); invited.sendSystemMessage("@group:joined_self", (byte) 0); + + if (group.getGroupLevel() < invited.getLevel()) + group.setGroupLevel(invited.getLevel()); + addGroupBuffsToMember(group, invited); core.chatService.joinChatRoom(invited.getCustomName(), group.getChatRoomId(), true); diff --git a/src/services/PlayerService.java b/src/services/PlayerService.java index ea075dc5..564bec61 100644 --- a/src/services/PlayerService.java +++ b/src/services/PlayerService.java @@ -58,6 +58,7 @@ import protocol.swg.ShowHelmet; import protocol.swg.objectControllerObjects.ChangeRoleIconChoice; import protocol.swg.objectControllerObjects.ShowFlyText; import protocol.swg.objectControllerObjects.ShowLootBox; +import resources.common.BountyListItem; import resources.common.FileUtilities; import resources.common.ObjControllerOpcodes; import resources.common.Opcodes; @@ -78,6 +79,7 @@ import resources.objects.player.PlayerMessageBuilder; import resources.objects.player.PlayerObject; import resources.objects.tangible.TangibleObject; import resources.objects.waypoint.WaypointObject; +import services.sui.SUIService.InputBoxType; import services.sui.SUIService.ListBoxType; import services.sui.SUIWindow; import services.sui.SUIWindow.Trigger; @@ -1252,6 +1254,26 @@ public class PlayerService implements INetworkDispatch { core.suiService.openSUIWindow(ringWindow); } + public void sendSetBountyWindow(final CreatureObject victim, final CreatureObject attacker) { + final SUIWindow bountyWindow = core.suiService.createInputBox(InputBoxType.INPUT_BOX_OK_CANCEL, "@bounty_hunter:setbounty_title", "@bounty_hunter:setbounty_prompt1 " + attacker.getCustomName() + "?" + "\n@bounty_hunter:setbounty_prompt2 " + victim.getBankCredits() + victim.getCashCredits(), + victim, null, (float) 10, new SUICallback() { + + @Override + public void process(SWGObject owner, int eventType, Vector returnList) { + if (eventType == 0 && returnList.get(0) != null) { + if (core.missionService.getBountyListItem(attacker.getObjectId()) != null) { + BountyListItem currentBounty = core.missionService.getBountyListItem(attacker.getObjectId()); + currentBounty.addBounty(Integer.parseInt(returnList.get(0))); + } else { + core.missionService.createNewBounty(attacker, Integer.parseInt(returnList.get(0))); + } + } + } + + }); + core.suiService.openSUIWindow(bountyWindow); + } + public String getFormalProfessionName(String template) { String formalName = ""; diff --git a/src/services/combat/CombatService.java b/src/services/combat/CombatService.java index 1a265c8c..9dabaf94 100644 --- a/src/services/combat/CombatService.java +++ b/src/services/combat/CombatService.java @@ -991,6 +991,8 @@ public class CombatService implements INetworkDispatch { if(target.getDuelList().contains(attacker)) handleEndDuel(target, attacker, false); core.playerService.sendCloningWindow(target, attacker.getSlottedObject("ghost") != null); + //if (attacker.getSlottedObject("ghost") != null) + //core.playerService.sendSetBountyWindow(target, attacker); } public boolean areInDuel(CreatureObject creature1, CreatureObject creature2) { diff --git a/src/services/mission/MissionObjective.java b/src/services/mission/MissionObjective.java index c81fcc0a..8f43fe9f 100644 --- a/src/services/mission/MissionObjective.java +++ b/src/services/mission/MissionObjective.java @@ -21,8 +21,11 @@ ******************************************************************************/ package services.mission; +import main.NGECore; + import com.sleepycat.persist.model.Persistent; +import resources.objects.creature.CreatureObject; import resources.objects.mission.MissionObject; @Persistent(version=0) @@ -42,10 +45,10 @@ public abstract class MissionObjective { this.objectivePhase = 0; } - public abstract void activate(); - public abstract void complete(); - public abstract void abort(); - public abstract void update(); + public abstract void activate(NGECore core, CreatureObject player); + public abstract void complete(NGECore core, CreatureObject player); + public abstract void abort(NGECore core, CreatureObject player); + public abstract void update(NGECore core, CreatureObject player); public long getStartTime() { return startTime; } diff --git a/src/services/mission/MissionService.java b/src/services/mission/MissionService.java index 40b5abf0..d463893a 100644 --- a/src/services/mission/MissionService.java +++ b/src/services/mission/MissionService.java @@ -26,6 +26,7 @@ import java.io.IOException; import java.nio.ByteOrder; import java.util.Map; import java.util.Random; +import java.util.Vector; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; @@ -35,24 +36,29 @@ import main.NGECore; import org.apache.mina.core.buffer.IoBuffer; import org.apache.mina.core.session.IoSession; +import com.sleepycat.je.Transaction; + import protocol.swg.ObjControllerMessage; import protocol.swg.objectControllerObjects.MissionAbort; import protocol.swg.objectControllerObjects.MissionAcceptRequest; import protocol.swg.objectControllerObjects.MissionAcceptResponse; import protocol.swg.objectControllerObjects.MissionListRequest; +import resources.common.BountyListItem; import resources.common.SpawnPoint; import resources.common.ObjControllerOpcodes; +import resources.objectives.BountyMissionObjective; import resources.objectives.DeliveryMissionObjective; import resources.objectives.DestroyMissionObjective; import resources.objects.creature.CreatureObject; import resources.objects.mission.MissionObject; +import resources.objects.player.PlayerObject; import resources.objects.tangible.TangibleObject; -import resources.objects.waypoint.WaypointObject; import engine.clientdata.StfTable; import engine.clients.Client; import engine.resources.common.CRC; import engine.resources.common.NameGen; import engine.resources.container.Traverser; +import engine.resources.database.ObjectDatabase; import engine.resources.objects.SWGObject; import engine.resources.scene.Point3D; import engine.resources.service.INetworkDispatch; @@ -63,7 +69,9 @@ 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 Map entryCounts = new ConcurrentHashMap(); + private Vector bountyList = new Vector(); + private ObjectDatabase bountiesODB; private Random ran = new Random(); public MissionService(NGECore core) { @@ -73,6 +81,8 @@ public class MissionService implements INetworkDispatch { catch (IOException e) { e.printStackTrace(); } loadMissionEntryCounts(); + + bountiesODB = core.getBountiesODB(); } @Override @@ -118,7 +128,7 @@ public class MissionService implements INetworkDispatch { if(client == null || client.getSession() == null) return; - SWGObject object = client.getParent(); + CreatureObject object = (CreatureObject) client.getParent(); if(object == null) return; @@ -137,8 +147,12 @@ public class MissionService implements INetworkDispatch { if (terminalType == TerminalType.GENERIC) { handleMissionListRequest(core.objectService.getObject(request.getObjectId()), request.getTickCount(), TerminalType.GENERIC); - } else if (terminalType == TerminalType.BOUNTYHUNTER) { - + } else if (terminalType == TerminalType.BOUNTY) { + if (!object.hasSkill("class_bountyhunter_phase1_novice")) { + object.sendSystemMessage("@mission/mission_generic:not_bounty_hunter_terminal", (byte) 0); + } else { + handleMissionListRequest(core.objectService.getObject(request.getObjectId()), request.getTickCount(), TerminalType.BOUNTY); + } } else if (terminalType == TerminalType.ENTERTAINER) { } else if (terminalType == TerminalType.ARTISAN) { @@ -191,7 +205,7 @@ public class MissionService implements INetworkDispatch { MissionObjective objective = mission.getObjective(); if (objective != null) - objective.abort(); + objective.abort(core, creature); core.objectService.destroyObject(mission.getObjectId()); } @@ -267,7 +281,7 @@ public class MissionService implements INetworkDispatch { if (type == TerminalType.GENERIC) randomDeliveryMission(player, mission); - else if (type == TerminalType.BOUNTYHUNTER) + else if (type == TerminalType.BOUNTY) randomBountyMission(player, mission); else if (type == TerminalType.ARTISAN) @@ -282,9 +296,9 @@ public class MissionService implements INetworkDispatch { } else if (typeTwoCount.get() < 4) { if (type == TerminalType.GENERIC) - randomDestroyMission(player, mission); + return; - else if (type == TerminalType.BOUNTYHUNTER) + else if (type == TerminalType.BOUNTY) return; else if (type == TerminalType.ARTISAN) @@ -293,8 +307,8 @@ public class MissionService implements INetworkDispatch { else return; - mission.setRepeatCount(requestCounter); - typeTwoCount.incrementAndGet(); + //mission.setRepeatCount(requestCounter); + //typeTwoCount.incrementAndGet(); } } }); @@ -338,7 +352,11 @@ public class MissionService implements INetworkDispatch { return true; } - private void createMissionObjective(CreatureObject creature, MissionObject mission) { + private MissionObjective createMissionObjective(CreatureObject creature, MissionObject mission) { + return createMissionObjective(creature, mission, false); + } + + private MissionObjective createMissionObjective(CreatureObject creature, MissionObject mission, boolean silent) { switch(mission.getMissionType()) { case "deliver": @@ -346,18 +364,32 @@ public class MissionService implements INetworkDispatch { mission.setObjective(deliveryObjective); - deliveryObjective.activate(); - break; + if (!silent) + deliveryObjective.activate(core, creature); + + return deliveryObjective; case "destroy": DestroyMissionObjective destroyObjective = new DestroyMissionObjective(mission); mission.setObjective(destroyObjective); - destroyObjective.activate(); - break; + if (!silent) + destroyObjective.activate(core, creature); + + return destroyObjective; + + case "bounty": + BountyMissionObjective bountyObjective = new BountyMissionObjective(mission); + + mission.setObjective(bountyObjective); + + if (!silent) + bountyObjective.activate(core, creature); + + return bountyObjective; default: - break; + return null; } } @@ -387,33 +419,135 @@ public class MissionService implements INetworkDispatch { mission.setMissionTemplateObject(CRC.StringtoCRC("object/tangible/mission/shared_mission_datadisk.iff")); mission.setMissionTargetName("Datadisk"); - - WaypointObject waypoint = (WaypointObject) core.objectService.createObject("object/waypoint/shared_waypoint.iff", player.getPlanet()); - if (waypoint == null) - return; - - waypoint.setColor(WaypointObject.ORANGE); - - } - - private void randomDestroyMission(SWGObject player, MissionObject mission) { - } private void randomBountyMission(SWGObject player, MissionObject mission) { + BountyListItem bountyTarget = null; + if (bountyList.size() > 0) { + boolean gotBounty = false; + while (!gotBounty) { + bountyTarget = getRandomBounty(); + + if (bountyTarget == null || bountyTarget.getAssignedHunters().size() >= 3 || bountyTarget.getCreditReward() < 20000) + continue; + else + gotBounty = true; + } + } + + if (bountyTarget == null) + return; + + mission.setMissionType("bounty"); + + String missionStf = "mission/mission_bounty_jedi"; + + if (!bountyTarget.getProfession().equals("")) { // TODO: Smuggler mission checks. + if (bountyTarget.getFaction().equals("neutral")) { + mission.setMissionTargetName("@mission/mission_bounty_jedi:neutral_jedi"); + mission.setMissionId(3); + } + else if (bountyTarget.getFaction().equals("rebel")) { + mission.setMissionTargetName("@mission/mission_bounty_jedi:rebel_jedi"); + mission.setMissionId(2); + } + else if (bountyTarget.getFaction().equals("imperial")) { + mission.setMissionTargetName("@mission/mission_bounty_jedi:imperial_jedi"); + mission.setMissionId(1); + } + mission.setMissionTitle(missionStf); + mission.setMissionDescription(missionStf); + } else { + // TODO: Dead code, but place-holder for implementation of smuggler missions. + if (bountyTarget.getFaction().equals("neutral")) { + mission.setMissionId(3); + } + else if (bountyTarget.getFaction().equals("rebel")) { + mission.setMissionId(2); + } + else if (bountyTarget.getFaction().equals("imperial")) { + mission.setMissionId(1); + } + mission.setMissionTitle(missionStf, "s"); + mission.setMissionDescription(missionStf, "s"); + } + + mission.setMissionLevel(90); + + mission.setCreditReward(bountyTarget.getCreditReward()); + + mission.setMissionTemplateObject(CRC.StringtoCRC("object/tangible/mission/shared_mission_bounty_jedi_target.iff")); + + mission.setBountyObjId(bountyTarget.getObjectId()); } public enum TerminalType {; public static final int GENERIC = 1; - public static final int BOUNTYHUNTER = 2; + public static final int BOUNTY = 2; public static final int ENTERTAINER = 3; public static final int ARTISAN = 4; public static final int EXPLORER = 5; } + public Vector getBountyList() { + return this.bountyList; + } + + public BountyListItem getRandomBounty() { + int bountyListId = ran.nextInt(bountyList.size()); + + return bountyList.get(bountyListId); + } + + public BountyListItem getBountyListItem(long objectId) { + Vector bounties = bountyList; + for (BountyListItem bounty : bounties) { + if (bounty.getObjectId() == objectId) + return bounty; + } + return null; + } + + public BountyListItem createNewBounty(CreatureObject bountyTarget, int reward) { + PlayerObject player = (PlayerObject) bountyTarget.getSlottedObject("ghost"); + if (player == null) + return null; + + if (getBountyListItem(bountyTarget.getObjectId()) != null) + return null; + + BountyListItem bounty = new BountyListItem(bountyTarget.getObjectId(), reward, core.playerService.getFormalProfessionName(player.getProfession()), bountyTarget.getFaction(), bountyTarget.getCustomName()); + + bountyList.add(bounty); + + //Transaction txn = bountiesODB.getEnvironment().beginTransaction(null, null); + //bountiesODB.put(bounty, Long.class, BountyListItem.class, txn); + //txn.commitSync(); + + //System.out.println("Put in bounty for " + bounty.getName() + " with amount " + reward); + + return bounty; + } + + public boolean addToExistingBounty(CreatureObject bountyTarget, int amountToAdd) { + PlayerObject player = (PlayerObject) bountyTarget.getSlottedObject("ghost"); + if (player == null) + return false; + + BountyListItem bounty = getBountyListItem(bountyTarget.getObjectId()); + + if (bounty == null) + return false; + + //Transaction txn = bountiesODB.getEnvironment().beginTransaction(null, null); + //bountiesODB.get(bounty, Long.class, BountyListItem.class); + //txn.commitSync(); + + return true; + } + @Override public void shutdown() { - } }