Debian Codegraph @

python/IPO/say.py

raw
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 [email protected]
20 #
21 # Updated to use new path functions in CFPython - Todd Mitchell
22
23 #### Constants ####
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, buy 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 += "When you're ready to send it, say 'send <friend name>'."
84 whoami.Say(reply)
85
86 # Sell items to the player if he/she asks for them.
87 elif text[0] == 'pen':
88 if activator.PayAmount(priceWritingPen*priceFactor):
89 whoami.Say("Here is your pen, enjoy!")
90 id = activator.Map.CreateObject('writing pen', x, y)
91 id.Name = 'IPO writing pen'
92 id.Value = 0
93 else:
94 whoami.Say("I'm sorry, you need %d platinum to buy a pen." % priceWritingPen)
95
96 elif text[0] == 'literacy':
97 if activator.PayAmount(priceScrollOfLiteracy*priceFactor):
98 whoami.Say('Here is your IPO Scroll of Literacy')
99 id = activator.Map.CreateObject('scroll of literacy', x, y)
100 id.Name = 'IPO Scroll of Literacy'
101 id.NamePl = 'IPO Scrolls of Literacy'
102 id.Value = 0
103 else:
104 whoami.Say('You need %s platinum for an IPO Scroll of Literacy'%priceScrollOfLiteracy)
105
106
107 elif text[0] == 'mailscroll':
108 if len(text) == 2:
109 if log.info(text[1]):
110 if activator.PayAmount(priceMailScroll*priceFactor):
111 whoami.Say('Here is your mailscroll')
112 id = activator.Map.CreateObject('scroll', x, y)
113 id.Name = 'mailscroll T: '+text[1]+' F: '+activatorname
114 id.NamePl = 'mailscrolls T: '+text[1]+' F: '+activatorname
115 id.Value = 0
116 else:
117 whoami.Say('You need %s platinum for a mailscroll'%priceMailScroll)
118 else:
119 whoami.Say('I don\'t know %s'%text[1])
120
121 else:
122 whoami.Say('Usage "mailscroll <friend>"')
123
124
125 elif text[0] == 'mailwarning':
126 if activator.DungeonMaster:
127 if len(text) == 2:
128 if log.info(text[1]):
129 whoami.Say('Here is your mailwarning')
130 id = activator.Map.CreateObject('diploma', x, y)
131 id.Name = 'mailwarning T: '+text[1]+' F: '+activatorname
132 id.NamePl = 'mailwarnings T: '+text[1]+' F: '+activatorname
133 id.Value = 0
134 else:
135 whoami.Say('I don\'t know any %s'%text[1])
136
137 else:
138 whoami.Say('Usage "mailwarning <player>"')
139 else:
140 whoami.Say('You need to be DM to be able to use this command')
141
142
143 elif text[0] in packages:
144 if len(text) == 2:
145 if log.info(text[1]):
146 price = packages[text[0]][0]
147 max = packages[text[0]][1]
148 item = packages[text[0]][2]
149
150 if activator.PayAmount(price*priceFactor):
151 box = activator.CreateObject(item)
152 box.Name = packages[text[0]][3] + ' T: '+text[1]+' F: '+activatorname
153 box.WeightLimit = max
154 box.Str = 0
155 whoami.Say('Here is your %s'%text[0])
156 else:
157 whoami.Say('You need %s platinum to buy a %s'%(price, text[0]))
158
159 else:
160 whoami.Say('I don\'t know any %s'%text[1])
161
162 else:
163 whoami.Say('Send a %s to who?'%text[0] )
164
165
166 elif text[0] == 'send':
167 if len(text) == 2:
168 count = 0
169 for package in packages.keys():
170 sackName = packages[package][3]
171 inv = activator.CheckInventory(sackName)
172 while inv:
173 next = inv.Below
174 text2 = inv.Name.split()
175 if len(text2) == 5 and text2[0] == sackName and text2[1] == 'T:' and text2[3] == 'F:' and text2[2] == text[1]:
176 map = Crossfire.ReadyMap(storage_map)
177 if map:
178 # rename container to prevent sending it multiple times
179 inv.Name = sackName+' F: '+text2[4]+' T: '+text2[2]
180
181 inv.Teleport(map, storage_x, storage_y)
182 count = count+1
183 else:
184 whoami.Say('I\'m sorry but the post can\'t send your package now.')
185 inv = next
186 if count <= 0:
187 whoami.Say('No package to send.')
188 elif count == 1:
189 whoami.Say('Package sent.')
190 else:
191 whoami.Say('%d packages sent.'%count)
192 else:
193 whoami.Say('Send packages to who?')
194
195
196 elif text[0] == 'receive':
197 map = Crossfire.ReadyMap(storage_map)
198 if map:
199 count = 0
200 for package in packages.keys():
201 sackName = packages[package][3]
202 item = map.ObjectAt(storage_x, storage_y)
203 while item:
204 previous = item.Above
205 text2 = item.Name.split()
206 if len(text2) == 5 and text2[0] == sackName and text2[4] == activatorname:
207 item.Name = item.Name+' (used)'
208 item.InsertInto(activator)
209 count = count+1
210 item = previous
211 if count <= 0:
212 whoami.Say('No package for you, sorry.')
213 else:
214 whoami.Say('Here you go.')
215 else:
216 whoami.Say("I'm sorry, our package delivery service is currently on strike. Please come back later.")
217
218
219 else:
220 whoami.Say("Welcome to the IPO! How can I help you?")
221 Crossfire.AddReply("buy", "What can I buy here?")
222 Crossfire.AddReply("receive", "Do I have any packages?")
223
224 Crossfire.SetReturnValue(1)