1 from plomrogue.errors import PlayError, GameError
2 from plomrogue.mapping import YX
10 def __init__(self, thing, args=()):
19 class Task_WAIT(Task):
27 class Task_MOVE(Task):
29 argtypes = 'string:direction'
31 def get_move_target(self):
32 return self.thing.game.map_geometry.move_yxyx(self.thing.position,
36 test_yxyx = self.get_move_target()
37 if test_yxyx in [t.position for t in self.thing.game.things
39 raise PlayError('blocked by other thing')
40 elif self.thing.game.maps[test_yxyx[0]][test_yxyx[1]] != '.':
41 raise PlayError('blocked by impassable tile')
44 self.thing.position = self.get_move_target()
45 if self.thing.carrying:
46 self.thing.carrying.position = self.thing.position
50 class Task_WRITE(Task):
52 argtypes = 'string:char string'
55 if not self.thing.game.can_do_tile_with_pw(*self.thing.position,
57 raise GameError('wrong password for tile')
60 big_yx = self.thing.position[0]
61 little_yx = self.thing.position[1]
62 self.thing.game.maps[big_yx][little_yx] = self.args[0]
66 class Task_FLATTEN_SURROUNDINGS(Task):
74 for yxyx in[self.thing.position] + \
75 list(self.thing.game.map_geometry.get_neighbors_yxyx(self.thing.position).values()):
76 if not self.thing.game.can_do_tile_with_pw(*yxyx, self.args[0]):
78 self.thing.game.maps[yxyx[0]][yxyx[1]] = '.'
82 class Task_PICK_UP(Task):
86 if self.thing.carrying:
87 raise PlayError('already carrying something')
88 nothing_to_pick_up = True
89 for t in [t for t in self.thing.game.things
90 if t != self.thing and t.position == self.thing.position
91 and t.type_ != 'Player']:
92 nothing_to_pick_up = False
94 if nothing_to_pick_up:
95 raise PlayError('nothing to pick up')
98 to_pick_up = [t for t in self.thing.game.things
99 if t != self.thing and t.position == self.thing.position][0]
100 self.thing.carrying = to_pick_up
104 class Task_DROP(Task):
108 if not self.thing.carrying:
109 raise PlayError('nothing to drop')
112 self.thing.carrying = None