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 self.thing.game.record_change(self.thing.position, 'other')
46 if self.thing.blocks_light:
47 self.thing.game.record_change(self.thing.position, 'fov')
48 self.thing.position = self._get_move_target()
49 self.thing.game.record_change(self.thing.position, 'other')
50 if self.thing.blocks_light:
51 self.thing.game.record_change(self.thing.position, 'fov')
52 if self.thing.carrying:
53 self.thing.carrying.position = self.thing.position
57 class Task_WRITE(Task):
58 argtypes = 'string:char string'
61 if not self.thing.game.can_do_tile_with_pw(*self.thing.position,
63 raise GameError('wrong password for tile')
66 big_yx = self.thing.position[0]
67 little_yx = self.thing.position[1]
68 self.thing.game.maps[big_yx][little_yx] = self.args[0]
69 self.thing.game.record_change((big_yx, little_yx), 'fov')
73 class Task_FLATTEN_SURROUNDINGS(Task):
80 for yxyx in [self.thing.position] + \
81 list(self.thing.game.map_geometry.get_neighbors_yxyx(
82 self.thing.position).values()):
83 if not self.thing.game.can_do_tile_with_pw(*yxyx, self.args[0]):
85 self.thing.game.maps[yxyx[0]][yxyx[1]] = self.thing.game.get_flatland()
86 self.thing.game.record_change(yxyx, 'fov')
90 class Task_PICK_UP(Task):
94 if self.thing.carrying:
95 raise PlayError('already carrying something')
96 to_pick_up = self.thing.game.get_thing(self.args[0])
97 neighbors = self.thing.game.map_geometry.\
98 get_neighbors_yxyx(self.thing.position).values()
99 reach = [self.thing.position] + list(neighbors)
100 if to_pick_up is None:
101 raise PlayError('no such thing exists')
102 elif to_pick_up == self.thing:
103 raise PlayError('cannot pick up oneself')
104 elif to_pick_up.type_ == 'Player':
105 raise PlayError('cannot pick up player')
106 elif to_pick_up.carried:
107 raise PlayError('thing already carried by a player')
108 elif to_pick_up.position not in reach:
109 raise PlayError('thing not in reach')
110 elif not to_pick_up.portable:
111 raise PlayError('thing not portable')
114 to_pick_up = self.thing.game.get_thing(self.args[0])
115 to_pick_up.position = self.thing.position[:]
116 self.thing.carrying = to_pick_up
117 to_pick_up.carried = True
118 self.thing.game.record_change(self.thing.position, 'other')
122 class Task_DROP(Task):
123 argtypes = 'string:direction+here'
126 if not self.thing.carrying:
127 raise PlayError('nothing to drop')
128 target_position = self._get_move_target()
129 if self.thing.carrying.type_ == 'Bottle' and self.thing.carrying.full:
130 for t in [t for t in self.thing.game.things
131 if t.type_ == 'BottleDeposit'
132 and t.position == target_position]:
133 raise PlayError('cannot drop full bottle into bottle deposit')
136 target_position = self._get_move_target()
137 dropped = self.thing.uncarry()
138 dropped.position = target_position
139 over_cookie_spawner = None
140 for t in [t for t in self.thing.game.things
141 if t.type_ == 'CookieSpawner'
142 and t.position == dropped.position]:
143 over_cookie_spawner = t
145 if over_cookie_spawner:
146 over_cookie_spawner.accept(dropped)
147 self.thing.game.remove_thing(dropped)
148 elif dropped.type_ == 'Bottle' and not dropped.full:
149 for t in [t for t in self.thing.game.things
150 if t.type_ == 'BottleDeposit'
151 and t.position == dropped.position]:
153 self.thing.game.remove_thing(dropped)
155 elif dropped.type_ == 'Hat':
156 for t in [t for t in self.thing.game.things
157 if t.type_ == 'HatRemixer'
158 and t.position == dropped.position]:
161 self.thing.game.record_change(self.thing.position, 'other')
165 class Task_DOOR(Task):
168 action_radius = list(self.thing.game.map_geometry.
169 get_neighbors_yxyx(self.thing.position).values())
170 for t in [t for t in self.thing.game.things if
171 t.type_ == 'Door' and t.position in action_radius]:
172 if t.blocks_movement:
176 self.thing.game.record_change(t.position, 'other')
177 self.thing.game.record_change(t.position, 'fov')
181 class Task_INTOXICATE(Task):
184 if self.thing.carrying is None:
185 raise PlayError('carrying nothing to drink from')
186 if self.thing.carrying.type_ not in {'Bottle', 'Cookie'}:
187 raise PlayError('cannot consume this kind of thing')
188 if self.thing.carrying.type_ == 'Bottle' and\
189 not self.thing.carrying.full:
190 raise PlayError('bottle is empty')
193 if self.thing.carrying.type_ == 'Bottle':
194 self.thing.carrying.full = False
195 self.thing.carrying.empty()
196 self.thing.send_msg('RANDOM_COLORS')
197 self.thing.send_msg('CHAT "You are drunk now."')
198 self.thing.drunk = 10000
199 self.thing.invalidate('fov')
200 self.thing.game.record_change(self.thing.position, 'other')
201 elif self.thing.carrying.type_ == 'Cookie':
202 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))
203 self.thing.add_cookie_char(self.thing.carrying.thing_char)
204 eaten = self.thing.uncarry()
205 self.thing.game.remove_thing(eaten)
209 class Task_COMMAND(Task):
213 if self.thing.carrying is None:
214 raise PlayError('nothing to command')
215 if not self.thing.carrying.commandable:
216 raise PlayError('cannot command this item type')
219 reply_lines = self.thing.carrying.interpret(self.args[0])
220 for line in reply_lines:
221 self.thing.send_msg('REPLY ' + quote(line))
225 class Task_INSTALL(Task):
228 def _get_uninstallables(self):
229 return [t for t in self.thing.game.things
231 and hasattr(t, 'installable') and t.installable
233 and t.position == self.thing.position]
236 if not self.thing.game.can_do_tile_with_pw(*self.thing.position,
238 raise GameError('wrong password for tile')
239 if self.thing.carrying:
240 if not hasattr(self.thing.carrying, 'installable')\
241 or not self.thing.carrying.installable:
242 raise PlayError('carried thing not installable')
243 elif len(self._get_uninstallables()) == 0:
244 raise PlayError('nothing to uninstall here')
247 if self.thing.carrying:
248 t = self.thing.uncarry()
250 self.thing.send_msg('CHAT "You install the thing you carry."')
252 self._get_uninstallables()[0].uninstall()
253 self.thing.send_msg('CHAT "You uninstall the thing here."')
254 self.thing.game.record_change(self.thing.position, 'other')
258 class Task_WEAR(Task):
261 if self.thing.name in self.thing.game.hats:
263 if not self.thing.carrying:
264 raise PlayError('carrying nothing to wear')
265 if self.thing.name in self.thing.game.hats:
266 raise PlayError('already wearing a hat')
267 if self.thing.carrying.type_ not in {'Hat', 'Bottle'}:
268 raise PlayError('can not wear the kind of thing you hold')
271 if self.thing.name in self.thing.game.hats:
272 t = self.thing.game.add_thing('Hat', self.thing.position)
273 t.design = self.thing.game.hats[self.thing.name]
274 del self.thing.game.hats[self.thing.name]
275 self.thing.send_msg('CHAT "You drop your hat."')
276 for remixer in [t for t in self.thing.game.things
277 if t.type_ == 'HatRemixer'
278 and t.position == self.thing.position]:
282 if self.thing.carrying.type_ == 'Bottle':
283 self.thing.send_msg('CHAT "Your attempt to wear a bottle on '
285 self.thing.carrying.sound('BOTTLE', 'SMASH')
286 elif self.thing.carrying.type_ == 'Hat':
287 self.thing.game.hats[self.thing.name] =\
288 self.thing.carrying.design
289 self.thing.send_msg('CHAT "You put on a hat."')
290 dropped = self.thing.uncarry()
291 self.thing.game.remove_thing(dropped)
292 self.thing.game.record_change(self.thing.position, 'other')
296 class Task_SPIN(Task):
299 if not self.thing.carrying:
300 raise PlayError('holding nothing to spin')
301 if not hasattr(self.thing.carrying, 'spinnable'):
302 raise PlayError('held object not spinnable')
305 self.thing.carrying.spin()
306 self.thing.send_msg('CHAT "You spin this object."')