Skip to content

Commit

Permalink
version 2.1.1 fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ShiJbey committed Oct 30, 2023
1 parent 05fd100 commit 4f5930c
Show file tree
Hide file tree
Showing 10 changed files with 457 additions and 147 deletions.
11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,17 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
[Semantic Versioning](https://semver.org/spec/v2.0.0.html). However, all releases before 1.0.0 have breaking changes
between minor-version updates.

## [2.1.1] - 2023-30-10

### Fixed

- `open_to_public` field now adds `OpenToPublic` component to help locations appear as candidates
to be frequented by characters.
- `monthly_effects` associated with job roles are now applied every timestep.
- Relationships are deactivated when a character departs or dies.
- Characters cannot gain the `lethargic` and `energetic` traits at the same time.
- Replaced `Event` type hints for `GlobalEventHistory` with `LifeEvent`.

## [2.1.0] - 2023-29-10

### Added
Expand Down
530 changes: 389 additions & 141 deletions notebooks/basic_simulation.ipynb

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/neighborly/__version__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@

MAJOR_VERSION = 2
MINOR_VERSION = 1
PATCH_VERSION = 0
PATCH_VERSION = 1
VERSION = f"{MAJOR_VERSION}.{MINOR_VERSION}.{PATCH_VERSION}"
5 changes: 4 additions & 1 deletion src/neighborly/defs/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

import attrs

from neighborly.components.business import Business, JobRole
from neighborly.components.business import Business, JobRole, OpenToPublic
from neighborly.components.character import Character, LifeStage, Sex, Species
from neighborly.components.location import (
FrequentedBy,
Expand Down Expand Up @@ -824,6 +824,9 @@ def initialize(self, district: GameObject, business: GameObject) -> None:

self.initialize_name(business)

if self.open_to_public:
business.add_component(OpenToPublic())

for trait in self.traits:
add_trait(business, trait)

Expand Down
6 changes: 5 additions & 1 deletion src/neighborly/events/defaults.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
remove_all_frequenting_characters,
remove_frequented_location,
)
from neighborly.helpers.relationship import get_relationship
from neighborly.helpers.relationship import deactivate_relationships, get_relationship
from neighborly.helpers.traits import add_trait, has_trait, remove_trait
from neighborly.life_event import EventRole, LifeEvent

Expand All @@ -44,6 +44,8 @@ def execute(self) -> None:
character.deactivate()
add_trait(character, "deceased")

deactivate_relationships(character)

# Remove the character from their residence
if resident_data := character.try_component(Resident):
residence = resident_data.residence
Expand Down Expand Up @@ -448,6 +450,8 @@ def execute(self) -> None:
add_trait(character, "departed")
character.deactivate()

deactivate_relationships(character)

# Have the character leave their job
if occupation := character.try_component(Occupation):
if occupation.business.get_component(Business).owner == character:
Expand Down
12 changes: 12 additions & 0 deletions src/neighborly/helpers/relationship.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,3 +218,15 @@ def remove_all_social_rules_from_source(gameobject: GameObject, source: object)
for rule in rules:
if rule.source == source:
remove_social_rule(gameobject, rule)


def deactivate_relationships(gameobject: GameObject) -> None:
"""Deactivates all an objects incoming and outgoing relationships."""

relationships = gameobject.get_component(Relationships)

for _, relationship in relationships.outgoing.items():
relationship.deactivate()

for _, relationship in relationships.incoming.items():
relationship.deactivate()
4 changes: 2 additions & 2 deletions src/neighborly/life_event.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,8 +414,8 @@ def to_dict(self) -> dict[str, Any]:
"""Serialize object into JSON-serializable dict."""
return {str(key): entry.to_dict() for key, entry in self._history.items()}

def __iter__(self) -> Iterator[Event]:
def __iter__(self) -> Iterator[LifeEvent]:
return self._history.values().__iter__()

def __getitem__(self, key: int) -> Event:
def __getitem__(self, key: int) -> LifeEvent:
return self._history[key]
6 changes: 6 additions & 0 deletions src/neighborly/plugins/data/traits.json
Original file line number Diff line number Diff line change
Expand Up @@ -555,6 +555,9 @@
"modifier_type": "FLAT"
}
],
"conflicts_with": [
"lethargic"
],
"spawn_frequency": 2,
"inheritance_chance_single": 0.3,
"inheritance_chance_both": 0.6
Expand All @@ -570,6 +573,9 @@
"modifier_type": "FLAT"
}
],
"conflicts_with": [
"energetic"
],
"spawn_frequency": 1,
"inheritance_chance_single": 0.3,
"inheritance_chance_both": 0.6
Expand Down
4 changes: 4 additions & 0 deletions src/neighborly/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
InstantiateJobRolesSystem,
InstantiateSkillsSystem,
InstantiateTraitsSystem,
JobRoleMonthlyEffectsSystem,
LateUpdateSystems,
LifeEventSystem,
MeetNewPeopleSystem,
Expand Down Expand Up @@ -195,6 +196,9 @@ def _init_systems(self) -> None:
self.world.system_manager.add_system(
system=PassiveRomanceChange(), system_group=UpdateSystems
)
self.world.system_manager.add_system(
system=JobRoleMonthlyEffectsSystem(), system_group=UpdateSystems
)
self.world.system_manager.add_system(
system=DeathSystem(), system_group=UpdateSystems
)
Expand Down
24 changes: 23 additions & 1 deletion src/neighborly/systems.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@

import polars as pl

from neighborly.components.business import Business, OpenToPublic, PendingOpening
from neighborly.components.business import (
Business,
Occupation,
OpenToPublic,
PendingOpening,
)
from neighborly.components.character import Character, LifeStage, Pregnant, Species
from neighborly.components.location import (
FrequentedBy,
Expand Down Expand Up @@ -756,3 +761,20 @@ def on_update(self, world: World) -> None:
get_relationship(acquaintance, character.gameobject),
"interaction_score",
).base_value += candidate_scores[acquaintance]


class JobRoleMonthlyEffectsSystem(System):
"""This system applies monthly effects associated with character's job roles.
Unlike the normal effects, monthly effects are not reversed when the character
leaves the role. The changes are permanent. This system is meant to give characters
a way of increasing specific skill points the longer they work at a job. This way
higher level jobs can require characters to meet skill thresholds.
"""

def on_update(self, world: World) -> None:
for _, (character, occupation, _) in world.get_components(
(Character, Occupation, Active)
):
for effect in occupation.job_role.monthly_effects:
effect.apply(character.gameobject)

0 comments on commit 4f5930c

Please sign in to comment.