| 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 [email protected] |
| 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 |
# Filename for the bank |
| 46 |
bankdatabase = "ImperialBank_DB" |
| 47 |
|
| 48 |
remarklist = ['Excellent','Thank You','Thank You','Thank You', 'Thank You', 'Great', 'OK', 'Wonderful', 'Swell', 'Dude', 'Big Spender'] |
| 49 |
exclaimlist = ['Hey','Hey','Hey','Hey', 'Now just a minute', 'AHEM', 'OK...Wait a minute', 'Look chowderhead'] |
| 50 |
buddylist = ['buddy','buddy','buddy','buddy','pal','friend','friend','friend','friend','dude','chum', 'sweetie'] |
| 51 |
whoami=Crossfire.WhoAmI() |
| 52 |
activator = Crossfire.WhoIsActivator() |
| 53 |
|
| 54 |
def formatted_amount(amount): |
| 55 |
""" Format a price as a string, giving full coin descriptions. Returns 'no money' if amount is 0. """ |
| 56 |
if amount == 0: |
| 57 |
return 'no money' |
| 58 |
|
| 59 |
return Crossfire.CostStringFromValue(amount) |
| 60 |
|
| 61 |
def find_mailbox(object): |
| 62 |
while (object.Name != 'mailbox'): |
| 63 |
object = object.Above |
| 64 |
if not object: |
| 65 |
return 0 |
| 66 |
return object |
| 67 |
|
| 68 |
def FindCoin(object): |
| 69 |
while (object.Name.find('silver coin')==-1): |
| 70 |
object = object.Above |
| 71 |
if not object: |
| 72 |
return 0 |
| 73 |
return object |
| 74 |
|
| 75 |
class GuildDues: |
| 76 |
def __init__(self): |
| 77 |
'''Standard constructor''' |
| 78 |
self.guildname = Crossfire.ScriptParameters() |
| 79 |
|
| 80 |
def do_help(self): |
| 81 |
'''Handle the 'help' and 'yes' commands.''' |
| 82 |
gm = '' |
| 83 |
|
| 84 |
if CheckClearance([self.guildname, "GuildMaster"], activator): |
| 85 |
gm = 'You can purchase guild extensions or new desks with the "buy" word.\n' |
| 86 |
|
| 87 |
whoami.Say('Let me know how much you want to pay. Say pay <amount> <cointype>' |
| 88 |
+ '\n\tValid coin types are ' |
| 89 |
+ ', '.join(CoinTypes) |
| 90 |
+ '.\nYou can check the balance by saying "balance".\n' |
| 91 |
+ gm |
| 92 |
+ 'I also provide mailscrolls at 10 platinum each, use "mailscroll".') |
| 93 |
|
| 94 |
def do_buy(self, text): |
| 95 |
'''Handles buying a guild extension''' |
| 96 |
|
| 97 |
if (not CheckClearance([self.guildname, "GuildMaster"], activator)): |
| 98 |
whoami.Say("Only guild masters and GMs can buy extensions or new desks for the guild.") |
| 99 |
return |
| 100 |
|
| 101 |
# This lists all items that can be bought, extensions or new desks |
| 102 |
Items = { |
| 103 |
'Stove':5000*12, |
| 104 |
'Cauldron':5000*12, |
| 105 |
"TanningDesk":5000*12, |
| 106 |
"ThaumaturgyDesk":5000*12, |
| 107 |
"JewelersBench":5000*24, |
| 108 |
"BowyerBench":5000*10, |
| 109 |
"Forge":5000*10, |
| 110 |
|
| 111 |
'BBQ':500000*12, |
| 112 |
'AlchemyLab':500000*24, |
| 113 |
"CrystalRoom":500000*12, |
| 114 |
"Tannery":500000*12, |
| 115 |
"JewelersRoom":500000*24, |
| 116 |
"ThaumaturgyRoom":500000*12, |
| 117 |
"Bowyer":500000*12, |
| 118 |
"Smithy":500000*12} |
| 119 |
|
| 120 |
# This is the list of cards to buy new desks |
| 121 |
Cards = ["Stove", "Cauldron", "TanningDesk", "ThaumaturgyDesk", "JewelersBench", "BowyerBench", "Forge"] |
| 122 |
|
| 123 |
mymap = whoami.Map |
| 124 |
path = mymap.Path |
| 125 |
path = path.replace("mainfloor", "") |
| 126 |
SecondFloor = Crossfire.ReadyMap(path + 'secondfloor') |
| 127 |
ToolShed = Crossfire.ReadyMap(path + "guild_toolshed") |
| 128 |
|
| 129 |
# This is the list of guild extensions, and the coordinates of the activation button |
| 130 |
Rooms = { |
| 131 |
"BBQ": (mymap, 40, 25), |
| 132 |
"AlchemyLab": (SecondFloor, 22, 12), |
| 133 |
"CrystalRoom": (SecondFloor, 22, 13), |
| 134 |
"Tannery": (SecondFloor, 22, 14), |
| 135 |
"ThaumaturgyRoom": (SecondFloor, 21, 13), |
| 136 |
"JewelersRoom": (SecondFloor, 21, 14), |
| 137 |
"Bowyer": (ToolShed, 22, 16), |
| 138 |
"Smithy": (ToolShed, 23, 16) } |
| 139 |
|
| 140 |
if len(text) == 1: |
| 141 |
help = "Buy what?\nYou can buy:\n" |
| 142 |
|
| 143 |
for i in Items: |
| 144 |
if i in Cards: |
| 145 |
help += " - " + i + " (card): " + formatted_amount(Items[i]) + "\n" |
| 146 |
else: |
| 147 |
Loc = Rooms.get(i) |
| 148 |
coin = Loc[0].ObjectAt(Loc[1], Loc[2]) |
| 149 |
coin = FindCoin(coin) |
| 150 |
|
| 151 |
if coin != 0: |
| 152 |
continue |
| 153 |
|
| 154 |
help += " - " + i + " (extension): " + formatted_amount(Items[i]) + "\n" |
| 155 |
|
| 156 |
whoami.Say(help) |
| 157 |
return |
| 158 |
|
| 159 |
item = text[1] |
| 160 |
if not item in Items.keys(): |
| 161 |
whoami.Say("I don't know that item, sorry") |
| 162 |
return |
| 163 |
|
| 164 |
Price = Items.get(item) |
| 165 |
bank = CFBank.CFBank(bankdatabase) |
| 166 |
balance = bank.getbalance(self.accountname) |
| 167 |
if Price > balance: |
| 168 |
whoami.Say("The guild does not have sufficient funds.") |
| 169 |
return |
| 170 |
|
| 171 |
if item in Cards: |
| 172 |
card = activator.CreateObject('diploma') |
| 173 |
card.Name = item |
| 174 |
card.Message = 'This enables you to buy a new ' + item + ' for your guild.' |
| 175 |
card.Value = 0 |
| 176 |
bank.withdraw(self.accountname, Price) |
| 177 |
whoami.Say("Here is your card\nThe guild now has %s on account." %(formatted_amount(bank.getbalance(self.accountname)))) |
| 178 |
|
| 179 |
return |
| 180 |
|
| 181 |
Loc = Rooms.get(item) |
| 182 |
coin = Loc[0].ObjectAt(Loc[1], Loc[2]) |
| 183 |
coin = FindCoin(coin) |
| 184 |
|
| 185 |
if coin != 0: |
| 186 |
whoami.Say("The guild already has this expansion!") |
| 187 |
return |
| 188 |
|
| 189 |
coin = mymap.CreateObject('silvercoin',40,29) |
| 190 |
coin.Teleport(Loc[0] ,Loc[1], Loc[2]) |
| 191 |
|
| 192 |
bank.withdraw(self.accountname, Price) |
| 193 |
whoami.Say("The new room has been unlocked.\n" |
| 194 |
+ "The guild now has %s on account." %(formatted_amount(bank.getbalance(self.accountname)))) |
| 195 |
|
| 196 |
def do_mailscroll(self, text): |
| 197 |
'''Handle getting a mailscroll for a friend.''' |
| 198 |
if len(text) == 1: |
| 199 |
whoami.Say('Usage "mailscroll <friend>"') |
| 200 |
return |
| 201 |
|
| 202 |
log = CFLog.CFLog() |
| 203 |
|
| 204 |
if not log.info(text[1]): |
| 205 |
whoami.Say('I don\'t know %s'%text[1]) |
| 206 |
return |
| 207 |
|
| 208 |
priceMailScroll = 5 |
| 209 |
priceFactor = 50 # platinum to silver conversion |
| 210 |
|
| 211 |
if activator.PayAmount(priceMailScroll*priceFactor): |
| 212 |
whoami.Say('Here is your mailscroll to %s'%text[1]) |
| 213 |
id = activator.CreateObject('scroll') |
| 214 |
id.Name = 'mailscroll T: '+text[1]+' F: '+activator.Name |
| 215 |
id.NamePl = 'mailscrolls T: '+text[1]+' F: '+activator.Name |
| 216 |
id.Value = 0 |
| 217 |
else: |
| 218 |
whoami.Say('You need %s platinum for a mailscroll'%priceMailScroll) |
| 219 |
|
| 220 |
def do_balance(self): |
| 221 |
'''Handle the display of the guild's balance.''' |
| 222 |
bank = CFBank.CFBank(bankdatabase) |
| 223 |
balance = bank.getbalance(self.accountname) |
| 224 |
whoami.Say("The guild currently has %s on account." %(formatted_amount(balance))) |
| 225 |
|
| 226 |
def do_pay(self, text): |
| 227 |
'''Handle player paying dues to the guild.''' |
| 228 |
if len(text) < 3: |
| 229 |
whoami.Say("How much ya wanna pay %s?\nYou can specify amounts in "%(random.choice(buddylist)) + |
| 230 |
', '.join(i.lower() for i in CoinTypes.keys())) |
| 231 |
return |
| 232 |
|
| 233 |
cost = text[1] |
| 234 |
currency = ' '.join(text[2:]) |
| 235 |
ucurrency = currency.upper() |
| 236 |
if not ucurrency in CoinTypes.keys(): |
| 237 |
whoami.Say("Sorry, I don't know what %s are" % currency) |
| 238 |
return |
| 239 |
|
| 240 |
conversionfactor = CoinTypes.get(ucurrency) |
| 241 |
total = int(cost)*conversionfactor |
| 242 |
if total and activator.PayAmount(total): |
| 243 |
guild = CFGuilds.CFGuild(self.guildname) |
| 244 |
guild.pay_dues(activator.Name,total) |
| 245 |
whoami.Say("%s, %s %s paid to the guild." % (random.choice(remarklist), cost, currency)) |
| 246 |
bank = CFBank.CFBank(bankdatabase) |
| 247 |
bank.deposit(self.accountname, total) |
| 248 |
else: |
| 249 |
if total == 0: |
| 250 |
whoami.Say("Uh? Ya wanna trick me, %s." % random.choice(buddylist)) |
| 251 |
elif int(cost) > 1: |
| 252 |
plural='' |
| 253 |
if ucurrency.endswith('NOTE'): |
| 254 |
plural = 's' |
| 255 |
whoami.Say("%s, you don't have %s %s%s." % (random.choice(exclaimlist), cost, currency, plural)) |
| 256 |
else: |
| 257 |
whoami.Say("You don't have any %s, %s." % (currency, random.choice(buddylist))) |
| 258 |
|
| 259 |
def do_withdraw(self, text): |
| 260 |
if (not activator.DungeonMaster==1 and not CheckClearance([self.guildname,"Master"],activator)): |
| 261 |
whoami.Say("Only guild masters, masters, and DMs can withdraw funds from the guild.") |
| 262 |
return |
| 263 |
|
| 264 |
try: |
| 265 |
Amount=int(text[1]) |
| 266 |
except: |
| 267 |
whoami.Say("Usage: withdraw <quantity> {cointype=silver}") |
| 268 |
return |
| 269 |
|
| 270 |
bank = CFBank.CFBank(bankdatabase) |
| 271 |
balance = bank.getbalance(self.accountname) |
| 272 |
|
| 273 |
if len(text) > 2: |
| 274 |
Type = ' '.join(text[2:]) |
| 275 |
else: |
| 276 |
Type = "silver" |
| 277 |
|
| 278 |
if not Type.upper() in CoinTypes.keys(): |
| 279 |
whoami.Say("Sorry, I have no clue what %s are"%Type) |
| 280 |
return |
| 281 |
|
| 282 |
Value = CoinTypes.get(Type.upper()) |
| 283 |
|
| 284 |
if Amount*Value <= balance: |
| 285 |
message = (str(Amount)) |
| 286 |
message +=" " + Type + " withdrawn.\nYour new present balance is " |
| 287 |
|
| 288 |
id = activator.CreateObject(ArchType.get(Type.upper())) |
| 289 |
CFItemBroker.Item(id).add(Amount) |
| 290 |
bank.withdraw(self.accountname, Amount*Value) |
| 291 |
message += formatted_amount(bank.getbalance(self.accountname))+"." |
| 292 |
whoami.Say(message) |
| 293 |
else: |
| 294 |
message="You only have " + formatted_amount(bank.getbalance(self.accountname))+" on your account." |
| 295 |
whoami.Say(message) |
| 296 |
|
| 297 |
def handle_jack(self): |
| 298 |
'''Handle Jack, the guild helper''' |
| 299 |
|
| 300 |
text = Crossfire.WhatIsMessage().split() |
| 301 |
command = text[0].lower() |
| 302 |
|
| 303 |
if command == 'buy': |
| 304 |
self.do_buy(text) |
| 305 |
return |
| 306 |
|
| 307 |
if command == 'mailscroll': |
| 308 |
self.do_mailscroll(text) |
| 309 |
return |
| 310 |
|
| 311 |
if command == 'balance': |
| 312 |
self.do_balance() |
| 313 |
return |
| 314 |
|
| 315 |
if command == 'pay': |
| 316 |
self.do_pay(text) |
| 317 |
return |
| 318 |
|
| 319 |
if command == 'withdraw': |
| 320 |
self.do_withdraw(text) |
| 321 |
return |
| 322 |
|
| 323 |
if command == 'help' or command == 'yes': |
| 324 |
self.do_help() |
| 325 |
return |
| 326 |
|
| 327 |
message = "Howdy %s, paying some guild dues today?" %(random.choice(buddylist)) |
| 328 |
whoami.Say(message) |
| 329 |
|
| 330 |
|
| 331 |
def handle(self): |
| 332 |
'''Main handling function''' |
| 333 |
if not self.guildname: |
| 334 |
activator.Write('dues error, please notify a DM') |
| 335 |
return |
| 336 |
|
| 337 |
bank = CFBank.CFBank(bankdatabase) |
| 338 |
self.accountname = self.guildname + str(self.guildname.__hash__()) |
| 339 |
|
| 340 |
if whoami.Name == 'Jack': |
| 341 |
self.handle_jack() |
| 342 |
return |
| 343 |
|
| 344 |
amount = Crossfire.WhoIsOther().Value * Crossfire.WhoIsOther().Quantity |
| 345 |
bank.deposit(self.accountname, amount) |
| 346 |
|
| 347 |
dues = GuildDues() |
| 348 |
dues.handle() |