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.remove_thing(self.thing.carrying)
128 elif self.thing.carrying.type_ == 'Hat':
129 for t in [t for t in self.thing.game.things
130 if t.type_ == 'HatRemixer'
131 and t.position == self.thing.position]:
132 t.accept(self.thing.carrying)
134 self.thing.carrying = None
138 class Task_DOOR(Task):
141 self.thing.carrying = None
142 action_radius = list(self.thing.game.map_geometry.
143 get_neighbors_yxyx(self.thing.position).values())
144 for t in [t for t in self.thing.game.things if
145 t.type_ == 'Door' and t.position in action_radius]:
150 self.thing.game.changed_fovs = True
154 class Task_INTOXICATE(Task):
157 if self.thing.carrying is None:
158 raise PlayError('carrying nothing to drink from')
159 if self.thing.carrying.type_ != 'Bottle':
160 raise PlayError('cannot drink from non-bottle')
161 if not self.thing.carrying.full:
162 raise PlayError('bottle is empty')
165 self.thing.carrying.full = False
166 self.thing.carrying.empty()
167 self.thing.send_msg('RANDOM_COLORS')
168 self.thing.send_msg('CHAT "You are drunk now."')
169 self.thing.drunk = 10000
170 self.thing.game.changed_fovs = True
174 class Task_COMMAND(Task):
178 if self.thing.carrying is None:
179 raise PlayError('nothing to command')
180 if not self.thing.carrying.commandable:
181 raise PlayError('cannot command this item type')
184 from plomrogue.misc import quote
185 reply_lines = self.thing.carrying.interpret(self.args[0])
186 for line in reply_lines:
187 self.thing.send_msg('REPLY ' + quote(line))
191 class Task_INSTALL(Task):
193 def _get_uninstallables(self):
194 return [t for t in self.thing.game.things
196 and hasattr(t, 'installable') and t.installable
198 and t.position == self.thing.position]
201 if self.thing.carrying:
202 if not hasattr(self.thing.carrying, 'installable')\
203 or not self.thing.carrying.installable:
204 raise PlayError('carried thing not installable')
205 elif len(self._get_uninstallables()) == 0:
206 raise PlayError('nothing to uninstall here')
209 if self.thing.carrying:
210 self.thing.carrying.install()
211 self.thing.carrying = None
212 self.thing.send_msg('CHAT "You install the thing you carry."')
214 self._get_uninstallables()[0].uninstall()
215 self.thing.send_msg('CHAT "You uninstall the thing here."')
219 class Task_WEAR(Task):
222 if self.thing.name in self.thing.game.hats:
224 if not self.thing.carrying:
225 raise PlayError('carrying nothing to wear')
226 if self.thing.name in self.thing.game.hats:
227 raise PlayError('already wearing a hat')
228 if self.thing.carrying.type_ != 'Hat':
229 raise PlayError('can only wear a hat')
232 if self.thing.name in self.thing.game.hats:
233 t = self.thing.game.add_thing('Hat', self.thing.position)
234 t.design = self.thing.game.hats[self.thing.name]
235 del self.thing.game.hats[self.thing.name]
236 self.thing.send_msg('CHAT "You drop your hat."')
237 for remixer in [t for t in self.thing.game.things
238 if t.type_ == 'HatRemixer'
239 and t.position == self.thing.position]:
243 from plomrogue.misc import quote
244 self.thing.game.hats[self.thing.name] = self.thing.carrying.design
245 self.thing.game.things.remove(self.thing.carrying)
246 self.thing.carrying = None
247 self.thing.send_msg('CHAT "You put on a hat."')