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 self.thing.game.record_change(self.thing.position, 'other')
54 self.thing.game.maps[self.thing.position[0]][self.thing.position[1]]
55 if terrain in self.thing.game.terrains:
56 terrain_type = self.thing.game.terrains[terrain]
57 if 'sittable' in terrain_type.tags:
58 self.thing.standing = False
59 self.thing.send_msg('CHAT "You sink into the %s."'
60 % terrain_type.description)
61 self.thing.invalidate('fov')
62 if self.thing.blocks_light:
63 self.thing.game.record_change(self.thing.position, 'fov')
64 if self.thing.carrying:
65 self.thing.carrying.position = self.thing.position
69 class Task_WRITE(Task):
70 argtypes = 'string:char string'
73 if not self.thing.game.can_do_tile_with_pw(*self.thing.position,
75 raise GameError('wrong password for tile')
78 big_yx = self.thing.position[0]
79 little_yx = self.thing.position[1]
80 self.thing.game.maps[big_yx][little_yx] = self.args[0]
81 self.thing.game.record_change((big_yx, little_yx), 'fov')
85 class Task_FLATTEN_SURROUNDINGS(Task):
92 for yxyx in [self.thing.position] + \
93 list(self.thing.game.map_geometry.get_neighbors_yxyx(
94 self.thing.position).values()):
95 if not self.thing.game.can_do_tile_with_pw(*yxyx, self.args[0]):
97 self.thing.game.maps[yxyx[0]][yxyx[1]] = self.thing.game.get_flatland()
98 self.thing.game.record_change(yxyx, 'fov')
102 class Task_PICK_UP(Task):
106 if self.thing.carrying:
107 raise PlayError('already carrying something')
108 to_pick_up = self.thing.game.get_thing(self.args[0])
109 neighbors = self.thing.game.map_geometry.\
110 get_neighbors_yxyx(self.thing.position).values()
111 reach = [self.thing.position] + list(neighbors)
112 if to_pick_up is None:
113 raise PlayError('no such thing exists')
114 elif to_pick_up == self.thing:
115 raise PlayError('cannot pick up oneself')
116 elif to_pick_up.type_ == 'Player':
117 raise PlayError('cannot pick up player')
118 elif to_pick_up.carried:
119 raise PlayError('thing already carried by a player')
120 elif to_pick_up.position not in reach:
121 raise PlayError('thing not in reach')
122 elif not to_pick_up.portable:
123 raise PlayError('thing not portable')
126 to_pick_up = self.thing.game.get_thing(self.args[0])
127 to_pick_up.position = self.thing.position[:]
128 self.thing.carrying = to_pick_up
129 to_pick_up.carried = True
130 self.thing.game.record_change(self.thing.position, 'other')
134 class Task_DROP(Task):
135 argtypes = 'string:direction+here'
138 if not self.thing.carrying:
139 raise PlayError('nothing to drop')
140 target_position = self._get_move_target()
141 if self.thing.carrying.type_ == 'Bottle' and self.thing.carrying.full:
142 for t in [t for t in self.thing.game.things
143 if t.type_ == 'BottleDeposit'
144 and t.position == target_position]:
145 raise PlayError('cannot drop full bottle into bottle deposit')
148 target_position = self._get_move_target()
149 dropped = self.thing.uncarry()
150 dropped.position = target_position
151 over_cookie_spawner = None
152 for t in [t for t in self.thing.game.things
153 if t.type_ == 'CookieSpawner'
154 and t.position == dropped.position]:
155 over_cookie_spawner = t
157 if over_cookie_spawner:
158 over_cookie_spawner.accept(dropped)
159 self.thing.game.remove_thing(dropped)
160 elif dropped.type_ == 'Bottle' and not dropped.full:
161 for t in [t for t in self.thing.game.things
162 if t.type_ == 'BottleDeposit'
163 and t.position == dropped.position]:
165 self.thing.game.remove_thing(dropped)
167 elif dropped.type_ == 'Hat':
168 for t in [t for t in self.thing.game.things
169 if t.type_ == 'HatRemixer'
170 and t.position == dropped.position]:
173 self.thing.game.record_change(self.thing.position, 'other')
177 class Task_DOOR(Task):
180 action_radius = list(self.thing.game.map_geometry.
181 get_neighbors_yxyx(self.thing.position).values())
182 for t in [t for t in self.thing.game.things if
183 t.type_ == 'Door' and t.position in action_radius]:
184 if t.blocks_movement:
188 self.thing.game.record_change(t.position, 'other')
189 self.thing.game.record_change(t.position, 'fov')
193 class Task_INTOXICATE(Task):
196 if self.thing.carrying is None:
197 raise PlayError('carrying nothing to consume')
198 if self.thing.carrying.type_ not in {'Bottle', 'Cookie', 'Psychedelic'}:
199 raise PlayError('cannot consume this kind of thing')
200 if self.thing.carrying.type_ == 'Bottle' and\
201 not self.thing.carrying.full:
202 raise PlayError('bottle is empty')
205 if self.thing.carrying.type_ == 'Bottle':
206 self.thing.carrying.full = False
207 self.thing.carrying.empty()
208 self.thing.send_msg('CHAT "You are drunk now."')
209 self.thing.need_for_toilet += 10000
210 self.thing.drunk = 10000
211 self.thing.invalidate('fov')
212 self.thing.game.record_change(self.thing.position, 'other')
213 elif self.thing.carrying.type_ == 'Psychedelic':
214 self.thing.tripping = 10000
215 self.thing.send_msg('CHAT "You start tripping."')
216 self.thing.send_msg('RANDOM_COLORS')
217 eaten = self.thing.uncarry()
218 self.thing.game.remove_thing(eaten)
219 elif self.thing.carrying.type_ == 'Cookie':
220 self.thing.send_msg('CHAT ' + quote('You eat a cookie and gain the ability to draw the following character: "%s"' % self.thing.carrying.thing_char))
221 self.thing.add_cookie_char(self.thing.carrying.thing_char)
222 eaten = self.thing.uncarry()
223 self.thing.game.remove_thing(eaten)
227 class Task_COMMAND(Task):
231 if self.thing.carrying is None:
232 raise PlayError('nothing to command')
233 if not self.thing.carrying.commandable:
234 raise PlayError('cannot command this item type')
237 reply_lines = self.thing.carrying.interpret(self.args[0])
238 for line in reply_lines:
239 self.thing.send_msg('REPLY ' + quote(line))
243 class Task_INSTALL(Task):
246 def _get_uninstallables(self):
247 return [t for t in self.thing.game.things
249 and hasattr(t, 'installable') and t.installable
251 and t.position == self.thing.position]
254 if not self.thing.game.can_do_tile_with_pw(*self.thing.position,
256 raise GameError('wrong password for tile')
257 if self.thing.carrying:
258 if not hasattr(self.thing.carrying, 'installable')\
259 or not self.thing.carrying.installable:
260 raise PlayError('carried thing not installable')
261 elif len(self._get_uninstallables()) == 0:
262 raise PlayError('nothing to uninstall here')
265 if self.thing.carrying:
266 t = self.thing.uncarry()
268 self.thing.send_msg('CHAT "You install the thing you carry."')
270 self._get_uninstallables()[0].uninstall()
271 self.thing.send_msg('CHAT "You uninstall the thing here."')
272 self.thing.game.record_change(self.thing.position, 'other')
276 class Task_WEAR(Task):
279 if self.thing.name in self.thing.game.hats:
281 if not self.thing.carrying:
282 raise PlayError('carrying nothing to wear')
283 if self.thing.name in self.thing.game.hats:
284 raise PlayError('already wearing a hat')
285 if self.thing.carrying.type_ not in {'Hat', 'Bottle'}:
286 raise PlayError('can not wear the kind of thing you hold')
289 if self.thing.name in self.thing.game.hats:
290 t = self.thing.game.add_thing('Hat', self.thing.position)
291 t.design = self.thing.game.hats[self.thing.name]
292 del self.thing.game.hats[self.thing.name]
293 self.thing.send_msg('CHAT "You drop your hat."')
294 for remixer in [t for t in self.thing.game.things
295 if t.type_ == 'HatRemixer'
296 and t.position == self.thing.position]:
300 if self.thing.carrying.type_ == 'Bottle':
301 self.thing.send_msg('CHAT "Your attempt to wear a bottle on '
303 self.thing.carrying.sound('BOTTLE', 'SMASH')
304 elif self.thing.carrying.type_ == 'Hat':
305 self.thing.game.hats[self.thing.name] =\
306 self.thing.carrying.design
307 self.thing.send_msg('CHAT "You put on a hat."')
308 dropped = self.thing.uncarry()
309 self.thing.game.remove_thing(dropped)
310 self.thing.game.record_change(self.thing.position, 'other')
314 class Task_SPIN(Task):
317 if not self.thing.carrying:
318 raise PlayError('holding nothing to spin')
319 if not hasattr(self.thing.carrying, 'spinnable'):
320 raise PlayError('held object not spinnable')
323 self.thing.carrying.spin()
324 self.thing.send_msg('CHAT "You spin this object."')