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 if test_yxyx in [t.position for t in self.thing.game.things
39 raise PlayError('blocked by other thing')
40 elif self.thing.game.maps[test_yxyx[0]][test_yxyx[1]] != '.':
41 raise PlayError('blocked by impassable tile')
44 self.thing.game.record_fov_change(self.thing.position)
45 self.thing.position = self._get_move_target()
46 self.thing.game.record_fov_change(self.thing.position)
47 if self.thing.carrying:
48 self.thing.carrying.position = self.thing.position
52 class Task_WRITE(Task):
53 argtypes = 'string:char string'
56 if not self.thing.game.can_do_tile_with_pw(*self.thing.position,
58 raise GameError('wrong password for tile')
61 big_yx = self.thing.position[0]
62 little_yx = self.thing.position[1]
63 self.thing.game.maps[big_yx][little_yx] = self.args[0]
64 self.thing.game.record_fov_change((big_yx, little_yx))
68 class Task_FLATTEN_SURROUNDINGS(Task):
75 for yxyx in [self.thing.position] + \
76 list(self.thing.game.map_geometry.get_neighbors_yxyx(
77 self.thing.position).values()):
78 if not self.thing.game.can_do_tile_with_pw(*yxyx, self.args[0]):
80 self.thing.game.maps[yxyx[0]][yxyx[1]] = '.'
81 self.thing.game.record_fov_change(yxyx)
85 class Task_PICK_UP(Task):
89 if self.thing.carrying:
90 raise PlayError('already carrying something')
91 to_pick_up = self.thing.game.get_thing(self.args[0])
92 neighbors = self.thing.game.map_geometry.\
93 get_neighbors_yxyx(self.thing.position).values()
94 reach = [self.thing.position] + list(neighbors)
95 if to_pick_up is None:
96 raise PlayError('no such thing exists')
97 elif to_pick_up == self.thing:
98 raise PlayError('cannot pick up oneself')
99 elif to_pick_up.type_ == 'Player':
100 raise PlayError('cannot pick up player')
101 elif to_pick_up.carried:
102 raise PlayError('thing already carried by a player')
103 elif to_pick_up.position not in reach:
104 raise PlayError('thing not in reach')
105 elif not to_pick_up.portable:
106 raise PlayError('thing not portable')
109 to_pick_up = self.thing.game.get_thing(self.args[0])
110 to_pick_up.position = self.thing.position[:]
111 self.thing.carrying = to_pick_up
112 to_pick_up.carried = True
116 class Task_DROP(Task):
117 argtypes = 'string:direction+here'
120 if not self.thing.carrying:
121 raise PlayError('nothing to drop')
122 target_position = self._get_move_target()
123 if self.thing.carrying.type_ == 'Bottle' and self.thing.carrying.full:
124 for t in [t for t in self.thing.game.things
125 if t.type_ == 'BottleDeposit'
126 and t.position == target_position]:
127 raise PlayError('cannot drop full bottle into bottle deposit')
130 target_position = self._get_move_target()
131 dropped = self.thing.uncarry()
132 dropped.position = target_position
133 if dropped.type_ == 'Bottle' and not dropped.full:
134 for t in [t for t in self.thing.game.things
135 if t.type_ == 'BottleDeposit'
136 and t.position == dropped.position]:
138 self.thing.game.remove_thing(dropped)
140 elif dropped.type_ == 'Hat':
141 for t in [t for t in self.thing.game.things
142 if t.type_ == 'HatRemixer'
143 and t.position == dropped.position]:
149 class Task_DOOR(Task):
152 action_radius = list(self.thing.game.map_geometry.
153 get_neighbors_yxyx(self.thing.position).values())
154 for t in [t for t in self.thing.game.things if
155 t.type_ == 'Door' and t.position in action_radius]:
160 self.thing.game.record_fov_change(t.position)
164 class Task_INTOXICATE(Task):
167 if self.thing.carrying is None:
168 raise PlayError('carrying nothing to drink from')
169 if self.thing.carrying.type_ != 'Bottle':
170 raise PlayError('cannot drink from non-bottle')
171 if not self.thing.carrying.full:
172 raise PlayError('bottle is empty')
175 self.thing.carrying.full = False
176 self.thing.carrying.empty()
177 self.thing.send_msg('RANDOM_COLORS')
178 self.thing.send_msg('CHAT "You are drunk now."')
179 self.thing.drunk = 10000
180 self.thing.invalidate_map_view()
184 class Task_COMMAND(Task):
188 if self.thing.carrying is None:
189 raise PlayError('nothing to command')
190 if not self.thing.carrying.commandable:
191 raise PlayError('cannot command this item type')
194 reply_lines = self.thing.carrying.interpret(self.args[0])
195 for line in reply_lines:
196 self.thing.send_msg('REPLY ' + quote(line))
200 class Task_INSTALL(Task):
203 def _get_uninstallables(self):
204 return [t for t in self.thing.game.things
206 and hasattr(t, 'installable') and t.installable
208 and t.position == self.thing.position]
211 if not self.thing.game.can_do_tile_with_pw(*self.thing.position,
213 raise GameError('wrong password for tile')
214 if self.thing.carrying:
215 if not hasattr(self.thing.carrying, 'installable')\
216 or not self.thing.carrying.installable:
217 raise PlayError('carried thing not installable')
218 elif len(self._get_uninstallables()) == 0:
219 raise PlayError('nothing to uninstall here')
222 if self.thing.carrying:
223 t = self.thing.uncarry()
225 self.thing.send_msg('CHAT "You install the thing you carry."')
227 self._get_uninstallables()[0].uninstall()
228 self.thing.send_msg('CHAT "You uninstall the thing here."')
232 class Task_WEAR(Task):
235 if self.thing.name in self.thing.game.hats:
237 if not self.thing.carrying:
238 raise PlayError('carrying nothing to wear')
239 if self.thing.name in self.thing.game.hats:
240 raise PlayError('already wearing a hat')
241 if self.thing.carrying.type_ not in {'Hat', 'Bottle'}:
242 raise PlayError('can not wear the kind of thing you hold')
245 if self.thing.name in self.thing.game.hats:
246 t = self.thing.game.add_thing('Hat', self.thing.position)
247 t.design = self.thing.game.hats[self.thing.name]
248 del self.thing.game.hats[self.thing.name]
249 self.thing.send_msg('CHAT "You drop your hat."')
250 for remixer in [t for t in self.thing.game.things
251 if t.type_ == 'HatRemixer'
252 and t.position == self.thing.position]:
256 if self.thing.carrying.type_ == 'Bottle':
257 self.thing.send_msg('CHAT "Your attempt to wear a bottle on '
259 self.thing.carrying.sound('BOTTLE', 'SMASH')
260 elif self.thing.carrying.type_ == 'Hat':
261 self.thing.game.hats[self.thing.name] =\
262 self.thing.carrying.design
263 self.thing.send_msg('CHAT "You put on a hat."')
264 self.thing.game.remove_thing(self.thing.carrying)
265 self.thing.carrying = None
269 class Task_SPIN(Task):
272 if not self.thing.carrying:
273 raise PlayError('holding nothing to spin')
274 if not hasattr(self.thing.carrying, 'spinnable'):
275 raise PlayError('held object not spinnable')
278 self.thing.carrying.spin()
279 self.thing.send_msg('CHAT "You spin this object."')