Пример #1
0
 def create_sim_info(self, offspring_data):
     (parent_a, parent_b) = self.get_parents()
     sim_creator = SimCreator(gender=offspring_data.gender,
                              age=Age.BABY,
                              first_name=offspring_data.first_name,
                              last_name=offspring_data.last_name)
     household = self._sim_info.household
     zone_id = household.home_zone_id
     (sim_info_list, _) = SimSpawner.create_sim_infos(
         (sim_creator, ),
         household=household,
         account=self.account,
         zone_id=zone_id,
         generate_deterministic_sim=True,
         creation_source='pregnancy')
     sim_info = sim_info_list[0]
     generate_offspring(parent_a._base,
                        parent_b._base,
                        sim_info._base,
                        seed=offspring_data.genetics)
     sim_info.resend_physical_attributes()
     trait_tracker = sim_info.trait_tracker
     for trait in tuple(trait_tracker.personality_traits):
         trait_tracker.remove_trait(trait)
     for trait in offspring_data.traits:
         trait_tracker.add_trait(trait)
     self.initialize_sim_info(sim_info, parent_a, parent_b)
     self._sim_info.relationship_tracker.add_relationship_bit(
         sim_info.id, self.BIRTHPARENT_BIT)
     return sim_info
Пример #2
0
 def add_parents(child, generation=0):
     if generation >= generations:
         return
     sim_creators = (SimCreator(gender=Gender.MALE,
                                age=Age.ADULT,
                                last_name=child.last_name),
                     SimCreator(gender=Gender.FEMALE, age=Age.ADULT))
     (sim_info_list, _) = SimSpawner.create_sim_infos(
         sim_creators,
         account=sim.account,
         zone_id=sim.zone_id,
         creation_source='cheat: genealogy.generate_dynasty')
     sim_info_list[0].death_tracker.set_death_type(
         DeathType.get_random_death_type())
     sim_info_list[1].death_tracker.set_death_type(
         DeathType.get_random_death_type())
     if set_to_min_lod:
         sim_info_list[0].request_lod(SimInfoLODLevel.MINIMUM)
         sim_info_list[1].request_lod(SimInfoLODLevel.MINIMUM)
     child.set_and_propagate_family_relation(FamilyRelationshipIndex.FATHER,
                                             sim_info_list[0])
     child.set_and_propagate_family_relation(FamilyRelationshipIndex.MOTHER,
                                             sim_info_list[1])
     add_parents(sim_info_list[0], generation=generation + 1)
     add_parents(sim_info_list[1], generation=generation + 1)
Пример #3
0
def debug_create_baby(actor_sim, position, gender, routing_surface=None):
    baby = None
    try:
        actor_sim_info = actor_sim.sim_info
        account = actor_sim.sim_info.account
        sim_creator = SimCreator(gender=gender, age=Age.BABY, first_name=SimSpawner.get_random_first_name(account, gender == Gender.FEMALE), last_name=SimSpawner.get_family_name_for_gender(account, actor_sim.last_name, gender == Gender.FEMALE))
        (sim_info_list, _) = SimSpawner.create_sim_infos((sim_creator,), household=actor_sim_info.household, account=account, zone_id=actor_sim_info.zone_id, creation_source='cheat: debug_create_baby')
        sim_info = sim_info_list[0]
        baby_def = Baby.get_default_baby_def()
        baby = create_object(baby_def, sim_info.sim_id)
        baby.set_sim_info(sim_info)
        fgl_context = placement.FindGoodLocationContext(starting_position=position, object_id=baby.id, search_flags=placement.FGLSearchFlagsDefault, object_footprints=(baby.get_footprint(),))
        (trans, orient) = placement.find_good_location(fgl_context)
        if trans is not None:
            baby.location = sims4.math.Location(sims4.math.Transform(trans, orient), routing_surface)
        client = services.client_manager().get_client_by_household_id(sim_info.household_id)
        while client is not None:
            client.selectable_sims.add_selectable_sim_info(sim_info)
    except Exception as e:
        logger.exception('Create baby fail', e)
        if actor_sim_info.household.sim_in_household(sim_info.sim_id):
            actor_sim_info.household.remove_sim_info(sim_info)
        client = services.client_manager().get_client_by_household_id(sim_info.household_id)
        if client is not None:
            client.selectable_sims.remove_selectable_sim_info(sim_info)
        while baby is not None:
            baby.destroy(source=actor_sim, cause='Create baby fail')
Пример #4
0
def create_lod_sim_infos(quantity: int = 1,
                         lod: SimInfoLODLevel = SimInfoLODLevel.MINIMUM,
                         _connection=None):
    output = sims4.commands.CheatOutput(_connection)
    account = services.client_manager().get(_connection).account
    for _ in range(quantity):
        gender = random.choice(list(Gender))
        age = random.choice([Age.TEEN, Age.YOUNGADULT, Age.ADULT, Age.ELDER])
        first_name = SimSpawner.get_random_first_name(gender)
        last_name = 'CheatFamilyLOD{}'.format(lod)
        sc = SimCreator(gender=gender,
                        age=age,
                        first_name=first_name,
                        last_name=last_name)
        household = services.household_manager().create_household(account)
        (si, _) = SimSpawner.create_sim_infos(
            (sc, ),
            household=household,
            zone_id=0,
            creation_source='cheat: LOD SimInfo')
        if not si[0].request_lod(lod):
            output('Failed to request {} lod for {}'.format(lod, si[0]))
        output('Created a SimInfo and requested {} LOD: {}.'.format(
            lod, si[0]))
    output('Created a total of {} SimInfos at {} LOD'.format(lod, quantity))
Пример #5
0
 def create_adoption_sim_info(self, sim_info, household=None, account=None, zone_id=None):
     sim_creator = SimCreator(age=sim_info.age, gender=sim_info.gender, species=sim_info.extended_species, first_name=sim_info.first_name, last_name=sim_info.last_name)
     (sim_info_list, new_household) = SimSpawner.create_sim_infos((sim_creator,), household=household, account=account, zone_id=0, creation_source='adoption')
     SimInfoBaseWrapper.copy_physical_attributes(sim_info_list[0], sim_info)
     sim_info_list[0].pelt_layers = sim_info.pelt_layers
     sim_info_list[0].breed_name_key = sim_info.breed_name_key
     sim_info_list[0].load_outfits(sim_info.save_outfits())
     sim_info_list[0].resend_physical_attributes()
     return (sim_info_list[0], new_household)
def create_sim_info_from_template(sim_template, _connection=None):
    sims4.commands.output('Processing sim_template: {}'.format(sim_template), _connection)
    sim_creator = sim_template.sim_creator
    (sim_info_list, household) = SimSpawner.create_sim_infos([sim_creator], creation_source='cheat: filter.create_from_sim_template')
    if sim_info_list:
        created_sim_info = sim_info_list.pop()
        sim_template.add_template_data_to_sim(created_sim_info)
        sims4.commands.output('Finished template creation: {}'.format(household), _connection)
    else:
        sims4.commands.output('Failed to create sim info from template: {}'.format(sim_template), _connection)
    def create_human_sim_info(gender: Gender = None,
                              age: Age = None,
                              first_name: str = None,
                              last_name: str = None,
                              trait_ids: Tuple[int] = (),
                              household: Household = None,
                              source: str = 'testing') -> Union[SimInfo, None]:
        """create_human_sim_info(\
            gender=None,\
            age=None,\
            species=None,\
            first_name=None,\
            last_name=None,\
            trait_ids=(),\
            household=None,\
            source='testing'\
        )

        Create SimInfo for a Human Sim.

        :param gender: The Gender of the created Sim.
        :type gender: Gender, optional
        :param age: The Age of the created Sim.
        :type age: Age, optional
        :param first_name: The First Name of the created Sim.
        :type first_name: str, optional
        :param last_name: The Last Name of the created Sim.
        :type last_name: str, optional
        :param trait_ids: The decimal identifiers of the Traits to add to the created Sim.
        :type trait_ids: Tuple[int], optional
        :param household: The household to place the created Sim in. If None, the Sim will be placed in a hidden household.
        :type household: Household, optional
        :param source: The reason for the Sims creation.
        :type source: str, optional
        :return: The SimInfo of the created Sim or None if the Sim failed to be created.
        :rtype: SimInfo
        """
        from sims4communitylib.utils.sims.common_household_utils import CommonHouseholdUtils
        household = household or CommonHouseholdUtils.create_empty_household(
            as_hidden_household=True)
        sim_creator = SimCreator(
            gender=gender,
            age=age,
            first_name=first_name
            or SimSpawner.get_random_first_name(gender, Species.HUMAN),
            last_name=last_name,
            traits=trait_ids)
        (sim_info_list, _) = SimSpawner.create_sim_infos(
            (sim_creator, ),
            household=household,
            generate_deterministic_sim=True,
            creation_source=source)
        if not sim_info_list:
            return None
        return sim_info_list[0]
 def add_parents(child, generation=0):
     if generation >= generations:
         return
     sim_creators = (SimCreator(gender=Gender.MALE, age=Age.ADULT, last_name=child.last_name), SimCreator(gender=Gender.FEMALE, age=Age.ADULT))
     (sim_info_list, _) = SimSpawner.create_sim_infos(sim_creators, household=sim.household, account=sim.account, zone_id=sim.zone_id, creation_source='cheat: genealogy.generate_dynasty')
     sim_info_list[0].death_tracker.set_death_type(1)
     sim_info_list[1].death_tracker.set_death_type(1)
     child.set_and_propagate_family_relation(FamilyRelationshipIndex.FATHER, sim_info_list[0])
     child.set_and_propagate_family_relation(FamilyRelationshipIndex.MOTHER, sim_info_list[1])
     add_parents(sim_info_list[0], generation=generation + 1)
     add_parents(sim_info_list[1], generation=generation + 1)
Пример #9
0
def get_menu_sim():
    global MENU_SIM_ID
    if MENU_SIM_ID is None:
        household = Household(SimSpawner._get_default_account(), starting_funds=0)
        household.set_to_hidden()
        (sim_info_list, _) = SimSpawner.create_sim_infos((SimCreator(),), household=household, creation_source='WickedWhims Menu')
        if sim_info_list:
            sim_info = sim_info_list[0]
            MENU_SIM_ID = TurboManagerUtil.Sim.get_sim_id(sim_info)
            _prepare_sim_outfit(sim_info)
    if MENU_SIM_ID is not None:
        return TurboManagerUtil.Sim.get_sim_info(MENU_SIM_ID)
Пример #10
0
 def create_sim_info(self, offspring_data):
     self.validate_partner()
     (parent_a, parent_b) = self.get_parents()
     sim_creator = SimCreator(age=offspring_data.age,
                              gender=offspring_data.gender,
                              species=offspring_data.species,
                              first_name=offspring_data.first_name,
                              last_name=offspring_data.last_name)
     household = self._sim_info.household
     zone_id = household.home_zone_id
     (sim_info_list, _) = SimSpawner.create_sim_infos(
         (sim_creator, ),
         household=household,
         account=self.account,
         zone_id=zone_id,
         generate_deterministic_sim=True,
         creation_source='pregnancy')
     sim_info = sim_info_list[0]
     sim_info.world_id = services.get_persistence_service(
     ).get_world_id_from_zone(zone_id)
     for trait in tuple(sim_info.trait_tracker.personality_traits):
         sim_info.remove_trait(trait)
     for trait in offspring_data.traits:
         sim_info.add_trait(trait)
     sim_info.apply_genetics(parent_a,
                             parent_b,
                             seed=offspring_data.genetics)
     sim_info.resend_extended_species()
     sim_info.resend_physical_attributes()
     default_track_overrides = {}
     mother = parent_a if parent_a.gender == Gender.FEMALE else parent_b
     father = parent_a if parent_a.gender == Gender.MALE else parent_b
     if self._origin in self.PREGNANCY_ORIGIN_MODIFIERS:
         father_override = self.PREGNANCY_ORIGIN_MODIFIERS[
             self._origin].default_relationships.father_override
         if father_override is not None:
             default_track_overrides[father] = father_override
         mother_override = self.PREGNANCY_ORIGIN_MODIFIERS[
             self._origin].default_relationships.mother_override
         if mother_override is not None:
             default_track_overrides[mother] = mother_override
     self.initialize_sim_info(
         sim_info,
         parent_a,
         parent_b,
         default_track_overrides=default_track_overrides)
     self._sim_info.relationship_tracker.add_relationship_bit(
         sim_info.id, self.BIRTHPARENT_BIT)
     return sim_info
Пример #11
0
 def get_sim_infos_and_positions(self, resolver, household):
     sim_creator = self.template.sim_creator
     (sim_info_list, _) = SimSpawner.create_sim_infos(
         (sim_creator, ),
         sim_name_type=sim_creator.sim_name_type,
         household=household)
     self.template.add_template_data_to_sim(sim_info_list[0],
                                            sim_creator=sim_creator)
     (position, location) = (None, None)
     spawning_object = self._get_spawning_object(resolver)
     if spawning_object is not None:
         (position, location) = self._get_position_and_location(
             spawning_object, resolver)
         use_fgl = position is None
     return ((sim_info_list[0], position, location, use_fgl), )
def create_sim_info_from_template(sim_template, _connection=None):
    sims4.commands.output('Processing sim_template: {}'.format(sim_template),
                          _connection)
    sim_creator = sim_template.sim_creator
    (sim_info_list, household) = SimSpawner.create_sim_infos(
        [sim_creator],
        creation_source='cheat: filter.create_from_sim_template')
    if sim_info_list:
        created_sim_info = sim_info_list.pop()
        sim_template.add_template_data_to_sim(created_sim_info)
        sims4.commands.output(
            'Finished template creation: {}'.format(household), _connection)
    else:
        sims4.commands.output(
            'Failed to create sim info from template: {}'.format(sim_template),
            _connection)
Пример #13
0
 def create_sim_info(self, offspring_data):
     (parent_a, parent_b) = self.get_parents()
     sim_creator = SimCreator(gender=offspring_data.gender, age=Age.BABY, first_name=offspring_data.first_name, last_name=offspring_data.last_name)
     household = self._sim_info.household
     zone_id = household.home_zone_id
     (sim_info_list, _) = SimSpawner.create_sim_infos((sim_creator,), household=household, account=self.account, zone_id=zone_id, generate_deterministic_sim=True, creation_source='pregnancy')
     sim_info = sim_info_list[0]
     generate_offspring(parent_a._base, parent_b._base, sim_info._base, seed=offspring_data.genetics)
     sim_info.resend_physical_attributes()
     trait_tracker = sim_info.trait_tracker
     for trait in tuple(trait_tracker.personality_traits):
         trait_tracker.remove_trait(trait)
     for trait in offspring_data.traits:
         trait_tracker.add_trait(trait)
     self.initialize_sim_info(sim_info, parent_a, parent_b)
     self._sim_info.relationship_tracker.add_relationship_bit(sim_info.id, self.BIRTHPARENT_BIT)
     return sim_info
Пример #14
0
def debug_create_baby(actor_sim, position, gender, routing_surface=None):
    baby = None
    try:
        actor_sim_info = actor_sim.sim_info
        account = actor_sim.sim_info.account
        sim_creator = SimCreator(
            gender=gender,
            age=Age.BABY,
            first_name=SimSpawner.get_random_first_name(
                account, gender == Gender.FEMALE),
            last_name=SimSpawner.get_family_name_for_gender(
                account, actor_sim.last_name, gender == Gender.FEMALE))
        (sim_info_list, _) = SimSpawner.create_sim_infos(
            (sim_creator, ),
            household=actor_sim_info.household,
            account=account,
            zone_id=actor_sim_info.zone_id,
            creation_source='cheat: debug_create_baby')
        sim_info = sim_info_list[0]
        baby_def = Baby.get_default_baby_def()
        baby = create_object(baby_def, sim_info.sim_id)
        baby.set_sim_info(sim_info)
        fgl_context = placement.FindGoodLocationContext(
            starting_position=position,
            object_id=baby.id,
            search_flags=placement.FGLSearchFlagsDefault,
            object_footprints=(baby.get_footprint(), ))
        (trans, orient) = placement.find_good_location(fgl_context)
        if trans is not None:
            baby.location = sims4.math.Location(
                sims4.math.Transform(trans, orient), routing_surface)
        client = services.client_manager().get_client_by_household_id(
            sim_info.household_id)
        while client is not None:
            client.selectable_sims.add_selectable_sim_info(sim_info)
    except Exception as e:
        logger.exception('Create baby fail', e)
        if actor_sim_info.household.sim_in_household(sim_info.sim_id):
            actor_sim_info.household.remove_sim_info(sim_info)
        client = services.client_manager().get_client_by_household_id(
            sim_info.household_id)
        if client is not None:
            client.selectable_sims.remove_selectable_sim_info(sim_info)
        while baby is not None:
            baby.destroy(source=actor_sim, cause='Create baby fail')
Пример #15
0
def test_sim_template_generation(_connection=None):
    sim_templates = services.get_instance_manager(
        sims4.resources.Types.SIM_TEMPLATE).types.values()
    failed_templates = []
    for sim_template in sim_templates:
        if sim_template.template_type != filters.sim_template.SimTemplateType.SIM:
            continue
        sim_creator = sim_template.sim_creator
        sim_creation_dictionary = sim_creator.build_creation_dictionary()
        tag_set = sim_creation_dictionary['tagSet']
        if sim_creator.species != Species.HUMAN:
            continue
        if sim_creator.age == Age.BABY:
            continue
        if sim_creator.resource_key:
            continue
        sims4.commands.output(
            'Processing Sim Template: {}'.format(sim_template), _connection)
        (sim_info_list, _) = SimSpawner.create_sim_infos(
            [sim_creator],
            creation_source='cheat: filter.test_sim_template_generation')
        if sim_info_list:
            created_sim_info = sim_info_list.pop()
            (current_outfit_category,
             current_outfit_index) = created_sim_info.get_current_outfit()
            tags = get_tags_from_outfit(created_sim_info._base,
                                        current_outfit_category,
                                        current_outfit_index)
            created_tag_set = set().union(*tags.values())
            if not tag_set.is_subset(created_tag_set):
                failed_templates.append(
                    (sim_template, sim_creator, tag_set - created_tag_set))
    if failed_templates:
        sims4.commands.output(
            'Failed to generate {} templates!'.format(len(failed_templates)),
            _connection)
        for (sim_template, sim_creator, missing_tags) in failed_templates:
            sims4.commands.output(
                'Failed to generate {}, sim creator: {}, missing tags: {}'.
                format(sim_template, sim_creator, missing_tags), _connection)
    sims4.commands.output('Finished Sim Template Generation Test!',
                          _connection)
Пример #16
0
 def create_household(cls,
                      inst,
                      zone_id,
                      account=None,
                      sim_creator=None,
                      sim_name_type=SimNameType.DEFAULT,
                      creation_source: str = 'household_template'):
     inst_or_cls = inst if inst is not None else cls
     sim_templates = inst_or_cls.get_household_member_templates()
     sim_creators = [
         sim_template.sim_creator for sim_template in sim_templates
     ]
     matching_sim_creator_index = None
     if sim_creator is not None:
         matching_sim_creator_indices = [
             index for (index, sim_template) in enumerate(sim_templates)
             if sim_template.matches_creation_data(sim_creator=sim_creator)
         ]
         if matching_sim_creator_indices:
             matching_sim_creator_index = random.choice(
                 matching_sim_creator_indices)
             sim_creators[matching_sim_creator_index] = sim_creator
     home_zone_id = zone_id or 0
     (created_sim_infos, household) = SimSpawner.create_sim_infos(
         sim_creators,
         zone_id=home_zone_id,
         account=account,
         starting_funds=cls._household_funds,
         sim_name_type=sim_name_type,
         creation_source=creation_source)
     household.set_household_lot_ownership(zone_id=home_zone_id)
     for (index, (created_sim_info, sim_creator,
                  sim_template)) in enumerate(
                      zip(created_sim_infos, sim_creators, sim_templates)):
         sim_template.add_template_data_to_sim(created_sim_info,
                                               sim_creator)
     inst_or_cls.set_household_relationships(created_sim_infos, household)
     if matching_sim_creator_index is not None:
         return (household, created_sim_infos[matching_sim_creator_index])
     return household
Пример #17
0
def create_sim_info_from_template(
        sim_template: TunableInstanceParam(sims4.resources.Types.SIM_TEMPLATE),
        spawn_sim: bool = False,
        _connection=None):
    sims4.commands.output('Processing sim_template: {}'.format(sim_template),
                          _connection)
    sim_creator = sim_template.sim_creator
    (sim_info_list, household) = SimSpawner.create_sim_infos(
        [sim_creator],
        creation_source='cheat: filter.create_from_sim_template')
    if sim_info_list:
        created_sim_info = sim_info_list.pop()
        sim_template.add_template_data_to_sim(created_sim_info)
        sims4.commands.output(
            'Finished template creation: {}'.format(household), _connection)
        if spawn_sim:
            services.get_zone_situation_manager(
            ).create_visit_situation_for_unexpected(created_sim_info)
    else:
        sims4.commands.output(
            'Failed to create sim info from template: {}'.format(sim_template),
            _connection)
Пример #18
0
 def _create_clone_sim_info(self, source_sim_info, resolver, household):
     sim_creator = SimCreator(
         gender=source_sim_info.gender,
         age=source_sim_info.age,
         first_name=SimSpawner.get_random_first_name(
             source_sim_info.gender, source_sim_info.species),
         last_name=source_sim_info._base.last_name,
         traits=source_sim_info.trait_tracker.equipped_traits)
     (sim_info_list, _) = SimSpawner.create_sim_infos(
         (sim_creator, ),
         household=household,
         account=source_sim_info.account,
         generate_deterministic_sim=True,
         creation_source='cloning',
         skip_adding_to_household=True)
     clone_sim_info = sim_info_list[0]
     source_sim_proto = source_sim_info.save_sim(for_cloning=True)
     clone_sim_id = clone_sim_info.sim_id
     clone_first_name = clone_sim_info._base.first_name
     clone_last_name = clone_sim_info._base.last_name
     clone_breed_name = clone_sim_info._base.breed_name
     clone_first_name_key = clone_sim_info._base.first_name_key
     clone_last_name_key = clone_sim_info._base.last_name_key
     clone_full_name_key = clone_sim_info._base.full_name_key
     clone_breed_name_key = clone_sim_info._base.breed_name_key
     clone_sim_info.load_sim_info(source_sim_proto,
                                  is_clone=True,
                                  default_lod=SimInfoLODLevel.FULL)
     clone_sim_info.sim_id = clone_sim_id
     clone_sim_info._base.first_name = clone_first_name
     clone_sim_info._base.last_name = clone_last_name
     clone_sim_info._base.breed_name = clone_breed_name
     clone_sim_info._base.first_name_key = clone_first_name_key
     clone_sim_info._base.last_name_key = clone_last_name_key
     clone_sim_info._base.full_name_key = clone_full_name_key
     clone_sim_info._base.breed_name_key = clone_breed_name_key
     clone_sim_info._household_id = household.id
     if not self._try_add_sim_info_to_household(
             clone_sim_info, resolver, household,
             skip_household_check=True):
         return
     source_trait_tracker = source_sim_info.trait_tracker
     clone_trait_tracker = clone_sim_info.trait_tracker
     for trait in clone_trait_tracker.personality_traits:
         if not source_trait_tracker.has_trait(trait):
             clone_sim_info.remove_trait(trait)
     for trait in clone_trait_tracker.gender_option_traits:
         if not source_trait_tracker.has_trait(trait):
             clone_sim_info.remove_trait(trait)
     correct_aspiration_trait = clone_sim_info.primary_aspiration.primary_trait
     for trait in tuple(clone_trait_tracker.aspiration_traits):
         if trait is not correct_aspiration_trait:
             clone_sim_info.remove_trait(trait)
     source_sim_info.relationship_tracker.create_relationship(
         clone_sim_info.sim_id)
     source_sim_info.relationship_tracker.add_relationship_score(
         clone_sim_info.sim_id, 1)
     self._ensure_parental_lineage_exists(source_sim_info,
                                          clone_sim_info)
     services.sim_info_manager().set_default_genealogy(
         sim_infos=(clone_sim_info, ))
     clone_sim_info.set_default_data()
     clone_sim_info.save_sim()
     household.save_data()
     if not household.is_active_household:
         clone_sim_info.request_lod(SimInfoLODLevel.BASE)
     clone_sim_info.resend_physical_attributes()
     clone_sim_info.relationship_tracker.clean_and_send_remaining_relationship_info(
     )
     return clone_sim_info