From ea9a1fdd821230b4d5da904d1c60258f31d7f931 Mon Sep 17 00:00:00 2001 From: Waverunner Date: Tue, 29 Apr 2014 17:49:03 -0400 Subject: [PATCH] Added setting of player bounties Mission for bounties still needs to be ironed out so you won't see them in the bounty mission terminal, however you can now set bounties for players. --- scripts/commands/pvp.py | 3 +- scripts/commands/setgodmode.py | 5 +- .../tangible/terminal/terminal_mission.py | 2 +- .../terminal/terminal_mission_bounty.py | 1 + src/resources/common/BountyListItem.java | 11 +-- src/services/ConnectionService.java | 2 + src/services/PlayerService.java | 17 +++-- src/services/combat/CombatService.java | 7 +- src/services/mission/MissionService.java | 67 ++++++++++++++----- src/services/object/ObjectService.java | 4 ++ 10 files changed, 85 insertions(+), 34 deletions(-) diff --git a/scripts/commands/pvp.py b/scripts/commands/pvp.py index 8fbdc155..1260a24c 100644 --- a/scripts/commands/pvp.py +++ b/scripts/commands/pvp.py @@ -17,7 +17,8 @@ def run(core, actor, target, commandString): if commandString != '' and commandString != faction: if commandString == 'rebel' or commandString == 'imperial' or commandString == 'neutral': - actor.sendSystemMessage('@faction_recruiter:sui_resig_complete_in_5', 0) + if faction != 'neutral': + actor.sendSystemMessage('@faction_recruiter:sui_resig_complete_in_5', 0) if actor.getFactionStatus() == FactionStatus.SpecialForces: actor.setPvpStatus(PvpStatus.GoingCovert, True) diff --git a/scripts/commands/setgodmode.py b/scripts/commands/setgodmode.py index 65b10b3f..63019d92 100644 --- a/scripts/commands/setgodmode.py +++ b/scripts/commands/setgodmode.py @@ -114,7 +114,10 @@ def run(core, actor, target, commandString): playerObject.setGodLevel(0) elif command == 'setBounty' and arg1: - core.missionService.createNewBounty(actor, int(arg1)) + if not core.missionService.addToExistingBounty(actor, int(arg1)): + core.missionService.createNewBounty(actor, int(arg1)) + + actor.sendSystemMessage('Your bounty has been set to an additional ' + str(arg1) + ' credits.', 0) return return diff --git a/scripts/object/tangible/terminal/terminal_mission.py b/scripts/object/tangible/terminal/terminal_mission.py index dd9fc3e1..10fe46c8 100644 --- a/scripts/object/tangible/terminal/terminal_mission.py +++ b/scripts/object/tangible/terminal/terminal_mission.py @@ -1,7 +1,7 @@ import sys def setup(core, object): - core.mapService.addLocation(object.getPlanet(), 'Mission Terminal', object.getPosition().x, object.getPosition().z, 41, 44, 0) + core.mapService.addLocation(object.getPlanet(), '@map_loc_cat_n:terminal_mission', object.getPosition().x, object.getPosition().z, 41, 44, 0) 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 4103f954..f97abb2a 100644 --- a/scripts/object/tangible/terminal/terminal_mission_bounty.py +++ b/scripts/object/tangible/terminal/terminal_mission_bounty.py @@ -2,4 +2,5 @@ import sys def setup(core, object): object.setAttachment("terminalType", 2) + core.mapService.addLocation(object.getPlanet(), '@map_loc_cat_n:terminal_mission_bounty', object.getPosition().x, object.getPosition().z, 41, 78, 0) return \ No newline at end of file diff --git a/src/resources/common/BountyListItem.java b/src/resources/common/BountyListItem.java index 5581483c..696d24df 100644 --- a/src/resources/common/BountyListItem.java +++ b/src/resources/common/BountyListItem.java @@ -29,6 +29,7 @@ import com.sleepycat.persist.model.PrimaryKey; @Entity public class BountyListItem { + @PrimaryKey private long objectId; private int creditReward; @@ -84,7 +85,7 @@ public class BountyListItem { } public void addBounty(int amountToAdd) { - this.creditReward =+ amountToAdd; + this.creditReward += amountToAdd; } public List getAssignedHunters() { @@ -95,11 +96,11 @@ public class BountyListItem { this.assignedHunters = assignedHunters; } - public boolean addBountyHunter(long objectId) { - return assignedHunters.add(objectId); + public void addBountyHunter(long objectId) { + assignedHunters.add(objectId); } - public boolean removeBountyHunter(long objectId) { - return assignedHunters.remove(objectId); + public void removeBountyHunter(long objectId) { + assignedHunters.remove(objectId); } } diff --git a/src/services/ConnectionService.java b/src/services/ConnectionService.java index ff79d72c..c27423cd 100644 --- a/src/services/ConnectionService.java +++ b/src/services/ConnectionService.java @@ -270,6 +270,8 @@ public class ConnectionService implements INetworkDispatch { } }*/ + core.missionService.getBountyList().remove(core.getBountiesODB().get(object.getObjectId(), Long.class, BountyListItem.class)); + ghost.toggleFlag(PlayerFlags.LD); object.setPerformanceListenee(null); diff --git a/src/services/PlayerService.java b/src/services/PlayerService.java index 4011ef36..62f6e14a 100644 --- a/src/services/PlayerService.java +++ b/src/services/PlayerService.java @@ -1255,18 +1255,21 @@ public class PlayerService implements INetworkDispatch { } 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(), + 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, 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))); - } + int bounty = Integer.parseInt(returnList.get(0)); + + if (bounty > victim.getBankCredits()) + return; + + if (!core.missionService.addToExistingBounty(attacker, bounty)) + core.missionService.createNewBounty(attacker, bounty); + + victim.setBankCredits(victim.getBankCredits() - bounty); } } diff --git a/src/services/combat/CombatService.java b/src/services/combat/CombatService.java index 1fa2fe93..301bf037 100644 --- a/src/services/combat/CombatService.java +++ b/src/services/combat/CombatService.java @@ -988,11 +988,12 @@ public class CombatService implements INetworkDispatch { target.setSpeedMultiplierBase(0); target.setTurnRadius(0); - if(target.getDuelList().contains(attacker)) handleEndDuel(target, attacker, false); + if(!target.getDuelList().contains(attacker) && attacker.getSlottedObject("ghost") != null) + core.playerService.sendSetBountyWindow(target, attacker); + else + 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/MissionService.java b/src/services/mission/MissionService.java index d463893a..f701ad2e 100644 --- a/src/services/mission/MissionService.java +++ b/src/services/mission/MissionService.java @@ -37,6 +37,7 @@ import org.apache.mina.core.buffer.IoBuffer; import org.apache.mina.core.session.IoSession; import com.sleepycat.je.Transaction; +import com.sleepycat.persist.EntityCursor; import protocol.swg.ObjControllerMessage; import protocol.swg.objectControllerObjects.MissionAbort; @@ -83,6 +84,8 @@ public class MissionService implements INetworkDispatch { loadMissionEntryCounts(); bountiesODB = core.getBountiesODB(); + + cleanupBounties(); // delete any characters from the bounties odb if they no longer exist. } @Override @@ -239,7 +242,7 @@ public class MissionService implements INetworkDispatch { missionStrings++; } } - System.out.println("Loaded " + missionStrings + " mission entry counts."); + //System.out.println("Loaded " + missionStrings + " mission entry counts."); } @@ -282,7 +285,8 @@ public class MissionService implements INetworkDispatch { randomDeliveryMission(player, mission); else if (type == TerminalType.BOUNTY) - randomBountyMission(player, mission); + //randomBountyMission(player, mission); + return; else if (type == TerminalType.ARTISAN) return; @@ -519,34 +523,65 @@ public class MissionService implements INetworkDispatch { BountyListItem bounty = new BountyListItem(bountyTarget.getObjectId(), reward, core.playerService.getFormalProfessionName(player.getProfession()), bountyTarget.getFaction(), bountyTarget.getCustomName()); + Transaction txn = bountiesODB.getEnvironment().beginTransaction(null, null); + bountiesODB.put(bounty, Long.class, BountyListItem.class, txn); + txn.commitSync(); + 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); - + + //System.out.println("Created bounty of " + reward + " to " + bounty.getName()); 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(); + bounty.addBounty(amountToAdd); + + Transaction txn = bountiesODB.getEnvironment().beginTransaction(null, null); + bountiesODB.put(bounty, Long.class, BountyListItem.class, txn); + txn.commitSync(); + //System.out.println("Added bounty of " + amountToAdd + " to " + bounty.getName()); return true; } + public boolean removeBounty(CreatureObject bountyTarget, boolean listRemove) { + Transaction txn = bountiesODB.getEnvironment().beginTransaction(null, null); + + if (listRemove) + bountyList.remove(bountiesODB.get(bountyTarget.getObjectId(), Long.class, BountyListItem.class)); + + bountiesODB.delete(bountyTarget.getObjectId(), Long.class, BountyListItem.class, txn); + txn.commitSync(); + return true; + } + + public boolean removeBounty(CreatureObject bountyTarget) { + return removeBounty(bountyTarget, true); + } + + private void cleanupBounties() { + AtomicInteger bountyCount = new AtomicInteger(); + Transaction txn = bountiesODB.getEnvironment().beginTransaction(null, null); + EntityCursor bountyCursor = bountiesODB.getEntityStore().getPrimaryIndex(Long.class, BountyListItem.class).entities(txn, null); + bountyCursor.forEach(bounty -> { + if (!core.characterService.playerExists(bounty.getObjectId())) { + bountyCursor.delete(); + bountyCount.getAndIncrement(); + } + }); + bountyCursor.close(); + txn.commitSync(); + + if (bountyCount.get() != 0) + System.out.println("Removed " + bountyCount.get() + " bounties."); + } + @Override public void shutdown() { } diff --git a/src/services/object/ObjectService.java b/src/services/object/ObjectService.java index 3aba2e5f..0923192d 100644 --- a/src/services/object/ObjectService.java +++ b/src/services/object/ObjectService.java @@ -913,6 +913,10 @@ public class ObjectService implements INetworkDispatch { if(!core.getConfig().getString("MOTD").equals("")) creature.sendSystemMessage(core.getConfig().getString("MOTD"), (byte) 2); + BountyListItem bounty = core.getBountiesODB().get(creature.getObjectId(), Long.class, BountyListItem.class); + if (bounty != null) + core.missionService.getBountyList().add(bounty); + core.playerService.postZoneIn(creature); }