Bug fixes: make it work with with new Python plugin, do not make it talk to itself, prevent abuse with out of range amounts; make source-code formatting consistent.
git-svn-id: svn://svn.code.sf.net/p/crossfire/code/trunk/maps@4026 282e977c-c81d-0410-88c4-b93c2d0d6712master
parent
82aeffd187
commit
a4251b7005
|
@ -29,84 +29,121 @@ import random
|
||||||
import CFBank
|
import CFBank
|
||||||
import CFItemBroker
|
import CFItemBroker
|
||||||
|
|
||||||
activator=Crossfire.WhoIsActivator()
|
activator = Crossfire.WhoIsActivator()
|
||||||
activatorname=activator.Name
|
activatorname = activator.Name
|
||||||
whoami=Crossfire.WhoAmI()
|
whoami = Crossfire.WhoAmI()
|
||||||
x=activator.X
|
x = activator.X
|
||||||
y=activator.Y
|
y = activator.Y
|
||||||
|
|
||||||
|
|
||||||
#EASILY SETTABLE PARAMETERS
|
#EASILY SETTABLE PARAMETERS
|
||||||
service_charge=5 #service charges for transactions as a percent
|
service_charge = 5 # service charges for transactions as a percent
|
||||||
exchange_rate=10000 #exchange rate for silver (value 1)
|
exchange_rate = 10000 # exchange rate of imperial to silver (value 1)
|
||||||
bankdatabase="ImperialBank_DB"
|
bankdatabase = "ImperialBank_DB"
|
||||||
|
|
||||||
fees=(service_charge/100.0)+1
|
fees = (service_charge/100.0)+1
|
||||||
bank = CFBank.CFBank(bankdatabase)
|
bank = CFBank.CFBank(bankdatabase)
|
||||||
|
|
||||||
text = string.split(Crossfire.WhatIsMessage())
|
text = string.split(Crossfire.WhatIsMessage())
|
||||||
thanks_message = ['Thank you for banking the Imperial Way.', 'Thank you, please come \
|
thanks_message = [ \
|
||||||
again.', 'Thank you, please come again.','Thank you for banking the Imperial Way.', \
|
'Thank you for banking the Imperial Way.', \
|
||||||
'Thank you for your patronage.', 'Thank you, have a nice day.', 'Thank you. "Service" \
|
'Thank you for banking the Imperial Way.', \
|
||||||
is our middle name.', 'Thank you. "Service" is our middle name.', 'Thank you for your \
|
'Thank you, please come again.', \
|
||||||
patronage.', 'Thank you, have a nice day.', 'Thank you. Hows about a big slobbery kiss?']
|
'Thank you, please come again.', \
|
||||||
|
'Thank you for your patronage.', \
|
||||||
|
'Thank you for your patronage.', \
|
||||||
|
'Thank you, have a nice day.', \
|
||||||
|
'Thank you, have a nice day.', \
|
||||||
|
'Thank you. "Service" is our middle name.', \
|
||||||
|
'Thank you. "Service" is our middle name.', \
|
||||||
|
'Thank you. Hows about a big slobbery kiss?' ]
|
||||||
|
|
||||||
|
|
||||||
if text[0] == 'help' or text[0] == 'yes':
|
if text[0] == 'help' or text[0] == 'yes':
|
||||||
message ='You can:\n-deposit,-withdraw,-balance,-exchange \
|
message ='You can:\n-deposit,-withdraw,-balance,-exchange \
|
||||||
\nAll transactions are in imperial notes\n(1 : 1000 gold coins). \
|
\nAll transactions are in imperial notes\n(1 : 1000 gold coins). \
|
||||||
\nA service charge of %d percent will be placed on all deposits' \
|
\nA service charge of %d percent will be placed on all deposits.' \
|
||||||
%(service_charge)
|
%(service_charge)
|
||||||
|
|
||||||
|
|
||||||
elif text[0] == 'deposit':
|
elif text[0] == 'deposit':
|
||||||
if len(text)==2:
|
if len(text) == 2:
|
||||||
if (activator.PayAmount(int((int(text[1])*exchange_rate)*fees))):
|
amount = int(text[1])
|
||||||
bank.deposit(activatorname, int(text[1]))
|
if amount <= 0:
|
||||||
message = '%d received, %d imperials deposited to bank account. %s' \
|
message = 'Usage "deposit <amount in imperials>"'
|
||||||
%((int(text[1])*(exchange_rate/50))*fees,int(text[1]),random.choice(thanks_message))
|
elif amount > 10000:
|
||||||
|
message = 'Sorry, we do not accept more than 10000 imperials for one deposit.'
|
||||||
|
elif activator.PayAmount(int(amount*exchange_rate*fees)):
|
||||||
|
bank.deposit(activatorname, amount)
|
||||||
|
message = '%d platinum received, %d imperials deposited to bank account. %s' \
|
||||||
|
%((amount*(exchange_rate/50))*fees, amount, random.choice(thanks_message))
|
||||||
else:
|
else:
|
||||||
message = 'You would need %d gold'%((int(text[1])*(exchange_rate/10))*fees)
|
message = 'You would need %d gold'%((amount*(exchange_rate/10))*fees)
|
||||||
else:
|
else:
|
||||||
message = 'Usage "deposit <amount in imperials>"'
|
message = 'Usage "deposit <amount in imperials>"'
|
||||||
|
|
||||||
|
|
||||||
elif text[0] == 'withdraw':
|
elif text[0] == 'withdraw':
|
||||||
if len(text)==2:
|
if len(text) == 2:
|
||||||
if (bank.withdraw(activatorname, int(text[1]))):
|
amount = int(text[1])
|
||||||
message = '%d imperials withdrawn from bank account. %s' \
|
if amount <= 0:
|
||||||
%(int(text[1]),random.choice(thanks_message))
|
message = 'Usage "withdraw <amount in imperials>"'
|
||||||
id = activator.Map.CreateObject('imperial', (x, y))
|
elif amount > 10000:
|
||||||
CFItemBroker.Item(id).add(int(text[1]))
|
message = 'Sorry, we do not accept more than 10000 imperials for one withdraw.'
|
||||||
|
elif bank.withdraw(activatorname, amount):
|
||||||
|
message = '%d imperials withdrawn from bank account. %s' \
|
||||||
|
%(amount, random.choice(thanks_message))
|
||||||
|
id = activator.Map.CreateObject('imperial', x, y)
|
||||||
|
CFItemBroker.Item(id).add(amount)
|
||||||
|
activator.Take(id)
|
||||||
else:
|
else:
|
||||||
message = 'Not enough imperials on your account'
|
message = 'Not enough imperials on your account'
|
||||||
else:
|
else:
|
||||||
message = 'Usage "withdraw <amount in imperials>"'
|
message = 'Usage "withdraw <amount in imperials>"'
|
||||||
|
|
||||||
|
|
||||||
elif text[0] == 'exchange':
|
elif text[0] == 'exchange':
|
||||||
if len(text)==2:
|
if len(text) == 2:
|
||||||
inv=activator.CheckInventory('imperial')
|
amount = int(text[1])
|
||||||
if inv:
|
if amount <= 0:
|
||||||
pay = CFItemBroker.Item(inv).subtract(int(text[1]))
|
message = 'Usage "exchange <amount>" (imperials to platinum coins)'
|
||||||
if pay:
|
elif amount > 10000:
|
||||||
id = activator.Map.CreateObject('platinum coin', (x, y))
|
message = 'Sorry, we do not exchange more than 10000 imperials all at once.'
|
||||||
CFItemBroker.Item(id).add(int(text[1])*(exchange_rate/50))
|
else:
|
||||||
message = random.choice(thanks_message)
|
inv = activator.CheckInventory('imperial')
|
||||||
else:
|
if inv:
|
||||||
message = 'Sorry, you do not have %d imperials' %int(text[1])
|
pay = CFItemBroker.Item(inv).subtract(amount)
|
||||||
else:
|
if pay:
|
||||||
message = 'Sorry, you do not have any imperials'
|
|
||||||
else:
|
# Drop the coins on the floor, then try
|
||||||
message = 'Usage "exchange <amount>" (imperials to platimum coins)'
|
# to pick them up. This effectively
|
||||||
|
# prevents the player from carrying too
|
||||||
|
# many coins.
|
||||||
|
id = activator.Map.CreateObject('platinum coin', x, y)
|
||||||
|
CFItemBroker.Item(id).add(amount*(exchange_rate/50))
|
||||||
|
activator.Take(id)
|
||||||
|
|
||||||
|
message = random.choice(thanks_message)
|
||||||
|
else:
|
||||||
|
message = 'Sorry, you do not have %d imperials'%(amount)
|
||||||
|
else:
|
||||||
|
message = 'Sorry, you do not have any imperials'
|
||||||
|
else:
|
||||||
|
message = 'Usage "exchange <amount>" (imperials to platinum coins)'
|
||||||
|
|
||||||
|
|
||||||
elif text[0] == 'balance':
|
elif text[0] == 'balance':
|
||||||
balance = bank.getbalance(activatorname)
|
balance = bank.getbalance(activatorname)
|
||||||
if balance == 1:
|
if balance == 1:
|
||||||
message = 'Amount in bank: 1 imperial note'
|
message = 'Amount in bank: 1 imperial note'
|
||||||
elif balance:
|
elif balance:
|
||||||
message = 'Amount in bank: %d imperial notes'%(balance)
|
message = 'Amount in bank: %d imperial notes'%(balance)
|
||||||
else:
|
else:
|
||||||
message = 'Sorry, you have no balance.'
|
message = 'Sorry, you have no balance.'
|
||||||
|
|
||||||
|
|
||||||
else:
|
else:
|
||||||
message = 'Do you need help?'
|
message = 'Do you need help?'
|
||||||
|
|
||||||
whoami.Say(message)
|
whoami.Say(message)
|
||||||
|
Crossfire.SetReturnValue(1)
|
||||||
|
|
Loading…
Reference in New Issue