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'
41 def get_move_target(self):
42 return self.thing.world.game.map_geometry.move(self.thing.position,
44 self.thing.world.game.map_size)
47 test_pos = self.get_move_target()
48 if self.thing.world.maps[test_pos[0]][test_pos[1]] != '.':
49 raise GameError('%s would move into illegal terrain' % self.thing.id_)
50 for t in self.thing.world.things_at_pos(test_pos):
52 raise GameError('%s would move into other thing' % self.thing.id_)
55 self.thing.position = self.get_move_target()
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