From 1ed0aedd6fcbceef8c2e71cde09c09c9a4bf11df Mon Sep 17 00:00:00 2001 From: Jason Weston Date: Mon, 26 Oct 2020 20:12:17 -0400 Subject: [PATCH 1/3] pacifist --- light/graph/elements/graph_nodes.py | 3 ++- light/graph/events/graph_events.py | 20 ++++++++++++++++++++ scripts/examples/simple_world.json | 1 + 3 files changed, 23 insertions(+), 1 deletion(-) diff --git a/light/graph/elements/graph_nodes.py b/light/graph/elements/graph_nodes.py index 4fa397554..7ef5ce2fd 100644 --- a/light/graph/elements/graph_nodes.py +++ b/light/graph/elements/graph_nodes.py @@ -537,13 +537,14 @@ def __init__(self, node_id, name, props=None, db_id=None): self.dead = self._props.get("dead") self.is_player = self._props.get("is_player", False) self.usually_npc = self._props.get("usually_npc", False) + self.pacifist = self._props.get("pacificist", False) self.following = None self.followed_by = {} self.blocking = None self.blocked_by = {} - + # Game properties to track for this agent, TODO move to other class? self._human = False self._current_player = None diff --git a/light/graph/events/graph_events.py b/light/graph/events/graph_events.py index 2bff3b2b9..82ef41f32 100644 --- a/light/graph/events/graph_events.py +++ b/light/graph/events/graph_events.py @@ -1081,6 +1081,15 @@ def __init__( self.attack = None self.defense = None + def is_not_pacifist(self, world): + if not self.actor.pacifist: + return True + self.pacifist = True + self.__self_view = "You couldn't do that, you are a pacifist!" + world.broadcast_to_agents(self, [self.actor]) + self.executed = True + return False + def execute(self, world: "World") -> List[GraphEvent]: """ On execution, have one agent hit another, calculating @@ -1089,6 +1098,12 @@ def execute(self, world: "World") -> List[GraphEvent]: If an agent died, trigger a death event. """ assert not self.executed + + self.pacifist = False + self.__successful_hit = self.is_not_pacifist(world) + if not self.__successful_hit: + return [] + # Populate for views self.__actor_name = self.actor.get_prefix_view() attack_target = self.target_nodes[0] @@ -1144,6 +1159,11 @@ def execute(self, world: "World") -> List[GraphEvent]: def view_as(self, viewer: GraphAgent) -> Optional[str]: """Provide the way that the given viewer should view this event""" + if self.pacifist: + if viewer == self.actor: + return self.__self_view + return "" + if self.attack == 0: # The attack missed if viewer == self.actor: diff --git a/scripts/examples/simple_world.json b/scripts/examples/simple_world.json index ee4552cc7..cd8cffb2e 100644 --- a/scripts/examples/simple_world.json +++ b/scripts/examples/simple_world.json @@ -52,6 +52,7 @@ "kitty_3_5": { "agent": true, "aggression": 0, + "pacificist": true, "char_type": "creature", "classes": [ "agent" From fe352d963b345321011e36701a03bf09fdf59b00 Mon Sep 17 00:00:00 2001 From: Jason Weston Date: Mon, 26 Oct 2020 20:12:42 -0400 Subject: [PATCH 2/3] pacifism --- light/graph/elements/graph_nodes.py | 2 +- light/graph/events/graph_events.py | 4 ++-- light/graph/structured_graph.py | 9 ++------- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/light/graph/elements/graph_nodes.py b/light/graph/elements/graph_nodes.py index 7ef5ce2fd..5795c3d31 100644 --- a/light/graph/elements/graph_nodes.py +++ b/light/graph/elements/graph_nodes.py @@ -544,7 +544,7 @@ def __init__(self, node_id, name, props=None, db_id=None): self.blocking = None self.blocked_by = {} - + # Game properties to track for this agent, TODO move to other class? self._human = False self._current_player = None diff --git a/light/graph/events/graph_events.py b/light/graph/events/graph_events.py index 82ef41f32..d2dddf250 100644 --- a/light/graph/events/graph_events.py +++ b/light/graph/events/graph_events.py @@ -1089,7 +1089,7 @@ def is_not_pacifist(self, world): world.broadcast_to_agents(self, [self.actor]) self.executed = True return False - + def execute(self, world: "World") -> List[GraphEvent]: """ On execution, have one agent hit another, calculating @@ -1163,7 +1163,7 @@ def view_as(self, viewer: GraphAgent) -> Optional[str]: if viewer == self.actor: return self.__self_view return "" - + if self.attack == 0: # The attack missed if viewer == self.actor: diff --git a/light/graph/structured_graph.py b/light/graph/structured_graph.py index 897a5c749..843ae2457 100644 --- a/light/graph/structured_graph.py +++ b/light/graph/structured_graph.py @@ -592,17 +592,12 @@ def from_worldbuilder_json(input_json: str): agents = {} for ind, props in entities["character"].items(): - n = g.add_agent( - props["name"], props, - uid=str(ind), - ) + n = g.add_agent(props["name"], props, uid=str(ind),) agents[int(ind)] = n objects = {} for ind, obj in entities["object"].items(): - n = g.add_object( - obj["name"], obj, uid=str(ind) - ) + n = g.add_object(obj["name"], obj, uid=str(ind)) objects[int(ind)] = n grid = {} From 4f90522d8f0bd43a6833498b2b07be8fd3ca4fdc Mon Sep 17 00:00:00 2001 From: Jason Weston Date: Mon, 26 Oct 2020 20:13:55 -0400 Subject: [PATCH 3/3] lint --- light/graph/elements/graph_nodes.py | 2 +- scripts/examples/simple_world.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/light/graph/elements/graph_nodes.py b/light/graph/elements/graph_nodes.py index 5795c3d31..456bac35c 100644 --- a/light/graph/elements/graph_nodes.py +++ b/light/graph/elements/graph_nodes.py @@ -537,7 +537,7 @@ def __init__(self, node_id, name, props=None, db_id=None): self.dead = self._props.get("dead") self.is_player = self._props.get("is_player", False) self.usually_npc = self._props.get("usually_npc", False) - self.pacifist = self._props.get("pacificist", False) + self.pacifist = self._props.get("pacifist", False) self.following = None self.followed_by = {} diff --git a/scripts/examples/simple_world.json b/scripts/examples/simple_world.json index cd8cffb2e..b08567e90 100644 --- a/scripts/examples/simple_world.json +++ b/scripts/examples/simple_world.json @@ -52,7 +52,7 @@ "kitty_3_5": { "agent": true, "aggression": 0, - "pacificist": true, + "pacifist": true, "char_type": "creature", "classes": [ "agent"