1 from plomrogue.errors import GameError
2 from plomrogue.misc import quote
3 from plomrogue.mapping import YX
10 def __init__(self, thing, args=()):
18 def get_args_string(self):
22 stringed_args += [quote(arg)]
23 elif type(arg) == int:
24 stringed_args += [str(arg)]
26 raise GameError('stringifying arg type not implemented')
27 return ' '.join(stringed_args)
31 class Task_WAIT(Task):
38 class Task_MOVE(Task):
39 argtypes = 'string:direction'
43 self.thing.world.maps[YX(0,0)].
44 move(self.thing.position[1], self.args[0]))
45 if test_pos == (YX(0,0), None):
46 raise GameError('would move outside map bounds')
47 if self.thing.world.maps[test_pos[0]][test_pos[1]] != '.':
48 raise GameError('%s would move into illegal terrain' % self.thing.id_)
49 for t in self.thing.world.things_at_pos(test_pos):
51 raise GameError('%s would move into other thing' % self.thing.id_)
54 self.thing.position = YX(0,0), self.thing.world.maps[YX(0,0)].\
55 move(self.thing.position[1], self.args[0])
59 class Task_PICKUP(Task):
60 argtypes = 'int:nonneg'
63 to_pick_up = self.thing.world.get_thing(self.args[0],
65 if to_pick_up is None or \
66 to_pick_up.id_ not in self.thing.get_pickable_items():
67 raise GameError('thing of ID %s not in reach to pick up'
71 to_pick_up = self.thing.world.get_thing(self.args[0])
72 self.thing.inventory += [self.args[0]]
73 to_pick_up.in_inventory = True
74 to_pick_up.position = self.thing.position
78 class TaskOnInventoryItem(Task):
79 argtypes = 'int:nonneg'
81 def _basic_inventory_item_check(self):
82 item = self.thing.world.get_thing(self.args[0], create_unfound=False)
84 raise GameError('no thing of ID %s' % self.args[0])
85 if item.id_ not in self.thing.inventory:
86 raise GameError('no thing of ID %s in inventory' % self.args[0])
89 def _eliminate_from_inventory(self):
90 item = self.thing.world.get_thing(self.args[0])
91 del self.thing.inventory[self.thing.inventory.index(item.id_)]
92 item.in_inventory = False
97 class Task_DROP(TaskOnInventoryItem):
98 argtypes = 'int:nonneg'
101 self._basic_inventory_item_check()
104 self._eliminate_from_inventory()
108 class Task_EAT(TaskOnInventoryItem):
109 argtypes = 'int:nonneg'
112 to_eat = self._basic_inventory_item_check()
113 if to_eat.type_ != 'food':
114 raise GameError('thing of ID %s s not food' % self.args[0])
117 to_eat = self._eliminate_from_inventory()
118 del self.thing.world.things[self.thing.world.things.index(to_eat)]
119 self.thing.health += 50