1 from plomrogue.errors import GameError
2 from plomrogue.mapping import YX
9 def __init__(self, game, id_=None, position=(YX(0,0))):
12 self.id_ = self.game.new_thing_id()
15 self.position = position
19 class Thing(ThingBase):
21 def __init__(self, *args, **kwargs):
22 super().__init__(*args, **kwargs)
29 class ThingAnimate(Thing):
31 def __init__(self, *args, **kwargs):
32 super().__init__(*args, **kwargs)
36 def set_task(self, task_name, args=()):
37 task_class = self.game.tasks[task_name]
38 self.task = task_class(self, args)
39 self.task.check() # will throw GameError if necessary
41 def set_next_task(self, task_name, args=()):
42 task_class = self.game.tasks[task_name]
43 self.next_tasks += [task_class(self, args)]
45 def get_next_task(self):
46 if len(self.next_tasks) > 0:
47 task = self.next_tasks.pop(0)
55 self.task = self.get_next_task()
60 except GameError as e:
65 if self.task.todo <= 0:
66 self._last_task_result = self.task.do()
67 self.game.changed = True
68 self.task = self.get_next_task()
72 class ThingPlayer(ThingAnimate):
75 def __init__(self, *args, **kwargs):
76 super().__init__(*args, **kwargs)
77 self.nickname = 'undefined'