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 if len([d for d in reachable_doors if not d.portable]) == 0:
209 raise PlayError('can only open/close doors that are installed')
210 for door in reachable_doors:
211 if not door.blocks_movement:
215 if self.thing.carrying and self.thing.carrying.type_ == 'DoorKey'\
216 and self.thing.carrying.door == door:
218 raise PlayError('cannot open locked door without its key')
221 action_radius = list(self.thing.game.map_geometry.
222 get_neighbors_yxyx(self.thing.position).values())
223 for t in [t for t in self.thing.game.things if
224 t.type_ == 'Door' and t.position in action_radius]:
225 if t.blocks_movement:
229 if self.thing.carrying and\
230 self.thing.carrying.type_ == 'DoorKey' and\
231 self.thing.carrying.door == t:
232 self.thing.send_msg('CHAT "You lock the door."')
234 self.thing.game.record_change(t.position, 'other')
235 self.thing.game.record_change(t.position, 'fov')
239 class Task_INTOXICATE(Task):
242 if self.thing.carrying is None:
243 raise PlayError('carrying nothing to consume')
244 if not self.thing.carrying.consumable:
245 raise PlayError('cannot consume this kind of thing')
246 if self.thing.carrying.type_ == 'Bottle' and\
247 not self.thing.carrying.full:
248 raise PlayError('bottle is empty')
251 if self.thing.carrying.type_ == 'Bottle':
252 self.thing.carrying.full = False
253 self.thing.carrying.empty()
254 self.thing.send_msg('CHAT "You are drunk now."')
255 self.thing.need_for_toilet += 1
256 self.thing.drunk += 100000
257 self.thing.invalidate('fov')
258 self.thing.game.record_change(self.thing.position, 'other')
259 elif self.thing.carrying.type_ == 'Psychedelic':
260 self.thing.tripping += 100000
261 self.thing.send_msg('CHAT "You start tripping."')
262 self.thing.send_msg('RANDOM_COLORS')
263 eaten = self.thing.uncarry()
264 self.thing.game.remove_thing(eaten)
265 elif self.thing.carrying.type_ == 'Cookie':
266 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))
267 self.thing.add_cookie_char(self.thing.carrying.thing_char)
268 eaten = self.thing.uncarry()
269 self.thing.game.remove_thing(eaten)
270 elif self.thing.carrying.type_ == 'Stimulant':
271 self.thing.send_msg('CHAT "You feel a flash of energy."')
272 self.thing.energy += 50
273 eaten = self.thing.uncarry()
274 self.thing.game.remove_thing(eaten)
278 class Task_COMMAND(Task):
282 if self.thing.carrying is None:
283 raise PlayError('nothing to command')
284 if not self.thing.carrying.commandable:
285 raise PlayError('cannot command this item type')
288 reply_lines = self.thing.carrying.interpret(self.args[0])
289 for line in reply_lines:
290 self.thing.send_msg('REPLY ' + quote(line))
294 class Task_INSTALL(Task):
297 def _get_uninstallables(self):
298 return [t for t in self.thing.game.things
300 and hasattr(t, 'installable') and t.installable
302 and t.position == self.thing.position]
305 if not self.thing.game.can_do_tile_with_pw(*self.thing.position,
307 raise GameError('wrong password for tile')
308 if self.thing.carrying:
309 if not hasattr(self.thing.carrying, 'installable')\
310 or not self.thing.carrying.installable:
311 raise PlayError('carried thing not installable')
312 elif len(self._get_uninstallables()) == 0:
313 raise PlayError('nothing to uninstall here')
316 if self.thing.carrying:
317 t = self.thing.uncarry()
319 self.thing.send_msg('CHAT "You install the thing you carry."')
321 self._get_uninstallables()[0].uninstall()
322 self.thing.send_msg('CHAT "You uninstall the thing here."')
323 self.thing.game.record_change(self.thing.position, 'other')
327 class Task_WEAR(Task):
330 if self.thing.name in self.thing.game.hats:
332 if not self.thing.carrying:
333 raise PlayError('carrying nothing to wear')
334 if self.thing.name in self.thing.game.hats:
335 raise PlayError('already wearing a hat')
336 if self.thing.carrying.type_ not in {'Hat', 'Bottle'}:
337 raise PlayError('can not wear the kind of thing you hold')
340 if self.thing.name in self.thing.game.hats:
341 t = self.thing.game.add_thing('Hat', self.thing.position)
342 t.design = self.thing.game.hats[self.thing.name]
343 del self.thing.game.hats[self.thing.name]
344 self.thing.send_msg('CHAT "You drop your hat."')
345 for remixer in [t for t in self.thing.game.things
346 if t.type_ == 'HatRemixer'
347 and t.position == self.thing.position]:
351 if self.thing.carrying.type_ == 'Bottle':
352 self.thing.send_msg('CHAT "Your attempt to wear a bottle on '
354 self.thing.carrying.sound('BOTTLE', 'SMASH')
355 elif self.thing.carrying.type_ == 'Hat':
356 self.thing.game.hats[self.thing.name] =\
357 self.thing.carrying.design
358 self.thing.send_msg('CHAT "You put on a hat."')
359 dropped = self.thing.uncarry()
360 self.thing.game.remove_thing(dropped)
361 self.thing.game.record_change(self.thing.position, 'other')
365 class Task_SPIN(Task):
368 if not self.thing.carrying:
369 raise PlayError('holding nothing to spin')
370 if not hasattr(self.thing.carrying, 'spinnable'):
371 raise PlayError('held object not spinnable')
374 self.thing.carrying.spin()
375 self.thing.send_msg('CHAT "You spin this object."')
379 class Task_DANCE(Task):
382 self.thing.send_msg('CHAT "You dance."')
383 self.thing.dancing += 10
384 self.thing.game.changed = True