2 powerbroker.py -- glowing crystals that buy and sell mana
4 Usage: add an event_apply and event_say to a non-pickable glowing crystal.
14 me = Crossfire.WhoAmI()
17 return payer.PayAmount(quantity) == 1
19 def pay(payee, quantity):
23 item = payee.CreateObject(
'platinum coin')
26 item = payee.CreateObject(
'gold coin')
29 item = payee.CreateObject(
'silver coin')
33 Crossfire.SetReturnValue(0)
39 stock = Crossfire.GetPrivateDictionary().
get(
'total_mana')
45 Crossfire.GetPrivateDictionary()[
'total_mana'] =
mana_stock() + amount
49 return sp * P0 * (1 + 1/N0*(N0 -
mana_stock()))
58 message = Crossfire.WhatIsMessage().lower()
63 me.Say(
"Sorry, we are out of stock right now. Come back later.")
66 me.Say(
"If you want to sell mana, transfer it into the power broker.")
69 me.Say(
"I can only sell you up to %d mana right now." % max_buy)
73 if charge(Crossfire.WhoIsActivator(), price):
74 me.Say(
"Bought %d mana for %s." % (amount, Crossfire.CostStringFromValue(price)))
78 me.Say(
"You can't afford that!")
79 confirm(
"%d mana would cost you %s. Buy?" % (amount, Crossfire.CostStringFromValue(price)), do_buy_mana)
81 me.Say(
"How much mana would you like to buy? %d silver per mana point." %
buy_price(1))
84 message = Crossfire.WhatIsMessage().lower()
87 me.Say(
"Sorry, we're not interested in buying mana right now.")
91 me.Say(
"Sold %d mana for %s." % (me.SP, Crossfire.CostStringFromValue(price)))
92 pay(Crossfire.WhoIsActivator(), price)
95 confirm(
"Sell %d mana for %s?" % (me.SP, Crossfire.CostStringFromValue(price)), do_sell_mana)
99 Crossfire.AddReply(
"yes",
"Yes!")
100 Crossfire.AddReply(
"no",
"No, thank you.")
101 Crossfire.GetPrivateDictionary()[
'confirm_action'] = action
104 action = Crossfire.GetPrivateDictionary().
get(
'confirm_action')
105 if action
is not None:
106 reply = Crossfire.WhatIsMessage().lower()
109 del Crossfire.GetPrivateDictionary()[
'confirm_action']
111 me.Say(
"Thank you, come again!")
112 del Crossfire.GetPrivateDictionary()[
'confirm_action']
114 me.Say(
"Please answer either 'yes' or 'no'.")
123 qty =
int(message.split()[1])
125 me.Say(
"Added %d mana to stock." % qty)
128 me.Say(
"I didn't understand that.")
134 message = Crossfire.WhatIsMessage().lower()
135 if message ==
'status' and Crossfire.WhoIsActivator().DungeonMaster:
137 elif message.split()[0] ==
'stock' and Crossfire.WhoIsActivator().DungeonMaster:
144 if Crossfire.WhatIsEvent().Subtype == 1:
146 elif Crossfire.WhatIsEvent().Subtype == 6: