X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=new2%2Fplomrogue%2Fthings.py;fp=new2%2Fplomrogue%2Fthings.py;h=138a1fac7ccdcd1ba0603023f478cd7d92b1b9bb;hb=33bfdaf647c6736d99aadc017ee935f3301d758a;hp=0000000000000000000000000000000000000000;hpb=2f73d4246c98d4b25d18d0faa987d9ed165a48ae;p=plomrogue2-experiments diff --git a/new2/plomrogue/things.py b/new2/plomrogue/things.py new file mode 100644 index 0000000..138a1fa --- /dev/null +++ b/new2/plomrogue/things.py @@ -0,0 +1,78 @@ +from plomrogue.errors import GameError +from plomrogue.mapping import YX + + + +class ThingBase: + type_ = '?' + + def __init__(self, game, id_=None, position=(YX(0,0))): + self.game = game + if id_ is None: + self.id_ = self.game.new_thing_id() + else: + self.id_ = id_ + self.position = position + + + +class Thing(ThingBase): + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + + def proceed(self): + pass + + + +class ThingAnimate(Thing): + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.next_tasks = [] + self.set_task('WAIT') + + def set_task(self, task_name, args=()): + task_class = self.game.tasks[task_name] + self.task = task_class(self, args) + self.task.check() # will throw GameError if necessary + + def set_next_task(self, task_name, args=()): + task_class = self.game.tasks[task_name] + self.next_tasks += [task_class(self, args)] + + def get_next_task(self): + if len(self.next_tasks) > 0: + task = self.next_tasks.pop(0) + task.check() + return task + else: + return None + + def proceed(self): + if self.task is None: + self.task = self.get_next_task() + return + + try: + self.task.check() + except GameError as e: + self.task = None + raise GameError + return + self.task.todo -= 1 + if self.task.todo <= 0: + self._last_task_result = self.task.do() + self.game.changed = True + self.task = self.get_next_task() + + + +class ThingPlayer(ThingAnimate): + type_ = 'player' + + def __init__(self, *args, **kwargs): + super().__init__(*args, **kwargs) + self.nickname = 'undefined' +