home · contact · privacy
Fix various minor, mostly "unused" flake8 complaints.
[plomrogue2] / plomrogue / tasks.py
1 from plomrogue.errors import PlayError, GameError
2
3
4
5 class Task:
6     argtypes = ''
7     todo = 3
8
9     def __init__(self, thing, args=()):
10         self.thing = thing
11         self.args = args
12
13     def check(self):
14         pass
15
16
17
18 class Task_WAIT(Task):
19     todo = 1
20
21     def do(self):
22         pass
23
24
25
26 class Task_MOVE(Task):
27     todo = 1
28     argtypes = 'string:direction'
29
30     def get_move_target(self):
31         return self.thing.game.map_geometry.move_yxyx(self.thing.position,
32                                                       self.args[0])
33
34     def check(self):
35         test_yxyx = self.get_move_target()
36         if test_yxyx in [t.position for t in self.thing.game.things
37                          if t.blocking]:
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')
41
42     def do(self):
43         self.thing.position = self.get_move_target()
44         if self.thing.carrying:
45             self.thing.carrying.position = self.thing.position
46
47
48
49 class Task_WRITE(Task):
50     todo = 1
51     argtypes = 'string:char string'
52
53     def check(self):
54         if not self.thing.game.can_do_tile_with_pw(*self.thing.position,
55                                                    self.args[1]):
56             raise GameError('wrong password for tile')
57
58     def do(self):
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]
62
63
64
65 class Task_FLATTEN_SURROUNDINGS(Task):
66     todo = 10
67     argtypes = 'string'
68
69     def check(self):
70         pass
71
72     def do(self):
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]):
76                 continue
77             self.thing.game.maps[yxyx[0]][yxyx[1]] = '.'
78
79
80
81 class Task_PICK_UP(Task):
82     todo = 1
83
84     def check(self):
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
92             break
93         if nothing_to_pick_up:
94             raise PlayError('nothing to pick up')
95
96     def do(self):
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
100
101
102
103 class Task_DROP(Task):
104     todo = 1
105
106     def check(self):
107         if not self.thing.carrying:
108             raise PlayError('nothing to drop')
109
110     def do(self):
111         self.thing.carrying = None