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.position = self.get_move_target()
42 if self.thing.carrying:
43 self.thing.carrying.position = self.thing.position
47 class Task_WRITE(Task):
48 argtypes = 'string:char string'
51 if not self.thing.game.can_do_tile_with_pw(*self.thing.position,
53 raise GameError('wrong password for tile')
56 big_yx = self.thing.position[0]
57 little_yx = self.thing.position[1]
58 self.thing.game.maps[big_yx][little_yx] = self.args[0]
62 class Task_FLATTEN_SURROUNDINGS(Task):
69 for yxyx in [self.thing.position] + \
70 list(self.thing.game.map_geometry.get_neighbors_yxyx(
71 self.thing.position).values()):
72 if not self.thing.game.can_do_tile_with_pw(*yxyx, self.args[0]):
74 self.thing.game.maps[yxyx[0]][yxyx[1]] = '.'
78 class Task_PICK_UP(Task):
82 if self.thing.carrying:
83 raise PlayError('already carrying something')
84 to_pick_up = self.thing.game.get_thing(self.args[0])
85 neighbors = self.thing.game.map_geometry.\
86 get_neighbors_yxyx(self.thing.position).values()
87 reach = [self.thing.position] + list(neighbors)
88 if to_pick_up is None:
89 raise PlayError('no such thing exists')
90 elif to_pick_up == self.thing:
91 raise PlayError('cannot pick up oneself')
92 elif to_pick_up.type_ == 'Player':
93 raise PlayError('cannot pick up player')
94 elif to_pick_up.position not in reach:
95 raise PlayError('thing not in reach')
96 elif not to_pick_up.portable:
97 raise PlayError('thing not portable')
100 to_pick_up = self.thing.game.get_thing(self.args[0])
101 to_pick_up.position = self.thing.position[:]
102 self.thing.carrying = to_pick_up
106 class Task_DROP(Task):
109 if not self.thing.carrying:
110 raise PlayError('nothing to drop')
111 if self.thing.carrying.type_ == 'Bottle' and self.thing.carrying.full:
112 for t in [t for t in self.thing.game.things
113 if t.type_ == 'BottleDeposit'
114 and t.position == self.thing.position]:
115 raise PlayError('cannot drop full bottle into bottle deposit')
118 if self.thing.carrying.type_ == 'Bottle' and not 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]:
123 self.thing.game.things.remove(self.thing.carrying)
125 elif self.thing.carrying.type_ == 'Hat':
126 for t in [t for t in self.thing.game.things
127 if t.type_ == 'HatRemixer'
128 and t.position == self.thing.position]:
129 t.accept(self.thing.carrying)
131 self.thing.carrying = None
135 class Task_DOOR(Task):
138 self.thing.carrying = None
139 action_radius = list(self.thing.game.map_geometry.
140 get_neighbors_yxyx(self.thing.position).values())
141 for t in [t for t in self.thing.game.things if
142 t.type_ == 'Door' and t.position in action_radius]:
150 class Task_INTOXICATE(Task):
153 if self.thing.carrying is None:
154 raise PlayError('carrying nothing to drink from')
155 if self.thing.carrying.type_ != 'Bottle':
156 raise PlayError('cannot drink from non-bottle')
157 if not self.thing.carrying.full:
158 raise PlayError('bottle is empty')
161 self.thing.carrying.full = False
162 self.thing.carrying.empty()
163 self.thing.send_msg('RANDOM_COLORS')
164 self.thing.send_msg('CHAT "You are drunk now."')
165 self.thing.drunk = 10000
169 class Task_COMMAND(Task):
173 if self.thing.carrying is None:
174 raise PlayError('nothing to command')
175 if not self.thing.carrying.commandable:
176 raise PlayError('cannot command this item type')
179 from plomrogue.misc import quote
180 reply_lines = self.thing.carrying.interpret(self.args[0])
181 for line in reply_lines:
182 self.thing.send_msg('REPLY ' + quote(line))
186 class Task_INSTALL(Task):
188 def _get_uninstallables(self):
189 return [t for t in self.thing.game.things
191 and hasattr(t, 'installable') and t.installable
193 and t.position == self.thing.position]
196 if self.thing.carrying:
197 if not hasattr(self.thing.carrying, 'installable')\
198 or not self.thing.carrying.installable:
199 raise PlayError('carried thing not installable')
200 elif len(self._get_uninstallables()) == 0:
201 raise PlayError('nothing to uninstall here')
204 if self.thing.carrying:
205 self.thing.carrying.install()
206 self.thing.carrying = None
207 self.thing.send_msg('CHAT "You install the thing you carry."')
209 self._get_uninstallables()[0].uninstall()
210 self.thing.send_msg('CHAT "You uninstall the thing here."')
214 class Task_WEAR(Task):
217 if self.thing.name in self.thing.game.hats:
219 if not self.thing.carrying:
220 raise PlayError('carrying nothing to wear')
221 if self.thing.name in self.thing.game.hats:
222 raise PlayError('already wearing a hat')
223 if self.thing.carrying.type_ != 'Hat':
224 raise PlayError('can only wear a hat')
227 if self.thing.name in self.thing.game.hats:
228 t = self.thing.game.thing_types['Hat'](self.thing.game,
229 position=self.thing.position)
230 self.thing.game.things += [t]
231 t.design = self.thing.game.hats[self.thing.name]
232 del self.thing.game.hats[self.thing.name]
233 self.thing.send_msg('CHAT "You drop your hat."')
234 for t in [t for t in self.thing.game.things
235 if t.type_ == 'HatRemixer'
236 and t.position == self.thing.position]:
240 self.thing.game.hats[self.thing.name] = self.thing.carrying.design
241 self.thing.game.things.remove(self.thing.carrying)
242 self.thing.carrying = None
243 self.thing.send_msg('CHAT "You put on a hat."')