Skip to content

Commit

Permalink
fix?
Browse files Browse the repository at this point in the history
  • Loading branch information
selkirks committed Jan 19, 2025
1 parent 7ff12ea commit 74aecaa
Show file tree
Hide file tree
Showing 3 changed files with 224 additions and 124 deletions.
71 changes: 44 additions & 27 deletions scripts/events_module/relationship/pregnancy_events.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import random
from random import choice, randint
from typing import Dict, List, Union, Optional

import i18n
import ujson

from scripts.cat.cats import Cat
from scripts.cat.enums import CatAgeEnum
Expand All @@ -19,17 +19,26 @@
get_personality_compatibility,
change_relationship_values,
get_alive_status_cats,
adjust_list_text,
)
from scripts.game_structure.localization import load_lang_resource


class Pregnancy_Events:
"""All events which are related to pregnancy such as kitting and defining who are the parents."""

biggest_family = {}
PREGNANT_STRINGS: Optional[Dict[str, Union[List, Dict[str, List]]]] = {}
currently_loaded_lang: str = None

PREGNANT_STRINGS = None
with open(f"resources/dicts/conditions/pregnancy.json", "r") as read_file:
PREGNANT_STRINGS = ujson.loads(read_file.read())
@staticmethod
def rebuild_strings():
if Pregnancy_Events.currently_loaded_lang == i18n.config.get("locale"):
return
Pregnancy_Events.PREGNANT_STRINGS = load_lang_resource(
"conditions/pregnancy.json"
)
Pregnancy_Events.currently_loaded_lang = i18n.config.get("locale")

@staticmethod
def set_biggest_family():
Expand Down Expand Up @@ -164,18 +173,18 @@ def handle_adoption(cat: Cat, other_cat=None, clan=game.clan):
amount, None, None, clan, adoptive_parents=adoptive_parents
)

insert = "this should not display"
insert2 = "this should not display"
if amount == 1:
insert = "a single kitten"
insert2 = "it"
if amount > 1:
insert = f"a litter of {amount} kits"
insert2 = "them"

print_event = f"{cat.name} found {insert} and decides to adopt {insert2}."
event = "hardcoded.adoption_kittens_single"
cats_names = str(cat.name)
if other_cat:
print_event = f"{cat.name} and {other_cat.name} found {insert} and decided to adopt {insert2}."
event = "hardcoded.adoption_kittens_pair"
cats_names = adjust_list_text([str(cat.name), str(other_cat.name)])

print_event = i18n.t(
event,
names=cats_names,
insert=i18n.t("conditions.pregnancy.kit_amount", count=amount),
count=amount,
)

cats_involved = {"m_c": cat}
if other_cat:
Expand Down Expand Up @@ -214,6 +223,8 @@ def handle_zero_moon_pregnant(cat: Cat, other_cat=None, clan=game.clan):
if (cat and cat.no_kits) or (other_cat and other_cat.no_kits):
return

Pregnancy_Events.rebuild_strings()

if clan.clan_settings["same sex birth"]:
# 50/50 for single cats to get pregnant or just bring a litter back
if not other_cat and random.randint(0, 1):
Expand Down Expand Up @@ -327,6 +338,8 @@ def handle_one_moon_pregnant(cat: Cat, clan=game.clan):
else:
correct_guess = "large"

Pregnancy_Events.rebuild_strings()

if thinking_amount[0] == "correct":
if correct_guess == "small":
text = Pregnancy_Events.PREGNANT_STRINGS["litter_guess"][0]
Expand Down Expand Up @@ -397,17 +410,15 @@ def handle_two_moon_pregnant(cat: Cat, clan=game.clan):
kit.relationships = {}
kit.create_one_relationship(cat)

if kits_amount == 1:
insert = "single kitten"
else:
insert = f"litter of {kits_amount} kits"
insert = i18n.t("conditions.pregnancy.kit_amount", count=kits_amount)

# Since cat has given birth, apply the birth cooldown.
cat.birth_cooldown = game.config["pregnancy"]["birth_cooldown"]

# choose event string
# TODO: currently they don't choose which 'mate' is the 'blood' parent or not
# change or leaf as it is?
Pregnancy_Events.rebuild_strings()
events = Pregnancy_Events.PREGNANT_STRINGS
event_list = []
if not cat.outside and other_cat is None:
Expand Down Expand Up @@ -476,18 +487,24 @@ def handle_two_moon_pregnant(cat: Cat, clan=game.clan):
if cat.status == "leader":
clan.leader_lives -= 1
cat.die()
death_event = "died shortly after kitting"
death_event = i18n.t("conditions.pregnancy.leader_kitting_death")
else:
cat.die()
death_event = f"{cat.name} died while kitting."
death_event = i18n.t(
"conditions.pregnancy.kitting_death", name=cat.name
)
History.add_death(cat, death_text=death_event)
elif not cat.outside: # if cat doesn't die, give recovering from birth
cat.get_injured("recovering from birth", event_triggered=True)
if "blood loss" in cat.injuries:
if cat.status == "leader":
death_event = "died after a harsh kitting"
death_event = i18n.t(
"conditions.pregnancy.leader_kitting_death_severe"
)
else:
death_event = f"{cat.name} died after a harsh kitting."
death_event = i18n.t(
"conditions.pregnancy.kitting_death_harsh", name=cat.name
)
History.add_possible_history(cat, "blood loss", death_text=death_event)
possible_events = events["birth"]["difficult_birth"]
# just makin sure meds aren't mentioned if they aren't around or if they are a parent
Expand Down Expand Up @@ -784,10 +801,10 @@ def get_kits(
# No parents provided, give a blood parent - this is an adoption.
if not blood_parent:
# Generate a blood parent if we haven't already.
insert = "their kits are"
if kits_amount == 1:
insert = "their kit is"
thought = f"Is glad that {insert} safe"
thought = i18n.t(
"conditions.pregnancy.halfblood_kitting_thought",
count=kits_amount,
)
blood_parent = create_new_cat(
Cat,
status=random.choice(["loner", "kittypet"]),
Expand Down
Loading

0 comments on commit 74aecaa

Please sign in to comment.