Rewrite.
git-svn-id: svn://svn.code.sf.net/p/crossfire/code/maps/trunk@14089 282e977c-c81d-0410-88c4-b93c2d0d6712master
parent
4279b270a4
commit
6763e0722f
|
@ -1,5 +1,5 @@
|
|||
"""
|
||||
Script for paying Guild Dues
|
||||
Script for paying Guild Dues, and to handle Jack in the mainfloor.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
|
@ -16,27 +16,40 @@ Script for paying Guild Dues
|
|||
# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
#
|
||||
# author:Avion temitchell@sourceforge.net
|
||||
#
|
||||
# Heavily modified by Nicolas Weeger, 2010-11-14
|
||||
"""
|
||||
|
||||
import Crossfire,CFGuilds,CFItemBroker,random,string,sys,CFBank,CFMail,CFLog
|
||||
import Crossfire
|
||||
import CFGuilds
|
||||
import CFItemBroker
|
||||
import random
|
||||
import CFBank
|
||||
import CFLog
|
||||
from CFGuildClearance import CheckClearance
|
||||
log = CFLog.CFLog()
|
||||
|
||||
CoinTypes={"SILVER":1,"GOLD":10,"PLATINUM":50,"JADE":5000,"AMBERIUM":500000, "IMPERIAL NOTE":10000,"TEN IMPERIAL NOTE":100000,"ONE HUNDRED IMPERIAL NOTE":1000000}
|
||||
# List of amounts a player can pay
|
||||
CoinTypes={
|
||||
"SILVER":1,
|
||||
"GOLD":10,
|
||||
"PLATINUM":50,
|
||||
"JADE":5000,
|
||||
"AMBERIUM":500000,
|
||||
"IMPERIAL NOTE":10000,
|
||||
"TEN IMPERIAL NOTE":100000,
|
||||
"ONE HUNDRED IMPERIAL NOTE":1000000 }
|
||||
|
||||
# Archetypes for the 'withdraw' command
|
||||
ArchType={"SILVER":"silvercoin","GOLD":"goldcoin","PLATINUM":"platinacoin","JADE":"jadecoin","AMBERIUM":"ambercoin", "IMPERIAL NOTE":"imperial","TEN IMPERIAL NOTE":"imperial10","ONE HUNDRED IMPERIAL NOTE":"imperial100"}
|
||||
|
||||
# Filename for the bank
|
||||
bankdatabase = "ImperialBank_DB"
|
||||
Items={'BBQ':200*30000, 'Stove':200*30000, 'AlchemyLab':400*30000, 'Cauldron':200*30000, "CrystalRoom":100,"Tannery":200*30000,"ThaumaturgyRoom":200*30000,"JewelrsRoom":400*30000,"ThaumaturgyDesk":200*30000,"TanningDesk":200*30000,"JewelrsBench":400*30000,"Bowyer":200*30000,"BowyerBench":200*25000,"Smithy":200*30000,"Forge":200*25000}
|
||||
Cards=["Stove","Cauldron","TanningDesk","ThaymaturgyDesk","JewelrsBench","BowyerBench","Forge"]
|
||||
|
||||
remarklist = ['Excellent','Thank You','Thank You','Thank You', 'Thank You', 'Great', 'OK', 'Wonderful', 'Swell', 'Dude', 'Big Spender']
|
||||
exclaimlist = ['Hey','Hey','Hey','Hey', 'Now just a minute', 'AHEM', 'OK...Wait a minute', 'Look chowderhead']
|
||||
buddylist = ['buddy','buddy','buddy','buddy','pal','friend','friend','friend','friend','dude','chum', 'sweetie']
|
||||
whoami=Crossfire.WhoAmI()
|
||||
mymap=whoami.Map
|
||||
path=mymap.Path
|
||||
path=path.replace("mainfloor","")
|
||||
SecondFloor=Crossfire.ReadyMap(path+'secondfloor')
|
||||
ToolShed=Crossfire.ReadyMap(path+"guild_toolshed")
|
||||
Rooms={"BBQ":(mymap,40,25),"AlchemyLab":(SecondFloor,22,12),"CrystalRoom":(SecondFloor,22,13),"Tannery":(SecondFloor,22,14),"ThaumaturgyRoom":(SecondFloor,21,13),"JewelrsRoom":(SecondFloor,22,14),"Bowyer":(ToolShed,22,16),"Smithy":(ToolShed,23,16)}
|
||||
activator = Crossfire.WhoIsActivator()
|
||||
|
||||
def formatted_amount(amount):
|
||||
""" Format a price as a string, giving full coin descriptions. Returns 'no money' if amount is 0. """
|
||||
|
@ -57,140 +70,257 @@ def FindCoin(object):
|
|||
if not object:
|
||||
return 0
|
||||
return object
|
||||
guildname=Crossfire.ScriptParameters()
|
||||
bank = CFBank.CFBank(bankdatabase)
|
||||
accountname=guildname+str(guildname.__hash__())
|
||||
if (guildname):
|
||||
if whoami.Name=='Jack':
|
||||
guild = CFGuilds.CFGuild(guildname)
|
||||
activator=Crossfire.WhoIsActivator()
|
||||
X=activator.X
|
||||
Y=activator.Y
|
||||
bank = CFBank.CFBank(bankdatabase)
|
||||
in_guild=CFGuilds.SearchGuilds(activator.Name)
|
||||
text = Crossfire.WhatIsMessage().split()
|
||||
if text[0].upper() == 'HELP' or text[0].upper() == 'YES':
|
||||
message=('Let me know how much you want to pay. Say pay <amount> <cointype>\n\tValid coin types are '+', '.join(CoinTypes)+'.\nYou can also check the balance by saying "balance".\nGuild Masters can also purchase items with the "buy" command.\nI also provide mailscrolls at 10 plat each.')
|
||||
elif text[0].upper()=="BUY":
|
||||
try:
|
||||
Item=text[1]
|
||||
except:
|
||||
Item=None
|
||||
message="Syntax: Buy <item>\n Valid items are: \n"+'\n'.join([' - ' + i +': '+ formatted_amount(Items[i]) for i in Items])+'.'
|
||||
if Item!=None:
|
||||
if ( not CheckClearance([guildname, "GuildMaster"],activator)):
|
||||
message="Only guild masters and GMs can buy expansions for the guild."
|
||||
else:
|
||||
try:
|
||||
Price=Items.get(Item)
|
||||
except:
|
||||
Item=None
|
||||
Price=None
|
||||
message="Syntax: Buy <item>\n Valid items are: "+', '.join(Items)+'.'
|
||||
if Price!=None:
|
||||
balance=bank.getbalance(accountname)
|
||||
if Price<=balance:
|
||||
Card=Cards.__contains__(Item)
|
||||
if Card==True:
|
||||
pack=activator.Map.CreateObject('package', 40, 29)
|
||||
pack.Name = 'IPO-package F: ACME T: ' + guildname
|
||||
card=mymap.CreateObject('diploma',40,29)
|
||||
card.Name=Item
|
||||
message = "Your card has been ordered and should arrive in the mail shortly."
|
||||
mailbox=mymap.ObjectAt(12,21)
|
||||
mailbox=find_mailbox(mailbox)
|
||||
if mailbox==0:
|
||||
mailbox=mymap.ObjectAt(30,5)
|
||||
mailbox=find_mailbox(mailbox)
|
||||
if mailbox==0:
|
||||
message+=" The postman couldn't find the mailbox. Please contact a DM to install your mailbox."
|
||||
else:
|
||||
cardnew=card.InsertInto(pack)
|
||||
packnew=pack.InsertInto(mailbox)
|
||||
bank.withdraw(accountname, Price)
|
||||
else:
|
||||
Loc=Rooms.get(Item)
|
||||
coin=Loc[0].ObjectAt(Loc[1],Loc[2])
|
||||
coin=FindCoin(coin)
|
||||
message="The guild already has this expansion!"
|
||||
if (coin==0):
|
||||
coin=mymap.CreateObject('silvercoin',40,29)
|
||||
coin.Teleport(Loc[0],Loc[1],Loc[2])
|
||||
#activator.Teleport(mymap,X,Y)
|
||||
bank.withdraw(accountname, Price)
|
||||
message="The new room has been unlocked.\n"
|
||||
message+="The guild now has a balance of "
|
||||
message+=str(bank.getbalance(accountname))+" silver coins."
|
||||
else:
|
||||
message="The guild does not have sufficient funds."
|
||||
elif text[0] == 'mailscroll':
|
||||
if len(text) == 2:
|
||||
if log.info(text[1]):
|
||||
if activator.PayAmount(priceMailScroll*priceFactor*2):
|
||||
whoami.Say('Here is your mailscroll')
|
||||
id = activator.Map.CreateObject('scroll', X, Y)
|
||||
id.Name = 'mailscroll T: '+text[1]+' F: '+activator.Name
|
||||
id.NamePl = 'mailscrolls T: '+text[1]+' F: '+activator.Name
|
||||
id.Value = 0
|
||||
else:
|
||||
whoami.Say('You need %s platinum for a mailscroll'%priceMailScroll)
|
||||
else:
|
||||
whoami.Say('I don\'t know %s'%text[1])
|
||||
else:
|
||||
whoami.Say('Usage "mailscroll <friend>"')
|
||||
elif text[0].upper()=='WITHDRAW':
|
||||
if (not activator.DungeonMaster==1 and not CheckClearance([guildname,"Master"],activator)):
|
||||
message="Only guild masters, masters, and DMs can withdraw funds from the guild."
|
||||
else:
|
||||
try:
|
||||
Amount=int(text[1])
|
||||
except:
|
||||
message = "Useage: withdraw <quantity> {cointype=Silver}"
|
||||
Amount=None
|
||||
|
||||
if Amount!=None:
|
||||
balance=bank.getbalance(accountname)
|
||||
try:
|
||||
Type=' '.join(text[2:])
|
||||
except:
|
||||
Type="Silver"
|
||||
Value=CoinTypes.get(Type.upper(),1)
|
||||
if Value==1:
|
||||
Type="SILVER"
|
||||
if Amount*Value <= balance:
|
||||
message=(str(Amount))
|
||||
message+=" "+Type+" withdrawn.\nYour new present balance is "
|
||||
id = activator.Map.CreateObject(ArchType.get(Type.upper()), activator.X, activator.Y)
|
||||
bank.withdraw(accountname, Amount*Value)
|
||||
CFItemBroker.Item(id).add(Amount)
|
||||
activator.Take(id)
|
||||
message+=str(bank.getbalance(accountname))+"."
|
||||
else:
|
||||
message="You only have "+formatted_amount(bank.getbalance(accountname))+" on account."
|
||||
|
||||
elif text[0].upper()=='BALANCE':
|
||||
balance=bank.getbalance(accountname)
|
||||
message="The guild currently has %s on account." %(formatted_amount(balance))
|
||||
elif text[0].upper() == 'PAY':
|
||||
if len(text)>2:
|
||||
cost = text[1]
|
||||
conversionfactor = CoinTypes.get(' '.join(text[2:]).upper())
|
||||
total=int(cost)*conversionfactor
|
||||
if activator.PayAmount(total):
|
||||
guild.pay_dues(activator.Name,total)
|
||||
message = "%s, %s %s paid to the guild." %(random.choice(remarklist),cost, ' '.join(text[2:]))
|
||||
bank.deposit(accountname, total)
|
||||
else:
|
||||
if cost > 1:
|
||||
message ="%s, you don't have %s %ss." %(random.choice(exclaimlist),cost,' '.join(text[2:]))
|
||||
else:
|
||||
message ="You don't have any %s, %s." %(' '.join(text[2:]),random.choice(buddylist))
|
||||
else:
|
||||
message = "How much ya wanna pay %s?" %(random.choice(buddylist))
|
||||
else:
|
||||
message = "Howdy %s, paying some guild dues today?" %(random.choice(buddylist))
|
||||
|
||||
class GuildDues:
|
||||
def __init__(self):
|
||||
'''Standard constructor'''
|
||||
self.guildname = Crossfire.ScriptParameters()
|
||||
|
||||
def do_help(self):
|
||||
'''Handle the 'help' and 'yes' commands.'''
|
||||
gm = ''
|
||||
|
||||
if CheckClearance([self.guildname, "GuildMaster"], activator):
|
||||
gm = 'You can purchase guild extensions or new desks with the "buy" word.\n'
|
||||
|
||||
whoami.Say('Let me know how much you want to pay. Say pay <amount> <cointype>'
|
||||
+ '\n\tValid coin types are '
|
||||
+ ', '.join(CoinTypes)
|
||||
+ '.\nYou can check the balance by saying "balance".\n'
|
||||
+ gm
|
||||
+ 'I also provide mailscrolls at 10 platinum each, use "mailscroll".')
|
||||
|
||||
def do_buy(self, text):
|
||||
'''Handles buying a guild extension'''
|
||||
|
||||
if (not CheckClearance([self.guildname, "GuildMaster"], activator)):
|
||||
whoami.Say("Only guild masters and GMs can buy extensions or new desks for the guild.")
|
||||
return
|
||||
|
||||
# This lists all items that can be bought, extensions or new desks
|
||||
Items = {
|
||||
'BBQ':200*30000,
|
||||
'Stove':200*30000,
|
||||
'AlchemyLab':400*30000,
|
||||
'Cauldron':200*30000,
|
||||
"CrystalRoom":100,
|
||||
"Tannery":200*30000,
|
||||
"ThaumaturgyRoom":200*30000,
|
||||
"JewelersRoom":400*30000,
|
||||
"ThaumaturgyDesk":200*30000,
|
||||
"TanningDesk":200*30000,
|
||||
"JewelersBench":400*30000,
|
||||
"Bowyer":200*30000,
|
||||
"BowyerBench":200*25000,
|
||||
"Smithy":200*30000,
|
||||
"Forge":200*25000}
|
||||
|
||||
if len(text) == 1:
|
||||
whoami.Say('Buy what extension or desk?\n'
|
||||
+ "Valid items are: \n"+'\n'.join([' - ' + i +': '+ formatted_amount(Items[i]) for i in Items])+'.')
|
||||
return
|
||||
|
||||
# This is the list of cards to buy new desks
|
||||
Cards = ["Stove", "Cauldron", "TanningDesk", "ThaumaturgyDesk", "JewelersBench", "BowyerBench", "Forge"]
|
||||
mymap=whoami.Map
|
||||
path=mymap.Path
|
||||
path=path.replace("mainfloor","")
|
||||
SecondFloor=Crossfire.ReadyMap(path+'secondfloor')
|
||||
ToolShed=Crossfire.ReadyMap(path+"guild_toolshed")
|
||||
|
||||
# This is the list of guild extensions, and the coordinates of the activation button
|
||||
Rooms = {
|
||||
"BBQ":(mymap,40,25),
|
||||
"AlchemyLab":(SecondFloor,22,12),
|
||||
"CrystalRoom":(SecondFloor,22,13),
|
||||
"Tannery":(SecondFloor,22,14),
|
||||
"ThaumaturgyRoom":(SecondFloor,21,13),
|
||||
"JewelersRoom":(SecondFloor,22,14),
|
||||
"Bowyer":(ToolShed,22,16),
|
||||
"Smithy":(ToolShed,23,16) }
|
||||
|
||||
item = text[1]
|
||||
if not item in Items.keys():
|
||||
whoami.Say("I don't know that item, sorry")
|
||||
return
|
||||
|
||||
Price = Items.get(item)
|
||||
bank = CFBank.CFBank(bankdatabase)
|
||||
balance = bank.getbalance(self.accountname)
|
||||
if Price > balance:
|
||||
whoami.Say("The guild does not have sufficient funds.")
|
||||
return
|
||||
|
||||
if item in Cards:
|
||||
card = activator.CreateObject('diploma')
|
||||
card.Name = item
|
||||
card.Message = 'This enables you to buy a new ' + item + ' for your guild.'
|
||||
card.Value = 0
|
||||
bank.withdraw(self.accountname, Price)
|
||||
whoami.Say("Here is your card\nThe guild now has %s on account." %(formatted_amount(bank.getbalance(self.accountname))))
|
||||
|
||||
return
|
||||
|
||||
Loc = Rooms.get(item)
|
||||
coin = Loc[0].ObjectAt(Loc[1], Loc[2])
|
||||
coin = FindCoin(coin)
|
||||
|
||||
if coin != 0:
|
||||
whoami.Say("The guild already has this expansion!")
|
||||
return
|
||||
|
||||
coin = mymap.CreateObject('silvercoin',40,29)
|
||||
coin.Teleport(Loc[0] ,Loc[1], Loc[2])
|
||||
|
||||
bank.withdraw(self.accountname, Price)
|
||||
whoami.Say("The new room has been unlocked.\n"
|
||||
+ "The guild now has %s on account." %(formatted_amount(bank.getbalance(self.accountname))))
|
||||
|
||||
def do_mailscroll(self, text):
|
||||
'''Handle getting a mailscroll for a friend.'''
|
||||
if len(text) == 1:
|
||||
whoami.Say('Usage "mailscroll <friend>"')
|
||||
return
|
||||
|
||||
log = CFLog.CFLog()
|
||||
|
||||
if not log.info(text[1]):
|
||||
whoami.Say('I don\'t know %s'%text[1])
|
||||
return
|
||||
|
||||
priceMailScroll = 5
|
||||
priceFactor = 50 # platinum to silver conversion
|
||||
|
||||
if activator.PayAmount(priceMailScroll*priceFactor):
|
||||
whoami.Say('Here is your mailscroll to %s'%text[1])
|
||||
id = activator.CreateObject('scroll')
|
||||
id.Name = 'mailscroll T: '+text[1]+' F: '+activator.Name
|
||||
id.NamePl = 'mailscrolls T: '+text[1]+' F: '+activator.Name
|
||||
id.Value = 0
|
||||
else:
|
||||
whoami.Say('You need %s platinum for a mailscroll'%priceMailScroll)
|
||||
|
||||
def do_balance(self):
|
||||
'''Handle the display of the guild's balance.'''
|
||||
bank = CFBank.CFBank(bankdatabase)
|
||||
balance = bank.getbalance(self.accountname)
|
||||
whoami.Say("The guild currently has %s on account." %(formatted_amount(balance)))
|
||||
|
||||
def do_pay(self, text):
|
||||
'''Handle player paying dues to the guild.'''
|
||||
if len(text) < 2:
|
||||
whoami.Say("How much ya wanna pay %s?\nYou can specify amounts in "%(random.choice(buddylist)) +
|
||||
', '.join(i.lower() for i in CoinTypes.keys()))
|
||||
return
|
||||
|
||||
cost = text[1]
|
||||
type = ' '.join(text[2:])
|
||||
utype = type.upper()
|
||||
if not utype in CoinTypes.keys():
|
||||
whoami.Say("Sorry, I don't know what are %s"%type)
|
||||
return
|
||||
|
||||
conversionfactor = CoinTypes.get(utype)
|
||||
total = int(cost)*conversionfactor
|
||||
if activator.PayAmount(total):
|
||||
guild = CFGuilds.CFGuild(self.guildname)
|
||||
guild.pay_dues(activator.Name,total)
|
||||
whoami.Say("%s, %s %s paid to the guild." %(random.choice(remarklist), cost, type))
|
||||
bank = CFBank.CFBank(bankdatabase)
|
||||
bank.deposit(self.accountname, total)
|
||||
else:
|
||||
if cost > 1:
|
||||
whoami.Say("%s, you don't have %s %ss." %(random.choice(exclaimlist), cost, type))
|
||||
else:
|
||||
whoami.Say("You don't have any %s, %s." %(type, random.choice(buddylist)))
|
||||
|
||||
def do_withdraw(self, text):
|
||||
if (not activator.DungeonMaster==1 and not CheckClearance([self.guildname,"Master"],activator)):
|
||||
whoami.Say("Only guild masters, masters, and DMs can withdraw funds from the guild.")
|
||||
return
|
||||
|
||||
try:
|
||||
Amount=int(text[1])
|
||||
except:
|
||||
whoami.Say("Usage: withdraw <quantity> {cointype=silver}")
|
||||
return
|
||||
|
||||
bank = CFBank.CFBank(bankdatabase)
|
||||
balance = bank.getbalance(self.accountname)
|
||||
|
||||
if len(text) > 2:
|
||||
Type = ' '.join(text[2:])
|
||||
else:
|
||||
Type = "silver"
|
||||
|
||||
if not Type.upper() in CoinTypes.keys():
|
||||
whoami.Say("Sorry, I have no clue what %s are"%Type)
|
||||
return
|
||||
|
||||
Value = CoinTypes.get(Type.upper())
|
||||
|
||||
if Amount*Value <= balance:
|
||||
message = (str(Amount))
|
||||
message +=" " + Type + " withdrawn.\nYour new present balance is "
|
||||
|
||||
id = activator.CreateObject(ArchType.get(Type.upper()))
|
||||
CFItemBroker.Item(id).add(Amount)
|
||||
bank.withdraw(self.accountname, Amount*Value)
|
||||
message += formatted_amount(bank.getbalance(self.accountname))+"."
|
||||
whoami.Say(message)
|
||||
else:
|
||||
bank.deposit(accountname, 5000)
|
||||
else:
|
||||
activator.Write('dues Error, please notify a DM')
|
||||
message="You only have " + formatted_amount(bank.getbalance(self.accountname))+" on your account."
|
||||
whoami.Say(message)
|
||||
|
||||
def handle_jack(self):
|
||||
'''Handle Jack, the guild helper'''
|
||||
|
||||
text = Crossfire.WhatIsMessage().split()
|
||||
command = text[0].lower()
|
||||
|
||||
if command == 'buy':
|
||||
self.do_buy(text)
|
||||
return
|
||||
|
||||
if command == 'mailscroll':
|
||||
self.do_mailscroll(text)
|
||||
return
|
||||
|
||||
if command == 'balance':
|
||||
self.do_balance()
|
||||
return
|
||||
|
||||
if command == 'pay':
|
||||
self.do_pay(text)
|
||||
return
|
||||
|
||||
if command == 'withdraw':
|
||||
self.do_withdraw(text)
|
||||
return
|
||||
|
||||
if command == 'help' or command == 'yes':
|
||||
self.do_help()
|
||||
return
|
||||
|
||||
message = "Howdy %s, paying some guild dues today?" %(random.choice(buddylist))
|
||||
whoami.Say(message)
|
||||
|
||||
|
||||
def handle(self):
|
||||
'''Main handling function'''
|
||||
if not self.guildname:
|
||||
activator.Write('dues error, please notify a DM')
|
||||
return
|
||||
|
||||
bank = CFBank.CFBank(bankdatabase)
|
||||
self.accountname = self.guildname + str(self.guildname.__hash__())
|
||||
|
||||
if whoami.Name == 'Jack':
|
||||
self.handle_jack()
|
||||
return
|
||||
|
||||
# todo: don't hardcode
|
||||
bank.deposit(self.accountname, 5000)
|
||||
|
||||
dues = GuildDues()
|
||||
dues.handle()
|
||||
|
|
Loading…
Reference in New Issue