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 CFItemBroker
|
||||
|
||||
activator=Crossfire.WhoIsActivator()
|
||||
activatorname=activator.Name
|
||||
whoami=Crossfire.WhoAmI()
|
||||
x=activator.X
|
||||
y=activator.Y
|
||||
activator = Crossfire.WhoIsActivator()
|
||||
activatorname = activator.Name
|
||||
whoami = Crossfire.WhoAmI()
|
||||
x = activator.X
|
||||
y = activator.Y
|
||||
|
||||
|
||||
#EASILY SETTABLE PARAMETERS
|
||||
service_charge=5 #service charges for transactions as a percent
|
||||
exchange_rate=10000 #exchange rate for silver (value 1)
|
||||
bankdatabase="ImperialBank_DB"
|
||||
service_charge = 5 # service charges for transactions as a percent
|
||||
exchange_rate = 10000 # exchange rate of imperial to silver (value 1)
|
||||
bankdatabase = "ImperialBank_DB"
|
||||
|
||||
fees=(service_charge/100.0)+1
|
||||
fees = (service_charge/100.0)+1
|
||||
bank = CFBank.CFBank(bankdatabase)
|
||||
|
||||
text = string.split(Crossfire.WhatIsMessage())
|
||||
thanks_message = ['Thank you for banking the Imperial Way.', 'Thank you, please come \
|
||||
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?']
|
||||
|
||||
thanks_message = [ \
|
||||
'Thank you for banking the Imperial Way.', \
|
||||
'Thank you for banking the Imperial Way.', \
|
||||
'Thank you, please come again.', \
|
||||
'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':
|
||||
message ='You can:\n-deposit,-withdraw,-balance,-exchange \
|
||||
\nAll transactions are in imperial notes\n(1 : 1000 gold coins). \
|
||||
\nA service charge of %d percent will be placed on all deposits' \
|
||||
message ='You can:\n-deposit,-withdraw,-balance,-exchange \
|
||||
\nAll transactions are in imperial notes\n(1 : 1000 gold coins). \
|
||||
\nA service charge of %d percent will be placed on all deposits.' \
|
||||
%(service_charge)
|
||||
|
||||
|
||||
elif text[0] == 'deposit':
|
||||
if len(text)==2:
|
||||
if (activator.PayAmount(int((int(text[1])*exchange_rate)*fees))):
|
||||
bank.deposit(activatorname, int(text[1]))
|
||||
message = '%d received, %d imperials deposited to bank account. %s' \
|
||||
%((int(text[1])*(exchange_rate/50))*fees,int(text[1]),random.choice(thanks_message))
|
||||
if len(text) == 2:
|
||||
amount = int(text[1])
|
||||
if amount <= 0:
|
||||
message = 'Usage "deposit <amount in imperials>"'
|
||||
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:
|
||||
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:
|
||||
message = 'Usage "deposit <amount in imperials>"'
|
||||
|
||||
|
||||
elif text[0] == 'withdraw':
|
||||
if len(text)==2:
|
||||
if (bank.withdraw(activatorname, int(text[1]))):
|
||||
message = '%d imperials withdrawn from bank account. %s' \
|
||||
%(int(text[1]),random.choice(thanks_message))
|
||||
id = activator.Map.CreateObject('imperial', (x, y))
|
||||
CFItemBroker.Item(id).add(int(text[1]))
|
||||
if len(text) == 2:
|
||||
amount = int(text[1])
|
||||
if amount <= 0:
|
||||
message = 'Usage "withdraw <amount in imperials>"'
|
||||
elif amount > 10000:
|
||||
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:
|
||||
message = 'Not enough imperials on your account'
|
||||
else:
|
||||
message = 'Usage "withdraw <amount in imperials>"'
|
||||
|
||||
|
||||
elif text[0] == 'exchange':
|
||||
if len(text)==2:
|
||||
inv=activator.CheckInventory('imperial')
|
||||
if inv:
|
||||
pay = CFItemBroker.Item(inv).subtract(int(text[1]))
|
||||
if pay:
|
||||
id = activator.Map.CreateObject('platinum coin', (x, y))
|
||||
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])
|
||||
else:
|
||||
message = 'Sorry, you do not have any imperials'
|
||||
else:
|
||||
message = 'Usage "exchange <amount>" (imperials to platimum coins)'
|
||||
if len(text) == 2:
|
||||
amount = int(text[1])
|
||||
if amount <= 0:
|
||||
message = 'Usage "exchange <amount>" (imperials to platinum coins)'
|
||||
elif amount > 10000:
|
||||
message = 'Sorry, we do not exchange more than 10000 imperials all at once.'
|
||||
else:
|
||||
inv = activator.CheckInventory('imperial')
|
||||
if inv:
|
||||
pay = CFItemBroker.Item(inv).subtract(amount)
|
||||
if pay:
|
||||
|
||||
# Drop the coins on the floor, then try
|
||||
# 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':
|
||||
balance = bank.getbalance(activatorname)
|
||||
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.'
|
||||
balance = bank.getbalance(activatorname)
|
||||
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?'
|
||||
|
||||
whoami.Say(message)
|
||||
Crossfire.SetReturnValue(1)
|
||||
|
|
Loading…
Reference in New Issue