From: Christian Heller Date: Sun, 6 Jan 2019 18:51:38 +0000 (+0100) Subject: Give feedback on aborted tasks. X-Git-Url: https://plomlompom.com/repos/%7B%7Bdb.prefix%7D%7D/%7B%7B%20web_path%20%7D%7D/reset_cookie?a=commitdiff_plain;h=71a615834e518a028e246d072d8bd5931e78405b;p=plomrogue2-experiments Give feedback on aborted tasks. --- diff --git a/server.py b/server.py index 5847a54..7e2d80d 100755 --- a/server.py +++ b/server.py @@ -180,6 +180,8 @@ class CommandHandler(game_common.Commander, server_.game.Commander): """ self.send_all('TURN_FINISHED ' + str(self.world.turn)) self.world.proceed_to_next_player_turn() + msg = str(self.world.get_player().last_task_result) + self.send_all('LAST_PLAYER_TASK_RESULT ' + msg) self.send_all_gamestate() def cmd_FIB(self, numbers, connection_id): diff --git a/server_/game.py b/server_/game.py index 974de92..878917f 100644 --- a/server_/game.py +++ b/server_/game.py @@ -1,6 +1,7 @@ import sys sys.path.append('../') import game_common +import parser class GameError(Exception): @@ -60,7 +61,7 @@ class Task: self.thing = thing self.args = args self.kwargs = kwargs - self.todo = 1 + self.todo = 3 def check(self): if self.name == 'move': @@ -85,12 +86,14 @@ class Thing(game_common.Thing): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.task = Task(self, 'wait') + self.last_task_result = None def task_wait(self): - pass + return 'success' def task_move(self, direction): move_pos(direction, self.position) + return 'success' def decide_task(self): if self.position[1] > 1: @@ -116,15 +119,16 @@ class Thing(game_common.Thing): """ try: self.task.check() - except GameError: + except GameError as e: self.task = None + self.last_task_result = e if is_AI: self.decide_task() return self.task.todo -= 1 if self.task.todo <= 0: task = getattr(self, 'task_' + self.task.name) - task(*self.task.args, **self.task.kwargs) + self.last_task_result = task(*self.task.args, **self.task.kwargs) self.task = None if is_AI and self.task is None: self.decide_task()