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(
75 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
91 and t != self.thing and t.position == self.thing.position and
93 nothing_to_pick_up = False
95 if nothing_to_pick_up:
96 raise PlayError('nothing to pick up')
99 to_pick_up = [t for t in self.thing.game.things
101 and t != self.thing and t.position == self.thing.position][0]
102 self.thing.carrying = to_pick_up
106 class Task_DROP(Task):
110 if not self.thing.carrying:
111 raise PlayError('nothing to drop')
114 self.thing.carrying = None