1 from plomrogue.errors import GameError
2 from plomrogue.misc import quote
9 def __init__(self, thing, args=()):
17 def get_args_string(self):
21 stringed_args += [quote(arg)]
22 elif type(arg) == int:
23 stringed_args += [str(arg)]
25 raise GameError('stringifying arg type not implemented')
26 return ' '.join(stringed_args)
30 class Task_WAIT(Task):
37 class Task_MOVE(Task):
38 argtypes = 'string:direction'
42 self.thing.world.maps[(0,0)].
43 move(self.thing.position[1], self.args[0]))
44 if test_pos == ((0,0), None):
45 raise GameError('would move outside map bounds')
46 if self.thing.world.maps[test_pos[0]][test_pos[1]] != '.':
47 raise GameError('%s would move into illegal terrain' % self.thing.id_)
48 for t in self.thing.world.things_at_pos(test_pos):
50 raise GameError('%s would move into other thing' % self.thing.id_)
53 self.thing.position = (0,0), self.thing.world.maps[(0,0)].\
54 move(self.thing.position[1], self.args[0])
55 for id_ in self.thing.inventory:
56 t = self.thing.world.get_thing(id_)
57 t.position = self.thing.position
61 class Task_PICKUP(Task):
62 argtypes = 'int:nonneg'
65 to_pick_up = self.thing.world.get_thing(self.args[0],
67 if to_pick_up is None or \
68 to_pick_up.id_ not in self.thing.get_pickable_items():
69 raise GameError('thing of ID %s not in reach to pick up'
73 to_pick_up = self.thing.world.get_thing(self.args[0])
74 self.thing.inventory += [self.args[0]]
75 to_pick_up.in_inventory = True
76 to_pick_up.position = self.thing.position
80 class TaskOnInventoryItem(Task):
81 argtypes = 'int:nonneg'
83 def _basic_inventory_item_check(self):
84 item = self.thing.world.get_thing(self.args[0], create_unfound=False)
86 raise GameError('no thing of ID %s' % self.args[0])
87 if item.id_ not in self.thing.inventory:
88 raise GameError('no thing of ID %s in inventory' % self.args[0])
91 def _eliminate_from_inventory(self):
92 item = self.thing.world.get_thing(self.args[0])
93 del self.thing.inventory[self.thing.inventory.index(item.id_)]
94 item.in_inventory = False
99 class Task_DROP(TaskOnInventoryItem):
100 argtypes = 'int:nonneg'
103 self._basic_inventory_item_check()
106 self._eliminate_from_inventory()
110 class Task_EAT(TaskOnInventoryItem):
111 argtypes = 'int:nonneg'
114 to_eat = self._basic_inventory_item_check()
115 if to_eat.type_ != 'food':
116 raise GameError('thing of ID %s s not food' % self.args[0])
119 to_eat = self._eliminate_from_inventory()
120 del self.thing.world.things[self.thing.world.things.index(to_eat)]
121 self.thing.health += 50