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
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_fov_change(self.thing.position)
46 self.thing.position = self._get_move_target()
47 self.thing.game.record_fov_change(self.thing.position)
48 if self.thing.carrying:
49 self.thing.carrying.position = self.thing.position
53 class Task_WRITE(Task):
54 argtypes = 'string:char string'
57 if not self.thing.game.can_do_tile_with_pw(*self.thing.position,
59 raise GameError('wrong password for tile')
62 big_yx = self.thing.position[0]
63 little_yx = self.thing.position[1]
64 self.thing.game.maps[big_yx][little_yx] = self.args[0]
65 self.thing.game.record_fov_change((big_yx, little_yx))
69 class Task_FLATTEN_SURROUNDINGS(Task):
76 for yxyx in [self.thing.position] + \
77 list(self.thing.game.map_geometry.get_neighbors_yxyx(
78 self.thing.position).values()):
79 if not self.thing.game.can_do_tile_with_pw(*yxyx, self.args[0]):
81 self.thing.game.maps[yxyx[0]][yxyx[1]] = self.thing.game.get_flatland()
82 self.thing.game.record_fov_change(yxyx)
86 class Task_PICK_UP(Task):
90 if self.thing.carrying:
91 raise PlayError('already carrying something')
92 to_pick_up = self.thing.game.get_thing(self.args[0])
93 neighbors = self.thing.game.map_geometry.\
94 get_neighbors_yxyx(self.thing.position).values()
95 reach = [self.thing.position] + list(neighbors)
96 if to_pick_up is None:
97 raise PlayError('no such thing exists')
98 elif to_pick_up == self.thing:
99 raise PlayError('cannot pick up oneself')
100 elif to_pick_up.type_ == 'Player':
101 raise PlayError('cannot pick up player')
102 elif to_pick_up.carried:
103 raise PlayError('thing already carried by a player')
104 elif to_pick_up.position not in reach:
105 raise PlayError('thing not in reach')
106 elif not to_pick_up.portable:
107 raise PlayError('thing not portable')
110 to_pick_up = self.thing.game.get_thing(self.args[0])
111 to_pick_up.position = self.thing.position[:]
112 self.thing.carrying = to_pick_up
113 to_pick_up.carried = True
114 # FIXME: pseudo-FOV-change actually
115 self.thing.game.record_fov_change(self.thing.position)
119 class Task_DROP(Task):
120 argtypes = 'string:direction+here'
123 if not self.thing.carrying:
124 raise PlayError('nothing to drop')
125 target_position = self._get_move_target()
126 if self.thing.carrying.type_ == 'Bottle' and self.thing.carrying.full:
127 for t in [t for t in self.thing.game.things
128 if t.type_ == 'BottleDeposit'
129 and t.position == target_position]:
130 raise PlayError('cannot drop full bottle into bottle deposit')
133 target_position = self._get_move_target()
134 dropped = self.thing.uncarry()
135 dropped.position = target_position
136 over_cookie_spawner = None
137 for t in [t for t in self.thing.game.things
138 if t.type_ == 'CookieSpawner'
139 and t.position == dropped.position]:
140 over_cookie_spawner = t
142 if over_cookie_spawner:
143 over_cookie_spawner.accept(dropped)
144 self.thing.game.remove_thing(dropped)
145 elif dropped.type_ == 'Bottle' and not dropped.full:
146 for t in [t for t in self.thing.game.things
147 if t.type_ == 'BottleDeposit'
148 and t.position == dropped.position]:
150 self.thing.game.remove_thing(dropped)
152 elif dropped.type_ == 'Hat':
153 for t in [t for t in self.thing.game.things
154 if t.type_ == 'HatRemixer'
155 and t.position == dropped.position]:
158 # FIXME: pseudo-FOV-change actually
159 self.thing.game.record_fov_change(self.thing.position)
163 class Task_DOOR(Task):
166 action_radius = list(self.thing.game.map_geometry.
167 get_neighbors_yxyx(self.thing.position).values())
168 for t in [t for t in self.thing.game.things if
169 t.type_ == 'Door' and t.position in action_radius]:
174 self.thing.game.record_fov_change(t.position)
178 class Task_INTOXICATE(Task):
181 if self.thing.carrying is None:
182 raise PlayError('carrying nothing to drink from')
183 if self.thing.carrying.type_ not in {'Bottle', 'Cookie'}:
184 raise PlayError('cannot consume this kind of thing')
185 if self.thing.carrying.type_ == 'Bottle' and\
186 not self.thing.carrying.full:
187 raise PlayError('bottle is empty')
190 if self.thing.carrying.type_ == 'Bottle':
191 self.thing.carrying.full = False
192 self.thing.carrying.empty()
193 self.thing.send_msg('RANDOM_COLORS')
194 self.thing.send_msg('CHAT "You are drunk now."')
195 self.thing.drunk = 10000
196 # FIXME: pseudo-FOV-change actually
197 self.thing.game.record_fov_change(self.thing.position)
198 elif self.thing.carrying.type_ == 'Cookie':
199 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))
200 self.thing.add_cookie_char(self.thing.carrying.thing_char)
201 eaten = self.thing.uncarry()
202 self.thing.game.remove_thing(eaten)
206 class Task_COMMAND(Task):
210 if self.thing.carrying is None:
211 raise PlayError('nothing to command')
212 if not self.thing.carrying.commandable:
213 raise PlayError('cannot command this item type')
216 reply_lines = self.thing.carrying.interpret(self.args[0])
217 for line in reply_lines:
218 self.thing.send_msg('REPLY ' + quote(line))
222 class Task_INSTALL(Task):
225 def _get_uninstallables(self):
226 return [t for t in self.thing.game.things
228 and hasattr(t, 'installable') and t.installable
230 and t.position == self.thing.position]
233 if not self.thing.game.can_do_tile_with_pw(*self.thing.position,
235 raise GameError('wrong password for tile')
236 if self.thing.carrying:
237 if not hasattr(self.thing.carrying, 'installable')\
238 or not self.thing.carrying.installable:
239 raise PlayError('carried thing not installable')
240 elif len(self._get_uninstallables()) == 0:
241 raise PlayError('nothing to uninstall here')
244 if self.thing.carrying:
245 t = self.thing.uncarry()
247 self.thing.send_msg('CHAT "You install the thing you carry."')
249 self._get_uninstallables()[0].uninstall()
250 self.thing.send_msg('CHAT "You uninstall the thing here."')
251 # FIXME: pseudo-FOV-change actually
252 self.thing.game.record_fov_change(self.thing.position)
256 class Task_WEAR(Task):
259 if self.thing.name in self.thing.game.hats:
261 if not self.thing.carrying:
262 raise PlayError('carrying nothing to wear')
263 if self.thing.name in self.thing.game.hats:
264 raise PlayError('already wearing a hat')
265 if self.thing.carrying.type_ not in {'Hat', 'Bottle'}:
266 raise PlayError('can not wear the kind of thing you hold')
269 if self.thing.name in self.thing.game.hats:
270 t = self.thing.game.add_thing('Hat', self.thing.position)
271 t.design = self.thing.game.hats[self.thing.name]
272 del self.thing.game.hats[self.thing.name]
273 self.thing.send_msg('CHAT "You drop your hat."')
274 for remixer in [t for t in self.thing.game.things
275 if t.type_ == 'HatRemixer'
276 and t.position == self.thing.position]:
280 if self.thing.carrying.type_ == 'Bottle':
281 self.thing.send_msg('CHAT "Your attempt to wear a bottle on '
283 self.thing.carrying.sound('BOTTLE', 'SMASH')
284 elif self.thing.carrying.type_ == 'Hat':
285 self.thing.game.hats[self.thing.name] =\
286 self.thing.carrying.design
287 self.thing.send_msg('CHAT "You put on a hat."')
288 dropped = self.uncarry()
289 self.thing.game.remove_thing(dropped)
290 # FIXME: pseudo-FOV-change actually
291 self.thing.game.record_fov_change(self.thing.position)
295 class Task_SPIN(Task):
298 if not self.thing.carrying:
299 raise PlayError('holding nothing to spin')
300 if not hasattr(self.thing.carrying, 'spinnable'):
301 raise PlayError('held object not spinnable')
304 self.thing.carrying.spin()
305 self.thing.send_msg('CHAT "You spin this object."')