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):
79 argtypes = 'int:nonneg'
82 if self.thing.carrying:
83 raise PlayError('already carrying something')
84 to_pick_up = self.thing.game.get_thing(self.args[0])
85 if to_pick_up is None:
86 raise PlayError('no thing of ID %s exists %s' % self.args[0])
87 elif to_pick_up == self.thing:
88 raise PlayError('cannot pick up oneself')
89 elif to_pick_up.type_ == 'Player':
90 raise PlayError('cannot pick up player')
91 elif to_pick_up.position != self.thing.position:
92 raise PlayError('thing of ID %s not in reach' % self.args[0])
93 elif not to_pick_up.portable:
94 raise PlayError('thing of ID %s not portable' % self.args[0])
97 to_pick_up = self.thing.game.get_thing(self.args[0])
98 self.thing.carrying = to_pick_up
102 class Task_DROP(Task):
105 if not self.thing.carrying:
106 raise PlayError('nothing to drop')
107 if self.thing.carrying.type_ == 'Bottle' and self.thing.carrying.full:
108 for t in [t for t in self.thing.game.things
109 if t.type_ == 'BottleDeposit'
110 and t.position == self.thing.position]:
111 raise PlayError('cannot drop full bottle into bottle deposit')
114 if self.thing.carrying.type_ == 'Bottle' and not 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]:
119 self.thing.game.things.remove(self.thing.carrying)
121 self.thing.carrying = None
125 class Task_DOOR(Task):
128 self.thing.carrying = None
129 action_radius = list(self.thing.game.map_geometry.
130 get_neighbors_yxyx(self.thing.position).values())
131 for t in [t for t in self.thing.game.things if
132 t.type_ == 'Door' and t.position in action_radius]:
140 class Task_INTOXICATE(Task):
143 if self.thing.carrying is None:
144 raise PlayError('carrying nothing to drink from')
145 if self.thing.carrying.type_ != 'Bottle':
146 raise PlayError('cannot drink from non-bottle')
147 if not self.thing.carrying.full:
148 raise PlayError('bottle is empty')
151 self.thing.carrying.full = False
152 self.thing.carrying.empty()
153 for c_id in self.thing.game.sessions:
154 if self.thing.game.sessions[c_id]['thing_id'] == self.thing.id_:
155 self.thing.game.io.send('RANDOM_COLORS', c_id)
156 self.thing.game.io.send('CHAT "You are drunk now."', c_id)
158 self.thing.drunk = 10000
161 class Task_COMMAND(Task):
165 if self.thing.carrying is None:
166 raise PlayError('nothing to command')
167 if not self.thing.carrying.commandable:
168 raise PlayError('cannot command this item type')
171 from plomrogue.misc import quote
172 reply = self.thing.carrying.interpret(self.args[0])
173 for c_id in self.thing.game.sessions:
174 if self.thing.game.sessions[c_id]['thing_id'] == self.thing.id_:
175 self.thing.game.io.send('REPLY ' + quote(reply), c_id)