1 from plomrogue.errors import PlayError, GameError
9 def __init__(self, thing, args=()):
18 class Task_WAIT(Task):
25 class Task_MOVE(Task):
26 argtypes = 'string:direction'
28 def get_move_target(self):
29 return self.thing.game.map_geometry.move_yxyx(self.thing.position,
33 test_yxyx = self.get_move_target()
34 if test_yxyx in [t.position for t in self.thing.game.things
36 raise PlayError('blocked by other thing')
37 elif self.thing.game.maps[test_yxyx[0]][test_yxyx[1]] != '.':
38 raise PlayError('blocked by impassable tile')
41 self.thing.game.record_fov_change(self.thing.position)
42 self.thing.position = self.get_move_target()
43 self.thing.game.record_fov_change(self.thing.position)
44 if self.thing.carrying:
45 self.thing.carrying.position = self.thing.position
49 class Task_WRITE(Task):
50 argtypes = 'string:char string'
53 if not self.thing.game.can_do_tile_with_pw(*self.thing.position,
55 raise GameError('wrong password for tile')
58 big_yx = self.thing.position[0]
59 little_yx = self.thing.position[1]
60 self.thing.game.maps[big_yx][little_yx] = self.args[0]
61 self.thing.game.record_fov_change((big_yx, little_yx))
65 class Task_FLATTEN_SURROUNDINGS(Task):
72 for yxyx in [self.thing.position] + \
73 list(self.thing.game.map_geometry.get_neighbors_yxyx(
74 self.thing.position).values()):
75 if not self.thing.game.can_do_tile_with_pw(*yxyx, self.args[0]):
77 self.thing.game.maps[yxyx[0]][yxyx[1]] = '.'
78 self.thing.game.record_fov_change(yxyx)
82 class Task_PICK_UP(Task):
86 if self.thing.carrying:
87 raise PlayError('already carrying something')
88 to_pick_up = self.thing.game.get_thing(self.args[0])
89 neighbors = self.thing.game.map_geometry.\
90 get_neighbors_yxyx(self.thing.position).values()
91 reach = [self.thing.position] + list(neighbors)
92 if to_pick_up is None:
93 raise PlayError('no such thing exists')
94 elif to_pick_up == self.thing:
95 raise PlayError('cannot pick up oneself')
96 elif to_pick_up.type_ == 'Player':
97 raise PlayError('cannot pick up player')
98 elif to_pick_up.carried:
99 raise PlayError('thing already carried by a player')
100 elif to_pick_up.position not in reach:
101 raise PlayError('thing not in reach')
102 elif not to_pick_up.portable:
103 raise PlayError('thing not portable')
106 to_pick_up = self.thing.game.get_thing(self.args[0])
107 to_pick_up.position = self.thing.position[:]
108 self.thing.carrying = to_pick_up
109 to_pick_up.carried = True
113 class Task_DROP(Task):
116 if not self.thing.carrying:
117 raise PlayError('nothing to drop')
118 if self.thing.carrying.type_ == 'Bottle' and self.thing.carrying.full:
119 for t in [t for t in self.thing.game.things
120 if t.type_ == 'BottleDeposit'
121 and t.position == self.thing.position]:
122 raise PlayError('cannot drop full bottle into bottle deposit')
125 dropped = self.thing.uncarry()
126 if dropped.type_ == 'Bottle' and not dropped.full:
127 for t in [t for t in self.thing.game.things
128 if t.type_ == 'BottleDeposit'
129 and t.position == self.thing.position]:
131 self.thing.game.remove_thing(dropped)
133 elif dropped.type_ == 'Hat':
134 for t in [t for t in self.thing.game.things
135 if t.type_ == 'HatRemixer'
136 and t.position == self.thing.position]:
142 class Task_DOOR(Task):
145 action_radius = list(self.thing.game.map_geometry.
146 get_neighbors_yxyx(self.thing.position).values())
147 for t in [t for t in self.thing.game.things if
148 t.type_ == 'Door' and t.position in action_radius]:
153 self.thing.game.record_fov_change(t.position)
157 class Task_INTOXICATE(Task):
160 if self.thing.carrying is None:
161 raise PlayError('carrying nothing to drink from')
162 if self.thing.carrying.type_ != 'Bottle':
163 raise PlayError('cannot drink from non-bottle')
164 if not self.thing.carrying.full:
165 raise PlayError('bottle is empty')
168 self.thing.carrying.full = False
169 self.thing.carrying.empty()
170 self.thing.send_msg('RANDOM_COLORS')
171 self.thing.send_msg('CHAT "You are drunk now."')
172 self.thing.drunk = 10000
173 self.thing.invalidate_map_view()
177 class Task_COMMAND(Task):
181 if self.thing.carrying is None:
182 raise PlayError('nothing to command')
183 if not self.thing.carrying.commandable:
184 raise PlayError('cannot command this item type')
187 from plomrogue.misc import quote
188 reply_lines = self.thing.carrying.interpret(self.args[0])
189 for line in reply_lines:
190 self.thing.send_msg('REPLY ' + quote(line))
194 class Task_INSTALL(Task):
196 def _get_uninstallables(self):
197 return [t for t in self.thing.game.things
199 and hasattr(t, 'installable') and t.installable
201 and t.position == self.thing.position]
204 if self.thing.carrying:
205 if not hasattr(self.thing.carrying, 'installable')\
206 or not self.thing.carrying.installable:
207 raise PlayError('carried thing not installable')
208 elif len(self._get_uninstallables()) == 0:
209 raise PlayError('nothing to uninstall here')
212 if self.thing.carrying:
213 t = self.thing.uncarry()
215 self.thing.send_msg('CHAT "You install the thing you carry."')
217 self._get_uninstallables()[0].uninstall()
218 self.thing.send_msg('CHAT "You uninstall the thing here."')
222 class Task_WEAR(Task):
225 if self.thing.name in self.thing.game.hats:
227 if not self.thing.carrying:
228 raise PlayError('carrying nothing to wear')
229 if self.thing.name in self.thing.game.hats:
230 raise PlayError('already wearing a hat')
231 if self.thing.carrying.type_ != 'Hat':
232 raise PlayError('can only wear a hat')
235 if self.thing.name in self.thing.game.hats:
236 t = self.thing.game.add_thing('Hat', self.thing.position)
237 t.design = self.thing.game.hats[self.thing.name]
238 del self.thing.game.hats[self.thing.name]
239 self.thing.send_msg('CHAT "You drop your hat."')
240 for remixer in [t for t in self.thing.game.things
241 if t.type_ == 'HatRemixer'
242 and t.position == self.thing.position]:
246 from plomrogue.misc import quote
247 self.thing.game.hats[self.thing.name] = self.thing.carrying.design
248 self.thing.game.remove_thing(self.thing.carrying)
249 self.thing.carrying = None
250 self.thing.send_msg('CHAT "You put on a hat."')