- 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
master
temitchell 2003-10-25 02:20:08 +00:00
parent 616a6f3c72
commit 55d9353f1c
7 changed files with 37 additions and 27 deletions

View File

@ -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

View File

@ -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?'

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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:

View File

@ -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: