From 14e71babd5fbd682618143040551c60b66eeeb91 Mon Sep 17 00:00:00 2001 From: RobCubed Date: Tue, 28 Oct 2014 21:21:29 -0400 Subject: [PATCH 1/4] Bank tip now works both locally, targeted, and across planets. Fixed up tip type detection. Fixed error where tip resets total amount of target. --- scripts/commands/tip.py | 72 ++++++++++++++++++++++++++++------------- 1 file changed, 50 insertions(+), 22 deletions(-) diff --git a/scripts/commands/tip.py b/scripts/commands/tip.py index b34992f2..02628183 100644 --- a/scripts/commands/tip.py +++ b/scripts/commands/tip.py @@ -1,4 +1,6 @@ +from resources.objects.creature import CreatureObject from java.util import Date +from engine.resources.objects import SWGObject from services.chat import ChatService from services.chat import Mail from services.sui import SUIWindow @@ -8,6 +10,7 @@ from services.sui.SUIService import MessageBoxType from java.util import Vector from main import NGECore import sys +import math # initialize global vars (happens at compile time) commandArgs = "" @@ -15,7 +18,6 @@ commandLength = 0 actorID = long(0) targetID = long(0) tipAmount = 0 -tipAmountBank = 0 bankSurcharge = 0 @@ -30,16 +32,36 @@ def run(core, actor, target, commandString): global commandArgs global commandLength global tipAmount - global tipAmountBank global bankSurcharge - + actorID = actor.getObjectID() - targetID = target.getObjectID() commandArgs = commandString.split(" ") commandLength = len(commandArgs) - tipAmount = commandArgs[0] - tipAmountBank = commandArgs[0] - bankSurcharge = int(0.05) * int(tipAmountBank) + + # Determine type of tip + if not commandArgs[0].isdigit(): + tipAmount = int(commandArgs[1]) + bankSurcharge = int(math.ceil(0.05 * float(tipAmount))) # Accurate tipping tax - prevents floating point error + targetID = core.chatService.getObjectByFirstName(commandArgs[0]).getObjectID(); + if isinstance(commandArgs[2], basestring): + if not commandArgs[2].lower() == "bank": + actor.sendSystemMessage('Unrecognized tip command', 0) + return + else: + actor.sendSystemMessage('Unrecognized tip command', 0) + return + else: + tipAmount = int(commandArgs[0]) + bankSurcharge = int(math.ceil(0.05 * float(tipAmount))) + targetID = target.getObjectID() + if commandLength > 1: + if isinstance(commandArgs[1], basestring): + if not commandArgs[1].lower() == "bank": + actor.sendSystemMessage('Unrecognized tip command', 0) + return + else: + actor.sendSystemMessage('Unrecognized tip command', 0) + return #/tip int || /tip target int @@ -52,8 +74,8 @@ def run(core, actor, target, commandString): if (actor.inRange(target.getPosition(), 100)): # 100 = 10m if int(tipAmount) > 0 and int(tipAmount) <= 1000000: if actorFunds >= int(tipAmount): - currentTarget.setCashCredits(int(tipAmount)) - actor.setCashCredits(actorFunds - int(tipAmount)) + currentTarget.addCashCredits(int(tipAmount)) + actor.deductCashCredits(int(tipAmount)) currentTarget.sendSystemMessage(actor.getCustomName() + ' tips you ' + tipAmount + ' credits.', 0) actor.sendSystemMessage('You successfully tip ' + tipAmount + ' credits to ' + currentTarget.getCustomName() + '.', 0) @@ -66,7 +88,7 @@ def run(core, actor, target, commandString): return #/tip target 30000000 bank - if commandLength == 2: + if commandLength >= 2: suiSvc = core.suiService suiWindow = suiSvc.createMessageBox(MessageBoxType.MESSAGE_BOX_YES_NO, "@base_player:tip_wire_title", "@base_player:tip_wire_prompt", actor, actor, 10) @@ -80,13 +102,20 @@ def run(core, actor, target, commandString): return return -def handleBankTip(owner, window, eventType, returnList): +def handleBankTip(core, owner, eventType, returnList): core = NGECore.getInstance() chatSvc = core.chatService actorGlobal = core.objectService.getObject(actorID) - targetGlobal = core.objectService.getObject(targetID) + targetGlobal = 0 + + #We need to determine how the tip is being delivered, either by /tip 1000 bank (targeted) or /tip name 1000 bank + if not commandArgs[0].isdigit(): + targetGlobal = core.chatService.getObjectByFirstName(commandArgs[0]); + else: + targetGlobal = core.objectService.getObject(targetID) actorFunds = actorGlobal.getBankCredits() - totalLost = int(tipAmountBank) + bankSurcharge + totalLost = int(tipAmount) + bankSurcharge + if eventType == 0: if int(totalLost) > actorFunds: @@ -101,7 +130,7 @@ def handleBankTip(owner, window, eventType, returnList): targetMail.setTimeStamp((int) (date.getTime() / 1000)) targetMail.setRecieverId(targetID) targetMail.setStatus(Mail.NEW) - targetMail.setMessage(tipAmount + ' credits from ' + actorGlobal.getCustomName() + ' have been successfully delivered from escrow to your bank account') + targetMail.setMessage(`tipAmount` + ' credits from ' + actorGlobal.getCustomName() + ' have been successfully delivered from escrow to your bank account') targetMail.setSubject('@base_player:wire_mail_subject') targetMail.setSenderName('bank') @@ -110,15 +139,14 @@ def handleBankTip(owner, window, eventType, returnList): actorMail.setRecieverId(actorID) actorMail.setStatus(Mail.NEW) actorMail.setTimeStamp((int) (date.getTime() / 1000)) - actorMail.setMessage('An amount of ' + tipAmount + ' credits have been transfered from your bank to escrow. It will be delivered to ' + - targetGlobal.getCustomName() + ' as soon as possible.') + actorMail.setMessage('An amount of ' + `tipAmount` + ' credits have been transfered from your bank to escrow. It will be delivered to ' + targetGlobal.getCustomName() + ' as soon as possible.') actorMail.setSubject('@base_player:wire_mail_subject') actorMail.setSenderName('bank') - targetGlobal.setBankCredits(int(tipAmount) + int(targetGlobal.getBankCredits())) - actorGlobal.setBankCredits(int(actorFunds) - int(totalLost)) - actorGlobal.sendSystemMessage('You have successfully sent ' + tipAmount + ' bank credits to ' + targetGlobal.getCustomName(), 0) - targetGlobal.sendSystemMessage('You have successfully received ' + tipAmount + ' bank credits from ' + actorGlobal.getCustomName(), 0) + targetGlobal.addBankCredits(int(tipAmount)) + actorGlobal.deductBankCredits(int(totalLost)) + actorGlobal.sendSystemMessage('You have successfully sent ' + `tipAmount` + ' bank credits to ' + targetGlobal.getCustomName(), 0) + targetGlobal.sendSystemMessage('You have successfully received ' + `tipAmount` + ' bank credits from ' + actorGlobal.getCustomName(), 0) chatSvc.storePersistentMessage(actorMail) chatSvc.storePersistentMessage(targetMail) @@ -127,6 +155,6 @@ def handleBankTip(owner, window, eventType, returnList): return else: - actorGlobal.sendSystemMessage('You lack the bank funds to wire ' + tipAmount + ' bank funds to ' + targetGlobal.getCustomName() + '.', 0) + actorGlobal.sendSystemMessage('You lack the bank funds to wire ' + `tipAmount` + ' bank funds to ' + targetGlobal.getCustomName() + '.', 0) return - return + return \ No newline at end of file From 6e605a0caa4de3c549d914a43f5bdc275a2f1293 Mon Sep 17 00:00:00 2001 From: RobCubed Date: Tue, 28 Oct 2014 21:24:19 -0400 Subject: [PATCH 2/4] Removed repeated bankSurcharge calculation --- scripts/commands/tip.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/scripts/commands/tip.py b/scripts/commands/tip.py index 02628183..d1f2c6ca 100644 --- a/scripts/commands/tip.py +++ b/scripts/commands/tip.py @@ -33,15 +33,15 @@ def run(core, actor, target, commandString): global commandLength global tipAmount global bankSurcharge - + actorID = actor.getObjectID() commandArgs = commandString.split(" ") commandLength = len(commandArgs) + bankSurcharge = int(math.ceil(0.05 * float(tipAmount))) # Accurate tipping tax - prevents floating point error # Determine type of tip if not commandArgs[0].isdigit(): tipAmount = int(commandArgs[1]) - bankSurcharge = int(math.ceil(0.05 * float(tipAmount))) # Accurate tipping tax - prevents floating point error targetID = core.chatService.getObjectByFirstName(commandArgs[0]).getObjectID(); if isinstance(commandArgs[2], basestring): if not commandArgs[2].lower() == "bank": @@ -52,7 +52,6 @@ def run(core, actor, target, commandString): return else: tipAmount = int(commandArgs[0]) - bankSurcharge = int(math.ceil(0.05 * float(tipAmount))) targetID = target.getObjectID() if commandLength > 1: if isinstance(commandArgs[1], basestring): From 9edc362d9bbf7df0bf8a573cb3f725564ba4e819 Mon Sep 17 00:00:00 2001 From: RobCubed Date: Tue, 28 Oct 2014 21:26:02 -0400 Subject: [PATCH 3/4] bankSurcharge placement after tipAmount found --- scripts/commands/tip.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/scripts/commands/tip.py b/scripts/commands/tip.py index d1f2c6ca..9a4fac64 100644 --- a/scripts/commands/tip.py +++ b/scripts/commands/tip.py @@ -37,7 +37,6 @@ def run(core, actor, target, commandString): actorID = actor.getObjectID() commandArgs = commandString.split(" ") commandLength = len(commandArgs) - bankSurcharge = int(math.ceil(0.05 * float(tipAmount))) # Accurate tipping tax - prevents floating point error # Determine type of tip if not commandArgs[0].isdigit(): @@ -61,6 +60,8 @@ def run(core, actor, target, commandString): else: actor.sendSystemMessage('Unrecognized tip command', 0) return + + bankSurcharge = int(math.ceil(0.05 * float(tipAmount))) # Accurate tipping tax - prevents floating point error #/tip int || /tip target int From d5ea0b500da62f26fecb5e285b6bfb5418c3367f Mon Sep 17 00:00:00 2001 From: RobCubed Date: Wed, 29 Oct 2014 22:25:38 -0400 Subject: [PATCH 4/4] Refactored tips. Line of sight not working correctly. --- scripts/commands/tip.py | 270 +++++++++++++++++++++------------------- 1 file changed, 139 insertions(+), 131 deletions(-) diff --git a/scripts/commands/tip.py b/scripts/commands/tip.py index 9a4fac64..16bf0b93 100644 --- a/scripts/commands/tip.py +++ b/scripts/commands/tip.py @@ -12,149 +12,157 @@ from main import NGECore import sys import math -# initialize global vars (happens at compile time) -commandArgs = "" -commandLength = 0 -actorID = long(0) -targetID = long(0) -tipAmount = 0 -bankSurcharge = 0 - - def setup(): return def run(core, actor, target, commandString): - - # set the global variables - global actorID - global targetID - global commandArgs - global commandLength - global tipAmount - global bankSurcharge - - actorID = actor.getObjectID() + processTip = {0: failure, + 1: tipTarget, + 2: tipTargetBank, + 3: tipName, + 4: tipNameBank} commandArgs = commandString.split(" ") - commandLength = len(commandArgs) + type = tipType(core, actor, target, commandArgs) + processTip[type](core, actor, target, commandArgs) + +def failure(core, actor, target, commandArgs): + sys.stdout.write("Failure\n") - # Determine type of tip - if not commandArgs[0].isdigit(): +def tipTarget(core, actor, target, commandArgs): + tipTo = getDirectTarget(core, actor, target) + tipAmount = int(commandArgs[0]) + # Prioritize LOCKED target. ONLY IF NO LOCKED TARGET, do we transfer to the mouseover target! + transferMoneyDirect(actor, tipTo, tipAmount) + +def tipTargetBank(core, actor, target, commandArgs): + tipTo = getDirectTarget(core, actor, target) + tipAmount = int(commandArgs[0]) + # Prioritize LOCKED target. ONLY IF NO LOCKED TARGET, do we transfer to the mouseover target! + transferMoneyBank(actor, tipTo, tipAmount, core) + +def tipName(core, actor, target, commandArgs): + tipTo = getRemoteTarget(core, commandArgs[0]) + if tipTo is not None: tipAmount = int(commandArgs[1]) - targetID = core.chatService.getObjectByFirstName(commandArgs[0]).getObjectID(); - if isinstance(commandArgs[2], basestring): - if not commandArgs[2].lower() == "bank": - actor.sendSystemMessage('Unrecognized tip command', 0) - return - else: - actor.sendSystemMessage('Unrecognized tip command', 0) - return - else: - tipAmount = int(commandArgs[0]) - targetID = target.getObjectID() - if commandLength > 1: - if isinstance(commandArgs[1], basestring): - if not commandArgs[1].lower() == "bank": - actor.sendSystemMessage('Unrecognized tip command', 0) - return - else: - actor.sendSystemMessage('Unrecognized tip command', 0) - return - - bankSurcharge = int(math.ceil(0.05 * float(tipAmount))) # Accurate tipping tax - prevents floating point error + transferMoneyDirect(actor, tipTo, tipAmount) + else: + return - - #/tip int || /tip target int - if commandLength == 1: - - tipAmount = commandArgs[0] - actorFunds = actor.getCashCredits() - currentTarget = core.objectService.getObject(target.getObjectId()) - - if (actor.inRange(target.getPosition(), 100)): # 100 = 10m - if int(tipAmount) > 0 and int(tipAmount) <= 1000000: - if actorFunds >= int(tipAmount): - currentTarget.addCashCredits(int(tipAmount)) - actor.deductCashCredits(int(tipAmount)) - - currentTarget.sendSystemMessage(actor.getCustomName() + ' tips you ' + tipAmount + ' credits.', 0) - actor.sendSystemMessage('You successfully tip ' + tipAmount + ' credits to ' + currentTarget.getCustomName() + '.', 0) - return - actor.sendSystemMessage('You lack the cash funds to tip ' + tipAmount + ' credits to ' + currentTarget.getCustomName() + '.', 0) - return - actor.sendSystemMessage('Invalid tip amount, set amount between 1 and 1,000,000 credits', 0) - return - actor.sendSystemMessage('Target is too far away. Try a wire bank transfer instead.', 0) +def tipNameBank(core, actor, target, commandArgs): + tipTo = getRemoteTarget(core, commandArgs[0]) + if tipTo is not None: + tipAmount = int(commandArgs[1]) + transferMoneyBank(actor, tipTo, tipAmount, core) + else: return + +def transferMoneyDirect(tipFrom, tipTo, transferTotal): + actorFunds = tipFrom.getCashCredits() - #/tip target 30000000 bank - if commandLength >= 2: - suiSvc = core.suiService - suiWindow = suiSvc.createMessageBox(MessageBoxType.MESSAGE_BOX_YES_NO, "@base_player:tip_wire_title", "@base_player:tip_wire_prompt", actor, actor, 10) - - returnParams = Vector() - returnParams.add('btnOk:Text') - returnParams.add('btnCancel:Text') - suiWindow.addHandler(0, '', Trigger.TRIGGER_OK, returnParams, handleBankTip) - suiWindow.addHandler(1, '', Trigger.TRIGGER_CANCEL, returnParams, handleBankTip) - - suiSvc.openSUIWindow(suiWindow) + if (tipFrom.inRange(tipTo.getPosition(), 100)): # 100 = 10m + if int(transferTotal) > 0 and int(transferTotal) <= 1000000: + if actorFunds >= int(transferTotal): + tipTo.addCashCredits(int(transferTotal)) + tipFrom.deductCashCredits(int(transferTotal)) + + tipTo.sendSystemMessage(tipFrom.getCustomName() + ' tips you ' + `transferTotal` + ' credits.', 0) + tipFrom.sendSystemMessage('You successfully tip ' + `transferTotal` + ' credits to ' + tipTo.getCustomName() + '.', 0) + return + tipFrom.sendSystemMessage('You lack the cash funds to tip ' + `transferTotal` + ' credits to ' + tipTo.getCustomName() + '.', 0) + return + tipFrom.sendSystemMessage('Invalid tip amount, set amount between 1 and 1,000,000 credits', 0) return + tipFrom.sendSystemMessage('Target is too far away. Try a wire bank transfer instead.', 0) return -def handleBankTip(core, owner, eventType, returnList): - core = NGECore.getInstance() - chatSvc = core.chatService - actorGlobal = core.objectService.getObject(actorID) - targetGlobal = 0 - - #We need to determine how the tip is being delivered, either by /tip 1000 bank (targeted) or /tip name 1000 bank - if not commandArgs[0].isdigit(): - targetGlobal = core.chatService.getObjectByFirstName(commandArgs[0]); - else: - targetGlobal = core.objectService.getObject(targetID) - actorFunds = actorGlobal.getBankCredits() - totalLost = int(tipAmount) + bankSurcharge - - - if eventType == 0: - if int(totalLost) > actorFunds: - actorGlobal.sendSystemMessage('You do not have ' + str(totalLost) + ' credits (surcharge included) to tip the desired amount to ' + targetGlobal.getCustomName() + '.', 0) - return - if int(tipAmount) > 0 and int(actorFunds) >= int(totalLost): - date = Date() - targetName = targetGlobal.getCustomName() - - targetMail = Mail() - targetMail.setMailId(chatSvc.generateMailId()) - targetMail.setTimeStamp((int) (date.getTime() / 1000)) - targetMail.setRecieverId(targetID) - targetMail.setStatus(Mail.NEW) - targetMail.setMessage(`tipAmount` + ' credits from ' + actorGlobal.getCustomName() + ' have been successfully delivered from escrow to your bank account') - targetMail.setSubject('@base_player:wire_mail_subject') - targetMail.setSenderName('bank') - - actorMail = Mail() - actorMail.setMailId(chatSvc.generateMailId()) - actorMail.setRecieverId(actorID) - actorMail.setStatus(Mail.NEW) - actorMail.setTimeStamp((int) (date.getTime() / 1000)) - actorMail.setMessage('An amount of ' + `tipAmount` + ' credits have been transfered from your bank to escrow. It will be delivered to ' + targetGlobal.getCustomName() + ' as soon as possible.') - actorMail.setSubject('@base_player:wire_mail_subject') - actorMail.setSenderName('bank') - - targetGlobal.addBankCredits(int(tipAmount)) - actorGlobal.deductBankCredits(int(totalLost)) - actorGlobal.sendSystemMessage('You have successfully sent ' + `tipAmount` + ' bank credits to ' + targetGlobal.getCustomName(), 0) - targetGlobal.sendSystemMessage('You have successfully received ' + `tipAmount` + ' bank credits from ' + actorGlobal.getCustomName(), 0) - - chatSvc.storePersistentMessage(actorMail) - chatSvc.storePersistentMessage(targetMail) - chatSvc.sendPersistentMessageHeader(actorGlobal.getClient(), actorMail) - chatSvc.sendPersistentMessageHeader(targetGlobal.getClient(), targetMail) - return +def transferMoneyBank(tipFrom, tipTo, transferTotal, core): + def handleBankTip(core, owner, eventType, returnList): + bankSurcharge = int(math.ceil(0.05 * float(transferTotal))) + core = NGECore.getInstance() + chatSvc = core.chatService + actorGlobal = tipFrom + targetGlobal = tipTo + actorFunds = actorGlobal.getBankCredits() + totalLost = int(transferTotal) + bankSurcharge - else: - actorGlobal.sendSystemMessage('You lack the bank funds to wire ' + `tipAmount` + ' bank funds to ' + targetGlobal.getCustomName() + '.', 0) + if eventType == 0: + if int(totalLost) > actorFunds: + actorGlobal.sendSystemMessage('You do not have ' + str(totalLost) + ' credits (surcharge included) to tip the desired amount to ' + targetGlobal.getCustomName() + '.', 0) + return + if int(transferTotal) > 0 and int(actorFunds) >= int(totalLost): + date = Date() + targetName = targetGlobal.getCustomName() + + targetMail = Mail() + targetMail.setMailId(chatSvc.generateMailId()) + targetMail.setTimeStamp((int) (date.getTime() / 1000)) + targetMail.setRecieverId(targetGlobal.getObjectId()) + targetMail.setStatus(Mail.NEW) + targetMail.setMessage(`transferTotal` + ' credits from ' + actorGlobal.getCustomName() + ' have been successfully delivered from escrow to your bank account') + targetMail.setSubject('@base_player:wire_mail_subject') + targetMail.setSenderName('bank') + + actorMail = Mail() + actorMail.setMailId(chatSvc.generateMailId()) + actorMail.setRecieverId(actorGlobal.getObjectId()) + actorMail.setStatus(Mail.NEW) + actorMail.setTimeStamp((int) (date.getTime() / 1000)) + actorMail.setMessage('An amount of ' + `transferTotal` + ' credits have been transfered from your bank to escrow. It will be delivered to ' + targetGlobal.getCustomName() + ' as soon as possible.') + actorMail.setSubject('@base_player:wire_mail_subject') + actorMail.setSenderName('bank') + + targetGlobal.addBankCredits(int(transferTotal)) + actorGlobal.deductBankCredits(int(totalLost)) + actorGlobal.sendSystemMessage('You have successfully sent ' + `transferTotal` + ' bank credits to ' + targetGlobal.getCustomName(), 0) + targetGlobal.sendSystemMessage('You have successfully received ' + `transferTotal` + ' bank credits from ' + actorGlobal.getCustomName(), 0) + + chatSvc.storePersistentMessage(actorMail) + chatSvc.storePersistentMessage(targetMail) + chatSvc.sendPersistentMessageHeader(actorGlobal.getClient(), actorMail) + chatSvc.sendPersistentMessageHeader(targetGlobal.getClient(), targetMail) + return + else: + actorGlobal.sendSystemMessage('You lack the bank funds to wire ' + `transferTotal` + ' bank funds to ' + targetGlobal.getCustomName() + '.', 0) + return return - return \ No newline at end of file + + suiSvc = core.suiService + suiWindow = suiSvc.createMessageBox(MessageBoxType.MESSAGE_BOX_YES_NO, "@base_player:tip_wire_title", "@base_player:tip_wire_prompt", tipFrom, tipFrom, 10) + + returnParams = Vector() + returnParams.add('btnOk:Text') + returnParams.add('btnCancel:Text') + suiWindow.addHandler(0, '', Trigger.TRIGGER_OK, returnParams, handleBankTip) + suiWindow.addHandler(1, '', Trigger.TRIGGER_CANCEL, returnParams, handleBankTip) + + suiSvc.openSUIWindow(suiWindow) + + +def getDirectTarget(core, actor, target): + if core.objectService.getObject(actor.getTargetId()) is not None and target is None: + return core.objectService.getObject(actor.getTargetId()) + else: + return target + +def getRemoteTarget(core, name): + target = core.chatService.getObjectByFirstName(name) + if target is not None: + return target + return None + + +def tipType(core, actor, target, commandArgs): + commandLength = len(commandArgs) + if commandLength == 1 and commandArgs[0].isdigit() and (((actor.getTargetId() is not None) and (actor.getTargetId() != actor.getObjectId()) and (actor.getTargetId() != 0L)) or (target is not None)): + return 1 + if commandLength == 2: + if commandArgs[0].isdigit() and isinstance(commandArgs[1], basestring) and (((actor.getTargetId() is not None) and (actor.getTargetId() != actor.getObjectId()) and (actor.getTargetId() != 0L)) or (target is not None)): + if commandArgs[1].lower() == "bank": + return 2 + if isinstance(commandArgs[0], basestring) and commandArgs[1].isdigit(): + if not commandArgs[0].lower() == "bank": + return 3 + if commandLength == 3 and isinstance(commandArgs[0], basestring) and commandArgs[1].isdigit() and isinstance(commandArgs[2], basestring): + if commandArgs[2].lower() == "bank" and not commandArgs[0].lower() == "bank": + return 4 + return 0 \ No newline at end of file