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 *= 2
199 self.thing.need_for_toilet += 1
200 self.thing.drunk = 10000
201 self.thing.invalidate('fov')
202 self.thing.game.record_change(self.thing.position, 'other')
203 elif self.thing.carrying.type_ == 'Psychedelic':
204 self.thing.tripping = 10000
205 self.thing.send_msg('CHAT "You start tripping."')
206 self.thing.send_msg('RANDOM_COLORS')
207 eaten = self.thing.uncarry()
208 self.thing.game.remove_thing(eaten)
209 elif self.thing.carrying.type_ == 'Cookie':
210 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))
211 self.thing.add_cookie_char(self.thing.carrying.thing_char)
212 eaten = self.thing.uncarry()
213 self.thing.game.remove_thing(eaten)
217 class Task_COMMAND(Task):
221 if self.thing.carrying is None:
222 raise PlayError('nothing to command')
223 if not self.thing.carrying.commandable:
224 raise PlayError('cannot command this item type')
227 reply_lines = self.thing.carrying.interpret(self.args[0])
228 for line in reply_lines:
229 self.thing.send_msg('REPLY ' + quote(line))
233 class Task_INSTALL(Task):
236 def _get_uninstallables(self):
237 return [t for t in self.thing.game.things
239 and hasattr(t, 'installable') and t.installable
241 and t.position == self.thing.position]
244 if not self.thing.game.can_do_tile_with_pw(*self.thing.position,
246 raise GameError('wrong password for tile')
247 if self.thing.carrying:
248 if not hasattr(self.thing.carrying, 'installable')\
249 or not self.thing.carrying.installable:
250 raise PlayError('carried thing not installable')
251 elif len(self._get_uninstallables()) == 0:
252 raise PlayError('nothing to uninstall here')
255 if self.thing.carrying:
256 t = self.thing.uncarry()
258 self.thing.send_msg('CHAT "You install the thing you carry."')
260 self._get_uninstallables()[0].uninstall()
261 self.thing.send_msg('CHAT "You uninstall the thing here."')
262 self.thing.game.record_change(self.thing.position, 'other')
266 class Task_WEAR(Task):
269 if self.thing.name in self.thing.game.hats:
271 if not self.thing.carrying:
272 raise PlayError('carrying nothing to wear')
273 if self.thing.name in self.thing.game.hats:
274 raise PlayError('already wearing a hat')
275 if self.thing.carrying.type_ not in {'Hat', 'Bottle'}:
276 raise PlayError('can not wear the kind of thing you hold')
279 if self.thing.name in self.thing.game.hats:
280 t = self.thing.game.add_thing('Hat', self.thing.position)
281 t.design = self.thing.game.hats[self.thing.name]
282 del self.thing.game.hats[self.thing.name]
283 self.thing.send_msg('CHAT "You drop your hat."')
284 for remixer in [t for t in self.thing.game.things
285 if t.type_ == 'HatRemixer'
286 and t.position == self.thing.position]:
290 if self.thing.carrying.type_ == 'Bottle':
291 self.thing.send_msg('CHAT "Your attempt to wear a bottle on '
293 self.thing.carrying.sound('BOTTLE', 'SMASH')
294 elif self.thing.carrying.type_ == 'Hat':
295 self.thing.game.hats[self.thing.name] =\
296 self.thing.carrying.design
297 self.thing.send_msg('CHAT "You put on a hat."')
298 dropped = self.thing.uncarry()
299 self.thing.game.remove_thing(dropped)
300 self.thing.game.record_change(self.thing.position, 'other')
304 class Task_SPIN(Task):
307 if not self.thing.carrying:
308 raise PlayError('holding nothing to spin')
309 if not hasattr(self.thing.carrying, 'spinnable'):
310 raise PlayError('held object not spinnable')
313 self.thing.carrying.spin()
314 self.thing.send_msg('CHAT "You spin this object."')