def tags(self): tags = [] tags_local = self.get('tags', '') if isinstance(tags_local, list): tags += tags_local elif isinstance(tags_local, str): tags += tags_local.split(",") tags.append(self.profession) if self.economic > math_helpers.value_of_variable('high'): tags.append('wealthy') if self.economic > math_helpers.value_of_variable('great'): tags.append('rich') if self.education > math_helpers.value_of_variable('high'): tags.append('educated') if self.education > math_helpers.value_of_variable('great'): tags.append('smart') # Lowercase, remove empties, and remove dupes tags = [tag.lower().strip() for tag in tags if tag] tags = list(set(tags)) return ",".join(tags)
def update_biorhythms(self, age=None): if age is None: age = self.age HUSBAND_IMPROVEMENTS = "Extraversion,Artistic,Happiness,Happiness,Happiness,Business,Meekness,Conscienciousness,Religiousness" HUSBAND_DEGRADATIONS = "Extraversion,Artistic,Happiness,Meekness,Conscienciousness" WIFE_IMPROVEMENTS = "Extraversion,Artistic,Happiness,Happiness,Happiness,Business,Meekness,Conscienciousness,Religiousness" WIFE_DEGRADATIONS = "Extraversion,Artistic,Happiness,Conscienciousness,Religiousness" HAPPY_FORMULA = "Happiness,Anger-,Terror-,Extraversion,Intelligence-,Meekness,Appearance,Realism-" PASSION_FORMULA = "Artistic,Extraversion,Constitution,Religiousness-,Constraint-,Realism-,Passion,Meekness-" CONSCIENCE_FORMULA = "Conscienciousness,Terror-,Intelligence,Manipulation-,Charisma" HEALTH_FORMULA = "Constitution,Strength,Dexterity,Anger-,Intelligence,Weight-,Lifespan,Neuroticism-,Immune System" happy = math_helpers.get_formula_from_obj(self.attribute_mods, HAPPY_FORMULA, -10, 20) passion = math_helpers.get_formula_from_obj(self.attribute_mods, PASSION_FORMULA, -10, 20) conscience = math_helpers.get_formula_from_obj(self.attribute_mods, CONSCIENCE_FORMULA, -10, 20) health = math_helpers.get_formula_from_obj(self.attribute_mods, HEALTH_FORMULA, -10, 20) if self.education is None or not isinstance(self.education, float): self.education = math_helpers.rand_range(1.0, 120.0, 3, 4.0) if self.economic is None or not isinstance(self.economic, float): self.economic = math_helpers.rand_range(1.0, 120.0, 3, 4.0) if self.conflict is None or not isinstance(self.conflict, float): self.conflict = math_helpers.rand_range(1.0, 120.0, 3, 4.0) # TODO: Revise by modified age if age > 60: self.attribute_mod_update('Constitution', -.4) self.attribute_mod_update('Appearance', -.2) conscience += 3 passion -= 3 health -= 1 elif age > 40: self.attribute_mod_update('Constitution', -.3) self.attribute_mod_update('Appearance', -.1) self.attribute_mod_update('Wisdom', .3) conscience += 1 passion -= 1 elif age > 20: self.attribute_mod_update('Passion', .2) self.attribute_mod_update('Happiness', .2) self.attribute_mod_update('Constitution', .2) self.attribute_mod_update('Conscienciousness', .2) self.attribute_mod_update('Appearance', .1) conscience -= 1 passion += 3 happy += 2 health += 4 elif age > 17: self.attribute_mod_update('Appearance', .2) if self.education >= 40.0: conscience += 3 happy -= 1 passion += 1 elif self.education >= 13: conscience += 1 passion -= 1 happy -= 1 health -= 2 elif self.education >= 5: conscience -= 1 passion += 2 happy += 1 health -= 1 else: health -= 1 happy -= 1 if self.economic >= 40.0: conscience -= 3 happy += 3 passion += 2 health += 1 elif self.economic >= 13: conscience -= 1 passion += 1 happy += 1 elif self.economic >= 5: conscience += 1 passion += 1 happy -= 1 health -= 1 else: health -= 2 happy -= 2 passion += 2 if self.conflict >= 40.0: conscience -= 3 happy -= 2 passion += 2 health -= 2 elif self.conflict >= 13: conscience -= 2 passion += 1 happy -= 2 health -= 1 elif self.conflict >= 5: conscience -= 1 passion += 1 happy -= 1 health -= 1 # rands = numpy.random.randint(-2, 2, 4) # happy = math_helpers.clamp(happy+rands[0], -10, 10) # passion = math_helpers.clamp(passion+rands[1], -10, 10) # conscience = math_helpers.clamp(conscience+rands[2], -10, 10) # health = math_helpers.clamp(health+rands[3], -10, 10) self.conscience = conscience self.passion = passion self.happy = happy self.health = health #Annual family modifiers economic_tithe = float(self.economic) * .03 #Inflation and growth from working - #TODO: Make job dependent self.economic += math_helpers.weighted_number(mid=0.03, max=self.economic / 4, weight=8) #shift some money between parents if self.married and self.spouse: spouse = self.spouse #TODO: Should everyone have house? house = self.get("house", random_number=True, mid=0.02, max=self.economic) house = math_helpers.value_of_variable(house) if self.economic > spouse.economic: self.economic -= economic_tithe spouse.economic += economic_tithe #Increase parents stats through marriage improvements = HUSBAND_IMPROVEMENTS if self.gender is "Male" else WIFE_IMPROVEMENTS degradations = HUSBAND_DEGRADATIONS if self.gender is "Male" else WIFE_DEGRADATIONS for improvement in numpy.random.choice(improvements.split(","), 2): self.attribute_mod_update(improvement, 1) for degradation in numpy.random.choice(degradations.split(","), 1): self.attribute_mod_update(degradation, -1) house += economic_tithe self.set("house", house) self.economic -= economic_tithe if self.economic < 2: self.attribute_mod_update("Happiness", -1) if not self.deceased and self.health < -9: self.pass_away()
def apply_event_effects(person_data={}, world_data={}, event_data={}, event_type='birthplace', year=None, age=None, tag_manager={}, event_id=42): message = "" if not year: year = world_data.get("year", 1100) world_data["year"] = year if age is None: age = person_data.get("age", 16 + numpy.random.randint(20)) person_data["age"] = age name = event_data.get("name", "in a barn") properties = event_data.get("properties", {}) if isinstance(properties, basestring): properties = math_helpers.convert_string_to_properties_object(properties) math_helpers.add_tags(tag_manager, 'event', event_data.get("tags", [])) effect_was_applied = False generated_items = [] addional_messages = [] effects = event_data.get("effects", []) for effect in effects: # Don't consider if it's a unique effect prevent = effect.get("unique", False) if prevent and effect_was_applied: continue family = world_data.get("family", {}) # Roll the dice, if the chance occurs then parse the rest chance = effect.get("chance", None) if chance: chance_modifier = family.get("conflict", 1) try: chance_modifier = float(chance_modifier) except ValueError: chance_modifier = 1 try: chance = math_helpers.value_of_variable(chance) chance += chance_modifier chance /= 100 if not numpy.random.random() < chance: continue except ValueError: continue else: pass # Check the requirements # family.enemy has Elves, "family.*.profession sailor", family.*.profession has doctor requirement = effect.get("requirement", None) if requirement: passes = math_helpers.check_requirements(requirement, world_data) if not passes: continue # Update the message # "An innkeeper named [barmaid.name] assists, You were born the day your father was killed in battle. His [weapon.type] and [armor.type] are passed to you. ef_message = effect.get("message", None) if ef_message: addional_messages.append(ef_message) # Generators can create objects/items for use in the story #TODO: Generate a generator also if it's in a message text and not called out explicitly generator_data = {"generator": effect.get("generator", None), "role": effect.get("role", None), "years": effect.get("years", None), "override": effect.get("override", None), "power": effect.get("refresh", None) or effect.get("power", None) } # Run methods for everything in effects effect_data = effect.get("effect", None) # pay = good, father.leave, disease = infection effect_data = math_helpers.convert_string_to_properties_object(effect_data) effect_data = math_helpers.add_or_merge_dicts(effect_data, generator_data) generated_items_new = apply_effects(person_data, world_data, effect_data, tag_manager) generated_items = generated_items + generated_items_new # Properties are always applied to the person after all effects are run ef_properties = effect.get("properties", None) # JSON or str, "mother.profession = waitress, lifespan +2 if ef_properties: if isinstance(ef_properties, basestring): ef_properties = math_helpers.convert_string_to_properties_object(ef_properties) properties = math_helpers.add_or_merge_dicts(properties, ef_properties) effect_was_applied = True severity = 1 if event_type == 'birthplace': if isinstance(name, basestring) and name is not '': name_lower = name[0].lower() + name[1:] else: name_lower = name person_name = person_data.get("name", "Jon Snow") message += "<b>" + person_name + " was born " + str(name_lower) + "</b>" addional_messages = [message] + addional_messages if properties: message_new = apply_properties(person_data, world_data, properties, generated_items) if message_new: addional_messages.append(message_new) if generated_items and "item_list" in person_data: person_data["item_list"] += generated_items addional_messages = [m.strip() for m in addional_messages] message = "<br/>".join(addional_messages) return {"id": event_id, "age": age, "year": year, "message": message, "world_data": json.dumps(world_data), "severity": severity}
def apply_event_effects( person_data={}, world_data={}, event_data={}, event_type="birthplace", year=None, age=None, tag_manager={}, event_id=42, ): message = "" if not year: year = world_data.get("year", 1100) world_data["year"] = year if age is None: age = person_data.get("age", 16 + numpy.random.randint(20)) person_data["age"] = age name = event_data.get("name", "in a barn") properties = event_data.get("properties", {}) if isinstance(properties, basestring): properties = math_helpers.convert_string_to_properties_object(properties) math_helpers.add_tags(tag_manager, "event", event_data.get("tags", [])) effect_was_applied = False generated_items = [] addional_messages = [] effects = event_data.get("effects", []) for effect in effects: # Don't consider if it's a unique effect prevent = effect.get("unique", False) if prevent and effect_was_applied: continue family = world_data.get("family", {}) # Roll the dice, if the chance occurs then parse the rest chance = effect.get("chance", None) if chance: chance_modifier = family.get("conflict", 1) try: chance_modifier = float(chance_modifier) except ValueError: chance_modifier = 1 try: chance = math_helpers.value_of_variable(chance) chance += chance_modifier chance /= 100 if not numpy.random.random() < chance: continue except ValueError: continue else: pass # Check the requirements # family.enemy has Elves, "family.*.profession sailor", family.*.profession has doctor requirement = effect.get("requirement", None) if requirement: passes = math_helpers.check_requirements(requirement, world_data) if not passes: continue # Update the message # "An innkeeper named [barmaid.name] assists, You were born the day your father was killed in battle. His [weapon.type] and [armor.type] are passed to you. ef_message = effect.get("message", None) if ef_message: addional_messages.append(ef_message) # Generators can create objects/items for use in the story # TODO: Generate a generator also if it's in a message text and not called out explicitly generator_data = { "generator": effect.get("generator", None), "role": effect.get("role", None), "years": effect.get("years", None), "override": effect.get("override", None), "power": effect.get("refresh", None) or effect.get("power", None), } # Run methods for everything in effects effect_data = effect.get("effect", None) # pay = good, father.leave, disease = infection effect_data = math_helpers.convert_string_to_properties_object(effect_data) effect_data = math_helpers.add_or_merge_dicts(effect_data, generator_data) generated_items_new = apply_effects(person_data, world_data, effect_data, tag_manager) generated_items = generated_items + generated_items_new # Properties are always applied to the person after all effects are run ef_properties = effect.get("properties", None) # JSON or str, "mother.profession = waitress, lifespan +2 if ef_properties: if isinstance(ef_properties, basestring): ef_properties = math_helpers.convert_string_to_properties_object(ef_properties) properties = math_helpers.add_or_merge_dicts(properties, ef_properties) effect_was_applied = True severity = 1 if event_type == "birthplace": if isinstance(name, basestring) and name is not "": name_lower = name[0].lower() + name[1:] else: name_lower = name person_name = person_data.get("name", "Jon Snow") message += "<b>" + person_name + " was born " + str(name_lower) + "</b>" addional_messages = [message] + addional_messages if properties: message_new = apply_properties(person_data, world_data, properties, generated_items) if message_new: addional_messages.append(message_new) if generated_items and "item_list" in person_data: person_data["item_list"] += generated_items addional_messages = [m.strip() for m in addional_messages] message = "<br/>".join(addional_messages) return { "id": event_id, "age": age, "year": year, "message": message, "world_data": json.dumps(world_data), "severity": severity, }