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 self.thing.invalidate('fov')
51 if self.thing.blocks_light:
52 self.thing.game.record_change(self.thing.position, 'fov')
53 if self.thing.carrying:
54 self.thing.carrying.position = self.thing.position
58 class Task_WRITE(Task):
59 argtypes = 'string:char string'
62 if not self.thing.game.can_do_tile_with_pw(*self.thing.position,
64 raise GameError('wrong password for tile')
67 big_yx = self.thing.position[0]
68 little_yx = self.thing.position[1]
69 self.thing.game.maps[big_yx][little_yx] = self.args[0]
70 self.thing.game.record_change((big_yx, little_yx), 'fov')
74 class Task_FLATTEN_SURROUNDINGS(Task):
81 for yxyx in [self.thing.position] + \
82 list(self.thing.game.map_geometry.get_neighbors_yxyx(
83 self.thing.position).values()):
84 if not self.thing.game.can_do_tile_with_pw(*yxyx, self.args[0]):
86 self.thing.game.maps[yxyx[0]][yxyx[1]] = self.thing.game.get_flatland()
87 self.thing.game.record_change(yxyx, 'fov')
91 class Task_PICK_UP(Task):
95 if self.thing.carrying:
96 raise PlayError('already carrying something')
97 to_pick_up = self.thing.game.get_thing(self.args[0])
98 neighbors = self.thing.game.map_geometry.\
99 get_neighbors_yxyx(self.thing.position).values()
100 reach = [self.thing.position] + list(neighbors)
101 if to_pick_up is None:
102 raise PlayError('no such thing exists')
103 elif to_pick_up == self.thing:
104 raise PlayError('cannot pick up oneself')
105 elif to_pick_up.type_ == 'Player':
106 raise PlayError('cannot pick up player')
107 elif to_pick_up.carried:
108 raise PlayError('thing already carried by a player')
109 elif to_pick_up.position not in reach:
110 raise PlayError('thing not in reach')
111 elif not to_pick_up.portable:
112 raise PlayError('thing not portable')
115 to_pick_up = self.thing.game.get_thing(self.args[0])
116 to_pick_up.position = self.thing.position[:]
117 self.thing.carrying = to_pick_up
118 to_pick_up.carried = True
119 self.thing.game.record_change(self.thing.position, 'other')
123 class Task_DROP(Task):
124 argtypes = 'string:direction+here'
127 if not self.thing.carrying:
128 raise PlayError('nothing to drop')
129 target_position = self._get_move_target()
130 if self.thing.carrying.type_ == 'Bottle' and self.thing.carrying.full:
131 for t in [t for t in self.thing.game.things
132 if t.type_ == 'BottleDeposit'
133 and t.position == target_position]:
134 raise PlayError('cannot drop full bottle into bottle deposit')
137 target_position = self._get_move_target()
138 dropped = self.thing.uncarry()
139 dropped.position = target_position
140 over_cookie_spawner = None
141 for t in [t for t in self.thing.game.things
142 if t.type_ == 'CookieSpawner'
143 and t.position == dropped.position]:
144 over_cookie_spawner = t
146 if over_cookie_spawner:
147 over_cookie_spawner.accept(dropped)
148 self.thing.game.remove_thing(dropped)
149 elif dropped.type_ == 'Bottle' and not dropped.full:
150 for t in [t for t in self.thing.game.things
151 if t.type_ == 'BottleDeposit'
152 and t.position == dropped.position]:
154 self.thing.game.remove_thing(dropped)
156 elif dropped.type_ == 'Hat':
157 for t in [t for t in self.thing.game.things
158 if t.type_ == 'HatRemixer'
159 and t.position == dropped.position]:
162 self.thing.game.record_change(self.thing.position, 'other')
166 class Task_DOOR(Task):
169 action_radius = list(self.thing.game.map_geometry.
170 get_neighbors_yxyx(self.thing.position).values())
171 for t in [t for t in self.thing.game.things if
172 t.type_ == 'Door' and t.position in action_radius]:
173 if t.blocks_movement:
177 self.thing.game.record_change(t.position, 'other')
178 self.thing.game.record_change(t.position, 'fov')
182 class Task_INTOXICATE(Task):
185 if self.thing.carrying is None:
186 raise PlayError('carrying nothing to consume')
187 if self.thing.carrying.type_ not in {'Bottle', 'Cookie', 'Psychedelic'}:
188 raise PlayError('cannot consume this kind of thing')
189 if self.thing.carrying.type_ == 'Bottle' and\
190 not self.thing.carrying.full:
191 raise PlayError('bottle is empty')
194 if self.thing.carrying.type_ == 'Bottle':
195 self.thing.carrying.full = False
196 self.thing.carrying.empty()
197 self.thing.send_msg('CHAT "You are drunk now."')
198 self.thing.need_for_toilet += 10000
199 self.thing.drunk = 10000
200 self.thing.invalidate('fov')
201 self.thing.game.record_change(self.thing.position, 'other')
202 elif self.thing.carrying.type_ == 'Psychedelic':
203 self.thing.tripping = 10000
204 self.thing.send_msg('CHAT "You start tripping."')
205 self.thing.send_msg('RANDOM_COLORS')
206 eaten = self.thing.uncarry()
207 self.thing.game.remove_thing(eaten)
208 elif self.thing.carrying.type_ == 'Cookie':
209 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))
210 self.thing.add_cookie_char(self.thing.carrying.thing_char)
211 eaten = self.thing.uncarry()
212 self.thing.game.remove_thing(eaten)
216 class Task_COMMAND(Task):
220 if self.thing.carrying is None:
221 raise PlayError('nothing to command')
222 if not self.thing.carrying.commandable:
223 raise PlayError('cannot command this item type')
226 reply_lines = self.thing.carrying.interpret(self.args[0])
227 for line in reply_lines:
228 self.thing.send_msg('REPLY ' + quote(line))
232 class Task_INSTALL(Task):
235 def _get_uninstallables(self):
236 return [t for t in self.thing.game.things
238 and hasattr(t, 'installable') and t.installable
240 and t.position == self.thing.position]
243 if not self.thing.game.can_do_tile_with_pw(*self.thing.position,
245 raise GameError('wrong password for tile')
246 if self.thing.carrying:
247 if not hasattr(self.thing.carrying, 'installable')\
248 or not self.thing.carrying.installable:
249 raise PlayError('carried thing not installable')
250 elif len(self._get_uninstallables()) == 0:
251 raise PlayError('nothing to uninstall here')
254 if self.thing.carrying:
255 t = self.thing.uncarry()
257 self.thing.send_msg('CHAT "You install the thing you carry."')
259 self._get_uninstallables()[0].uninstall()
260 self.thing.send_msg('CHAT "You uninstall the thing here."')
261 self.thing.game.record_change(self.thing.position, 'other')
265 class Task_WEAR(Task):
268 if self.thing.name in self.thing.game.hats:
270 if not self.thing.carrying:
271 raise PlayError('carrying nothing to wear')
272 if self.thing.name in self.thing.game.hats:
273 raise PlayError('already wearing a hat')
274 if self.thing.carrying.type_ not in {'Hat', 'Bottle'}:
275 raise PlayError('can not wear the kind of thing you hold')
278 if self.thing.name in self.thing.game.hats:
279 t = self.thing.game.add_thing('Hat', self.thing.position)
280 t.design = self.thing.game.hats[self.thing.name]
281 del self.thing.game.hats[self.thing.name]
282 self.thing.send_msg('CHAT "You drop your hat."')
283 for remixer in [t for t in self.thing.game.things
284 if t.type_ == 'HatRemixer'
285 and t.position == self.thing.position]:
289 if self.thing.carrying.type_ == 'Bottle':
290 self.thing.send_msg('CHAT "Your attempt to wear a bottle on '
292 self.thing.carrying.sound('BOTTLE', 'SMASH')
293 elif self.thing.carrying.type_ == 'Hat':
294 self.thing.game.hats[self.thing.name] =\
295 self.thing.carrying.design
296 self.thing.send_msg('CHAT "You put on a hat."')
297 dropped = self.thing.uncarry()
298 self.thing.game.remove_thing(dropped)
299 self.thing.game.record_change(self.thing.position, 'other')
303 class Task_SPIN(Task):
306 if not self.thing.carrying:
307 raise PlayError('holding nothing to spin')
308 if not hasattr(self.thing.carrying, 'spinnable'):
309 raise PlayError('held object not spinnable')
312 self.thing.carrying.spin()
313 self.thing.send_msg('CHAT "You spin this object."')