def build_from_json(self, id, json): names = None gender = None age = None control = "EMPTY" if "gender" in json.keys(): gender = json["gender"] else: gender = fundamentals.Gender.generate_random() if "names" in json.keys(): control = "PARTIAL" names = Character_Names().build_from_json(gender, json["names"]) else: control = "FULL" names = Character_Names.generate_random(gender) if "age" in json.keys(): age = int(json["age"]) else: # TODO: Generate random value instead of rasing and error. renpy.error( "ERROR: Minimal_Character.build_from_json(): Character does not have a 'age' field." ) result = self.build_random(id=id, names=names, gender=gender, age=age) return result
def get_body_trait(observer_character, observed_character, trait_key): character_body = observed_character.body if trait_key == traits.ENUM__TRAITS__FITNESS: return character_body.fitness elif trait_key == traits.ENUM__TRAITS__FACE_ATTRACTIVENESS: return character_body.body_parts["FACE"].qualities["ATTRACTIVENESS"] elif trait_key == traits.ENUM__TRAITS__PENIS_SIZE: if "PENIS_SHAFT" in character_body.body_parts.keys(): return character_body.body_parts["PENIS_SHAFT"].qualities["SIZE"] else: return traits.ENUM__SIZES__INEXISTENT elif trait_key == traits.ENUM__TRAITS__BREASTS_SIZE: if "BREASTS" in character_body.body_parts.keys(): return character_body.body_parts["BREASTS"].qualities["SIZE"] else: return traits.ENUM__SIZES__INEXISTENT elif trait_key == traits.ENUM__TRAITS__ETHNICITY: return character_body.ethnicity elif trait_key == traits.ENUM__TRAITS__HAIR_COLOR: return character_body.body_parts["HAIR"].qualities["CURRENT_COLOR"] elif trait_key == traits.ENUM__TRAITS__HEIGHT: return character_body.height elif trait_key == traits.ENUM__TRAITS__BODY_ROUNDESS: return character_body.body_roundness else: renpy.error( "ERROR: get_body_trait(): Can't find entry for trait_key '" + trait_key + "'.") return 0
def __init__(self, expression = None, function = None): """A Condition must have either an expression or a function. If it has both, the function will be discarded on creation. If both are None, an exception will raised.""" self._expression = expression self._function = function if self._expression is None and self._function is None: renpy.error("ERROR: Condition: Both expression and function can't be None!") if self._expression is not None: self._function = None
def check_maintained_trait(observer_character, observed_character, trait_key): if False: pass else: renpy.error( "ERROR: check_fundamental_trait(): Can't find entry for trait_key '" + trait_key + "'.") return False
def build(self, gender, standard_name, standard_possessive=None, first=None, first_possessive=None, last=None, last_possessive=None, should_consume_names=True, should_fail_if_in_used_database=True, should_fail_if_not_in_database=False): self._reset() self.standard = standard_name if (standard_possessive != None): self.standard_possessive = standard_possessive else: self.standard_possessive = self.standard + "'s" self.first = self.standard self.first_possessive = self.standard_possessive if last != None: self.last = last else: self.last = "" if last_possessive != None: self.last_possessive = last_possessive else: if self.last != "": self.last_possessive = possessive_from_name( female_names, self.last) if should_consume_names: if gender == Gender.FEMALE: resource = female_names else: resource = male_names if not consume_name(resource, self.standard, should_fail_if_in_used_database= should_fail_if_in_used_database, should_fail_if_not_in_database= should_fail_if_not_in_database): renpy.error( "ERROR: Character_Names.build(): Can't build name '" + self.standard + "'. Name already in used names list.") if not consume_name(family_names, self.last, should_fail_if_in_used_database= should_fail_if_in_used_database, should_fail_if_not_in_database= should_fail_if_not_in_database): renpy.error( "ERROR: Character_Names.build(): Can't build name '" + self.standard + "'. Name already in used names list.") return self
def get_maintained_trait(observer_character, observed_character, trait_key): if trait_key == traits.ENUM__TRAITS__CHARM: return 1 elif trait_key == traits.ENUM__TRAITS__KNOWLEDGE: return 3 else: renpy.error( "ERROR: get_fundamental_trait(): Can't find entry for trait_key '" + trait_key + "'.") return 0
def check_fundamental_trait(observer_character, observed_character, trait_key): character_body = observed_character.body if trait_key == traits.ENUM__TRAITS__IS_FEMALE: return observed_character.gender == fundamentals.Gender.FEMALE elif trait_key == traits.ENUM__TRAITS__IS_MALE: return observed_character.gender == fundamentals.Gender.MALE else: renpy.error( "ERROR: check_fundamental_trait(): Can't find entry for trait_key '" + trait_key + "'.") return False
def build(self, id, names, gender, age): self._reset(id) if id is None or id == "": renpy.error( "ERROR: Cannot create Minimal_Character without an 'id'.") self._reset(id) self.set_names(names) self.set_gender(gender) self.set_age(age) register_character(self) return self
def check_body_trait(observer_character, observed_character, trait_key): character_body = observed_character.body if trait_key == traits.ENUM__TRAITS__IS_FIT: return character_body.fitness >= traits.ENUM__FITNESS_LEVEL__BARELY_FIT elif trait_key == traits.ENUM__TRAITS__IS_BALD: return character_body.body_parts["HAIR"].qualities[ "SIZE"] == traits.ENUM__SIZES__INEXISTENT else: renpy.error( "ERROR: check_body_trait(): Can't find entry for trait_key '" + trait_key + "'.") return False
def get_fundamental_trait(observer_character, observed_character, trait_key): if trait_key == traits.ENUM__TRAITS__GENDER: return observed_character.gender elif trait_key == traits.ENUM__TRAITS__AGE: return observed_character.age elif trait_key == traits.ENUM__TRAITS__AGE_GROUP: return fundamentals.get_age_group_from_age(observed_character.age) else: renpy.error( "ERROR: get_fundamental_trait(): Can't find entry for trait_key '" + trait_key + "'.") return 0
def build_part1_from_json(cls, id, json, use_default=False, game_settings=None): result = cls() json_keys = json.keys() parent_location = None destinations = [] local_menu_callable = "" is_public = False if "name" in json_keys: name = json["name"] else: renpy.error( "ERROR: Location.build_part1_from_json(): Name field not found in json for id '{0}'." .format(id)) if "visit_callable" in json_keys: visit_callable = json["visit_callable"] elif use_default and (game_settings is not None): visit_callable = game_settings.registered_default_location_visit_callable else: renpy.error( "ERROR: Location.build_part1_from_json(): visit_callable field not found in json for id '{0}'." .format(id)) if "local_menu_callable" in json_keys: local_menu_callable = json["local_menu_callable"] if "is_public" in json_keys: is_public = json["is_public"] result.build(id, name, visit_callable) if "connections" in json_keys: connections = json["connections"] for connection in connections: register_temporary_connection( _Temporary_Connection( starting_point_id=id, destination_id=connection["destination_id"], from_starting_point_to_destination_text=connection[ "exit_text"], from_destination_to_starting_point_text=connection[ "coming_in_text"])) if "formal_name" in json_keys: result.formal_name = json["formal_name"] return result
def get_trait(observer_character_id, observed_character_id, trait_key): if observed_character_id not in fundamentals.characters_database.keys(): renpy.error("ERROR: get_trait(): Can't find observed character '" + observed_character_id + "' in character_database.") return 0 observed_character = fundamentals.characters_database[observed_character_id] if trait_key in observed_character.traits.keys(): return observed_character.traits[trait_key] if observer_character_id is not None and observer_character_id not in fundamentals.characters_database.keys(): renpy.error("ERROR: get_trait(): Can't find observer character '" + observer_character_id + "' in character_database.") return 0 observer_character = fundamentals.characters_database[observer_character_id] if trait_key not in trait_getters_by_trait_key.keys(): renpy.error("ERROR: get_trait(): Can't find trait controller for trait '" + trait_key + "' in trait_controllers_by_trait_key.") return 0 trait_getter = trait_getters_by_trait_key[trait_key] return trait_getter(observer_character, observed_character, trait_key)
def build_from_json(self, gender, json): if gender == None or gender == "" or (gender != Gender.FEMALE and gender != Gender.MALE): renpy.error( "ERROR: Character_Names.build_from_json(): Character does not have a 'standard' field." ) standard = None standard_possessive = None first = None first_possessive = None last = None last_possessive = None if gender == Gender.FEMALE: resource = female_names else: resource = male_names if "standard" in json.keys(): standard = json["standard"] consume_name(resource, standard, should_fail_if_in_used_database=True, should_fail_if_not_in_database=False) if "standard_possessive" in json.keys(): standard_possessive = json["standard_possessive"] if "first" in json.keys(): first = json["first"] consume_name(resource, first, should_fail_if_in_used_database=True, should_fail_if_not_in_database=False) if "first_possessive" in json.keys(): first_possessive = json["first_possessive"] if "last" in json.keys(): last = json["last"] consume_name(family_names, last, should_fail_if_in_used_database=False, should_fail_if_not_in_database=False) if "last_possessive" in json.keys(): last_possessive = json["last_possessive"] if first != None and standard == None: standard = first random_parts = Character_Names.generate_random(gender, standard, standard_possessive, first, first_possessive, last, last_possessive) if standard == None: standard = random_parts.standard if standard_possessive == None: standard_possessive = random_parts.standard_possessive if first == None: first = random_parts.first if first_possessive == None: first_possessive = random_parts.first_possessive if last == None: last = random_parts.last if last_possessive == None: last_possessive = random_parts.last_possessive self.build(gender, standard, standard_possessive, first, first_possessive, last, last_possessive, should_consume_names=False) return self