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

Pacificism #108

Merged
merged 3 commits into from
Oct 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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