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.game.map_geometry.move(self.thing.position,
44 self.thing.game.map_size)
47 test_pos = self.get_move_target()
48 if self.thing.game.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.game.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.game.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.game.get_thing(self.args[0],
73 self.thing.inventory += [self.args[0]]
74 to_pick_up.in_inventory = True
75 to_pick_up.position = self.thing.position
79 class TaskOnInventoryItem(Task):
80 argtypes = 'int:nonneg'
82 def _basic_inventory_item_check(self):
83 item = self.thing.game.get_thing(self.args[0], create_unfound=False)
85 raise GameError('no thing of ID %s' % self.args[0])
86 if item.id_ not in self.thing.inventory:
87 raise GameError('no thing of ID %s in inventory' % self.args[0])
90 def _eliminate_from_inventory(self):
91 item = self.thing.game.get_thing(self.args[0], create_unfound=False)
92 del self.thing.inventory[self.thing.inventory.index(item.id_)]
93 item.in_inventory = False
98 class Task_DROP(TaskOnInventoryItem):
99 argtypes = 'int:nonneg'
102 self._basic_inventory_item_check()
105 self._eliminate_from_inventory()
109 class Task_EAT(TaskOnInventoryItem):
110 argtypes = 'int:nonneg'
113 to_eat = self._basic_inventory_item_check()
114 if to_eat.type_ != 'food':
115 raise GameError('thing of ID %s s not food' % self.args[0])
118 to_eat = self._eliminate_from_inventory()
119 del self.thing.game.things[self.thing.game.things.index(to_eat)]
120 self.thing.health += 50