2 Created by: Joris Bontje <jbontje@suespammers.org>
4 This module implements banking in Crossfire. It provides the 'say' event for
14 activator = Crossfire.WhoIsActivator()
15 whoami = Crossfire.WhoAmI()
26 'IMPERIAL NOTE': 10000,
27 '10 IMPERIAL NOTE': 100000,
28 '100 IMPERIAL NOTE': 1000000,
33 'SILVER':
'silvercoin',
35 'PLATINUM':
'platinacoin',
37 'AMBERIUM':
'ambercoin',
38 'IMPERIAL NOTE':
'imperial',
39 '10 IMPERIAL NOTE':
'imperial10',
40 '100 IMPERIAL NOTE':
'imperial100',
45 'Thank you for banking the Imperial Way.',
46 'Thank you for banking the Imperial Way.',
47 'Thank you, please come again.',
48 'Thank you, please come again.',
49 'Thank you for your patronage.',
50 'Thank you for your patronage.',
51 'Thank you, have a nice day.',
52 'Thank you, have a nice day.',
53 'Thank you. "Service" is our middle name.',
54 'Thank you. "Service" is our middle name.',
55 'Thank you. Hows about a big slobbery kiss?',
59 """Piece together several arguments to form a coin name."""
60 coinName = str.join(
" ", argv)
62 if coinName[-1] ==
's':
63 coinName = coinName[:-1]
67 """Return the exchange rate for the given type of coin."""
68 if coinName.upper()
in CoinTypes:
69 return CoinTypes[coinName.upper()]
74 """Deposit the given amount for the player."""
76 bank.deposit(player.Name, amount)
77 whoami.Say(
"%s credited to your account." \
78 % Crossfire.CostStringFromValue(amount))
81 """Print a help message for the player."""
82 whoami.Say(
"The Bank of Skud can help you keep your money safe. In addition, you will be able to access your money from any bank in the world! What would you like to do?")
84 Crossfire.AddReply(
"coins",
"I'd like to know more about existing coins.")
85 Crossfire.AddReply(
"balance",
"I want to check my balance.")
86 Crossfire.AddReply(
"deposit",
"I'd like to deposit some money.")
87 Crossfire.AddReply(
"withdraw",
"I'd like to withdraw some money.")
88 Crossfire.AddReply(
"convert",
"I'd like to compute money conversions.")
91 """Find out how much money the player has in his/her account."""
94 balance = bank.getbalance(activator.Name)
99 if exchange_rate
is None:
100 whoami.Say(
"Hmm... I've never seen that kind of money.")
103 balance /= exchange_rate * 1.0
104 whoami.Say(
"You have %.3f %s in the bank." % (balance, coinName))
106 whoami.Say(
"Sorry, you have no balance.")
108 whoami.Say(
"You have %s in the bank." % \
109 Crossfire.CostStringFromValue(balance))
112 """Deposit a certain amount of money."""
116 amount =
int(text[1])
117 if exchange_rate
is None:
118 whoami.Say(
"Hmm... I've never seen that kind of money.")
121 whoami.Say(
"Regulations prohibit negative deposits.")
125 actualAmount = amount * exchange_rate
126 if activator.PayAmount(actualAmount):
129 whoami.Say(
"But you don't have that much in your inventory!")
131 whoami.Say(
"What would you like to deposit?")
132 Crossfire.AddReply(
"deposit <amount> <coin type>",
"Some money.")
135 """Withdraw money from the player's account."""
139 amount =
int(argv[1])
140 if exchange_rate
is None:
141 whoami.Say(
"Hmm... I've never seen that kind of money.")
144 whoami.Say(
"Sorry, you can't withdraw that amount.")
149 if bank.withdraw(activator.Name, amount * exchange_rate):
150 message =
"%d %s withdrawn from your account. %s" \
151 % (amount, coinName, random.choice(thanks_message))
154 withdrawal = activator.Map.CreateObject(
155 ArchType.get(coinName.upper()), x, y)
157 activator.Take(withdrawal)
159 message =
"I'm sorry, you don't have enough money."
161 message =
"How much money would you like to withdraw?"
162 Crossfire.AddReply(
"withdraw <amount> <coin name>",
"This much!")
169 if len(argc) < 4
or argc[3] !=
"to":
174 if not toCoin
or not fromCoin:
180 fromAmount =
int(argc[1])
181 amount =
int(fromAmount * fromValue / toValue)
182 whoami.Say(
"{} {} coin{} would be {} {} coin{}".format(fromAmount, fromCoin,
"s" if fromAmount > 1
else "", amount, toCoin,
"s" if amount > 1
else ""))
185 if not attempt(argc):
186 whoami.Say(
"Sorry, I don't understand what you want to convert.\nTry something like \"4 platinum to silver\" please.")
189 whoami.Say(
"""The smallest coin available is the silver coin.
190 The gold coin is worth 10 silver coins, while the platinum coin is worth 50.
191 A jade coin is worth 5000 silver, and an amberium 500000.
193 There also exist imperial notes, worth 10000 silver coins.
197 text = Crossfire.WhatIsMessage().
split()
198 if text[0] ==
"learn":
200 elif text[0] ==
"balance":
202 elif text[0] ==
"deposit":
204 elif text[0] ==
"withdraw":
206 elif text[0] ==
"convert":
208 elif text[0] ==
"coins":
211 whoami.Say(
"Hello, what can I help you with today?")
212 Crossfire.AddReply(
"learn",
"I want to learn how to use the bank.")
214 Crossfire.SetReturnValue(1)
218 whoami.Say(
"I don't know how much money that is.")