1 from plomrogue.errors import PlayError, GameError
2 from plomrogue.misc import quote
10 def __init__(self, thing, args=()):
14 def _get_move_target(self):
15 if self.args[0] == 'HERE':
16 return self.thing.position
17 return self.thing.game.map_geometry.move_yxyx(self.thing.position,
25 class Task_WAIT(Task):
32 class Task_MOVE(Task):
33 argtypes = 'string:direction'
36 test_yxyx = self._get_move_target()
37 move_blockers = self.thing.game.get_movement_blockers()
38 if test_yxyx in [t.position for t in self.thing.game.things
39 if t.blocks_movement]:
40 raise PlayError('blocked by other thing')
41 elif self.thing.game.maps[test_yxyx[0]][test_yxyx[1]] in move_blockers:
42 raise PlayError('blocked by impassable tile')
45 if self.thing.type_ == 'Player' and not self.thing.standing:
46 self.thing.standing = True
47 self.thing.send_msg('CHAT "You get up."')
48 self.thing.game.record_change(self.thing.position, 'other')
49 if self.thing.blocks_light:
50 self.thing.game.record_change(self.thing.position, 'fov')
51 self.thing.position = self._get_move_target()
52 for t in [t for t in self.thing.game.things
53 if t.type_ == 'Player' and not t == self.thing
54 and t.position == self.thing.position]:
55 self.thing.send_msg('CHAT %s' %
56 quote('You get awkwardly close to %s.' % t.name))
57 for c_id in self.thing.game.sessions:
58 if self.thing.game.sessions[c_id]['thing_id'] == t.id_:
59 t.send_msg('CHAT %s' %
60 quote('%s gets awkwardly close to you.' %
63 self.thing.game.record_change(self.thing.position, 'other')
64 self.thing.try_to_sit()
65 self.thing.invalidate('fov')
66 if self.thing.blocks_light:
67 self.thing.game.record_change(self.thing.position, 'fov')
68 if self.thing.carrying:
69 self.thing.carrying.position = self.thing.position
70 if self.thing.carrying.type_ == 'Crate':
71 for t in self.thing.carrying.content:
72 t.position = self.thing.position
76 class Task_WRITE(Task):
77 argtypes = 'string:char string'
80 if not self.thing.game.can_do_tile_with_pw(*self.thing.position,
82 raise GameError('wrong password for tile')
85 big_yx = self.thing.position[0]
86 little_yx = self.thing.position[1]
87 self.thing.game.maps[big_yx][little_yx] = self.args[0]
88 self.thing.game.record_change((big_yx, little_yx), 'fov')
92 class Task_FLATTEN_SURROUNDINGS(Task):
99 for yxyx in [self.thing.position] + \
100 list(self.thing.game.map_geometry.get_neighbors_yxyx(
101 self.thing.position).values()):
102 if not self.thing.game.can_do_tile_with_pw(*yxyx, self.args[0]):
104 self.thing.game.maps[yxyx[0]][yxyx[1]] = self.thing.game.get_flatland()
105 self.thing.game.record_change(yxyx, 'fov')
109 class Task_PICK_UP(Task):
113 if self.thing.carrying:
114 raise PlayError('already carrying something')
115 to_pick_up = self.thing.game.get_thing(self.args[0])
116 neighbors = self.thing.game.map_geometry.\
117 get_neighbors_yxyx(self.thing.position).values()
118 reach = [self.thing.position] + list(neighbors)
119 if to_pick_up is None:
120 raise PlayError('no such thing exists')
121 elif to_pick_up == self.thing:
122 raise PlayError('cannot pick up oneself')
123 elif to_pick_up.type_ == 'Player':
124 raise PlayError('cannot pick up player')
125 elif to_pick_up.carried:
126 raise PlayError('thing already carried by a player')
127 elif to_pick_up.position not in reach:
128 raise PlayError('thing not in reach')
129 elif not to_pick_up.portable:
130 raise PlayError('thing not portable')
133 to_pick_up = self.thing.game.get_thing(self.args[0])
134 to_pick_up.position = self.thing.position[:]
135 self.thing.carrying = to_pick_up
136 to_pick_up.carried = True
137 for t in [t for t in self.thing.game.things
138 if t.type_ == 'Crate' and to_pick_up in t.content]:
139 t.remove_from_crate(to_pick_up)
140 self.thing.send_msg('CHAT "You take the item out of the crate."')
142 self.thing.game.record_change(self.thing.position, 'other')
146 class Task_DROP(Task):
147 argtypes = 'string:direction+here'
150 if not self.thing.carrying:
151 raise PlayError('nothing to drop')
152 target_position = self._get_move_target()
153 targets = [t for t in self.thing.game.things
154 if t.position == target_position
155 and not t == self.thing.carrying]
156 for target in targets:
157 if target.type_ == 'CookieSpawner' and\
158 not self.thing.carrying.cookable:
159 raise PlayError('cannot cook items of this type')
160 elif target.type_ == 'BottleDeposit':
161 if not self.thing.carrying.type_ == 'Bottle':
162 raise PlayError('cannot only put bottle into bottle deposit')
163 if self.thing.carrying.full:
164 raise PlayError('cannot drop full '
165 'bottle into bottle deposit')
166 elif target.type_ == 'Crate' and\
167 self.thing.carrying.type_ == 'Crate':
168 raise PlayError('cannot put crate into crate')
171 target_position = self._get_move_target()
172 dropped = self.thing.uncarry()
173 dropped.position = target_position
174 if dropped.type_ == 'Crate':
175 for item in dropped.content:
176 item.position = target_position
177 targets = [t for t in self.thing.game.things
178 if t.position == dropped.position and not t == dropped]
179 for target in targets:
180 if target.type_ == 'CookieSpawner':
181 target.accept(dropped)
182 self.thing.game.remove_thing(dropped)
184 elif target.type_ == 'BottleDeposit':
186 self.thing.game.remove_thing(dropped)
188 elif target.type_ == 'Crate':
189 target.accept(dropped)
190 self.thing.send_msg('CHAT "You put the item into the crate."')
192 elif target.type_ == 'HatRemixer':
195 self.thing.game.record_change(self.thing.position, 'other')
199 class Task_DOOR(Task):
202 action_radius = list(self.thing.game.map_geometry.
203 get_neighbors_yxyx(self.thing.position).values())
204 reachable_doors = [t for t in self.thing.game.things if
205 t.type_ == 'Door' and t.position in action_radius]
206 if len(reachable_doors) == 0:
207 raise PlayError('not standing next to a door to open/close')
208 for door in reachable_doors:
209 if not door.blocks_movement:
213 if self.thing.carrying and self.thing.carrying.type_ == 'DoorKey'\
214 and self.thing.carrying.door == door:
216 raise PlayError('cannot open locked door without its key')
219 action_radius = list(self.thing.game.map_geometry.
220 get_neighbors_yxyx(self.thing.position).values())
221 for t in [t for t in self.thing.game.things if
222 t.type_ == 'Door' and t.position in action_radius]:
223 if t.blocks_movement:
227 if self.thing.carrying and\
228 self.thing.carrying.type_ == 'DoorKey' and\
229 self.thing.carrying.door == t:
230 self.thing.send_msg('CHAT "You lock the door."')
232 self.thing.game.record_change(t.position, 'other')
233 self.thing.game.record_change(t.position, 'fov')
237 class Task_INTOXICATE(Task):
240 if self.thing.carrying is None:
241 raise PlayError('carrying nothing to consume')
242 if not self.thing.carrying.consumable:
243 raise PlayError('cannot consume this kind of thing')
244 if self.thing.carrying.type_ == 'Bottle' and\
245 not self.thing.carrying.full:
246 raise PlayError('bottle is empty')
249 if self.thing.carrying.type_ == 'Bottle':
250 self.thing.carrying.full = False
251 self.thing.carrying.empty()
252 self.thing.send_msg('CHAT "You are drunk now."')
253 self.thing.need_for_toilet += 1
254 self.thing.drunk += 100000
255 self.thing.invalidate('fov')
256 self.thing.game.record_change(self.thing.position, 'other')
257 elif self.thing.carrying.type_ == 'Psychedelic':
258 self.thing.tripping += 100000
259 self.thing.send_msg('CHAT "You start tripping."')
260 self.thing.send_msg('RANDOM_COLORS')
261 eaten = self.thing.uncarry()
262 self.thing.game.remove_thing(eaten)
263 elif self.thing.carrying.type_ == 'Cookie':
264 self.thing.send_msg('CHAT ' + quote('You eat a cookie that grants the ability to draw the following character: "%s"' % self.thing.carrying.thing_char))
265 self.thing.add_cookie_char(self.thing.carrying.thing_char)
266 eaten = self.thing.uncarry()
267 self.thing.game.remove_thing(eaten)
268 elif self.thing.carrying.type_ == 'Stimulant':
269 self.thing.send_msg('CHAT "You feel a flash of energy."')
270 self.thing.energy += 50
271 eaten = self.thing.uncarry()
272 self.thing.game.remove_thing(eaten)
276 class Task_COMMAND(Task):
280 if self.thing.carrying is None:
281 raise PlayError('nothing to command')
282 if not self.thing.carrying.commandable:
283 raise PlayError('cannot command this item type')
286 reply_lines = self.thing.carrying.interpret(self.args[0])
287 for line in reply_lines:
288 self.thing.send_msg('REPLY ' + quote(line))
292 class Task_INSTALL(Task):
295 def _get_uninstallables(self):
296 return [t for t in self.thing.game.things
298 and hasattr(t, 'installable') and t.installable
300 and t.position == self.thing.position]
303 if not self.thing.game.can_do_tile_with_pw(*self.thing.position,
305 raise GameError('wrong password for tile')
306 if self.thing.carrying:
307 if not hasattr(self.thing.carrying, 'installable')\
308 or not self.thing.carrying.installable:
309 raise PlayError('carried thing not installable')
310 elif len(self._get_uninstallables()) == 0:
311 raise PlayError('nothing to uninstall here')
314 if self.thing.carrying:
315 t = self.thing.uncarry()
317 self.thing.send_msg('CHAT "You install the thing you carry."')
319 self._get_uninstallables()[0].uninstall()
320 self.thing.send_msg('CHAT "You uninstall the thing here."')
321 self.thing.game.record_change(self.thing.position, 'other')
325 class Task_WEAR(Task):
328 if self.thing.name in self.thing.game.hats:
330 if not self.thing.carrying:
331 raise PlayError('carrying nothing to wear')
332 if self.thing.name in self.thing.game.hats:
333 raise PlayError('already wearing a hat')
334 if self.thing.carrying.type_ not in {'Hat', 'Bottle'}:
335 raise PlayError('can not wear the kind of thing you hold')
338 if self.thing.name in self.thing.game.hats:
339 t = self.thing.game.add_thing('Hat', self.thing.position)
340 t.design = self.thing.game.hats[self.thing.name]
341 del self.thing.game.hats[self.thing.name]
342 self.thing.send_msg('CHAT "You drop your hat."')
343 for remixer in [t for t in self.thing.game.things
344 if t.type_ == 'HatRemixer'
345 and t.position == self.thing.position]:
349 if self.thing.carrying.type_ == 'Bottle':
350 self.thing.send_msg('CHAT "Your attempt to wear a bottle on '
352 self.thing.carrying.sound('BOTTLE', 'SMASH')
353 elif self.thing.carrying.type_ == 'Hat':
354 self.thing.game.hats[self.thing.name] =\
355 self.thing.carrying.design
356 self.thing.send_msg('CHAT "You put on a hat."')
357 dropped = self.thing.uncarry()
358 self.thing.game.remove_thing(dropped)
359 self.thing.game.record_change(self.thing.position, 'other')
363 class Task_SPIN(Task):
366 if not self.thing.carrying:
367 raise PlayError('holding nothing to spin')
368 if not hasattr(self.thing.carrying, 'spinnable'):
369 raise PlayError('held object not spinnable')
372 self.thing.carrying.spin()
373 self.thing.send_msg('CHAT "You spin this object."')
377 class Task_DANCE(Task):
380 self.thing.send_msg('CHAT "You dance."')
381 self.thing.dancing += 10
382 self.thing.game.changed = True