1 from plomrogue.errors import PlayError, GameError
9 def __init__(self, thing, args=()):
18 class Task_WAIT(Task):
26 class Task_MOVE(Task):
28 argtypes = 'string:direction'
30 def get_move_target(self):
31 return self.thing.game.map_geometry.move_yxyx(self.thing.position,
35 test_yxyx = self.get_move_target()
36 if test_yxyx in [t.position for t in self.thing.game.things
38 raise PlayError('blocked by other thing')
39 elif self.thing.game.maps[test_yxyx[0]][test_yxyx[1]] != '.':
40 raise PlayError('blocked by impassable tile')
43 self.thing.position = self.get_move_target()
44 if self.thing.carrying:
45 self.thing.carrying.position = self.thing.position
49 class Task_WRITE(Task):
51 argtypes = 'string:char string'
54 if not self.thing.game.can_do_tile_with_pw(*self.thing.position,
56 raise GameError('wrong password for tile')
59 big_yx = self.thing.position[0]
60 little_yx = self.thing.position[1]
61 self.thing.game.maps[big_yx][little_yx] = self.args[0]
65 class Task_FLATTEN_SURROUNDINGS(Task):
73 for yxyx in[self.thing.position] + \
74 list(self.thing.game.map_geometry.get_neighbors_yxyx(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]] = '.'
81 class Task_PICK_UP(Task):
85 if self.thing.carrying:
86 raise PlayError('already carrying something')
87 nothing_to_pick_up = True
88 for t in [t for t in self.thing.game.things
89 if t != self.thing and t.position == self.thing.position
90 and t.type_ != 'Player']:
91 nothing_to_pick_up = False
93 if nothing_to_pick_up:
94 raise PlayError('nothing to pick up')
97 to_pick_up = [t for t in self.thing.game.things
98 if t != self.thing and t.position == self.thing.position][0]
99 self.thing.carrying = to_pick_up
103 class Task_DROP(Task):
107 if not self.thing.carrying:
108 raise PlayError('nothing to drop')
111 self.thing.carrying = None