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
44 self.thing.game.changed_fovs = True
48 class Task_WRITE(Task):
49 argtypes = 'string:char string'
52 if not self.thing.game.can_do_tile_with_pw(*self.thing.position,
54 raise GameError('wrong password for tile')
57 big_yx = self.thing.position[0]
58 little_yx = self.thing.position[1]
59 self.thing.game.maps[big_yx][little_yx] = self.args[0]
60 self.thing.game.changed_fovs = True
64 class Task_FLATTEN_SURROUNDINGS(Task):
71 for yxyx in [self.thing.position] + \
72 list(self.thing.game.map_geometry.get_neighbors_yxyx(
73 self.thing.position).values()):
74 if not self.thing.game.can_do_tile_with_pw(*yxyx, self.args[0]):
76 self.thing.game.maps[yxyx[0]][yxyx[1]] = '.'
77 self.thing.game.changed_fovs = True
81 class Task_PICK_UP(Task):
85 if self.thing.carrying:
86 raise PlayError('already carrying something')
87 to_pick_up = self.thing.game.get_thing(self.args[0])
88 neighbors = self.thing.game.map_geometry.\
89 get_neighbors_yxyx(self.thing.position).values()
90 reach = [self.thing.position] + list(neighbors)
91 if to_pick_up is None:
92 raise PlayError('no such thing exists')
93 elif to_pick_up == self.thing:
94 raise PlayError('cannot pick up oneself')
95 elif to_pick_up.type_ == 'Player':
96 raise PlayError('cannot pick up player')
97 elif to_pick_up.position not in reach:
98 raise PlayError('thing not in reach')
99 elif not to_pick_up.portable:
100 raise PlayError('thing not portable')
103 to_pick_up = self.thing.game.get_thing(self.args[0])
104 to_pick_up.position = self.thing.position[:]
105 self.thing.carrying = to_pick_up
109 class Task_DROP(Task):
112 if not self.thing.carrying:
113 raise PlayError('nothing to drop')
114 if self.thing.carrying.type_ == 'Bottle' and self.thing.carrying.full:
115 for t in [t for t in self.thing.game.things
116 if t.type_ == 'BottleDeposit'
117 and t.position == self.thing.position]:
118 raise PlayError('cannot drop full bottle into bottle deposit')
121 if self.thing.carrying.type_ == 'Bottle' and not self.thing.carrying.full:
122 for t in [t for t in self.thing.game.things
123 if t.type_ == 'BottleDeposit'
124 and t.position == self.thing.position]:
126 self.thing.game.things.remove(self.thing.carrying)
127 self.thing.game.changed_fovs = True
129 elif self.thing.carrying.type_ == 'Hat':
130 for t in [t for t in self.thing.game.things
131 if t.type_ == 'HatRemixer'
132 and t.position == self.thing.position]:
133 t.accept(self.thing.carrying)
134 self.thing.game.changed_fovs = True
136 self.thing.carrying = None
140 class Task_DOOR(Task):
143 self.thing.carrying = None
144 action_radius = list(self.thing.game.map_geometry.
145 get_neighbors_yxyx(self.thing.position).values())
146 for t in [t for t in self.thing.game.things if
147 t.type_ == 'Door' and t.position in action_radius]:
152 self.thing.game.changed_fovs = True
156 class Task_INTOXICATE(Task):
159 if self.thing.carrying is None:
160 raise PlayError('carrying nothing to drink from')
161 if self.thing.carrying.type_ != 'Bottle':
162 raise PlayError('cannot drink from non-bottle')
163 if not self.thing.carrying.full:
164 raise PlayError('bottle is empty')
167 self.thing.carrying.full = False
168 self.thing.carrying.empty()
169 self.thing.send_msg('RANDOM_COLORS')
170 self.thing.send_msg('CHAT "You are drunk now."')
171 self.thing.drunk = 10000
172 self.thing.game.changed_fovs = True
176 class Task_COMMAND(Task):
180 if self.thing.carrying is None:
181 raise PlayError('nothing to command')
182 if not self.thing.carrying.commandable:
183 raise PlayError('cannot command this item type')
186 from plomrogue.misc import quote
187 reply_lines = self.thing.carrying.interpret(self.args[0])
188 for line in reply_lines:
189 self.thing.send_msg('REPLY ' + quote(line))
193 class Task_INSTALL(Task):
195 def _get_uninstallables(self):
196 return [t for t in self.thing.game.things
198 and hasattr(t, 'installable') and t.installable
200 and t.position == self.thing.position]
203 if self.thing.carrying:
204 if not hasattr(self.thing.carrying, 'installable')\
205 or not self.thing.carrying.installable:
206 raise PlayError('carried thing not installable')
207 elif len(self._get_uninstallables()) == 0:
208 raise PlayError('nothing to uninstall here')
211 if self.thing.carrying:
212 self.thing.carrying.install()
213 self.thing.carrying = None
214 self.thing.send_msg('CHAT "You install the thing you carry."')
216 self._get_uninstallables()[0].uninstall()
217 self.thing.send_msg('CHAT "You uninstall the thing here."')
221 class Task_WEAR(Task):
224 if self.thing.name in self.thing.game.hats:
226 if not self.thing.carrying:
227 raise PlayError('carrying nothing to wear')
228 if self.thing.name in self.thing.game.hats:
229 raise PlayError('already wearing a hat')
230 if self.thing.carrying.type_ != 'Hat':
231 raise PlayError('can only wear a hat')
234 if self.thing.name in self.thing.game.hats:
235 t = self.thing.game.thing_types['Hat'](self.thing.game,
236 position=self.thing.position)
237 self.thing.game.things += [t]
238 t.design = self.thing.game.hats[self.thing.name]
239 del self.thing.game.hats[self.thing.name]
240 self.thing.send_msg('CHAT "You drop your hat."')
241 for remixer in [t for t in self.thing.game.things
242 if t.type_ == 'HatRemixer'
243 and t.position == self.thing.position]:
247 from plomrogue.misc import quote
248 self.thing.game.hats[self.thing.name] = self.thing.carrying.design
249 self.thing.game.things.remove(self.thing.carrying)
250 self.thing.carrying = None
251 self.thing.send_msg('CHAT "You put on a hat."')