diff --git a/scripts/cat/cats.py b/scripts/cat/cats.py index d2170841bf..22754784e3 100644 --- a/scripts/cat/cats.py +++ b/scripts/cat/cats.py @@ -566,38 +566,24 @@ def die(self, body: bool = True): self.illnesses.clear() # Deal with leader death - text = "" darkforest = game.clan.instructor.df isoutside = self.outside if self.status == "leader": - if game.clan.leader_lives > 0: - lives_left = game.clan.leader_lives - death_thought = Thoughts.leader_death_thought( - self, lives_left, darkforest - ) - final_thought = event_text_adjust(self, death_thought, main_cat=self) - self.thought = final_thought - return "" - elif game.clan.leader_lives <= 0: + if game.clan.leader_lives <= 0: self.dead = True game.just_died.append(self.ID) game.clan.leader_lives = 0 - death_thought = Thoughts.leader_death_thought(self, 0, darkforest) - final_thought = event_text_adjust(self, death_thought, main_cat=self) - self.thought = final_thought - if game.clan.instructor.df is False: - text = ( - "They've lost their last life and have travelled to StarClan." - ) - else: - text = "They've lost their last life and have travelled to the Dark Forest." + death_thought = Thoughts.leader_death_thought(self, game.clan.leader_lives, darkforest) else: self.dead = True game.just_died.append(self.ID) death_thought = Thoughts.new_death_thought(self, darkforest, isoutside) - final_thought = event_text_adjust(self, death_thought, main_cat=self) - self.thought = final_thought + final_thought = event_text_adjust(self, death_thought, main_cat=self) + self.thought = final_thought + if not self.dead: + return "" + for app in self.apprentice.copy(): fetched_cat = Cat.fetch_cat(app) if fetched_cat: @@ -902,44 +888,23 @@ def status_change(self, new_status, resort=False): game.clan.remove_med_cat(self) # updates mentors - if self.status == "apprentice": - pass - - elif self.status == "medicine cat apprentice": + if (self.status == "apprentice" + or self.status == "medicine cat apprentice" + or self.status == "mediator" + or self.status == "mediator apprentice" + ): pass - - elif self.status == "warrior": - if old_status == "leader" and ( - game.clan.leader and game.clan.leader.ID == self.ID - ): + elif self.status == "warrior" or self.status == "elder": + if old_status == "leader" and game.clan.leader and game.clan.leader.ID == self.ID: game.clan.leader = None game.clan.leader_predecessors += 1 if game.clan and game.clan.deputy and game.clan.deputy.ID == self.ID: game.clan.deputy = None game.clan.deputy_predecessors += 1 - elif self.status == "medicine cat": if game.clan is not None: game.clan.new_medicine_cat(self) - elif self.status == "elder": - if ( - old_status == "leader" - and game.clan.leader - and game.clan.leader.ID == self.ID - ): - game.clan.leader = None - game.clan.leader_predecessors += 1 - - if game.clan.deputy and game.clan.deputy.ID == self.ID: - game.clan.deputy = None - game.clan.deputy_predecessors += 1 - - elif self.status == "mediator": - pass - - elif self.status == "mediator apprentice": - pass # update class dictionary self.all_cats[self.ID] = self @@ -954,10 +919,7 @@ def rank_change_traits_skill(self, mentor): if self.status in ["warrior", "medicine cat", "mediator"]: # Give a couple doses of mentor influence: if mentor: - max_influence = randint(0, 2) - i = 0 - while max_influence > i: - i += 1 + for _ in range(randint(0, 2)): affect_personality = self.personality.mentor_influence( Cat.fetch_cat(mentor).personality ) @@ -1199,101 +1161,60 @@ def generate_lead_ceremony(self): ) # if we have relations, then make sure we only take the top 8 - if dead_relations: - i = 0 - for rel in dead_relations: - if i == 8: - break - if rel.cat_to.status == "leader": - life_giving_leader = rel.cat_to - continue - life_givers.append(rel.cat_to.ID) - i += 1 + for i in range(min(8,len(dead_relations))): + if rel.cat_to.status == "leader": + life_giving_leader = rel.cat_to + continue + life_givers.append(rel.cat_to.ID) + # check amount of life givers, if we need more, then grab from the other dead cats if len(life_givers) < 8: amount = 8 - len(life_givers) if starclan: - # this part just checks how many SC cats are available, if there aren't enough to fill all the slots, - # then we just take however many are available - - possible_sc_cats = [ - i - for i in game.clan.starclan_cats - if self.fetch_cat(i) - and i not in life_givers - and self.fetch_cat(i).status not in ["leader", "newborn"] - ] + cats_in_starclan_or_darkforest = game.clan.starclan_cats + else: + cats_in_starclan_or_darkforest = game.clan.darkforest_cats + + possible_life_givers = [ + cat + for cat in cats_in_starclan_or_darkforest + if self.fetch_cat(cat) + and cat not in life_givers + and self.fetch_cat(cat).status not in ["leader", "newborn"] + ] - if len(possible_sc_cats) - 1 < amount: - extra_givers = possible_sc_cats - else: - extra_givers = sample(possible_sc_cats, k=amount) + if len(possible_life_givers) - 1 < amount: + extra_givers = possible_life_givers else: - possible_df_cats = [ - i - for i in game.clan.darkforest_cats - if self.fetch_cat(i) - and i not in life_givers - and self.fetch_cat(i).status not in ["leader", "newborn"] - ] - if len(possible_df_cats) - 1 < amount: - extra_givers = possible_df_cats - else: - extra_givers = sample(possible_df_cats, k=amount) + extra_givers = sample(possible_life_givers, k=amount) life_givers.extend(extra_givers) # making sure we have a leader at the end ancient_leader = False if not life_giving_leader: + if starclan: + cats_in_starclan_or_darkforest = game.clan.starclan_cats.copy() + else: + cats_in_starclan_or_darkforest = game.clan.darkforest_cats.copy() + # choosing if the life giving leader will be the oldest leader or previous leader - coin_flip = randint(1, 2) - if coin_flip == 1: + if randint(1, 2) == 1: # pick the oldest leader in SC ancient_leader = True - if starclan: - sc_cats = game.clan.starclan_cats.copy() - sc_cats.sort(key=lambda x: -1 * int(Cat.fetch_cat(x).dead_for)) - for kitty in sc_cats: - if ( - self.fetch_cat(kitty) - and self.fetch_cat(kitty).status == "leader" - ): - life_giving_leader = kitty - break - else: - df_kitties = game.clan.darkforest_cats.copy() - df_kitties.sort(key=lambda x: -1 * int(Cat.fetch_cat(x).dead_for)) - for kitty in df_kitties: - if ( - self.fetch_cat(kitty) - and self.fetch_cat(kitty).status == "leader" - ): - life_giving_leader = kitty - break + cats_in_starclan_or_darkforest.sort(key=lambda x: -1 * int(Cat.fetch_cat(x).dead_for)) else: # pick previous leader - if starclan: - sc_cats = game.clan.starclan_cats.copy() - sc_cats.sort(key=lambda x: int(Cat.fetch_cat(x).dead_for)) - for kitty in sc_cats: - if ( - self.fetch_cat(kitty) - and self.fetch_cat(kitty).status == "leader" - ): - life_giving_leader = kitty - break - else: - df_kitties = game.clan.darkforest_cats.copy() - df_kitties.sort(key=lambda x: int(Cat.fetch_cat(x).dead_for)) - for kitty in df_kitties: - if ( - self.fetch_cat(kitty) - and self.fetch_cat(kitty).status == "leader" - ): - life_giving_leader = kitty - break + cats_in_starclan_or_darkforest.sort(key=lambda x: int(Cat.fetch_cat(x).dead_for)) + + for kitty in cats_in_starclan_or_darkforest: + if ( + self.fetch_cat(kitty) + and self.fetch_cat(kitty).status == "leader" + ): + life_giving_leader = kitty + break if life_giving_leader: life_givers.append(life_giving_leader) @@ -1367,16 +1288,14 @@ def generate_lead_ceremony(self): continue life_list.extend(list(possible_lives[life]["life_giving"])) - i = 0 chosen_life = {} - while i < 10: + for _ in range(10): attempted = [] if life_list: chosen_life = choice(life_list) if chosen_life not in used_lives and chosen_life not in attempted: break attempted.append(chosen_life) - i += 1 else: print( f"WARNING: life list had no items for giver #{giver_cat.ID}. Using default life. " @@ -1389,7 +1308,7 @@ def generate_lead_ceremony(self): used_lives.append(chosen_life) if "virtue" in chosen_life: poss_virtues = [ - i for i in chosen_life["virtue"] if i not in used_virtues + poss_virtue for poss_virtue in chosen_life["virtue"] if poss_virtue not in used_virtues ] or ["faith", "friendship", "love", "strength"] virtue = choice(poss_virtues) used_virtues.append(virtue) @@ -1546,8 +1465,8 @@ def thoughts(self): while ( other_cat == self.ID and len(all_cats) > 1 - or (all_cats.get(other_cat).dead and dead_chance != 1) or (other_cat not in self.relationships) + or (all_cats.get(other_cat).dead and dead_chance != 1) ): other_cat = choice(list(all_cats.keys())) i += 1 @@ -1556,7 +1475,10 @@ def thoughts(self): break # for dead cats elif where_kitty in ["starclan", "hell", "UR"]: - while other_cat == self.ID and len(all_cats) > 1: + while ( + other_cat == self.ID + and len(all_cats) > 1 + ): other_cat = choice(list(all_cats.keys())) i += 1 if i > 100: @@ -1648,18 +1570,12 @@ def moon_skip_illness(self, illness): moons_with = game.clan.age - self.illnesses[illness]["moon_start"] - # focus buff - moons_prior = game.config["focus"]["rest and recover"]["moons_earlier_healed"] - - if self.illnesses[illness]["duration"] - moons_with <= 0: - self.healed_condition = True - return False - + moons_until_cured = self.illnesses[illness]["duration"] - moons_with # CLAN FOCUS! - if the focus 'rest and recover' is selected - elif ( - game.clan.clan_settings.get("rest and recover") - and self.illnesses[illness]["duration"] + moons_prior - moons_with <= 0 - ): + if(game.clan.clan_settings.get("rest and recover")): + moons_until_cured -= game.config["focus"]["rest and recover"]["moons_earlier_healed"] + + if moons_until_cured <= 0: self.healed_condition = True return False @@ -1685,28 +1601,18 @@ def moon_skip_injury(self, injury): game.clan.leader_lives -= 1 self.die() return False - - moons_with = game.clan.age - self.injuries[injury]["moon_start"] - - # focus buff - moons_prior = game.config["focus"]["rest and recover"]["moons_earlier_healed"] - + # if the cat has an infected wound, the wound shouldn't heal till the illness is cured - if ( - not self.injuries[injury]["complication"] - and self.injuries[injury]["duration"] - moons_with <= 0 - ): - self.healed_condition = True - return False - - # CLAN FOCUS! - if the focus 'rest and recover' is selected - elif ( - not self.injuries[injury]["complication"] - and game.clan.clan_settings.get("rest and recover") - and self.injuries[injury]["duration"] + moons_prior - moons_with <= 0 - ): - self.healed_condition = True - return False + if (not self.injuries[injury]["complication"]): + + moons_with = game.clan.age - self.injuries[injury]["moon_start"] + moons_until_healed = self.injuries[injury]["duration"] - moons_with + # CLAN FOCUS! - if the focus 'rest and recover' is selected + if(game.clan.clan_settings.get("rest and recover")): + moons_until_healed -= game.config["focus"]["rest and recover"]["moons_earlier_healed"] + if(moons_until_healed <= 0): + self.healed_condition = True + return False def moon_skip_permanent_condition(self, condition): """handles the moon skip for permanent conditions""" @@ -1854,9 +1760,7 @@ def get_ill(self, name, event_triggered=False, lethal=True, severity="default"): if medical_cats_condition_fulfilled(Cat.all_cats.values(), amount_per_med): duration = med_duration if severity != "minor": - duration += randrange(-1, 1) - if duration == 0: - duration = 1 + duration += clamp(duration + randrange(-1, 1), 1, duration + 1) if game.clan and game.clan.game_mode == "cruel season" and mortality != 0: mortality = int(mortality * 0.5) @@ -1924,9 +1828,7 @@ def get_injured(self, name, event_triggered=False, lethal=True, severity="defaul ): duration = med_duration if severity != "minor": - duration += randrange(-1, 1) - if duration == 0: - duration = 1 + duration += clamp(duration + randrange(-1, 1), 1, duration + 1) if mortality != 0 and (game.clan and game.clan.game_mode == "cruel season"): mortality = int(mortality * 0.5) @@ -2027,17 +1929,7 @@ def get_permanent_condition(self, name, born_with=False, event_triggered=False): return # remove accessories if need be - if "NOTAIL" in self.pelt.scars and self.pelt.accessory in [ - "RED FEATHERS", - "BLUE FEATHERS", - "JAY FEATHERS", - "GULL FEATHERS", - "SPARROW FEATHERS", - "CLOVER", - "DAISY", - ]: - self.pelt.accessory = None - if "HALFTAIL" in self.pelt.scars and self.pelt.accessory in [ + if ("NOTAIL" in self.pelt.scars or "HALFTAIL" in self.pelt.scars) and self.pelt.accessory in [ "RED FEATHERS", "BLUE FEATHERS", "JAY FEATHERS", @@ -2264,6 +2156,14 @@ def load_conditions(self): # ---------------------------------------------------------------------------- # def is_valid_mentor(self, potential_mentor: Cat): + + # If not an app, don't need a mentor + if "apprentice" not in self.status: + return False + # Dead cats don't need mentors + if self.dead or self.outside or self.exiled: + return False + # Dead or outside cats can't be mentors if potential_mentor.dead or potential_mentor.outside: return False @@ -2284,13 +2184,6 @@ def is_valid_mentor(self, potential_mentor: Cat): and potential_mentor.status != "mediator" ): return False - - # If not an app, don't need a mentor - if "apprentice" not in self.status: - return False - # Dead cats don't need mentors - if self.dead or self.outside or self.exiled: - return False return True def __remove_mentor(self): @@ -2520,26 +2413,25 @@ def set_mate(self, other_cat: Cat): if self.inheritance: self.inheritance.update_all_mates() + relationships = [] # Set starting relationship values if not self.dead: if other_cat.ID not in self.relationships: self.create_one_relationship(other_cat) self.relationships[other_cat.ID].mate = True - self_relationship = self.relationships[other_cat.ID] - self_relationship.romantic_love += 20 - self_relationship.comfortable += 20 - self_relationship.trust += 10 - self_relationship.mate = True + relationships.append(self.relationships[other_cat.ID]) if not other_cat.dead: if self.ID not in other_cat.relationships: other_cat.create_one_relationship(self) other_cat.relationships[self.ID].mate = True - other_relationship = other_cat.relationships[self.ID] - other_relationship.romantic_love += 20 - other_relationship.comfortable += 20 - other_relationship.trust += 10 - other_relationship.mate = True + relationships.append(other_cat.relationships[self.ID]) + + for relationship in relationships: + relationship.romantic_love += 20 + relationship.comfortable += 20 + relationship.trust += 10 + relationship.mate = True def unset_adoptive_parent(self, other_cat: Cat): """Unset the adoptive parent from self""" @@ -2567,22 +2459,22 @@ def set_adoptive_parent(self, other_cat: Cat): self.adoptive_parents.append(other_cat.ID) self.create_inheritance_new_cat() + relationships = [] # Set starting relationship values if not self.dead: if other_cat.ID not in self.relationships: self.create_one_relationship(other_cat) - self_relationship = self.relationships[other_cat.ID] - self_relationship.platonic_like += 20 - self_relationship.comfortable += 20 - self_relationship.trust += 10 + relationships.append(self.relationships[other_cat.ID]) if not other_cat.dead: if self.ID not in other_cat.relationships: other_cat.create_one_relationship(self) - other_relationship = other_cat.relationships[self.ID] - other_relationship.platonic_like += 20 - other_relationship.comfortable += 20 - other_relationship.trust += 10 + relationships.append(other_cat.relationships[self.ID]) + + for relationship in relationships: + relationship.platonic_like += 20 + relationship.comfortable += 20 + relationship.trust += 10 def create_inheritance_new_cat(self): """Creates the inheritance class for a new cat.""" @@ -2615,16 +2507,10 @@ def create_relationships_new_cat(self): # if they dead (dead cats have no relationships) if self.dead or inter_cat.dead: continue - # if they are not outside of the Clan at the same time - if ( - self.outside - and not inter_cat.outside - or not self.outside - and inter_cat.outside - ): - continue - inter_cat.relationships[self.ID] = Relationship(inter_cat, self) - self.relationships[inter_cat.ID] = Relationship(self, inter_cat) + # if they are outside of the Clan at the same time + if (self.outside and self.outside == inter_cat.outside): + inter_cat.relationships[self.ID] = Relationship(inter_cat, self) + self.relationships[inter_cat.ID] = Relationship(self, inter_cat) def init_all_relationships(self): """Create Relationships to all current Clancats.""" @@ -2779,17 +2665,17 @@ def load_relationship_of_cat(self): def mediate_relationship(mediator, cat1, cat2, allow_romantic, sabotage=False): # Gather some important info + relationships = [] # Gathering the relationships. if cat1.ID in cat2.relationships: - rel1 = cat1.relationships[cat2.ID] + relationships.append(cat1.relationships[cat2.ID]) else: - rel1 = cat1.create_one_relationship(cat2) + relationships.append(cat1.create_one_relationship(cat2)) if cat2.ID in cat1.relationships: - rel2 = cat2.relationships[cat1.ID] + relationships.append(cat2.relationships[cat1.ID]) else: - rel2 = cat2.create_one_relationship(cat1) - + relationships.append(cat2.create_one_relationship(cat1)) # Output string. output = "" @@ -2838,11 +2724,13 @@ def mediate_relationship(mediator, cat1, cat2, allow_romantic, sabotage=False): if mediator.status != "mediator apprentice": exp_gain = randint(10, 24) - gm_modifier = 1 + if game.clan and game.clan.game_mode == "expanded": gm_modifier = 3 elif game.clan and game.clan.game_mode == "cruel season": gm_modifier = 6 + else: + gm_modifier = 1 if mediator.experience_level == "average": lvl_modifier = 1.25 @@ -2859,7 +2747,7 @@ def mediate_relationship(mediator, cat1, cat2, allow_romantic, sabotage=False): # determine the traits to effect # Are they mates? - mates = rel1.cat_from.ID in rel1.cat_to.mate + mates = relationships[0].cat_from.ID in relationships[0].cat_to.mate pos_traits = ["platonic", "respect", "comfortable", "trust"] if allow_romantic and (mates or cat1.is_potential_mate(cat2)): @@ -2905,171 +2793,102 @@ def mediate_relationship(mediator, cat1, cat2, allow_romantic, sabotage=False): ran = (5, 10) else: ran = (4, 6) - if sabotage: - rel1.romantic_love = Cat.effect_relation( - rel1.romantic_love, - -(randint(ran[0], ran[1]) + bonus) + personality_bonus, - ) - rel2.romantic_love = Cat.effect_relation( - rel2.romantic_love, - -(randint(ran[0], ran[1]) + bonus) + personality_bonus, - ) + sabotage_modifier = -1 output += "Romantic interest decreased. " else: - rel1.romantic_love = Cat.effect_relation( - rel1.romantic_love, - (randint(ran[0], ran[1]) + bonus) + personality_bonus, - ) - rel2.romantic_love = Cat.effect_relation( - rel2.romantic_love, - (randint(ran[0], ran[1]) + bonus) + personality_bonus, - ) + sabotage_modifier = 1 output += "Romantic interest increased. " + for relationship in relationships: + relationship.romantic_love = Cat.effect_relation( + relationship.romantic_love, + sabotage_modifier*(randint(ran[0], ran[1]) + bonus) + personality_bonus, + ) elif trait == "platonic": ran = (4, 6) - if sabotage: - rel1.platonic_like = Cat.effect_relation( - rel1.platonic_like, - -(randint(ran[0], ran[1]) + bonus) + personality_bonus, - ) - rel2.platonic_like = Cat.effect_relation( - rel2.platonic_like, - -(randint(ran[0], ran[1]) + bonus) + personality_bonus, - ) + sabotage_modifier = -1 output += "Platonic like decreased. " else: - rel1.platonic_like = Cat.effect_relation( - rel1.platonic_like, - (randint(ran[0], ran[1]) + bonus) + personality_bonus, - ) - rel2.platonic_like = Cat.effect_relation( - rel2.platonic_like, - (randint(ran[0], ran[1]) + bonus) + personality_bonus, - ) + sabotage_modifier = 1 output += "Platonic like increased. " + for relationship in relationships: + relationship.platonic_like = Cat.effect_relation( + relationship.platonic_like, + sabotage_modifier*(randint(ran[0], ran[1]) + bonus) + personality_bonus, + ) elif trait == "respect": ran = (4, 6) - if sabotage: - rel1.admiration = Cat.effect_relation( - rel1.admiration, - -(randint(ran[0], ran[1]) + bonus) + personality_bonus, - ) - rel2.admiration = Cat.effect_relation( - rel2.admiration, - -(randint(ran[0], ran[1]) + bonus) + personality_bonus, - ) + sabotage_modifier = -1 output += "Respect decreased. " else: - rel1.admiration = Cat.effect_relation( - rel1.admiration, - (randint(ran[0], ran[1]) + bonus) + personality_bonus, - ) - rel2.admiration = Cat.effect_relation( - rel2.admiration, - (randint(ran[0], ran[1]) + bonus) + personality_bonus, - ) + sabotage_modifier = 1 output += "Respect increased. " + for relationship in relationships: + relationship.admiration = Cat.effect_relation( + relationship.admiration, + sabotage_modifier*(randint(ran[0], ran[1]) + bonus) + personality_bonus, + ) elif trait == "comfortable": ran = (4, 6) - if sabotage: - rel1.comfortable = Cat.effect_relation( - rel1.comfortable, - -(randint(ran[0], ran[1]) + bonus) + personality_bonus, - ) - rel2.comfortable = Cat.effect_relation( - rel2.comfortable, - -(randint(ran[0], ran[1]) + bonus) + personality_bonus, - ) + sabotage_modifier = -1 output += "Comfort decreased. " else: - rel1.comfortable = Cat.effect_relation( - rel1.comfortable, - (randint(ran[0], ran[1]) + bonus) + personality_bonus, - ) - rel2.comfortable = Cat.effect_relation( - rel2.comfortable, - (randint(ran[0], ran[1]) + bonus) + personality_bonus, - ) + sabotage_modifier = 1 output += "Comfort increased. " + for relationship in relationships: + relationship.comfortable = Cat.effect_relation( + relationship.comfortable, + sabotage_modifier*(randint(ran[0], ran[1]) + bonus) + personality_bonus, + ) elif trait == "trust": ran = (4, 6) - if sabotage: - rel1.trust = Cat.effect_relation( - rel1.trust, - -(randint(ran[0], ran[1]) + bonus) + personality_bonus, - ) - rel2.trust = Cat.effect_relation( - rel2.trust, - -(randint(ran[0], ran[1]) + bonus) + personality_bonus, - ) + sabotage_modifier = -1 output += "Trust decreased. " else: - rel1.trust = Cat.effect_relation( - rel1.trust, - (randint(ran[0], ran[1]) + bonus) + personality_bonus, - ) - rel2.trust = Cat.effect_relation( - rel2.trust, - (randint(ran[0], ran[1]) + bonus) + personality_bonus, - ) + sabotage_modifier = 1 output += "Trust increased. " + for relationship in relationships: + relationship.trust = Cat.effect_relation( + relationship.trust, + sabotage_modifier*(randint(ran[0], ran[1]) + bonus) + personality_bonus, + ) elif trait == "dislike": ran = (4, 9) if sabotage: - rel1.dislike = Cat.effect_relation( - rel1.dislike, - (randint(ran[0], ran[1]) + bonus) - personality_bonus, - ) - rel2.dislike = Cat.effect_relation( - rel2.dislike, - (randint(ran[0], ran[1]) + bonus) - personality_bonus, - ) + sabotage_modifier = 1 output += "Dislike increased. " else: - rel1.dislike = Cat.effect_relation( - rel1.dislike, - -(randint(ran[0], ran[1]) + bonus) - personality_bonus, - ) - rel2.dislike = Cat.effect_relation( - rel2.dislike, - -(randint(ran[0], ran[1]) + bonus) - personality_bonus, - ) + sabotage_modifier = -1 output += "Dislike decreased. " + for relationship in relationships: + relationship.dislike = Cat.effect_relation( + relationship.dislike, + sabotage_modifier*(randint(ran[0], ran[1]) + bonus) - personality_bonus, + ) elif trait == "jealousy": ran = (4, 6) - if sabotage: - rel1.jealousy = Cat.effect_relation( - rel1.jealousy, - (randint(ran[0], ran[1]) + bonus) - personality_bonus, - ) - rel2.jealousy = Cat.effect_relation( - rel2.jealousy, - (randint(ran[0], ran[1]) + bonus) - personality_bonus, - ) + sabotage_modifier = 1 output += "Jealousy increased. " else: - rel1.jealousy = Cat.effect_relation( - rel1.jealousy, - -(randint(ran[0], ran[1]) + bonus) - personality_bonus, - ) - rel2.jealousy = Cat.effect_relation( - rel2.jealousy, - -(randint(ran[0], ran[1]) + bonus) - personality_bonus, - ) + sabotage_modifier = -1 output += "Jealousy decreased. " - + for relationship in relationships: + relationship.jealousy = Cat.effect_relation( + relationship.jealousy, + sabotage_modifier*(randint(ran[0], ran[1]) + bonus) - personality_bonus, + ) + return output @staticmethod diff --git a/scripts/cat/names.py b/scripts/cat/names.py index 4e2790411f..67f5b377a2 100644 --- a/scripts/cat/names.py +++ b/scripts/cat/names.py @@ -174,39 +174,26 @@ def __str__(self): # Generate possible prefix def give_prefix(self, eyes, colour, biome): - """Generate possible prefix.""" - # decided in game config: cat_name_controls - if game.config["cat_name_controls"]["always_name_after_appearance"]: - named_after_appearance = True - else: - named_after_appearance = not random.getrandbits( - 2 - ) # Chance for True is '1/4' - - named_after_biome_ = not random.getrandbits(3) # chance for True is 1/8 - - # Add possible prefix categories to list. + """Generate possible prefix. Prefix preference is biome->appearance->generic""" + name_distribution = random.randint(1,8) possible_prefix_categories = [] - if ( - eyes in self.names_dict["eye_prefixes"] - and game.config["cat_name_controls"]["allow_eye_names"] - ): - possible_prefix_categories.append(self.names_dict["eye_prefixes"][eyes]) - if colour in self.names_dict["colour_prefixes"]: - possible_prefix_categories.append( - self.names_dict["colour_prefixes"][colour] - ) - if biome is not None and biome in self.names_dict["biome_prefixes"]: - possible_prefix_categories.append(self.names_dict["biome_prefixes"][biome]) + # named after biome is '1/8' + if(name_distribution <= 1): + if biome is not None and biome in self.names_dict["biome_prefixes"]: + possible_prefix_categories.append(self.names_dict["biome_prefixes"][biome]) + # named after appearance is '1/4' or in game config: cat_name_controls or + elif name_distribution <= 3 or game.config["cat_name_controls"]["always_name_after_appearance"]: + if eyes in self.names_dict["eye_prefixes"] and game.config["cat_name_controls"][ + "allow_eye_names" + ]: + possible_prefix_categories.append(self.names_dict["eye_prefixes"][eyes]) + if colour in self.names_dict["colour_prefixes"]: + possible_prefix_categories.append( + self.names_dict["colour_prefixes"][colour] + ) - # Choose appearance-based prefix if possible and named_after_appearance because True. - if ( - named_after_appearance - and possible_prefix_categories - and not named_after_biome_ - or named_after_biome_ - and possible_prefix_categories - ): + # If prefix based on appearcane or biome was identified + if possible_prefix_categories: prefix_category = random.choice(possible_prefix_categories) self.prefix = random.choice(prefix_category) else: @@ -231,13 +218,13 @@ def give_prefix(self, eyes, colour, biome): # Generate possible suffix def give_suffix(self, pelt, biome, tortiepattern): """Generate possible suffix.""" - if pelt is None or pelt == "SingleColour": - self.suffix = random.choice(self.names_dict["normal_suffixes"]) - else: - named_after_pelt = not random.getrandbits(2) # Chance for True is '1/8'. - named_after_biome = not random.getrandbits(3) # 1/8 - # Pelt name only gets used if there's an associated suffix. - if named_after_pelt: + self.suffix = random.choice(self.names_dict["normal_suffixes"]) + + if pelt is not None and pelt != "SingleColour": + name_distribution = random.randint(1,8) + # 1/8 chance for pelt suffix + if(name_distribution <=1): + # Pelt name only gets used if there's an associated suffix. if ( pelt in ["Tortie", "Calico"] and tortiepattern in self.names_dict["tortie_pelt_suffixes"] @@ -247,17 +234,13 @@ def give_suffix(self, pelt, biome, tortiepattern): ) elif pelt in self.names_dict["pelt_suffixes"]: self.suffix = random.choice(self.names_dict["pelt_suffixes"][pelt]) - else: - self.suffix = random.choice(self.names_dict["normal_suffixes"]) - elif named_after_biome: + # 1/8 chance for biome suffix + elif(name_distribution <=2): if biome in self.names_dict["biome_suffixes"]: self.suffix = random.choice( self.names_dict["biome_suffixes"][biome] ) - else: - self.suffix = random.choice(self.names_dict["normal_suffixes"]) - else: - self.suffix = random.choice(self.names_dict["normal_suffixes"]) + def __repr__(self): # Handles predefined suffixes (such as newborns being kit), @@ -265,24 +248,13 @@ def __repr__(self): # Handles suffix assignment with outside cats if self.cat.status in ["exiled", "lost"]: - adjusted_status: str = "" - if self.cat.moons >= 15: - adjusted_status = "warrior" - elif self.cat.moons >= 6: - adjusted_status = "apprentice" - if self.cat.moons == 0: - adjusted_status = "newborn" - elif self.cat.moons < 6: - adjusted_status = "kitten" - elif self.cat.moons < 12: - adjusted_status = "apprentice" - else: - adjusted_status = "warrior" - if adjusted_status != "warrior": - return ( - self.prefix + self.names_dict["special_suffixes"][adjusted_status] - ) + if(self.cat.moons < 1): + return self.prefix + self.names_dict["special_suffixes"]["newborn"] + elif(self.cat.moons < 6): + return self.prefix + self.names_dict["special_suffixes"]["kitten"] + elif(self.cat.moons < 12): + return self.prefix + self.names_dict["special_suffixes"]["apprentice"] if ( self.cat.status in self.names_dict["special_suffixes"] and not self.specsuffix_hidden @@ -291,6 +263,7 @@ def __repr__(self): if game.config["fun"]["april_fools"]: return f"{self.prefix}egg" return self.prefix + self.suffix + names = Name() diff --git a/scripts/cat/pelts.py b/scripts/cat/pelts.py index b4d0a02988..90a6263077 100644 --- a/scripts/cat/pelts.py +++ b/scripts/cat/pelts.py @@ -615,6 +615,13 @@ class Pelt: "FULLWHITE", ] + #For converting outdated white patch format + OLD_WHITE_PATCH_DICT = { + 'POINTMARK': "SEALPOINT", + 'PANTS2': 'PANTSTWO', + 'ANY2': 'ANYTWO', + "VITILIGO2": "VITILIGOTWO" + } skin_sprites = [ "BLACK", "PINK", @@ -718,18 +725,12 @@ def generate_new_pelt(gender: str, parents: tuple = (), age: str = "adult"): def check_and_convert(self, convert_dict): """Checks for old-type properties for the appearance-related properties - that are stored in Pelt, and converts them. To be run when loading a cat in.""" - + that are stored in Pelt, and converts them. To be run when loading a cat in. """ + # First, convert from some old names that may be in white_patches. - if self.white_patches == "POINTMARK": - self.white_patches = "SEALPOINT" - elif self.white_patches == "PANTS2": - self.white_patches = "PANTSTWO" - elif self.white_patches == "ANY2": - self.white_patches = "ANYTWO" - elif self.white_patches == "VITILIGO2": - self.white_patches = "VITILIGOTWO" - + if self.white_patches in Pelt.OLD_WHITE_PATCH_DICT.keys(): + self.white_patches = Pelt.OLD_WHITE_PATCH_DICT[self.white_patches] + if self.vitiligo == "VITILIGO2": self.vitiligo = "VITILIGOTWO" @@ -759,10 +760,7 @@ def check_and_convert(self, convert_dict): self.eye_colour2 = "COBALT" if self.eye_colour in ["BLUEYELLOW", "BLUEGREEN"]: - if self.eye_colour == "BLUEYELLOW": - self.eye_colour2 = "YELLOW" - elif self.eye_colour == "BLUEGREEN": - self.eye_colour2 = "GREEN" + self.eye_colour2 = self.eye_colour.replace('BLUE','') self.eye_colour = "BLUE" if self.length == "long": @@ -850,25 +848,25 @@ def pattern_color_inheritance(self, parents: tuple = (), gender="female"): par_peltnames = set() par_pelts = [] par_white = [] - for p in parents: - if p: + for parent in parents: + if parent: # Gather pelt color. - par_peltcolours.add(p.pelt.colour) + par_peltcolours.add(parent.pelt.colour) # Gather pelt length - par_peltlength.add(p.pelt.length) + par_peltlength.add(parent.pelt.length) # Gather pelt name - if p.pelt.name in Pelt.torties: - par_peltnames.add(p.pelt.tortiebase.capitalize()) + if parent.pelt.name in Pelt.torties: + par_peltnames.add(parent.pelt.tortiebase.capitalize()) else: - par_peltnames.add(p.pelt.name) + par_peltnames.add(parent.pelt.name) # Gather exact pelts, for direct inheritance. - par_pelts.append(p.pelt) + par_pelts.append(parent.pelt) # Gather if they have white in their pelt. - par_white.append(p.pelt.white) + par_white.append(parent.pelt.white) else: # If order for white patches to work correctly, we also want to randomly generate a "pelt_white" # for each "None" parent (missing or unknown parent) @@ -901,24 +899,17 @@ def pattern_color_inheritance(self, parents: tuple = (), gender="female"): # ------------------------------------------------------------------------------------------------------------# # Determine pelt. - weights = [ - 0, - 0, - 0, - 0, - ] # Weights for each pelt group. It goes: (tabbies, spotted, plain, exotic) - for p_ in par_peltnames: - if p_ in Pelt.tabbies: + weights = [0, 0, 0, 0] # Weights for each pelt group. It goes: (tabbies, spotted, plain, exotic) + for _pelt in par_peltnames: + if _pelt in Pelt.tabbies: add_weight = (50, 10, 5, 7) - elif p_ in Pelt.spotted: + elif _pelt in Pelt.spotted: add_weight = (10, 50, 5, 5) - elif p_ in Pelt.plain: + elif _pelt in Pelt.plain: add_weight = (5, 5, 50, 0) - elif p_ in Pelt.exotic: + elif _pelt in Pelt.exotic: add_weight = (15, 15, 1, 45) - elif ( - p_ is None - ): # If there is at least one unknown parent, a None will be added to the set. + elif _pelt is None: # If there is at least one unknown parent, a None will be added to the set. add_weight = (35, 20, 30, 15) else: add_weight = (0, 0, 0, 0) @@ -940,8 +931,8 @@ def pattern_color_inheritance(self, parents: tuple = (), gender="female"): "base_female_tortie" ] # There is a default chance for female tortie tortie_chance_m = game.config["cat_generation"]["base_male_tortie"] - for p_ in par_pelts: - if p_.name in Pelt.torties: + for _pelt in par_pelts: + if _pelt.name in Pelt.torties: tortie_chance_f = int(tortie_chance_f / 2) tortie_chance_m = tortie_chance_m - 1 break @@ -966,16 +957,16 @@ def pattern_color_inheritance(self, parents: tuple = (), gender="female"): # ------------------------------------------------------------------------------------------------------------# # Weights for each colour group. It goes: (ginger_colours, black_colours, white_colours, brown_colours) weights = [0, 0, 0, 0] - for p_ in par_peltcolours: - if p_ in Pelt.ginger_colours: + for _pelt in par_peltcolours: + if _pelt in Pelt.ginger_colours: add_weight = (40, 0, 0, 10) - elif p_ in Pelt.black_colours: + elif _pelt in Pelt.black_colours: add_weight = (0, 40, 2, 5) - elif p_ in Pelt.white_colours: + elif _pelt in Pelt.white_colours: add_weight = (0, 5, 40, 0) - elif p_ in Pelt.brown_colours: + elif _pelt in Pelt.brown_colours: add_weight = (10, 5, 0, 35) - elif p_ is None: + elif _pelt is None: add_weight = (40, 40, 40, 40) else: add_weight = (0, 0, 0, 0) @@ -996,14 +987,14 @@ def pattern_color_inheritance(self, parents: tuple = (), gender="female"): # ------------------------------------------------------------------------------------------------------------# weights = [0, 0, 0] # Weights for each length. It goes (short, medium, long) - for p_ in par_peltlength: - if p_ == "short": + for _pelt in par_peltlength: + if _pelt == "short": add_weight = (50, 10, 2) - elif p_ == "medium": + elif _pelt == "medium": add_weight = (25, 50, 25) - elif p_ == "long": + elif _pelt == "long": add_weight = (2, 10, 50) - elif p_ is None: + elif _pelt is None: add_weight = (10, 10, 10) else: add_weight = (0, 0, 0) @@ -1026,8 +1017,8 @@ def pattern_color_inheritance(self, parents: tuple = (), gender="female"): # will keep that the same. percentage_add_per_parent = int(94 / len(par_white)) chance = 3 - for p_ in par_white: - if p_: + for _pelt in par_white: + if _pelt: chance += percentage_add_per_parent chosen_white = random.randint(1, 100) <= chance diff --git a/scripts/cat/personality.py b/scripts/cat/personality.py index 7ae5e4ff2c..1752024573 100644 --- a/scripts/cat/personality.py +++ b/scripts/cat/personality.py @@ -4,6 +4,8 @@ import ujson +from scripts.utility import clamp + class Personality: """Hold personality information for a cat, and functions to deal with it""" @@ -170,13 +172,7 @@ def stability(self, new_val): @staticmethod def adjust_to_range(val: int) -> int: """Take an integer and adjust it to be in the trait-range""" - - if val < Personality.facet_range[0]: - val = Personality.facet_range[0] - elif val > Personality.facet_range[1]: - val = Personality.facet_range[1] - - return val + return clamp(val, Personality.facet_range[0], Personality.facet_range[1]) def set_kit(self, kit: bool): """Switch the trait-type. True for kit, False for normal""" diff --git a/scripts/cat/skills.py b/scripts/cat/skills.py index c06cfdaf3a..633cf66eba 100644 --- a/scripts/cat/skills.py +++ b/scripts/cat/skills.py @@ -453,17 +453,13 @@ def mentor_influence(self, mentor): return amount_effect = random.randint(1, 4) - - if can_primary and can_secondary: - if random.randint(1, 2) == 1: + if can_primary: + if can_secondary and random.randint(1, 2) == 1: + self.secondary.points += amount_effect + path = self.secondary.path + else: self.primary.points += amount_effect path = self.primary.path - else: - self.secondary.points += amount_effect - path = self.secondary.path - elif can_primary: - self.primary.points += amount_effect - path = self.primary.path else: self.secondary.points += amount_effect path = self.secondary.path @@ -507,7 +503,7 @@ def progress_skill(self, the_cat): ) if not (the_cat.outside or the_cat.exiled): - if the_cat.status == "kitten": + if the_cat.status == "kitten" or "apprentice" in the_cat.status: # Check to see if the cat gains a secondary if not self.secondary and not int(random.random() * 22): # if there's no secondary skill, try to give one! @@ -518,6 +514,8 @@ def progress_skill(self, the_cat): # if the the_cat has skills, check if they get any points this moon if not int(random.random() * 4): amount_effect = random.randint(1, 4) + if "apprentice" in the_cat.status: + amount_effect += 1 if self.primary and self.secondary: if random.randint(1, 2) == 1: self.primary.points += amount_effect @@ -525,26 +523,6 @@ def progress_skill(self, the_cat): self.secondary.points += amount_effect elif self.primary: self.primary.points += amount_effect - - elif "apprentice" in the_cat.status: - # Check to see if the cat gains a secondary - if not self.secondary and not int(random.random() * 22): - # if there's no secondary skill, try to give one! - self.secondary = Skill.get_random_skill( - points=0, interest_only=True, exclude=self.primary.path - ) - - # Check if they get any points this moon - if not int(random.random() * 4): - amount_effect = random.randint(2, 5) - if self.primary and self.secondary: - if random.randint(1, 2) == 1: - self.primary.points += amount_effect - else: - self.secondary.points += amount_effect - elif self.primary: - self.primary.points += amount_effect - elif the_cat.moons > 120: # for old cats, we want to check if the skills start to degrade at all, age is the great equalizer diff --git a/scripts/cat/thoughts.py b/scripts/cat/thoughts.py index 419bf8ded4..871dcf473e 100644 --- a/scripts/cat/thoughts.py +++ b/scripts/cat/thoughts.py @@ -1,3 +1,4 @@ +import os import traceback from random import choice @@ -217,8 +218,9 @@ def cats_fulfill_thought_constraints( if outside_status and outside_status != "clancat" and len(r_c_in) > 0: return False - if "has_injuries" in thought: - if "m_c" in thought["has_injuries"]: + if 'has_injuries' in thought: + #This will always return false + if "m_c" in thought['has_injuries']: if main_cat.injuries or main_cat.illnesses: injuries_and_illnesses = ( list(main_cat.injuries.keys()) + list(main_cat.injuries.keys()) @@ -326,8 +328,8 @@ def create_thoughts( @staticmethod def load_thoughts(main_cat, other_cat, game_mode, biome, season, camp): - status = main_cat.status - status = status.replace(" ", "_") + + status = main_cat.status.replace(" ", "_") # match status: # case "medicine cat apprentice": # status = "medicine_cat_apprentice" @@ -339,9 +341,9 @@ def load_thoughts(main_cat, other_cat, game_mode, biome, season, camp): # status = 'former_Clancat' if not main_cat.dead: - life_dir = "alive" + life_dir = "/alive" else: - life_dir = "dead" + life_dir = "/dead" if main_cat.dead: if main_cat.outside: @@ -359,24 +361,27 @@ def load_thoughts(main_cat, other_cat, game_mode, biome, season, camp): try: if main_cat.age == "newborn": loaded_thoughts = load_lang_resource( - f"thoughts/{life_dir}{spec_dir}/newborn.json" + f"thoughts{life_dir}{spec_dir}/newborn.json" ) else: thoughts = load_lang_resource( - f"thoughts/{life_dir}{spec_dir}/{status}.json" + f"thoughts{life_dir}{spec_dir}/{status}.json" ) genthoughts = load_lang_resource( - f"thoughts/{life_dir}{spec_dir}/general.json" + f"thoughts{life_dir}{spec_dir}/general.json" ) loaded_thoughts = thoughts + genthoughts final_thoughts = Thoughts.create_thoughts( loaded_thoughts, main_cat, other_cat, game_mode, biome, season, camp ) - return final_thoughts + except IOError: - print("ERROR: loading thoughts") - + traceback.print_exc() + final_thoughts = i18n.t("defaults.thought") + + return final_thoughts + @staticmethod def get_chosen_thought(main_cat, other_cat, game_mode, biome, season, camp): # get possible thoughts @@ -393,7 +398,7 @@ def get_chosen_thought(main_cat, other_cat, game_mode, biome, season, camp): ) ) chosen_thought = choice(chosen_thought_group["thoughts"]) - except Exception: + except IOError: traceback.print_exc() chosen_thought = i18n.t("defaults.thought") @@ -418,7 +423,6 @@ def leader_death_thought(self, lives_left, darkforest): spec_dir = "/darkforest" else: spec_dir = "/starclan" - THOUGHTS: [] try: if lives_left > 0: loaded_thoughts = load_lang_resource( @@ -433,7 +437,7 @@ def leader_death_thought(self, lives_left, darkforest): ) chosen_thought = choice(thought_group["thoughts"]) return chosen_thought - except Exception: + except IOError: traceback.print_exc() chosen_thought = i18n.t("defaults.thought") return chosen_thought @@ -458,6 +462,6 @@ def new_death_thought(self, darkforest, isoutside): ) chosen_thought = choice(thought_group["thoughts"]) return chosen_thought - except Exception: + except IOError: traceback.print_exc() return i18n.t("defaults.thought") diff --git a/scripts/cat_relations/inheritance.py b/scripts/cat_relations/inheritance.py index cb64f50954..9dbd843e13 100644 --- a/scripts/cat_relations/inheritance.py +++ b/scripts/cat_relations/inheritance.py @@ -138,12 +138,10 @@ def update_all_related_inheritance(self): for cat_id in self.all_involved: # Don't update the inheritance of faded cats # They are not viewable by the player and won't be used in any checks. - if ( - cat_id in self.all_inheritances - and self.cat.fetch_cat(cat_id) - and not self.cat.fetch_cat(cat_id).faded - ): - self.all_inheritances[cat_id].update_inheritance() + if ( cat_id in self.all_inheritances): + fetched_cat = self.cat.fetch_cat(cat_id) + if(fetched_cat and not fetched_cat.faded): + self.all_inheritances[cat_id].update_inheritance() def update_all_mates(self): """ @@ -384,18 +382,18 @@ def init_kits(self, inter_id, inter_cat): self.all_involved.append(inter_id) self.all_but_cousins.append(inter_id) if len(inter_blood_parents) > 0: - name = [] + parent_names = [] for blood_parent_id in inter_blood_parents: blood_parent_cat = self.cat.fetch_cat(blood_parent_id) if blood_parent_cat is None: print(f"ERROR: the blood_parent of {str(inter_cat.name)}") else: - name.append(str(blood_parent_cat.name)) + parent_names.append(str(blood_parent_cat.name)) self.kits[inter_id]["additional"].append( i18n.t( "inheritance.blood_parent", - count=len(name), - name=adjust_list_text(name), + count=len(parent_names), + name=adjust_list_text(parent_names), ) ) diff --git a/scripts/cat_relations/relationship.py b/scripts/cat_relations/relationship.py index 9cba7de05b..00a9a61a73 100644 --- a/scripts/cat_relations/relationship.py +++ b/scripts/cat_relations/relationship.py @@ -12,7 +12,7 @@ import scripts.cat_relations.interaction as interactions from scripts.event_class import Single_Event from scripts.game_structure.game_essentials import game -from scripts.utility import get_personality_compatibility, process_text +from scripts.utility import clamp, get_personality_compatibility, process_text # ---------------------------------------------------------------------------- # @@ -118,19 +118,15 @@ def start_interaction(self) -> None: biome = str(game.clan.biome).casefold() game_mode = game.clan.game_mode - all_interactions = interactions.NEUTRAL_INTERACTIONS.copy() if in_de_crease != "neutral": - all_interactions = interactions.INTERACTION_MASTER_DICT[rel_type][ - in_de_crease - ].copy() - possible_interactions = self.get_relevant_interactions( - all_interactions, intensity, biome, season, game_mode - ) + all_interactions = interactions.INTERACTION_MASTER_DICT[rel_type][in_de_crease].copy() else: + all_interactions = interactions.NEUTRAL_INTERACTIONS.copy() intensity = None - possible_interactions = self.get_relevant_interactions( - all_interactions, intensity, biome, season, game_mode - ) + + possible_interactions = self.get_relevant_interactions( + all_interactions, intensity, biome, season, game_mode + ) # return if there are no possible interactions. if len(possible_interactions) <= 0: @@ -212,11 +208,11 @@ def start_interaction(self) -> None: # prepare string for display interaction_str = self.adjust_interaction_string(interaction_str) - - effect = i18n.t("relationships.neutral_postscript") - if in_de_crease != "neutral" and positive: + if in_de_crease == "neutral": + effect = i18n.t("relationships.neutral_postscript") + elif positive: effect = i18n.t(f"relationships.positive_postscript_{intensity}") - elif in_de_crease != "neutral" and not positive: + else: effect = i18n.t(f"relationships.negative_postscript_{intensity}") interaction_str = interaction_str + effect @@ -275,7 +271,7 @@ def get_amount(self, in_de_crease: str, intensity: str) -> int: compatibility = get_personality_compatibility(self.cat_from, self.cat_to) if compatibility is None: # neutral compatibility - amount = amount + pass elif compatibility: # positive compatibility amount += game.config["relationship"]["compatibility_effect"] @@ -632,11 +628,7 @@ def romantic_love(self): @romantic_love.setter def romantic_love(self, value): - if value > 100: - value = 100 - if value < 0: - value = 0 - self._romantic_love = value + self._romantic_love = clamp(value, 0, 100) @property def platonic_like(self): @@ -644,11 +636,7 @@ def platonic_like(self): @platonic_like.setter def platonic_like(self, value): - if value > 100: - value = 100 - if value < 0: - value = 0 - self._platonic_like = value + self._platonic_like = clamp(value, 0, 100) @property def dislike(self): @@ -656,11 +644,7 @@ def dislike(self): @dislike.setter def dislike(self, value): - if value > 100: - value = 100 - if value < 0: - value = 0 - self._dislike = value + self._dislike = clamp(value, 0, 100) @property def admiration(self): @@ -668,11 +652,7 @@ def admiration(self): @admiration.setter def admiration(self, value): - if value > 100: - value = 100 - if value < 0: - value = 0 - self._admiration = value + self._admiration = clamp(value, 0, 100) @property def comfortable(self): @@ -680,11 +660,7 @@ def comfortable(self): @comfortable.setter def comfortable(self, value): - if value > 100: - value = 100 - if value < 0: - value = 0 - self._comfortable = value + self._comfortable = clamp(value, 0, 100) @property def jealousy(self): @@ -692,11 +668,7 @@ def jealousy(self): @jealousy.setter def jealousy(self, value): - if value > 100: - value = 100 - if value < 0: - value = 0 - self._jealousy = value + self._jealousy = clamp(value, 0, 100) @property def trust(self): @@ -704,8 +676,4 @@ def trust(self): @trust.setter def trust(self, value): - if value > 100: - value = 100 - if value < 0: - value = 0 - self._trust = value + self._trust = clamp(value, 0, 100) diff --git a/scripts/clan_resources/freshkill.py b/scripts/clan_resources/freshkill.py index 6590ad5253..8e4191b02a 100644 --- a/scripts/clan_resources/freshkill.py +++ b/scripts/clan_resources/freshkill.py @@ -397,16 +397,11 @@ def tactic_less_nutrition_first( if ration_prey and status == "warrior": feeding_amount = feeding_amount / 2 - if ( - self.amount_food_needed() < self.total_amount * 1.2 - and self.nutrition_info[cat.ID].percentage < 100 - ): - feeding_amount += 1 - elif ( - self.amount_food_needed() < self.total_amount - and self.nutrition_info[cat.ID].percentage < 100 - ): - feeding_amount += 0.5 + if(self.nutrition_info[cat.ID].percentage < 100): + if (self.amount_food_needed() < self.total_amount * 1.2): + feeding_amount += 1 + elif (self.amount_food_needed() < self.total_amount): + feeding_amount += 0.5 if additional_food_round: needed_amount = 0 @@ -441,20 +436,15 @@ def tactic_hunter_first( for cat in living_cats.copy(): if not cat.skills: continue - if ( - cat.skills.primary - and cat.skills.primary.path == SkillPath.HUNTER - and cat.skills.primary.tier == search_rank - ): - best_hunter.insert(0, cat) - living_cats.remove(cat) - elif ( - cat.skills.secondary - and cat.skills.secondary.path == SkillPath.HUNTER - and cat.skills.secondary.tier == search_rank - ): - best_hunter.insert(0, cat) - living_cats.remove(cat) + skills = [cat.skills.primary, cat.skills.secondary] + for skill in skills: + if ( + skill + and skill.path == SkillPath.HUNTER + and skill.tier == search_rank + ): + best_hunter.insert(0, cat) + living_cats.remove(cat) self.feed_group(best_hunter, additional_food_round) self.tactic_status(living_cats, additional_food_round) @@ -518,26 +508,15 @@ def feed_group( if ration_prey and status == "warrior": feeding_amount = feeding_amount / 2 - if ( - self.total_amount * 2 > self.amount_food_needed() - and self.nutrition_info[cat.ID].percentage < 100 - ): - feeding_amount += 2 - if ( - self.total_amount * 1.8 > self.amount_food_needed() - and self.nutrition_info[cat.ID].percentage < 100 - ): - feeding_amount += 1.5 - elif ( - self.total_amount * 1.2 > self.amount_food_needed() - and self.nutrition_info[cat.ID].percentage < 100 - ): - feeding_amount += 1 - elif ( - self.total_amount > self.amount_food_needed() - and self.nutrition_info[cat.ID].percentage < 100 - ): - feeding_amount += 0.5 + if(self.nutrition_info[cat.ID].percentage < 100): + if (self.total_amount * 2 > self.amount_food_needed()): + feeding_amount += 2 + elif (self.total_amount * 1.8 > self.amount_food_needed()): + feeding_amount += 1.5 + elif (self.total_amount * 1.2 > self.amount_food_needed()): + feeding_amount += 1 + elif (self.total_amount > self.amount_food_needed()): + feeding_amount += 0.5 if additional_food_round: needed_amount = 0 diff --git a/scripts/events_module/short/handle_short_events.py b/scripts/events_module/short/handle_short_events.py index 76e9d502d1..aa20f1a417 100644 --- a/scripts/events_module/short/handle_short_events.py +++ b/scripts/events_module/short/handle_short_events.py @@ -446,10 +446,10 @@ def handle_death(self): if cat.status == "leader": if "all_lives" in self.chosen_event.tags: - game.clan.leader_lives -= 10 + game.clan.leader_lives = 0 elif "some_lives" in self.chosen_event.tags: game.clan.leader_lives -= random.randrange( - 2, self.current_lives - 1 + 2, max(2, self.current_lives - 1) ) else: game.clan.leader_lives -= 1