X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=server_%2Ftasks.py;fp=server_%2Ftasks.py;h=f07828d44439f3a9ce31d12bed971ffb6fa66a29;hb=52463b31fbb7f121a52f72e863a779560a6de531;hp=0000000000000000000000000000000000000000;hpb=9f42c96bb32044e5030cca15c8b72e69b16a8508;p=plomrogue2-experiments diff --git a/server_/tasks.py b/server_/tasks.py new file mode 100644 index 0000000..f07828d --- /dev/null +++ b/server_/tasks.py @@ -0,0 +1,69 @@ +from server_.game_error import GameError + + + +class TaskManager: + + def __init__(self, task_classes): + self.task_classes = task_classes + + def get_task_class(self, task_name): + for task_class in self.task_classes: + if task_class.__name__ == 'Task_' + task_name: + return task_class + return None + + +class Task: + argtypes = '' + + def __init__(self, thing, args=()): + self.thing = thing + self.args = args + self.todo = 3 + + @property + def name(self): + prefix = 'Task_' + class_name = self.__class__.__name__ + return class_name[len(prefix):] + + def check(self): + pass + + def get_args_string(self): + stringed_args = [] + for arg in self.args: + if type(arg) == str: + stringed_args += [server_.io.quote(arg)] + else: + raise GameError('stringifying arg type not implemented') + return ' '.join(stringed_args) + + + +class Task_WAIT(Task): + + def do(self): + return 'success' + + + +class Task_MOVE(Task): + argtypes = 'string:direction' + + def check(self): + test_pos = self.thing.world.map_.move(self.thing.position, self.args[0]) + if self.thing.world.map_[test_pos] != '.': + raise GameError('%s would move into illegal terrain' % self.thing.id_) + for t in self.thing.world.things: + if t.position == test_pos: + raise GameError('%s would move into other thing' % self.thing.id_) + + def do(self): + self.thing.position = self.thing.world.map_.move(self.thing.position, + self.args[0]) + + + +task_manager = TaskManager((Task_WAIT, Task_MOVE))