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])
58 class Task_PICKUP(Task):
59 argtypes = 'int:nonneg'
62 to_pick_up = self.thing.world.get_thing(self.args[0],
64 if to_pick_up is None or \
65 to_pick_up.id_ not in self.thing.get_pickable_items():
66 raise GameError('thing of ID %s not in reach to pick up'
70 to_pick_up = self.thing.world.get_thing(self.args[0])
71 self.thing.inventory += [self.args[0]]
72 to_pick_up.in_inventory = True
73 to_pick_up.position = self.thing.position
77 class TaskOnInventoryItem(Task):
78 argtypes = 'int:nonneg'
80 def _basic_inventory_item_check(self):
81 item = self.thing.world.get_thing(self.args[0], create_unfound=False)
83 raise GameError('no thing of ID %s' % self.args[0])
84 if item.id_ not in self.thing.inventory:
85 raise GameError('no thing of ID %s in inventory' % self.args[0])
88 def _eliminate_from_inventory(self):
89 item = self.thing.world.get_thing(self.args[0])
90 del self.thing.inventory[self.thing.inventory.index(item.id_)]
91 item.in_inventory = False
96 class Task_DROP(TaskOnInventoryItem):
97 argtypes = 'int:nonneg'
100 self._basic_inventory_item_check()
103 self._eliminate_from_inventory()
107 class Task_EAT(TaskOnInventoryItem):
108 argtypes = 'int:nonneg'
111 to_eat = self._basic_inventory_item_check()
112 if to_eat.type_ != 'food':
113 raise GameError('thing of ID %s s not food' % self.args[0])
116 to_eat = self._eliminate_from_inventory()
117 del self.thing.world.things[self.thing.world.things.index(to_eat)]
118 self.thing.health += 50