From 55d9353f1cdcd6a3e9f083e225e062946a20a2cc Mon Sep 17 00:00:00 2001 From: temitchell Date: Sat, 25 Oct 2003 02:20:08 +0000 Subject: [PATCH] - fixed issue with slotmachines where items created reset number of existing items in the same space. (using itemborker to set number of items add or remove as a safer way to manage this.) - touched up bank dialogue (and incorporated itembroker code) git-svn-id: svn://svn.code.sf.net/p/crossfire/code/trunk/maps@2413 282e977c-c81d-0410-88c4-b93c2d0d6712 --- python/CFItemBroker.py | 15 +++++++++------ python/IPO/banksay.py | 20 ++++++++++++-------- python/casino/diamondslots.py | 8 ++++---- python/casino/goldslots.py | 5 +++-- python/casino/imperialslots.py | 6 +++--- python/casino/platinumslots.py | 5 +++-- python/casino/silverslots.py | 5 +++-- 7 files changed, 37 insertions(+), 27 deletions(-) diff --git a/python/CFItemBroker.py b/python/CFItemBroker.py index 3379d3411..d89471a3c 100644 --- a/python/CFItemBroker.py +++ b/python/CFItemBroker.py @@ -1,22 +1,25 @@ #CFItemBroker.py #An often used bit of code to add or remove a number of objects -#Mostly useful for removing items (like in payment or as part of -#an inventory check) -#This will not check for the existance of an item as that would better +#Useful for removing items (like in payment or as part of +#an inventory check) This is also useful for setting the number +#of a newly created item(s) as it will check for existing item(s) and add +#the appropriate number of new items avoiding such sillyness as the +#number of the existing items being reset. +#This will not check for the existence of an item as that would better #be done in the calling script so you can be flexable. -# +# #ToddMitchell import CFPython -class ItemBroker: +class Item: def __init__(self, object): self.object = object self.numberof = CFPython.GetQuantity(self.object) def add(self, number): - tmp = self.numberof + number + tmp = (self.numberof + number)-1 CFPython.SetQuantity(self.object, tmp) return 1 diff --git a/python/IPO/banksay.py b/python/IPO/banksay.py index ceacad717..fb92f9808 100644 --- a/python/IPO/banksay.py +++ b/python/IPO/banksay.py @@ -52,7 +52,7 @@ thanks_message = ['Thank you for banking the Imperial Way.', 'Thank you, please again.', 'Thank you, please come again.','Thank you for banking the Imperial Way.', \ 'Thank you for your patronage.', 'Thank you, have a nice day.', 'Thank you. "Service" \ is our middle name.', 'Thank you. "Service" is our middle name.', 'Thank you for your \ -patronage.', 'Thank you, have a nice day.', 'Thank you. Hows about a big slobbery \ kiss?'] +patronage.', 'Thank you, have a nice day.', 'Thank you. Hows about a big slobbery kiss?'] @@ -66,8 +66,8 @@ elif text[0] == 'deposit': if len(text)==2: if (CFPython.PayAmount(activator, (int(text[1])*exchange_rate)*fees)): bank.deposit(activatorname, int(text[1])) - message = '%d imperials deposited to bank account. %s' \ - %(int(text[1]),random.choice(thanks_message)) + message = '%d recieved, %d imperials deposited to bank account. %s' \ + %((int(text[1])*(exchange_rate/50))*fees,int(text[1]),random.choice(thanks_message)) else: message = 'You would need %d gold'%((int(text[1])*(exchange_rate/10))*fees) else: @@ -79,7 +79,7 @@ elif text[0] == 'withdraw': message = '%d imperials withdrawn from bank account. %s' \ %(int(text[1]),random.choice(thanks_message)) id = CFPython.CreateObject('imperial', (x, y)) - CFPython.SetQuantity(id, int(text[1])) + CFItemBroker.Item(id).add(int(text[1])) else: message = 'Not enough imperials on your account' else: @@ -89,10 +89,10 @@ elif text[0] == 'exchange': if len(text)==2: inv=CFPython.CheckInventory(activator,'imperial') if inv: - pay = CFItemBroker.ItemBroker(inv).subtract(int(text[1])) + pay = CFItemBroker.Item(inv).subtract(int(text[1])) if pay: id = CFPython.CreateObject('platinum coin', (x, y)) - CFPython.SetQuantity(id, int(text[1])*(exchange_rate/50)) + CFItemBroker.Item(id).add(int(text[1])*(exchange_rate/50)) message = random.choice(thanks_message) else: message = 'Sorry, you do not have %d imperials' %int(text[1]) @@ -103,8 +103,12 @@ elif text[0] == 'exchange': elif text[0] == 'balance': balance = bank.getbalance(activatorname) - message = 'Amount in bank: %d Ip'%(balance) - + if balance == 1: + message = 'Amount in bank: 1 imperial note' + elif balance: + message = 'Amount in bank: %d imperial notes'%(balance) + else: + message = 'Sorry, you have no balance.' else: message = 'Do you need help?' diff --git a/python/casino/diamondslots.py b/python/casino/diamondslots.py index e753a4583..543e7dae3 100644 --- a/python/casino/diamondslots.py +++ b/python/casino/diamondslots.py @@ -7,7 +7,7 @@ import CFPython import sys sys.path.append('%s/%s/python' %(CFPython.GetDataDirectory(),CFPython.GetMapDirectory())) import CFGamble -import CFItemBroker +import CFItemBroker activator=CFPython.WhoIsActivator() activatorname=CFPython.GetName(activator) @@ -31,7 +31,7 @@ Slots=CFGamble.SlotMachine(slotname,slotlist,minpot,maxpot) object = CFPython.CheckInventory(activator,cointype) if (object): - pay = CFItemBroker.ItemBroker(object).subtract(cost) + pay = CFItemBroker.Item(object).subtract(cost) if (pay): Slots.placebet(cost) results = Slots.spin(spinners) @@ -63,7 +63,7 @@ if (object): payoff = cost*pay Slots.payoff(payoff) id = CFPython.CreateObject(cointype, (x, y)) - CFPython.SetQuantity(id, payoff) + CFItemBroker.Item(id).add(payoff) if payoff == 1: message = "you win %d %s!" %(payoff,cointype) else: @@ -91,7 +91,7 @@ if (object): payoff = pot*pay Slots.payoff(payoff) id = CFPython.CreateObject(cointype, (x, y)) - CFPython.SetQuantity(id, payoff) + CFItemBroker.Item(id).add(payoff) if payoff == 1: message = "you win %d %s!" %(payoff,cointype) else: diff --git a/python/casino/goldslots.py b/python/casino/goldslots.py index 5b2942c9d..685a485b0 100644 --- a/python/casino/goldslots.py +++ b/python/casino/goldslots.py @@ -6,6 +6,7 @@ import CFPython import sys sys.path.append('%s/%s/python' %(CFPython.GetDataDirectory(),CFPython.GetMapDirectory())) import CFGamble +import CFItemBroker activator=CFPython.WhoIsActivator() activatorname=CFPython.GetName(activator) @@ -57,7 +58,7 @@ if (CFPython.PayAmount(activator, cost*10)):#goldcoin payoff = cost*pay Slots.payoff(payoff) id = CFPython.CreateObject(cointype, (x, y)) - CFPython.SetQuantity(id, payoff) + CFItemBroker.Item(id).add(payoff) if payoff == 1: message = "you win %d %s!" %(payoff,cointype) else: @@ -83,7 +84,7 @@ if (CFPython.PayAmount(activator, cost*10)):#goldcoin payoff = pot*pay Slots.payoff(payoff) id = CFPython.CreateObject(cointype, (x, y)) - CFPython.SetQuantity(id, payoff) + CFItemBroker.Item(id).add(payoff) if payoff == 1: message == "you win %d %s!" %(payoff,cointype) else: diff --git a/python/casino/imperialslots.py b/python/casino/imperialslots.py index d32f9070d..e8273605d 100644 --- a/python/casino/imperialslots.py +++ b/python/casino/imperialslots.py @@ -31,7 +31,7 @@ Slots=CFGamble.SlotMachine(slotname,slotlist,minpot,maxpot) object = CFPython.CheckInventory(activator,cointype) if (object): - pay = CFItemBroker.ItemBroker(object).subtract(cost) + pay = CFItemBroker.Item(object).subtract(cost) if (pay): Slots.placebet(cost) results = Slots.spin(spinners) @@ -63,7 +63,7 @@ if (object): payoff = cost*pay Slots.payoff(payoff) id = CFPython.CreateObject(cointype, (x, y)) - CFPython.SetQuantity(id, payoff) + CFItemBroker.Item(id).add(payoff) if payoff == 1: message = "you win %d %s!" %(payoff,cointype) else: @@ -91,7 +91,7 @@ if (object): payoff = pot*pay Slots.payoff(payoff) id = CFPython.CreateObject(cointype, (x, y)) - CFPython.SetQuantity(id, payoff) + CFItemBroker.Item(id).add(payoff) if payoff == 1: message = "you win %d %s!" %(payoff,cointype) else: diff --git a/python/casino/platinumslots.py b/python/casino/platinumslots.py index 3cc291966..01e2b6066 100644 --- a/python/casino/platinumslots.py +++ b/python/casino/platinumslots.py @@ -6,6 +6,7 @@ import CFPython import sys sys.path.append('%s/%s/python' %(CFPython.GetDataDirectory(),CFPython.GetMapDirectory())) import CFGamble +import CFItemBroker activator=CFPython.WhoIsActivator() activatorname=CFPython.GetName(activator) @@ -59,7 +60,7 @@ if (CFPython.PayAmount(activator, cost*50)):#platinumcoin payoff = cost*pay Slots.payoff(payoff) id = CFPython.CreateObject(cointype, (x, y)) - CFPython.SetQuantity(id, payoff) + CFItemBroker.Item(id).add(payoff) if payoff == 1: message = "you win %d %s!" %(payoff,cointype) else: @@ -87,7 +88,7 @@ if (CFPython.PayAmount(activator, cost*50)):#platinumcoin payoff = pot*pay Slots.payoff(payoff) id = CFPython.CreateObject(cointype, (x, y)) - CFPython.SetQuantity(id, payoff) + CFItemBroker.Item(id).add(payoff) if payoff == 1: message = "you win %d %s!" %(payoff,cointype) else: diff --git a/python/casino/silverslots.py b/python/casino/silverslots.py index 690e26908..dab76f8f8 100644 --- a/python/casino/silverslots.py +++ b/python/casino/silverslots.py @@ -5,6 +5,7 @@ import CFPython import sys sys.path.append('%s/%s/python' %(CFPython.GetDataDirectory(),CFPython.GetMapDirectory())) import CFGamble +import CFItemBroker activator=CFPython.WhoIsActivator() activatorname=CFPython.GetName(activator) @@ -54,7 +55,7 @@ if (CFPython.PayAmount(activator, cost)):#silvercoin payoff = cost*pay Slots.payoff(payoff) id = CFPython.CreateObject(cointype, (x, y)) - CFPython.SetQuantity(id, payoff) + CFItemBroker.Item(id).add(payoff) if payoff == 1: message = "you win %d %s!" %(payoff,cointype) else: @@ -78,7 +79,7 @@ if (CFPython.PayAmount(activator, cost)):#silvercoin payoff = pot*pay Slots.payoff(payoff) id = CFPython.CreateObject(cointype, (x, y)) - CFPython.SetQuantity(id, payoff) + CFItemBroker.Item(id).add(payoff) if payoff == 1: message = "you win %d %s!" %(payoff,cointype) else: