1 from plomrogue.errors import PlayError, GameError
9 def __init__(self, thing, args=()):
13 def _get_move_target(self):
14 if self.args[0] == 'HERE':
15 return self.thing.position
16 return self.thing.game.map_geometry.move_yxyx(self.thing.position,
24 class Task_WAIT(Task):
31 class Task_MOVE(Task):
32 argtypes = 'string:direction'
35 test_yxyx = self._get_move_target()
36 if test_yxyx in [t.position for t in self.thing.game.things
38 raise PlayError('blocked by other thing')
39 elif self.thing.game.maps[test_yxyx[0]][test_yxyx[1]] != '.':
40 raise PlayError('blocked by impassable tile')
43 self.thing.game.record_fov_change(self.thing.position)
44 self.thing.position = self._get_move_target()
45 self.thing.game.record_fov_change(self.thing.position)
46 if self.thing.carrying:
47 self.thing.carrying.position = self.thing.position
51 class Task_WRITE(Task):
52 argtypes = 'string:char string'
55 if not self.thing.game.can_do_tile_with_pw(*self.thing.position,
57 raise GameError('wrong password for tile')
60 big_yx = self.thing.position[0]
61 little_yx = self.thing.position[1]
62 self.thing.game.maps[big_yx][little_yx] = self.args[0]
63 self.thing.game.record_fov_change((big_yx, little_yx))
67 class Task_FLATTEN_SURROUNDINGS(Task):
74 for yxyx in [self.thing.position] + \
75 list(self.thing.game.map_geometry.get_neighbors_yxyx(
76 self.thing.position).values()):
77 if not self.thing.game.can_do_tile_with_pw(*yxyx, self.args[0]):
79 self.thing.game.maps[yxyx[0]][yxyx[1]] = '.'
80 self.thing.game.record_fov_change(yxyx)
84 class Task_PICK_UP(Task):
88 if self.thing.carrying:
89 raise PlayError('already carrying something')
90 to_pick_up = self.thing.game.get_thing(self.args[0])
91 neighbors = self.thing.game.map_geometry.\
92 get_neighbors_yxyx(self.thing.position).values()
93 reach = [self.thing.position] + list(neighbors)
94 if to_pick_up is None:
95 raise PlayError('no such thing exists')
96 elif to_pick_up == self.thing:
97 raise PlayError('cannot pick up oneself')
98 elif to_pick_up.type_ == 'Player':
99 raise PlayError('cannot pick up player')
100 elif to_pick_up.carried:
101 raise PlayError('thing already carried by a player')
102 elif to_pick_up.position not in reach:
103 raise PlayError('thing not in reach')
104 elif not to_pick_up.portable:
105 raise PlayError('thing not portable')
108 to_pick_up = self.thing.game.get_thing(self.args[0])
109 to_pick_up.position = self.thing.position[:]
110 self.thing.carrying = to_pick_up
111 to_pick_up.carried = True
115 class Task_DROP(Task):
116 argtypes = 'string:direction+here'
119 if not self.thing.carrying:
120 raise PlayError('nothing to drop')
121 target_position = self._get_move_target()
122 if self.thing.carrying.type_ == 'Bottle' and self.thing.carrying.full:
123 for t in [t for t in self.thing.game.things
124 if t.type_ == 'BottleDeposit'
125 and t.position == target_position]:
126 raise PlayError('cannot drop full bottle into bottle deposit')
129 target_position = self._get_move_target()
130 dropped = self.thing.uncarry()
131 dropped.position = target_position
132 if dropped.type_ == 'Bottle' and not dropped.full:
133 for t in [t for t in self.thing.game.things
134 if t.type_ == 'BottleDeposit'
135 and t.position == dropped.position]:
137 self.thing.game.remove_thing(dropped)
139 elif dropped.type_ == 'Hat':
140 for t in [t for t in self.thing.game.things
141 if t.type_ == 'HatRemixer'
142 and t.position == dropped.position]:
148 class Task_DOOR(Task):
151 action_radius = list(self.thing.game.map_geometry.
152 get_neighbors_yxyx(self.thing.position).values())
153 for t in [t for t in self.thing.game.things if
154 t.type_ == 'Door' and t.position in action_radius]:
159 self.thing.game.record_fov_change(t.position)
163 class Task_INTOXICATE(Task):
166 if self.thing.carrying is None:
167 raise PlayError('carrying nothing to drink from')
168 if self.thing.carrying.type_ != 'Bottle':
169 raise PlayError('cannot drink from non-bottle')
170 if not self.thing.carrying.full:
171 raise PlayError('bottle is empty')
174 self.thing.carrying.full = False
175 self.thing.carrying.empty()
176 self.thing.send_msg('RANDOM_COLORS')
177 self.thing.send_msg('CHAT "You are drunk now."')
178 self.thing.drunk = 10000
179 self.thing.invalidate_map_view()
183 class Task_COMMAND(Task):
187 if self.thing.carrying is None:
188 raise PlayError('nothing to command')
189 if not self.thing.carrying.commandable:
190 raise PlayError('cannot command this item type')
193 from plomrogue.misc import quote
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):
202 def _get_uninstallables(self):
203 return [t for t in self.thing.game.things
205 and hasattr(t, 'installable') and t.installable
207 and t.position == self.thing.position]
210 if self.thing.carrying:
211 if not hasattr(self.thing.carrying, 'installable')\
212 or not self.thing.carrying.installable:
213 raise PlayError('carried thing not installable')
214 elif len(self._get_uninstallables()) == 0:
215 raise PlayError('nothing to uninstall here')
218 if self.thing.carrying:
219 t = self.thing.uncarry()
221 self.thing.send_msg('CHAT "You install the thing you carry."')
223 self._get_uninstallables()[0].uninstall()
224 self.thing.send_msg('CHAT "You uninstall the thing here."')
228 class Task_WEAR(Task):
231 if self.thing.name in self.thing.game.hats:
233 if not self.thing.carrying:
234 raise PlayError('carrying nothing to wear')
235 if self.thing.name in self.thing.game.hats:
236 raise PlayError('already wearing a hat')
237 if self.thing.carrying.type_ != 'Hat':
238 raise PlayError('can only wear a hat')
241 if self.thing.name in self.thing.game.hats:
242 t = self.thing.game.add_thing('Hat', self.thing.position)
243 t.design = self.thing.game.hats[self.thing.name]
244 del self.thing.game.hats[self.thing.name]
245 self.thing.send_msg('CHAT "You drop your hat."')
246 for remixer in [t for t in self.thing.game.things
247 if t.type_ == 'HatRemixer'
248 and t.position == self.thing.position]:
252 from plomrogue.misc import quote
253 self.thing.game.hats[self.thing.name] = self.thing.carrying.design
254 self.thing.game.remove_thing(self.thing.carrying)
255 self.thing.carrying = None
256 self.thing.send_msg('CHAT "You put on a hat."')