Lots of bug fixes: make it work with new Python plugin, fix truncated help message, set plural names of created objects, reword messages, prevent re-use of already sent packets, add safeguards for array-access; make source-code formatting consistent.

git-svn-id: svn://svn.code.sf.net/p/crossfire/code/trunk/maps@4024 282e977c-c81d-0410-88c4-b93c2d0d6712
master
akirschbaum 2005-11-10 19:28:00 +00:00
parent d198652a0b
commit 0a48aa8c1e
2 changed files with 101 additions and 102 deletions

View File

@ -26,7 +26,7 @@
# mailscroll <friend> - drops mailscroll to <friend> on the floor # mailscroll <friend> - drops mailscroll to <friend> on the floor
# mailwarning <foo> - drops mailwarning to <foo> on the floor # mailwarning <foo> - drops mailwarning to <foo> on the floor
# Constant price values # Constant price values (all prices in platinum coins)
priceWritingPen = 100 priceWritingPen = 100
priceScrollOfLiteracy = 5000 priceScrollOfLiteracy = 5000
priceMailScroll = 5 priceMailScroll = 5
@ -57,12 +57,18 @@ log = CFLog.CFLog()
text = string.split(Crossfire.WhatIsMessage()) text = string.split(Crossfire.WhatIsMessage())
if text[0] == 'help' or text[0] == 'yes': if text[0] == 'help' or text[0] == 'yes':
message = 'How can I help you ? Here is a quick list of commands:\n\n- pen (%s platinum)\n- literacy (%s platinum)\n- mailscroll <friend> (%s platinum)\n- bag <friend> (%s platinum)\n- package <friend> (%s platinum)\n- carton <friend> (%s platinum)\n- send <friend>\n- receive'%(priceWritingPen,priceScrollOfLiteracy,priceMailScroll,priceBag,pricePackage,priceCarton) # split the help message in two parts to prevent the server from truncating it.
message = 'How can I help you?\nHere is a quick list of commands I understand:\n\n- pen (%s platinum)\n- literacy (%s platinum)\n- mailscroll <friend> (%s platinum)\n- bag <friend> (%s platinum)\n- package <friend> (%s platinum)'%(priceWritingPen, priceScrollOfLiteracy, priceMailScroll, priceBag, pricePackage)
whoami.Say(message)
message = '- carton <friend> (%s platinum)\n- send <friend>\n- receive'%(priceCarton)
if activator.DungeonMaster:
message += '\n- mailwarning <player>'
whoami.Say(message) whoami.Say(message)
elif text[0] == 'pen': elif text[0] == 'pen':
if (activator.PayAmount(priceWritingPen*priceFactor)): if activator.PayAmount(priceWritingPen*priceFactor):
whoami.Say('Here is your IPO Writing Pen') whoami.Say('Here is your IPO Writing Pen')
id = activator.Map.CreateObject('writing pen', x, y) id = activator.Map.CreateObject('writing pen', x, y)
id.Name = 'IPO Writing Pen' id.Name = 'IPO Writing Pen'
@ -70,12 +76,14 @@ elif text[0] == 'pen':
else: else:
whoami.Say('You need %s platinum for an IPO Writing Pen'%priceWritingPen) whoami.Say('You need %s platinum for an IPO Writing Pen'%priceWritingPen)
elif text[0] == 'literacy': elif text[0] == 'literacy':
if (activator.PayAmount(priceScrollOfLiteracy*priceFactor)): if activator.PayAmount(priceScrollOfLiteracy*priceFactor):
whoami.Say('Here is your IPO Scroll of Literacy') whoami.Say('Here is your IPO Scroll of Literacy')
id = activator.Map.CreateObject('scroll of literacy', x, y) id = activator.Map.CreateObject('scroll of literacy', x, y)
id.SetName='IPO Scroll of Literacy' id.Name = 'IPO Scroll of Literacy'
id.SetValue=0 id.NamePl = 'IPO Scrolls of Literacy'
id.Value = 0
else: else:
whoami.Say('You need %s platinum for an IPO Scroll of Literacy'%priceScrollOfLiteracy) whoami.Say('You need %s platinum for an IPO Scroll of Literacy'%priceScrollOfLiteracy)
@ -83,38 +91,41 @@ elif text[0] == 'literacy':
elif text[0] == 'mailscroll': elif text[0] == 'mailscroll':
if len(text) == 2: if len(text) == 2:
if log.info(text[1]): if log.info(text[1]):
if (activator.PayAmount(priceMailScroll*priceFactor)): if activator.PayAmount(priceMailScroll*priceFactor):
whoami.Say('Here is your mailscroll') whoami.Say('Here is your mailscroll')
id = activator.Map.CreateObject('scroll', x, y) id = activator.Map.CreateObject('scroll', x, y)
id.Name = 'mailscroll T: '+text[1]+' F: '+activatorname id.Name = 'mailscroll T: '+text[1]+' F: '+activatorname
id.NamePl = 'mailscrolls T: '+text[1]+' F: '+activatorname
id.Value = 0 id.Value = 0
else: else:
whoami.Say('You need %s platinum for a mailscroll'%priceMailScroll) whoami.Say('You need %s platinum for a mailscroll'%priceMailScroll)
else: else:
whoami.Say('I don\'t know any %s'%text[1]) whoami.Say('I don\'t know %s'%text[1])
else: else:
whoami.Say('Usage "mailscroll <friend>"') whoami.Say('Usage "mailscroll <friend>"')
elif text[0] == 'mailwarning': elif text[0] == 'mailwarning':
if (activator.IsDungeonMaster): if activator.DungeonMaster:
if len(text) == 2: if len(text) == 2:
if log.info(text[1]): if log.info(text[1]):
whoami.Say('Here is your mailwarning') whoami.Say('Here is your mailwarning')
id = activator.Map.CreateObject('diploma', x, y) id = activator.Map.CreateObject('diploma', x, y)
id.Name = 'mailwarning T: '+text[1]+' F: '+activatorname id.Name = 'mailwarning T: '+text[1]+' F: '+activatorname
id.NamePl = 'mailwarnings T: '+text[1]+' F: '+activatorname
id.Value = 0 id.Value = 0
else: else:
whoami.Say('I don\'t know any %s'%text[1]) whoami.Say('I don\'t know any %s'%text[1])
else: else:
whoami.Say('Usage "mailwarning <foo>"') whoami.Say('Usage "mailwarning <player>"')
else: else:
whoami.Say('You need to be DM to be able to use this command') whoami.Say('You need to be DM to be able to use this command')
elif text[0] == 'bag' or text[0] == 'package' or text[0] == 'carton': elif text[0] == 'bag' or text[0] == 'package' or text[0] == 'carton':
if (len(text) == 2): if len(text) == 2:
if log.info(text[1]): if log.info(text[1]):
if text[0] == 'bag': if text[0] == 'bag':
price = priceBag price = priceBag
@ -129,13 +140,12 @@ elif text[0] == 'bag' or text[0] == 'package' or text[0] == 'carton':
max = 100000 max = 100000
item = 'r_sack' item = 'r_sack'
if ( activator.PayAmount(price*priceFactor) ): if activator.PayAmount(price*priceFactor):
box = activator.Map.CreateObject(item, x, y) box = activator.CreateObject(item)
box.Name = sackName+' T: '+text[1]+' F: '+activatorname box.Name = sackName+' T: '+text[1]+' F: '+activatorname
box.WeightLimit = max box.WeightLimit = max
box.Strength=0 box.Str = 0
whoami.Say(whoami, 'Here is your %s'%text[0]) whoami.Say('Here is your %s'%text[0])
activator.InsertObject(box)
else: else:
whoami.Say('You need %s platinum to buy a %s'%(price, text[0])) whoami.Say('You need %s platinum to buy a %s'%(price, text[0]))
@ -145,44 +155,55 @@ elif text[0] == 'bag' or text[0] == 'package' or text[0] == 'carton':
else: else:
whoami.Say('Send a %s to who?'%text[0] ) whoami.Say('Send a %s to who?'%text[0] )
elif text[0] == 'send': elif text[0] == 'send':
if len(text) == 2: if len(text) == 2:
count = 0
inv = activator.CheckInventory(sackName) inv = activator.CheckInventory(sackName)
map = 0
if inv != 0:
while inv: while inv:
next = inv.Below next = inv.Below
text2 = string.split(inv.Name) text2 = string.split(inv.Name)
if text2[0]==sackName and text2[1]=='T:' and text2[3]=='F:' and text2[2] == text[1]: if len(text2) == 5 and text2[0] == sackName and text2[1] == 'T:' and text2[3] == 'F:' and text2[2] == text[1]:
map = Crossfire.ReadyMap(storage_map) map = Crossfire.ReadyMap(storage_map)
if map == 0: if map:
whoami.Say('I\'m sorry but the post can\'t send your package now.') # rename container to prevent sending it multiple times
else: inv.Name = sackName+' F: '+text2[4]+' T: '+text2[2]
inv.Teleport(map, storage_x, storage_y) inv.Teleport(map, storage_x, storage_y)
whoami.Say('Package sent') count = count+1
inv = next
else: else:
whoami.Say('I\'m sorry but the post can\'t send your package now.')
inv = next
if count <= 0:
whoami.Say('No package to send.') whoami.Say('No package to send.')
elif count == 1:
whoami.Say('Package sent.')
else:
whoami.Say('%d packages sent.'%count)
else: else:
whoami.Say('Send packages to who?') whoami.Say('Send packages to who?')
elif text[0] == 'receive': elif text[0] == 'receive':
map = Crossfire.ReadyMap(storage_map) map = Crossfire.ReadyMap(storage_map)
if ( map != 0 ): if map:
item = map.ObjectAt(storage_x, storage_y)
count = 0 count = 0
item = map.ObjectAt(storage_x, storage_y)
while item: while item:
previous = item.Above previous = item.Above
text2 = string.split(item.Name) text2 = string.split(item.Name)
if ( len(text2) == 5 ) and ( text2[0] == sackName ) and ( text2[2] == activatorname ): if len(text2) == 5 and text2[0] == sackName and text2[4] == activatorname:
activator.InsertObjectInside(item) item.InsertInto(activator)
count = count+1 count = count+1
item = previous item = previous
if ( count == 0 ): if count <= 0:
whoami.Say('No package for you, sorry.') whoami.Say('No package for you, sorry.')
else: else:
whoami.Say('Here you go.') whoami.Say('Here you go.')
else: else:
whoami.Say('Sorry, our package delivery service is currently in strike. Please come back later.') whoami.Say('Sorry, our package delivery service is currently in strike. Please come back later.')
else: else:
whoami.Say('Do you need help?') whoami.Say('Do you need help?')
Crossfire.SetReturnValue(1) Crossfire.SetReturnValue(1)

View File

@ -32,49 +32,27 @@ activatorname=activator.Name
whoami = Crossfire.WhoAmI() whoami = Crossfire.WhoAmI()
idlist = [] idlist = []
inv = whoami.CheckInventory("mailscroll") inv = whoami.Inventory
if inv != None: while inv:
while inv!=None:
print("INV:%s" %inv.Name)
text = string.split(inv.Name) text = string.split(inv.Name)
if text[0]=='mailscroll' and text[1]=='T:' and text[3]=='F:': if text[0] == 'mailscroll' or text[0] == 'mailwarning':
if text[0] == 'mailscroll':
type = 1
else:
type = 3
if text[1] == 'T:' and text[3] == 'F:':
idlist.append(inv) idlist.append(inv)
toname = text[2] toname = text[2]
fromname = text[4] fromname = text[4]
message = 'From: %s\nTo: %s\nDate: %s\n\n%s\n'%(fromname, toname, date, inv.Message[:-1]) message = 'From: %s\nTo: %s\nDate: %s\n\n%s\n'%(fromname, toname, date, inv.Message[:-1])
activator.Write('mailscroll to '+toname+' sent.') activator.Write(text[0]+' to '+toname+' sent.')
mail.send(1, toname, fromname, message) mail.send(type, toname, fromname, message)
elif text[0]=='mailscroll' and text[1]=='F:' and text[3]=='T:': elif text[1] == 'F:' and text[3] == 'T:':
idlist.append(inv) idlist.append(inv)
fromname = text[2] fromname = text[2]
toname = text[4] toname = text[4]
message = inv.Message[:-1]+'\n' message = inv.Message[:-1]+'\n'
mail.send(1, toname, fromname, message) mail.send(type, toname, fromname, message)
else:
print "ID: %d"%inv
print "Name: "+inv.Name
inv=inv.Below
inv = whoami.CheckInventory("mailwarning")
if inv != None:
while inv!=None:
text=string.split(inv.Name)
if text[0]=='mailwarning' and text[1]=='T:' and text[3]=='F:':
idlist.append(inv)
toname=text[2]
fromname=text[4]
message='From: %s\nTo: %s\nDate: %s\n\n%s\n' % (fromname, toname, date, inv.Message[:-1])
activator.Write('mailwarning to '+toname+' sent.')
mail.send(3, toname, fromname, message)
elif text[0]=='mailwarning' and text[1]=='F:' and text[3]=='T:':
idlist.append(inv)
fromname=text[2]
toname=text[4]
message=inv.Message[:-1]+'\n'
mail.send(3, toname, fromname, message)
else:
print "ID: %d"%inv
print "Name: "+inv.Name
inv = inv.Below inv = inv.Below
for inv in idlist: for inv in idlist: