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 for t in [t for t in self.thing.game.things
53 if t.type_ == 'Player' and not t == self.thing
54 and t.position == self.thing.position]:
55 self.thing.send_msg('CHAT %s' %
56 quote('You get awkwardly close to %s.' % t.name))
57 for c_id in self.thing.game.sessions:
58 if self.thing.game.sessions[c_id]['thing_id'] == t.id_:
59 t.send_msg('CHAT %s' %
60 quote('%s gets awkwardly close to you.' %
63 self.thing.game.record_change(self.thing.position, 'other')
65 self.thing.game.maps[self.thing.position[0]][self.thing.position[1]]
66 if terrain in self.thing.game.terrains:
67 terrain_type = self.thing.game.terrains[terrain]
68 if 'sittable' in terrain_type.tags:
69 self.thing.standing = False
70 self.thing.send_msg('CHAT "You sink into the %s."'
71 % terrain_type.description)
72 self.thing.invalidate('fov')
73 if self.thing.blocks_light:
74 self.thing.game.record_change(self.thing.position, 'fov')
75 if self.thing.carrying:
76 self.thing.carrying.position = self.thing.position
80 class Task_WRITE(Task):
81 argtypes = 'string:char string'
84 if not self.thing.game.can_do_tile_with_pw(*self.thing.position,
86 raise GameError('wrong password for tile')
89 big_yx = self.thing.position[0]
90 little_yx = self.thing.position[1]
91 self.thing.game.maps[big_yx][little_yx] = self.args[0]
92 self.thing.game.record_change((big_yx, little_yx), 'fov')
96 class Task_FLATTEN_SURROUNDINGS(Task):
103 for yxyx in [self.thing.position] + \
104 list(self.thing.game.map_geometry.get_neighbors_yxyx(
105 self.thing.position).values()):
106 if not self.thing.game.can_do_tile_with_pw(*yxyx, self.args[0]):
108 self.thing.game.maps[yxyx[0]][yxyx[1]] = self.thing.game.get_flatland()
109 self.thing.game.record_change(yxyx, 'fov')
113 class Task_PICK_UP(Task):
117 if self.thing.carrying:
118 raise PlayError('already carrying something')
119 to_pick_up = self.thing.game.get_thing(self.args[0])
120 neighbors = self.thing.game.map_geometry.\
121 get_neighbors_yxyx(self.thing.position).values()
122 reach = [self.thing.position] + list(neighbors)
123 if to_pick_up is None:
124 raise PlayError('no such thing exists')
125 elif to_pick_up == self.thing:
126 raise PlayError('cannot pick up oneself')
127 elif to_pick_up.type_ == 'Player':
128 raise PlayError('cannot pick up player')
129 elif to_pick_up.carried:
130 raise PlayError('thing already carried by a player')
131 elif to_pick_up.position not in reach:
132 raise PlayError('thing not in reach')
133 elif not to_pick_up.portable:
134 raise PlayError('thing not portable')
137 to_pick_up = self.thing.game.get_thing(self.args[0])
138 to_pick_up.position = self.thing.position[:]
139 self.thing.carrying = to_pick_up
140 to_pick_up.carried = True
141 self.thing.game.record_change(self.thing.position, 'other')
145 class Task_DROP(Task):
146 argtypes = 'string:direction+here'
149 if not self.thing.carrying:
150 raise PlayError('nothing to drop')
151 target_position = self._get_move_target()
152 if self.thing.carrying.type_ == 'Bottle' and self.thing.carrying.full:
153 for t in [t for t in self.thing.game.things
154 if t.type_ == 'BottleDeposit'
155 and t.position == target_position]:
156 raise PlayError('cannot drop full bottle into bottle deposit')
159 target_position = self._get_move_target()
160 dropped = self.thing.uncarry()
161 dropped.position = target_position
162 over_cookie_spawner = None
163 for t in [t for t in self.thing.game.things
164 if t.type_ == 'CookieSpawner'
165 and t.position == dropped.position]:
166 over_cookie_spawner = t
168 if over_cookie_spawner:
169 over_cookie_spawner.accept(dropped)
170 self.thing.game.remove_thing(dropped)
171 elif dropped.type_ == 'Bottle' and not dropped.full:
172 for t in [t for t in self.thing.game.things
173 if t.type_ == 'BottleDeposit'
174 and t.position == dropped.position]:
176 self.thing.game.remove_thing(dropped)
178 elif dropped.type_ == 'Hat':
179 for t in [t for t in self.thing.game.things
180 if t.type_ == 'HatRemixer'
181 and t.position == dropped.position]:
184 self.thing.game.record_change(self.thing.position, 'other')
188 class Task_DOOR(Task):
191 action_radius = list(self.thing.game.map_geometry.
192 get_neighbors_yxyx(self.thing.position).values())
193 for t in [t for t in self.thing.game.things if
194 t.type_ == 'Door' and t.position in action_radius]:
195 if t.blocks_movement:
199 self.thing.game.record_change(t.position, 'other')
200 self.thing.game.record_change(t.position, 'fov')
204 class Task_INTOXICATE(Task):
207 if self.thing.carrying is None:
208 raise PlayError('carrying nothing to consume')
209 if self.thing.carrying.type_ not in {'Bottle', 'Cookie', 'Psychedelic'}:
210 raise PlayError('cannot consume this kind of thing')
211 if self.thing.carrying.type_ == 'Bottle' and\
212 not self.thing.carrying.full:
213 raise PlayError('bottle is empty')
216 if self.thing.carrying.type_ == 'Bottle':
217 self.thing.carrying.full = False
218 self.thing.carrying.empty()
219 self.thing.send_msg('CHAT "You are drunk now."')
220 self.thing.need_for_toilet += 10000
221 self.thing.drunk = 10000
222 self.thing.invalidate('fov')
223 self.thing.game.record_change(self.thing.position, 'other')
224 elif self.thing.carrying.type_ == 'Psychedelic':
225 self.thing.tripping = 10000
226 self.thing.send_msg('CHAT "You start tripping."')
227 self.thing.send_msg('RANDOM_COLORS')
228 eaten = self.thing.uncarry()
229 self.thing.game.remove_thing(eaten)
230 elif self.thing.carrying.type_ == 'Cookie':
231 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))
232 self.thing.add_cookie_char(self.thing.carrying.thing_char)
233 eaten = self.thing.uncarry()
234 self.thing.game.remove_thing(eaten)
238 class Task_COMMAND(Task):
242 if self.thing.carrying is None:
243 raise PlayError('nothing to command')
244 if not self.thing.carrying.commandable:
245 raise PlayError('cannot command this item type')
248 reply_lines = self.thing.carrying.interpret(self.args[0])
249 for line in reply_lines:
250 self.thing.send_msg('REPLY ' + quote(line))
254 class Task_INSTALL(Task):
257 def _get_uninstallables(self):
258 return [t for t in self.thing.game.things
260 and hasattr(t, 'installable') and t.installable
262 and t.position == self.thing.position]
265 if not self.thing.game.can_do_tile_with_pw(*self.thing.position,
267 raise GameError('wrong password for tile')
268 if self.thing.carrying:
269 if not hasattr(self.thing.carrying, 'installable')\
270 or not self.thing.carrying.installable:
271 raise PlayError('carried thing not installable')
272 elif len(self._get_uninstallables()) == 0:
273 raise PlayError('nothing to uninstall here')
276 if self.thing.carrying:
277 t = self.thing.uncarry()
279 self.thing.send_msg('CHAT "You install the thing you carry."')
281 self._get_uninstallables()[0].uninstall()
282 self.thing.send_msg('CHAT "You uninstall the thing here."')
283 self.thing.game.record_change(self.thing.position, 'other')
287 class Task_WEAR(Task):
290 if self.thing.name in self.thing.game.hats:
292 if not self.thing.carrying:
293 raise PlayError('carrying nothing to wear')
294 if self.thing.name in self.thing.game.hats:
295 raise PlayError('already wearing a hat')
296 if self.thing.carrying.type_ not in {'Hat', 'Bottle'}:
297 raise PlayError('can not wear the kind of thing you hold')
300 if self.thing.name in self.thing.game.hats:
301 t = self.thing.game.add_thing('Hat', self.thing.position)
302 t.design = self.thing.game.hats[self.thing.name]
303 del self.thing.game.hats[self.thing.name]
304 self.thing.send_msg('CHAT "You drop your hat."')
305 for remixer in [t for t in self.thing.game.things
306 if t.type_ == 'HatRemixer'
307 and t.position == self.thing.position]:
311 if self.thing.carrying.type_ == 'Bottle':
312 self.thing.send_msg('CHAT "Your attempt to wear a bottle on '
314 self.thing.carrying.sound('BOTTLE', 'SMASH')
315 elif self.thing.carrying.type_ == 'Hat':
316 self.thing.game.hats[self.thing.name] =\
317 self.thing.carrying.design
318 self.thing.send_msg('CHAT "You put on a hat."')
319 dropped = self.thing.uncarry()
320 self.thing.game.remove_thing(dropped)
321 self.thing.game.record_change(self.thing.position, 'other')
325 class Task_SPIN(Task):
328 if not self.thing.carrying:
329 raise PlayError('holding nothing to spin')
330 if not hasattr(self.thing.carrying, 'spinnable'):
331 raise PlayError('held object not spinnable')
334 self.thing.carrying.spin()
335 self.thing.send_msg('CHAT "You spin this object."')