Crossfire Server, Trunk
guild_dues.py
Go to the documentation of this file.
1 """
2 Script for paying Guild Dues, and to handle Jack in the mainfloor.
3 #
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 2 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 #
18 # author:Avion temitchell@sourceforge.net
19 #
20 # Heavily modified by Nicolas Weeger, 2010-11-14
21 """
22 
23 import Crossfire
24 import CFGuilds
25 import CFItemBroker
26 import random
27 import CFBank
28 import CFLog
29 from CFGuildClearance import CheckClearance
30 
31 # List of amounts a player can pay
32 CoinTypes={
33  "SILVER":1,
34  "GOLD":10,
35  "PLATINUM":50,
36  "JADE":5000,
37  "AMBERIUM":500000,
38  "IMPERIAL NOTE":10000,
39  "TEN IMPERIAL NOTE":100000,
40  "ONE HUNDRED IMPERIAL NOTE":1000000 }
41 
42 # Archetypes for the 'withdraw' command
43 ArchType={"SILVER":"silvercoin","GOLD":"goldcoin","PLATINUM":"platinacoin","JADE":"jadecoin","AMBERIUM":"ambercoin", "IMPERIAL NOTE":"imperial","TEN IMPERIAL NOTE":"imperial10","ONE HUNDRED IMPERIAL NOTE":"imperial100"}
44 
45 remarklist = ['Excellent','Thank You','Thank You','Thank You', 'Thank You', 'Great', 'OK', 'Wonderful', 'Swell', 'Dude', 'Big Spender']
46 exclaimlist = ['Hey','Hey','Hey','Hey', 'Now just a minute', 'AHEM', 'OK...Wait a minute', 'Look chowderhead']
47 buddylist = ['buddy','buddy','buddy','buddy','pal','friend','friend','friend','friend','dude','chum', 'sweetie']
48 whoami=Crossfire.WhoAmI()
49 activator = Crossfire.WhoIsActivator()
50 
51 def formatted_amount(amount):
52  """ Format a price as a string, giving full coin descriptions. Returns 'no money' if amount is 0. """
53  if amount == 0:
54  return 'no money'
55 
56  return Crossfire.CostStringFromValue(amount)
57 
58 def find_mailbox(object):
59  while (object.Name != 'mailbox'):
60  object = object.Above
61  if not object:
62  return 0
63  return object
64 
65 def FindCoin(object):
66  while (object.Name.find('silver coin')==-1):
67  object = object.Above
68  if not object:
69  return 0
70  return object
71 
72 class GuildDues:
73  def __init__(self):
74  '''Standard constructor'''
75  self.guildname = Crossfire.ScriptParameters()
76 
77  def do_help(self):
78  '''Handle the 'help' and 'yes' commands.'''
79  gm = ''
80 
81  if CheckClearance([self.guildname, "GuildMaster"], activator):
82  gm = 'You can purchase guild extensions or new desks with the "buy" word.\n'
83 
84  whoami.Say('Let me know how much you want to pay. Say pay <amount> <cointype>'
85  + '\n\tValid coin types are '
86  + ', '.join(CoinTypes)
87  + '.\nYou can check the balance by saying "balance".\n'
88  + gm
89  + 'I also provide mailscrolls at 10 platinum each, use "mailscroll".')
90 
91  def do_buy(self, text):
92  '''Handles buying a guild extension'''
93 
94  if (not CheckClearance([self.guildname, "GuildMaster"], activator)):
95  whoami.Say("Only guild masters can purchase guild extensions and replacement parts.")
96  return
97 
98  # This lists all items that can be bought, extensions or new desks
99  Items = {
100  'Stove':5000*12,
101  'Cauldron':5000*12,
102  "TanningDesk":5000*12,
103  "ThaumaturgyDesk":5000*12,
104  "JewelersBench":5000*24,
105  "BowyerBench":5000*10,
106  "Forge":5000*10,
107 
108  'BBQ':500000*12,
109  'AlchemyLab':500000*24,
110  "CrystalRoom":500000*12,
111  "Tannery":500000*12,
112  "JewelersRoom":500000*24,
113  "ThaumaturgyRoom":500000*12,
114  "Bowyer":500000*12,
115  "Smithy":500000*12}
116 
117  # This is the list of cards to buy new desks
118  Cards = ["Stove", "Cauldron", "TanningDesk", "ThaumaturgyDesk", "JewelersBench", "BowyerBench", "Forge"]
119 
120  mymap = whoami.Map
121  path = mymap.Path
122  path = path.replace("mainfloor", "")
123  SecondFloor = Crossfire.ReadyMap(path + 'secondfloor')
124  ToolShed = Crossfire.ReadyMap(path + "guild_toolshed")
125 
126  # This is the list of guild extensions, and the coordinates of the activation button
127  Rooms = {
128  "BBQ": (mymap, 40, 25),
129  "AlchemyLab": (SecondFloor, 22, 12),
130  "CrystalRoom": (SecondFloor, 22, 13),
131  "Tannery": (SecondFloor, 22, 14),
132  "ThaumaturgyRoom": (SecondFloor, 21, 13),
133  "JewelersRoom": (SecondFloor, 21, 14),
134  "Bowyer": (ToolShed, 22, 16),
135  "Smithy": (ToolShed, 23, 16) }
136 
137  if len(text) == 1:
138  help = "Buy what? Extensions are unlockable areas for your guild. Cards are for replacing missing crafting equipment like caudrons and benches. You can buy:\n"
139 
140  for i in Items:
141  if i in Cards:
142  help += " - " + i + " (card): " + formatted_amount(Items[i]) + "\n"
143  else:
144  Loc = Rooms.get(i)
145  coin = Loc[0].ObjectAt(Loc[1], Loc[2])
146  coin = FindCoin(coin)
147 
148  if coin != 0:
149  continue
150 
151  help += " - " + i + " (extension): " + formatted_amount(Items[i]) + "\n"
152 
153  whoami.Say(help)
154  return
155 
156  item = text[1]
157  if not item in Items.keys():
158  whoami.Say("I don't know that item, sorry")
159  return
160 
161  Price = Items.get(item)
162  with CFBank.open() as bank:
163  balance = bank.getbalance(self.accountname)
164  if Price > balance:
165  whoami.Say("The guild does not have sufficient funds.")
166  return
167 
168  if item in Cards:
169  card = activator.CreateObject('diploma')
170  card.Name = item
171  card.Message = 'This enables you to buy a new ' + item + ' for your guild.'
172  card.Value = 0
173  bank.withdraw(self.accountname, Price)
174  whoami.Say("Here is your card\nThe guild now has %s on account." %(formatted_amount(bank.getbalance(self.accountname))))
175  return
176 
177  Loc = Rooms.get(item)
178  coin = Loc[0].ObjectAt(Loc[1], Loc[2])
179  coin = FindCoin(coin)
180 
181  if coin != 0:
182  whoami.Say("The guild already has this expansion!")
183  return
184 
185  coin = mymap.CreateObject('silvercoin',40,29)
186  coin.Teleport(Loc[0] ,Loc[1], Loc[2])
187 
188  bank.withdraw(self.accountname, Price)
189  whoami.Say("The new room has been unlocked.\n"
190  + "The guild now has %s on account." %(formatted_amount(bank.getbalance(self.accountname))))
191 
192  def do_mailscroll(self, text):
193  '''Handle getting a mailscroll for a friend.'''
194  if len(text) == 1:
195  whoami.Say('Usage "mailscroll <friend>"')
196  return
197 
198  log = CFLog.CFLog()
199 
200  if not log.info(text[1]):
201  whoami.Say('I don\'t know %s'%text[1])
202  return
203 
204  priceMailScroll = 5
205  priceFactor = 50 # platinum to silver conversion
206 
207  if activator.PayAmount(priceMailScroll*priceFactor):
208  whoami.Say('Here is your mailscroll to %s'%text[1])
209  id = activator.CreateObject('scroll')
210  id.Name = 'mailscroll T: '+text[1]+' F: '+activator.Name
211  id.NamePl = 'mailscrolls T: '+text[1]+' F: '+activator.Name
212  id.Value = 0
213  else:
214  whoami.Say('You need %s platinum for a mailscroll'%priceMailScroll)
215 
216  def do_balance(self):
217  '''Handle the display of the guild's balance.'''
218  with CFBank.open() as bank:
219  balance = bank.getbalance(self.accountname)
220  whoami.Say("The guild currently has %s on account." %(formatted_amount(balance)))
221 
222  def do_pay(self, text):
223  '''Handle player paying dues to the guild.'''
224  if len(text) < 3:
225  whoami.Say("How much ya wanna pay %s?\nYou can specify amounts in "%(random.choice(buddylist)) +
226  ', '.join(i.lower() for i in CoinTypes.keys()))
227  return
228 
229  cost = text[1]
230  currency = ' '.join(text[2:])
231  ucurrency = currency.upper()
232  if not ucurrency in CoinTypes.keys():
233  whoami.Say("Sorry, I don't know what %s are" % currency)
234  return
235 
236  conversionfactor = CoinTypes.get(ucurrency)
237  total = int(cost)*conversionfactor
238  if total and activator.PayAmount(total):
239  guild = CFGuilds.CFGuild(self.guildname)
240  guild.pay_dues(activator.Name,total)
241  whoami.Say("%s, %s %s paid to the guild." % (random.choice(remarklist), cost, currency))
242  with CFBank.open() as bank:
243  bank.deposit(self.accountname, total)
244  else:
245  if total == 0:
246  whoami.Say("Uh? Ya wanna trick me, %s." % random.choice(buddylist))
247  elif int(cost) > 1:
248  plural=''
249  if ucurrency.endswith('NOTE'):
250  plural = 's'
251  whoami.Say("%s, you don't have %s %s%s." % (random.choice(exclaimlist), cost, currency, plural))
252  else:
253  whoami.Say("You don't have any %s, %s." % (currency, random.choice(buddylist)))
254 
255  def do_withdraw(self, text):
256  if (not activator.DungeonMaster==1 and not CheckClearance([self.guildname,"Master"],activator)):
257  whoami.Say("Only guild masters, masters, and DMs can withdraw funds from the guild.")
258  return
259 
260  try:
261  Amount=int(text[1])
262  except:
263  whoami.Say("Usage: withdraw <quantity> {cointype=silver}")
264  return
265 
266  with CFBank.open() as bank:
267  balance = bank.getbalance(self.accountname)
268 
269  if len(text) > 2:
270  Type = ' '.join(text[2:])
271  else:
272  Type = "silver"
273 
274  if not Type.upper() in CoinTypes.keys():
275  whoami.Say("Sorry, I have no clue what %s are"%Type)
276  return
277 
278  Value = CoinTypes.get(Type.upper())
279 
280  if Amount*Value <= balance:
281  message = (str(Amount))
282  message +=" " + Type + " withdrawn.\nYour new present balance is "
283 
284  id = activator.CreateObject(ArchType.get(Type.upper()))
285  CFItemBroker.Item(id).add(Amount)
286  bank.withdraw(self.accountname, Amount*Value)
287  message += formatted_amount(bank.getbalance(self.accountname))+"."
288  whoami.Say(message)
289  else:
290  message="You only have " + formatted_amount(bank.getbalance(self.accountname))+" on your account."
291  whoami.Say(message)
292 
293  def handle_jack(self):
294  '''Handle Jack, the guild helper'''
295 
296  text = Crossfire.WhatIsMessage().split()
297  command = text[0].lower()
298 
299  if command == 'buy':
300  self.do_buy(text)
301  return
302 
303  if command == 'mailscroll':
304  self.do_mailscroll(text)
305  return
306 
307  if command == 'balance':
308  self.do_balance()
309  return
310 
311  if command == 'pay':
312  self.do_pay(text)
313  return
314 
315  if command == 'withdraw':
316  self.do_withdraw(text)
317  return
318 
319  if command == 'help' or command == 'yes':
320  self.do_help()
321  return
322 
323  message = "Howdy %s, paying some guild dues today?" %(random.choice(buddylist))
324  whoami.Say(message)
325 
326 
327  def handle(self):
328  '''Main handling function'''
329  if not self.guildname:
330  activator.Write('dues error, please notify a DM')
331  return
332 
333  self.accountname = "/guilds/" + self.guildname
334 
335  if whoami.Name == 'Jack':
336  self.handle_jack()
337  return
338 
339  amount = Crossfire.WhoIsOther().Value * Crossfire.WhoIsOther().Quantity
340  bank = CFBank.open()
341  bank.deposit(self.accountname, amount)
342  bank.close()
343 
344 dues = GuildDues()
345 dues.handle()
guild_dues.GuildDues.handle
def handle(self)
Definition: guild_dues.py:327
guild_dues.GuildDues.do_mailscroll
def do_mailscroll(self, text)
Definition: guild_dues.py:192
guild_dues.GuildDues.do_pay
def do_pay(self, text)
Definition: guild_dues.py:222
guild_dues.GuildDues.accountname
accountname
Definition: guild_dues.py:333
CFBank.open
def open()
Definition: CFBank.py:69
guild_dues.formatted_amount
def formatted_amount(amount)
Definition: guild_dues.py:51
guild_dues.GuildDues.handle_jack
def handle_jack(self)
Definition: guild_dues.py:293
guild_dues.FindCoin
def FindCoin(object)
Definition: guild_dues.py:65
guild_dues.GuildDues.do_balance
def do_balance(self)
Definition: guild_dues.py:216
guild_dues.GuildDues.guildname
guildname
Definition: guild_dues.py:75
CFLog.CFLog
Definition: CFLog.py:34
guild_dues.GuildDues.do_withdraw
def do_withdraw(self, text)
Definition: guild_dues.py:255
make_face_from_files.str
str
Definition: make_face_from_files.py:30
CFGuilds.CFGuild
Definition: CFGuilds.py:131
CFItemBroker.Item
Definition: CFItemBroker.py:15
guild_dues.GuildDues.do_help
def do_help(self)
Definition: guild_dues.py:77
make_face_from_files.int
int
Definition: make_face_from_files.py:32
split
static std::vector< std::string > split(const std::string &field, const std::string &by)
Definition: mapper.cpp:2606
guild_dues.GuildDues
Definition: guild_dues.py:72
guild_dues.GuildDues.__init__
def __init__(self)
Definition: guild_dues.py:73
guild_dues.GuildDues.do_buy
def do_buy(self, text)
Definition: guild_dues.py:91
guild_dues.find_mailbox
def find_mailbox(object)
Definition: guild_dues.py:58
CFGuildClearance.CheckClearance
def CheckClearance(lParams, oActivator)
Definition: CFGuildClearance.py:21