Skip to content
This repository has been archived by the owner on Oct 11, 2023. It is now read-only.

Commit

Permalink
Merge pull request #108 from facebookresearch/pacificist
Browse files Browse the repository at this point in the history
Pacificism
  • Loading branch information
jaseweston authored Oct 27, 2020
2 parents 40d1749 + 4f90522 commit 02722ae
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
1 change: 1 addition & 0 deletions light/graph/elements/graph_nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -537,6 +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("pacifist", False)

self.following = None
self.followed_by = {}
Expand Down
20 changes: 20 additions & 0 deletions light/graph/events/graph_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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]
Expand Down Expand Up @@ -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:
Expand Down
9 changes: 2 additions & 7 deletions light/graph/structured_graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}
Expand Down
1 change: 1 addition & 0 deletions scripts/examples/simple_world.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
"kitty_3_5": {
"agent": true,
"aggression": 0,
"pacifist": true,
"char_type": "creature",
"classes": [
"agent"
Expand Down

0 comments on commit 02722ae

Please sign in to comment.