From 6e9be7e610bb1a7b705864ba48a9a4465ef98774 Mon Sep 17 00:00:00 2001 From: Waverunner Date: Wed, 30 Apr 2014 15:54:44 -0400 Subject: [PATCH] Setting bounties now accounts for all of your available funds --- scripts/commands/setgodmode.py | 7 ++-- src/resources/common/BountyListItem.java | 14 ++++++-- src/services/PlayerService.java | 42 +++++++++++++++++++----- src/services/mission/MissionService.java | 10 ++++-- 4 files changed, 56 insertions(+), 17 deletions(-) diff --git a/scripts/commands/setgodmode.py b/scripts/commands/setgodmode.py index 63019d92..b0e78d52 100644 --- a/scripts/commands/setgodmode.py +++ b/scripts/commands/setgodmode.py @@ -113,11 +113,8 @@ def run(core, actor, target, commandString): actor.removeAbility("admin") playerObject.setGodLevel(0) - elif command == 'setBounty' and 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) + elif command == 'setBounty': + core.playerService.sendSetBountyWindow(actor, actor) return return diff --git a/src/resources/common/BountyListItem.java b/src/resources/common/BountyListItem.java index 696d24df..1733c1a7 100644 --- a/src/resources/common/BountyListItem.java +++ b/src/resources/common/BountyListItem.java @@ -27,7 +27,7 @@ import java.util.List; import com.sleepycat.persist.model.Entity; import com.sleepycat.persist.model.PrimaryKey; -@Entity +@Entity(version=1) public class BountyListItem { @PrimaryKey @@ -37,7 +37,8 @@ public class BountyListItem { private String faction; private String name; private List assignedHunters; - + private List bountyPlacers; + public BountyListItem() { } public BountyListItem(long objectId, int creditReward, String profession, String faction, String name) { @@ -47,6 +48,7 @@ public class BountyListItem { this.faction = faction; this.setName(name); this.setAssignedHunters(new ArrayList(3)); + this.setBountyPlacers(new ArrayList()); } public long getObjectId() { @@ -103,4 +105,12 @@ public class BountyListItem { public void removeBountyHunter(long objectId) { assignedHunters.remove(objectId); } + + public List getBountyPlacers() { + return bountyPlacers; + } + + public void setBountyPlacers(List bountyPlacers) { + this.bountyPlacers = bountyPlacers; + } } diff --git a/src/services/PlayerService.java b/src/services/PlayerService.java index 62f6e14a..b37c49a0 100644 --- a/src/services/PlayerService.java +++ b/src/services/PlayerService.java @@ -1255,25 +1255,51 @@ public class PlayerService implements INetworkDispatch { } public void sendSetBountyWindow(final CreatureObject victim, final CreatureObject attacker) { - 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() { + 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 " + + String.valueOf(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) { int bounty = Integer.parseInt(returnList.get(0)); + int totalFunds = victim.getBankCredits() + victim.getCashCredits(); - if (bounty > victim.getBankCredits()) + if (bounty > totalFunds) { + victim.sendSystemMessage("@bounty_hunter:setbounty_too_much", DisplayType.Broadcast); + sendSetBountyWindow(victim, attacker); return; - - if (!core.missionService.addToExistingBounty(attacker, bounty)) - core.missionService.createNewBounty(attacker, bounty); - - victim.setBankCredits(victim.getBankCredits() - bounty); + } + + if (bounty < 20000) { + victim.sendSystemMessage("@bounty_hunter:setbounty_too_little", DisplayType.Broadcast); + sendSetBountyWindow(victim, attacker); + return; + } else if (bounty > 1000000) { + victim.sendSystemMessage("@bounty_hunter:setbounty_cap", DisplayType.Broadcast); + bounty = 1000000; + } + + // Try removing bounty amount from the bank first then cash. Remove amount accordingly if bank/cash is less than placed bounty. + if (bounty > victim.getBankCredits()) { + int difference = bounty - victim.getBankCredits(); + + victim.setCashCredits(victim.getCashCredits() - difference); + victim.setBankCredits(0); + } else if (bounty > victim.getCashCredits()) { + int difference = bounty - victim.getCashCredits(); + + victim.setBankCredits(victim.getBankCredits() - difference); + victim.setCashCredits(0); + } else { victim.setBankCredits(victim.getBankCredits() - bounty); } + + if (!core.missionService.addToExistingBounty(attacker, victim.getObjectId(), bounty)) + core.missionService.createNewBounty(attacker, victim.getObjectId(), bounty); } } }); + bountyWindow.setProperty("txtInput:NumericInteger", "true"); + bountyWindow.setProperty("txtInput:MaxLength", "7"); core.suiService.openSUIWindow(bountyWindow); } diff --git a/src/services/mission/MissionService.java b/src/services/mission/MissionService.java index f701ad2e..ce658a23 100644 --- a/src/services/mission/MissionService.java +++ b/src/services/mission/MissionService.java @@ -513,7 +513,7 @@ public class MissionService implements INetworkDispatch { return null; } - public BountyListItem createNewBounty(CreatureObject bountyTarget, int reward) { + public BountyListItem createNewBounty(CreatureObject bountyTarget, long placer, int reward) { PlayerObject player = (PlayerObject) bountyTarget.getSlottedObject("ghost"); if (player == null) return null; @@ -523,6 +523,9 @@ public class MissionService implements INetworkDispatch { BountyListItem bounty = new BountyListItem(bountyTarget.getObjectId(), reward, core.playerService.getFormalProfessionName(player.getProfession()), bountyTarget.getFaction(), bountyTarget.getCustomName()); + if (placer != 0) + bounty.getBountyPlacers().add(placer); + Transaction txn = bountiesODB.getEnvironment().beginTransaction(null, null); bountiesODB.put(bounty, Long.class, BountyListItem.class, txn); txn.commitSync(); @@ -533,7 +536,7 @@ public class MissionService implements INetworkDispatch { return bounty; } - public boolean addToExistingBounty(CreatureObject bountyTarget, int amountToAdd) { + public boolean addToExistingBounty(CreatureObject bountyTarget, long placer, int amountToAdd) { BountyListItem bounty = getBountyListItem(bountyTarget.getObjectId()); @@ -541,6 +544,9 @@ public class MissionService implements INetworkDispatch { return false; bounty.addBounty(amountToAdd); + + if (placer != 0) + bounty.getBountyPlacers().add(placer); Transaction txn = bountiesODB.getEnvironment().beginTransaction(null, null); bountiesODB.put(bounty, Long.class, BountyListItem.class, txn);