Crossfire Server, Trunk
say.py
Go to the documentation of this file.
1 # say.py -- script for say event of IPO employees
2 #
3 # Copyright (C) 2002 Joris Bontje
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 #
19 # The author can be reached via e-mail at jbontje@suespammers.org
20 #
21 # Updated to use new path functions in CFPython - Todd Mitchell
22 
23 
24 
25 # Price values in platinum coins.
26 priceWritingPen = 100
27 priceScrollOfLiteracy = 5000
28 priceMailScroll = 2
29 priceFactor = 50 # platinum to silver conversion
30 
31 # Define several different types of packages on sale.
32 # The format is: <name to display to player> : [ price (in plat), max weight, archetype, name ]
33 packages = {'bag' : [ 5, 5000, 'bag', 'IPO-bag'],
34  'package' : [ 45, 50000, 'package', 'IPO-package' ],
35  'carton' : [ 90, 100000, 'carton_box_1', 'IPO-carton' ] }
36 
37 # Map storage for packages
38 storage_map = '/planes/IPO_storage'
39 storage_x = 2
40 storage_y = 2
41 
42 import CFLog
43 import Crossfire
44 import string
45 
46 activator = Crossfire.WhoIsActivator()
47 activatorname = activator.Name
48 whoami = Crossfire.WhoAmI()
49 
50 x = activator.X
51 y = activator.Y
52 
53 log = CFLog.CFLog()
54 text = Crossfire.WhatIsMessage().split()
55 
56 # Have a conversation with the player about what's on sale.
57 if Crossfire.MatchString("buy", text[0]):
58  whoami.Say("Well, we have a few items for sale. You can also send out letters and packages to your friends. What can I interest you in?")
59  Crossfire.AddReply("items", "What items do you sell?")
60  Crossfire.AddReply("letter", "I'd like to send a letter.")
61  Crossfire.AddReply("mail", "I want to send a package.")
62 
63 elif Crossfire.MatchString("items", text[0]):
64  whoami.Say("Here are the items on sale:\n" +
65  " - pen (%i platinum)\n" % priceWritingPen +
66  " - literacy scroll (%i platinum)\n" % priceScrollOfLiteracy +
67  "Please tell me what you'd like to buy.")
68 
69  if activator.DungeonMaster:
70  whoami.Say("Oh, and as a dungeon master, you can also order:\n" +
71  " - mailwarning <player name> (free)")
72 
73 elif Crossfire.MatchString("letter", text[0]):
74  whoami.Say("For %i platinum you can send a letter to your friend. Just say 'mailscroll <friend name>'." % priceMailScroll)
75 
76 elif Crossfire.MatchString("mail", text[0]):
77  reply = "To send items, select one of our following containers:\n"
78 
79  for pack in packages.keys():
80  # weight is in grams, so need to convert.
81  reply += " - %s (limit %d kg, %d platinum)\n" % (pack, packages[pack][1] / 1000, packages[pack][0])
82 
83  reply += "To buy it, say <container type> <friend name>'.\n"
84  reply += "When you're ready to send it, say 'send <friend name>'."
85  whoami.Say(reply)
86 
87 # Sell items to the player if he/she asks for them.
88 elif text[0] == 'pen':
89  if activator.PayAmount(priceWritingPen*priceFactor):
90  whoami.Say("Here is your pen, enjoy!")
91  id = activator.Map.CreateObject('writing pen', x, y)
92  id.Name = 'IPO writing pen'
93  id.Value = 0
94  else:
95  whoami.Say("I'm sorry, you need %d platinum to buy a pen." % priceWritingPen)
96 
97 elif text[0] == 'literacy':
98  if activator.PayAmount(priceScrollOfLiteracy*priceFactor):
99  whoami.Say('Here is your IPO Scroll of Literacy')
100  id = activator.Map.CreateObject('scroll of literacy', x, y)
101  id.Name = 'IPO Scroll of Literacy'
102  id.NamePl = 'IPO Scrolls of Literacy'
103  id.Value = 0
104  else:
105  whoami.Say('You need %s platinum for an IPO Scroll of Literacy'%priceScrollOfLiteracy)
106 
107 
108 elif text[0] == 'mailscroll':
109  if len(text) == 2:
110  if log.info(text[1]):
111  if activator.PayAmount(priceMailScroll*priceFactor):
112  whoami.Say('Here is your mailscroll')
113  id = activator.Map.CreateObject('scroll', x, y)
114  id.Name = 'mailscroll T: '+text[1]+' F: '+activatorname
115  id.NamePl = 'mailscrolls T: '+text[1]+' F: '+activatorname
116  id.Value = 0
117  else:
118  whoami.Say('You need %s platinum for a mailscroll'%priceMailScroll)
119  else:
120  whoami.Say('I don\'t know %s'%text[1])
121 
122  else:
123  whoami.Say('Usage "mailscroll <friend>"')
124 
125 
126 elif text[0] == 'mailwarning':
127  if activator.DungeonMaster:
128  if len(text) == 2:
129  if log.info(text[1]):
130  whoami.Say('Here is your mailwarning')
131  id = activator.Map.CreateObject('diploma', x, y)
132  id.Name = 'mailwarning T: '+text[1]+' F: '+activatorname
133  id.NamePl = 'mailwarnings T: '+text[1]+' F: '+activatorname
134  id.Value = 0
135  else:
136  whoami.Say('I don\'t know any %s'%text[1])
137 
138  else:
139  whoami.Say('Usage "mailwarning <player>"')
140  else:
141  whoami.Say('You need to be DM to be able to use this command')
142 
143 
144 elif text[0] in packages:
145  if len(text) == 2:
146  if log.info(text[1]):
147  price = packages[text[0]][0]
148  max = packages[text[0]][1]
149  item = packages[text[0]][2]
150 
151  if activator.PayAmount(price*priceFactor):
152  box = activator.CreateObject(item)
153  box.Name = packages[text[0]][3] + ' T: '+text[1]+' F: '+activatorname
154  box.WeightLimit = max
155  box.Str = 0
156  whoami.Say('Here is your %s'%text[0])
157  else:
158  whoami.Say('You need %s platinum to buy a %s'%(price, text[0]))
159 
160  else:
161  whoami.Say('I don\'t know any %s'%text[1])
162 
163  else:
164  whoami.Say('Send a %s to who?'%text[0] )
165 
166 
167 elif text[0] == 'send':
168  if len(text) == 2:
169  count = 0
170  for package in packages.keys():
171  sackName = packages[package][3]
172  inv = activator.CheckInventory(sackName)
173  while inv:
174  next = inv.Below
175  text2 = inv.Name.split()
176  if len(text2) == 5 and text2[0] == sackName and text2[1] == 'T:' and text2[3] == 'F:' and text2[2] == text[1]:
177  map = Crossfire.ReadyMap(storage_map)
178  if map:
179  # rename container to prevent sending it multiple times
180  inv.Name = sackName+' F: '+text2[4]+' T: '+text2[2]
181 
182  inv.Teleport(map, storage_x, storage_y)
183  count = count+1
184  else:
185  whoami.Say('I\'m sorry but the post can\'t send your package now.')
186  inv = next
187  if count <= 0:
188  whoami.Say('No package to send.')
189  elif count == 1:
190  whoami.Say('Package sent.')
191  else:
192  whoami.Say('%d packages sent.'%count)
193  else:
194  whoami.Say('Send packages to who?')
195 
196 
197 elif text[0] == 'receive':
198  map = Crossfire.ReadyMap(storage_map)
199  if map:
200  count = 0
201  for package in packages.keys():
202  sackName = packages[package][3]
203  item = map.ObjectAt(storage_x, storage_y)
204  while item:
205  previous = item.Above
206  text2 = item.Name.split()
207  if len(text2) == 5 and text2[0] == sackName and text2[4] == activatorname:
208  item.Name = item.Name+' (used)'
209  item.InsertInto(activator)
210  count = count+1
211  item = previous
212  if count <= 0:
213  whoami.Say('No package for you, sorry.')
214  else:
215  whoami.Say('Here you go.')
216  else:
217  whoami.Say("I'm sorry, our package delivery service is currently on strike. Please come back later.")
218 
219 
220 else:
221  whoami.Say("Welcome to the IPO! How can I help you?")
222  Crossfire.AddReply("buy", "What can I buy here?")
223  Crossfire.AddReply("receive", "Do I have any packages?")
224 
225 Crossfire.SetReturnValue(1)
CFLog.CFLog
Definition: CFLog.py:34
split
static std::vector< std::string > split(const std::string &field, const std::string &by)
Definition: mapper.cpp:2606