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.position not in reach:
99 raise PlayError('thing not in reach')
100 elif not to_pick_up.portable:
101 raise PlayError('thing not portable')
104 to_pick_up = self.thing.game.get_thing(self.args[0])
105 to_pick_up.position = self.thing.position[:]
106 self.thing.carrying = to_pick_up
110 class Task_DROP(Task):
113 if not self.thing.carrying:
114 raise PlayError('nothing to drop')
115 if self.thing.carrying.type_ == 'Bottle' and self.thing.carrying.full:
116 for t in [t for t in self.thing.game.things
117 if t.type_ == 'BottleDeposit'
118 and t.position == self.thing.position]:
119 raise PlayError('cannot drop full bottle into bottle deposit')
122 if self.thing.carrying.type_ == 'Bottle' and not 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 == self.thing.position]:
127 self.thing.game.remove_thing(self.thing.carrying)
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)
135 self.thing.carrying = None
139 class Task_DOOR(Task):
142 self.thing.carrying = None
143 action_radius = list(self.thing.game.map_geometry.
144 get_neighbors_yxyx(self.thing.position).values())
145 for t in [t for t in self.thing.game.things if
146 t.type_ == 'Door' and t.position in action_radius]:
151 self.thing.game.record_fov_change(t.position)
155 class Task_INTOXICATE(Task):
158 if self.thing.carrying is None:
159 raise PlayError('carrying nothing to drink from')
160 if self.thing.carrying.type_ != 'Bottle':
161 raise PlayError('cannot drink from non-bottle')
162 if not self.thing.carrying.full:
163 raise PlayError('bottle is empty')
166 self.thing.carrying.full = False
167 self.thing.carrying.empty()
168 self.thing.send_msg('RANDOM_COLORS')
169 self.thing.send_msg('CHAT "You are drunk now."')
170 self.thing.drunk = 10000
171 self.thing.invalidate_map_view()
175 class Task_COMMAND(Task):
179 if self.thing.carrying is None:
180 raise PlayError('nothing to command')
181 if not self.thing.carrying.commandable:
182 raise PlayError('cannot command this item type')
185 from plomrogue.misc import quote
186 reply_lines = self.thing.carrying.interpret(self.args[0])
187 for line in reply_lines:
188 self.thing.send_msg('REPLY ' + quote(line))
192 class Task_INSTALL(Task):
194 def _get_uninstallables(self):
195 return [t for t in self.thing.game.things
197 and hasattr(t, 'installable') and t.installable
199 and t.position == self.thing.position]
202 if self.thing.carrying:
203 if not hasattr(self.thing.carrying, 'installable')\
204 or not self.thing.carrying.installable:
205 raise PlayError('carried thing not installable')
206 elif len(self._get_uninstallables()) == 0:
207 raise PlayError('nothing to uninstall here')
210 if self.thing.carrying:
211 self.thing.carrying.install()
212 self.thing.carrying = None
213 self.thing.send_msg('CHAT "You install the thing you carry."')
215 self._get_uninstallables()[0].uninstall()
216 self.thing.send_msg('CHAT "You uninstall the thing here."')
220 class Task_WEAR(Task):
223 if self.thing.name in self.thing.game.hats:
225 if not self.thing.carrying:
226 raise PlayError('carrying nothing to wear')
227 if self.thing.name in self.thing.game.hats:
228 raise PlayError('already wearing a hat')
229 if self.thing.carrying.type_ != 'Hat':
230 raise PlayError('can only wear a hat')
233 if self.thing.name in self.thing.game.hats:
234 t = self.thing.game.add_thing('Hat', self.thing.position)
235 t.design = self.thing.game.hats[self.thing.name]
236 del self.thing.game.hats[self.thing.name]
237 self.thing.send_msg('CHAT "You drop your hat."')
238 for remixer in [t for t in self.thing.game.things
239 if t.type_ == 'HatRemixer'
240 and t.position == self.thing.position]:
244 from plomrogue.misc import quote
245 self.thing.game.hats[self.thing.name] = self.thing.carrying.design
246 self.thing.game.remove_thing(self.thing.carrying)
247 self.thing.carrying = None
248 self.thing.send_msg('CHAT "You put on a hat."')