def spawn_sim(sim_info: SimInfo, location: CommonLocation = None, position: CommonVector3 = None, **kwargs) -> bool: """spawn_sim(sim_info, location=None, position=None, **kwargs) Spawn a Sim. ..note:: Do not provide sim_position or sim_location in kwargs as they are already specified as location and position. :param sim_info: The Sim to Spawn. :type sim_info: SimInfo :param location: The location to spawn the Sim at. Default is None. :type location: CommonLocation, optional :param position: The position to spawn the Sim at. Default is None. :type position: CommonVector3, optional :return: True, if the Sim was spawned successfully. False, if not. :rtype: bool """ try: SimSpawner.spawn_sim(sim_info, sim_location=location, sim_position=position, **kwargs) except Exception as ex: CommonExceptionHandler.log_exception( ModInfo.get_identity(), 'Failed to spawn Sim with SimInfo \'{}\' at location \'{}\'.'. format(sim_info, location), exception=ex) return False return True
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))
def _name_and_create_adoptee_gen(self, timeline): adopted_sim_info = self.get_participant(ParticipantType.PickedSim) last_name = SimSpawner.get_family_name_for_gender( self.sim.account, self.sim.last_name, adopted_sim_info.is_female) result = yield self._do_renames_gen(timeline, (adopted_sim_info, ), additional_tokens=(last_name, )) if not result: return result adopted_sim_info = self.get_participant(ParticipantType.PickedSim) parent_a = self.sim.sim_info parent_b = services.sim_info_manager().get(parent_a.spouse_sim_id) adopted_sim_info.relationship_tracker._clear_relationships() for relation in FamilyRelationshipIndex: relation_id = adopted_sim_info.get_relation(relation) relation_info = services.sim_info_manager().get(relation_id) if relation_info is not None: adopted_sim_info.genealogy.remove_family_link(relation) family_relation = relation_info.genealogy.get_family_relationship_bit( adopted_sim_info.sim_id) relation_info.genealogy.clear_family_relation(family_relation) relation_info.relationship_tracker.destroy_relationship( adopted_sim_info.sim_id) adopted_sim_info.genealogy.clear_family_relation(relation) if adopted_sim_info.household is not parent_a.household: adopted_sim_info.household.remove_sim_info(adopted_sim_info) PregnancyTracker.initialize_sim_info(adopted_sim_info, parent_a, parent_b) adopted_sim_info.trait_tracker.remove_trait(self.adoption_trait) if adopted_sim_info.age == Age.BABY: adopted_sim_info.set_zone_on_spawn() create_and_place_baby(adopted_sim_info, ignore_daycare=True) else: SimSpawner.spawn_sim(adopted_sim_info, sim_position=self.sim.position) return True
def _name_and_create_adoptee_gen(self, timeline): adopted_sim_info = self.get_participant(ParticipantType.PickedSim) last_name = SimSpawner.get_family_name_for_gender(self.sim.account, self.sim.last_name, adopted_sim_info.is_female) result = yield self._do_renames_gen(timeline, (adopted_sim_info,), additional_tokens=(last_name,)) if not result: return result adopted_sim_info = self.get_participant(ParticipantType.PickedSim) parent_a = self.sim.sim_info parent_b = services.sim_info_manager().get(parent_a.spouse_sim_id) adopted_sim_info.relationship_tracker._clear_relationships() for relation in FamilyRelationshipIndex: relation_id = adopted_sim_info.get_relation(relation) relation_info = services.sim_info_manager().get(relation_id) if relation_info is not None: adopted_sim_info.genealogy.remove_family_link(relation) family_relation = relation_info.genealogy.get_family_relationship_bit(adopted_sim_info.sim_id) relation_info.genealogy.clear_family_relation(family_relation) relation_info.relationship_tracker.destroy_relationship(adopted_sim_info.sim_id) adopted_sim_info.genealogy.clear_family_relation(relation) if adopted_sim_info.household is not parent_a.household: adopted_sim_info.household.remove_sim_info(adopted_sim_info) PregnancyTracker.initialize_sim_info(adopted_sim_info, parent_a, parent_b) adopted_sim_info.trait_tracker.remove_trait(self.adoption_trait) if adopted_sim_info.age == Age.BABY: adopted_sim_info.set_zone_on_spawn() create_and_place_baby(adopted_sim_info, ignore_daycare=True) else: SimSpawner.spawn_sim(adopted_sim_info, sim_position=self.sim.position) return True
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')
def _do_behavior(self): resolver = self.interaction.get_resolver() target_participant = resolver.get_participant( self.sim_info_source.participant) household = self.household_option(self.interaction) client_manager = services.client_manager() for (sim_info, position, location, use_fgl) in self.sim_info_source.get_sim_infos_and_positions( resolver, household): if target_participant is not None: self._apply_relationship_bits(target_participant, sim_info) single_sim_resolver = SingleSimResolver(sim_info) for loot in self.pre_spawn_loot: loot.apply_to_resolver(single_sim_resolver) self.sim_info_source.do_pre_spawn_behavior(sim_info, resolver, household) SimSpawner.spawn_sim(sim_info, position, spawn_action=self.spawn_action, sim_location=location, use_fgl=use_fgl) if self.set_summoning_purpose is not None: services.current_zone().venue_service.active_venue.summon_npcs( (sim_info, ), self.set_summoning_purpose) if self.set_genealogy is not None and target_participant is not None: self.set_genealogy(target_participant, sim_info) self.sim_info_source.do_post_spawn_behavior( sim_info, resolver, client_manager) return True
def create_pet_with_breed(breed: TunableInstanceParam( sims4.resources.Types.BREED), gender: Gender = Gender.FEMALE, age: Age = Age.ADULT, x: float = 0, y: float = 0, z: float = 0, _connection=None): if age not in (Age.CHILD, Age.ADULT, Age.ELDER): sims4.commands.output('Invalid age for pet: {}'.format(age), _connection) return client = services.client_manager().get(_connection) position = sims4.math.Vector3(x, y, z) if x and y and z else None sims4.commands.output('Creating pet with breed: {}'.format(breed.__name__), _connection) sim_creator = SimCreator(age=age, gender=gender, species=breed.breed_species, additional_tags=(breed.breed_tag, )) SimSpawner.create_sims((sim_creator, ), household=None, tgt_client=client, generate_deterministic_sim=True, sim_position=position, account=client.account, creation_source='cheat: pets.create_pet_with_breed')
def _do_behavior(self): stored_sim_info_object = self.interaction.get_participant( self.sim_info_subject) sim_info = stored_sim_info_object.get_stored_sim_info() if self.add_to_participant_household is not None: sim = self.interaction.get_participant( self.add_to_participant_household) if sim is None: logger.error( 'SimCreationElement: {} does not have participant {}', self.interaction, self.add_to_participant_household, owner='edwardramirez') return False household = sim.household if household is not sim_info.household: if not household.can_add_sim_info(sim_info): logger.error( 'SimCreationElement: Trying to add {} to household {}. Household too full.', household, sim_info, owner='edwardramirez') return False household.add_sim_info(sim_info) sim_info.assign_to_household(household) SimSpawner.spawn_sim(sim_info, stored_sim_info_object.position, spawn_action=self.spawn_action) client = services.client_manager().get_client_by_household_id( sim_info.household_id) if client is not None: client.add_selectable_sim_info(sim_info) return True
def end_vacation(self): active_household = services.active_household() current_zone_id = services.current_zone_id() current_region_id = get_region_description_id_from_zone_id( current_zone_id) rental_region_id = get_region_description_id_from_zone_id( self._zone_id) if current_region_id != rental_region_id or not active_household.any_member_belong_to_travel_group_id( self.id): at_home = current_zone_id == active_household.home_zone_id for sim_info in self: if active_household.id == sim_info.household_id and at_home: if not sim_info.is_instanced( allow_hidden_flags=ALL_HIDDEN_REASONS): SimSpawner.spawn_sim(sim_info) if sim_info.is_instanced( allow_hidden_flags=ALL_HIDDEN_REASONS): services.get_zone_situation_manager( ).make_sim_leave_now_must_run( sim_info.get_sim_instance( allow_hidden_flags=ALL_HIDDEN_REASONS)) else: sim_info.inject_into_inactive_zone( sim_info.household.home_zone_id) elif sim_info.is_instanced( allow_hidden_flags=ALL_HIDDEN_REASONS): services.get_zone_situation_manager( ).make_sim_leave_now_must_run( sim_info.get_sim_instance( allow_hidden_flags=ALL_HIDDEN_REASONS)) else: sim_info.inject_into_inactive_zone( sim_info.household.home_zone_id) services.travel_group_manager( ).destroy_travel_group_and_release_zone(self, return_objects=True) return for instanced_sim in active_household.instanced_sims_gen(): instanced_sim.queue.cancel_all() travel_info = InteractionOps_pb2.TravelSimsToZone() travel_info.zone_id = active_household.home_zone_id active_sims_on_zone = [ active_sim_info for active_sim_info in active_household if active_sim_info.zone_id == current_zone_id ] for sim_info in itertools.chain(self, active_sims_on_zone): if active_household.id == sim_info.household_id: if sim_info.sim_id not in travel_info.sim_ids: travel_info.sim_ids.append(sim_info.sim_id) else: sim_info.inject_into_inactive_zone( sim_info.household.home_zone_id) distributor.system.Distributor.instance().add_event( Consts_pb2.MSG_TRAVEL_SIMS_TO_ZONE, travel_info) services.game_clock_service().set_clock_speed(ClockSpeedMode.PAUSED) services.travel_group_manager().destroy_travel_group_and_release_zone( self)
def _create_non_baby_offspring(self, pregnancy_tracker, offspring_data_list, target): created_sim_infos = [] for offspring_data in offspring_data_list: sim_info = pregnancy_tracker.create_sim_info(offspring_data) created_sim_infos.append(sim_info) SimSpawner.spawn_sim(sim_info, target.position, sim_location=target.location) return tuple(created_sim_infos)
def post_career_event_travel(cls, sim_info, zone_id_override=None, outfit_change_reason=None): target_zone_id = sim_info.household.home_zone_id sims_to_move = set() if sim_info.zone_id != target_zone_id: sims_to_move.add(sim_info) if outfit_change_reason is not None: outfit_change = sim_info.get_outfit_for_clothing_change( None, outfit_change_reason, SingleSimResolver(sim_info)) sim_info.set_current_outfit(outfit_change) if zone_id_override is not None: main_zone_id = zone_id_override else: main_zone_id = services.get_career_service( ).get_main_career_event_zone_id_and_unlock_save() services.get_career_service().last_career_event_zone_id = None if main_zone_id is not None: if main_zone_id != target_zone_id: for household_sim_info in sim_info.household: if household_sim_info is not sim_info: if household_sim_info.zone_id == main_zone_id: sims_to_move.add(household_sim_info) if target_zone_id == services.current_zone_id(): for sim_to_move in sims_to_move: SimSpawner.spawn_sim(sim_to_move) return sims_ids_to_travel = set() for sim_to_move in sims_to_move: if sim_to_move.is_instanced(allow_hidden_flags=ALL_HIDDEN_REASONS): sims_ids_to_travel.add(sim_to_move.sim_id) else: sim_to_move.inject_into_inactive_zone(target_zone_id) if sims_ids_to_travel: persistence_service = services.get_persistence_service() if persistence_service.is_save_locked(): household = sim_info.household def post_save_lock_travel(): household_sims = { sim.sim_id: sim for sim in household.instanced_sims_gen() } sim_ids = set( sim_id for sim_id in sims_ids_to_travel if sim_id in household_sims if get_death_interaction(household_sims[sim_id]) is None) if sim_ids: travel_sims_to_zone(sim_ids, target_zone_id) persistence_service.add_save_unlock_callback( post_save_lock_travel) else: travel_sims_to_zone(sims_ids_to_travel, target_zone_id)
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 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)
def create_offspring_data(self): r = random.Random() r.seed(self._seed) offspring_count = pop_weighted( [(p.weight * p.modifiers.get_multiplier(SingleSimResolver(self._sim_info)), p.size) for p in self.MULTIPLE_OFFSPRING_CHANCES], random=r) offspring_count = min(self._sim_info.household.free_slot_count + 1, offspring_count) self._offspring_data = [] for offspring_index in range(offspring_count): if offspring_index and r.random( ) < self.MONOZYGOTIC_OFFSPRING_CHANCE: gender = self._offspring_data[offspring_index - 1].gender genetics = self._offspring_data[offspring_index - 1].genetics else: gender = Gender.MALE if r.random() < 0.5 else Gender.FEMALE genetics = r.randint(1, MAX_UINT32) last_name = SimSpawner.get_family_name_for_gender( self._sim_info.account, self._sim_info.last_name, gender == Gender.FEMALE) traits = self._select_traits_for_offspring(gender) self._offspring_data.append( PregnancyOffspringData(gender, genetics, last_name=last_name, traits=traits))
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
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)
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')
def spawn_sim(sim_info: SimInfo, location: CommonLocation=None, position: CommonVector3=None, **kwargs) -> bool: """spawn_sim(sim_info, location=None, position=None, **kwargs) Spawn a Sim. ..note:: Do not provide sim_position or sim_location in kwargs as they are already specified as location and position. :param sim_info: The Sim to Spawn. :type sim_info: SimInfo :param location: The location to spawn the Sim at. Default is None. :type location: CommonLocation, optional :param position: The position to spawn the Sim at. Default is None. :type position: CommonVector3, optional :return: True, if the Sim was spawned successfully. False, if not. :rtype: bool """ SimSpawner.spawn_sim(sim_info, sim_location=location, sim_position=position, **kwargs) return True
def spawn_sim(sim_info: SimInfo, location: Vector3) -> bool: """spawn_sim(sim_info, location) Spawn a Sim. :param sim_info: The Sim to Spawn. :type sim_info: SimInfo :param location: The location to spawn the Sim at. :type location: Vector3 :return: True, if the Sim was spawned successfully. False, if not. :rtype: bool """ try: SimSpawner.spawn_sim(sim_info, sim_location=location) except Exception as ex: CommonExceptionHandler.log_exception(ModInfo.get_identity().name, 'Failed to spawn Sim with SimInfo \'{}\' at location \'{}\'.'.format(sim_info, location), exception=ex) return False return True
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 baby_age_up(sim_info, client=DEFAULT): middle_bassinet = _replace_bassinet_for_age_up(sim_info) if middle_bassinet is not None: try: def run_age_up(kid): def age_up_exit_behavior(): new_bassinet = create_object( Baby.get_corresponding_definition( middle_bassinet.definition)) new_bassinet.location = middle_bassinet.location middle_bassinet.make_transient() kid.fade_opacity(1, 0) kid.visibility = VisibilityState(False) affordance = Baby.BABY_AGE_UP.age_up_affordance aop = AffordanceObjectPair( affordance, middle_bassinet, affordance, None, exit_functions=(age_up_exit_behavior, )) context = InteractionContext( kid, InteractionSource.SCRIPT, interactions.priority.Priority.Critical, insert_strategy=QueueInsertStrategy.NEXT) result = aop.test_and_execute(context) if result: result.interaction.add_liability( AGING_LIABILITY, AgingLiability(sim_info, Age.BABY)) else: logger.error('Failed to run baby age up interaction.', owner='jjacobson') return True if not SimSpawner.spawn_sim(sim_info, middle_bassinet.position, spawn_action=run_age_up): logger.error( 'Failed to spawn sim in process of baby age up. We are in an unrecoverable situation if this occurs.', owner='jjacobson') if client is DEFAULT: client = services.client_manager().get_client_by_household_id( sim_info.household_id) while client is not None: if sim_info not in client.selectable_sims: client.selectable_sims.add_selectable_sim_info(sim_info) else: client.on_sim_added_to_skewer(sim_info) client.selectable_sims.notify_dirty() except Exception as e: logger.exception('{} fail to age up with sim_info {}', middle_bassinet, sim_info, exc=e)
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 _do_behavior(self): stored_sim_info_object = self.interaction.get_participant(self.sim_info_subject) sim_info = stored_sim_info_object.get_stored_sim_info() if self.add_to_participant_household is not None: sim = self.interaction.get_participant(self.add_to_participant_household) if sim is None: logger.error('SimCreationElement: {} does not have participant {}', self.interaction, self.add_to_participant_household, owner='edwardramirez') return False household = sim.household if household is not sim_info.household: if not household.can_add_sim_info(sim_info): logger.error('SimCreationElement: Trying to add {} to household {}. Household too full.', household, sim_info, owner='edwardramirez') return False household.add_sim_info(sim_info) sim_info.assign_to_household(household) SimSpawner.spawn_sim(sim_info, stored_sim_info_object.position, spawn_action=self.spawn_action) client = services.client_manager().get_client_by_household_id(sim_info.household_id) if client is not None: client.add_selectable_sim_info(sim_info) return True
def spawn_for_age_up(sim_info, position, spawn_action=None, sim_location=None): sim_info.advance_age() if spawn_action is None: spawn_action = lambda _: None def _pre_add(obj): obj.opacity = 1 obj.visibility = VisibilityState(False) SimSpawner.spawn_sim(sim_info, position, spawn_action=spawn_action, sim_location=sim_location, pre_add_fn=_pre_add) target_sim = sim_info.get_sim_instance( allow_hidden_flags=ALL_HIDDEN_REASONS) return target_sim
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)
def bind_familiar(self, familiar_type, pet_familiar=None): if pet_familiar is None: name = SimSpawner.get_random_first_name(Gender.MALE, sim_name_type_override=FamiliarTracker.FAMILIAR_DATA[familiar_type].familiar_type.name_list) pet_familiar_id = None else: name = None pet_familiar_id = pet_familiar.sim_id services.relationship_service().add_relationship_bit(self._owner.sim_id, pet_familiar.sim_id, FamiliarTracker.PET_FAMILIAR_BIT) familiar_uid = id_generator.generate_object_id() new_familiar = FamiliarInfo(familiar_uid, familiar_type, name, pet_familiar_id) self._familiars[new_familiar.uid] = new_familiar return new_familiar.uid
def _setup_uninstantiated_travel(self, sim_id, rabbit_hole_id): sim_info = services.sim_info_manager().get(sim_id) home_zone_id = sim_info.household.home_zone_id if services.current_zone_id() != home_zone_id: sim_info.inject_into_inactive_zone(home_zone_id) return self._setup_uninstantiated_no_travel(sim_id, rabbit_hole_id) else: return SimSpawner.spawn_sim( sim_info, spawn_action=lambda _: self._setup_instantiated_no_travel( sim_info.id, rabbit_hole_id), update_skewer=False)
def create_offspring_data(self): r = random.Random() r.seed(self._seed) if self._offspring_count_override is not None: offspring_count = self._offspring_count_override else: offspring_count = pop_weighted([ (p.weight * p.modifiers.get_multiplier(SingleSimResolver(self._sim_info)), p.size) for p in self.MULTIPLE_OFFSPRING_CHANCES ], random=r) offspring_count = min(self._sim_info.household.free_slot_count + 1, offspring_count) species = self._sim_info.species age = self._sim_info.get_birth_age() aging_data = AgingTuning.get_aging_data(species) num_personality_traits = aging_data.get_personality_trait_count(age) self._offspring_data = [] for offspring_index in range(offspring_count): if offspring_index and r.random( ) < self.MONOZYGOTIC_OFFSPRING_CHANCE: gender = self._offspring_data[offspring_index - 1].gender genetics = self._offspring_data[offspring_index - 1].genetics else: gender_chance_stat = self._sim_info.get_statistic( self.GENDER_CHANCE_STAT) if gender_chance_stat is None: gender_chance = 0.5 else: gender_chance = (gender_chance_stat.get_value() - gender_chance_stat.min_value) / ( gender_chance_stat.max_value - gender_chance_stat.min_value) gender = Gender.FEMALE if r.random( ) < gender_chance else Gender.MALE genetics = r.randint(1, MAX_UINT32) last_name = SimSpawner.get_last_name(self._sim_info.last_name, gender, species) offspring_data = PregnancyOffspringData(age, gender, species, genetics, last_name=last_name) (parent_a, parent_b) = self.get_parents() offspring_data.traits = self.select_traits_for_offspring( offspring_data, parent_a, parent_b, num_personality_traits, origin=self._origin) self._offspring_data.append(offspring_data)
def _name_and_create_adoptee_gen(self, timeline): adopted_sim_info = self.get_participant(ParticipantType.PickedSim) if adopted_sim_info is None: return False yield last_name = SimSpawner.get_last_name(self.sim.last_name, adopted_sim_info.gender, adopted_sim_info.species) result = yield from self._do_renames_gen( timeline, (adopted_sim_info, ), additional_tokens=(last_name, )) if not result: return result yield parent_a = self.sim.sim_info parent_b = services.sim_info_manager().get(parent_a.spouse_sim_id) adoption_service = services.get_adoption_service() adoption_service.remove_sim_info(adopted_sim_info) (adopted_sim_info, _) = adoption_service.create_adoption_sim_info( adopted_sim_info, household=parent_a.household, account=parent_a.account, zone_id=parent_a.household.home_zone_id) PregnancyTracker.initialize_sim_info(adopted_sim_info, parent_a, parent_b) self.interaction_parameters['picked_item_ids'] = { adopted_sim_info.sim_id } services.daycare_service().exclude_sim_from_daycare(adopted_sim_info) if adopted_sim_info.age == Age.BABY: adopted_sim_info.set_zone_on_spawn() if not assign_bassinet_for_baby(adopted_sim_info): create_and_place_baby(adopted_sim_info) else: SimSpawner.spawn_sim(adopted_sim_info, sim_position=self.sim.position) return True yield
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
def start_top_career_event(self, start_situation_fn=None): career_event = self._get_top_career_event() target_zone_id = career_event.get_required_zone_id() sim_info = self._career.sim_info if start_situation_fn is not None: def _start_travel(): event_situation_id = start_situation_fn(target_zone_id) career_event.set_event_situation_id(event_situation_id) else: def _start_travel(): return travel_sim_to_zone(sim_info.id, target_zone_id) def _start_event(): self.start_immediately(career_event) if start_situation_fn is not None: event_situation_id = start_situation_fn(target_zone_id) career_event.set_event_situation_id(event_situation_id) if target_zone_id is None: target_zone_id = 0 _start_event() elif sim_info.is_instanced(allow_hidden_flags=ALL_HIDDEN_REASONS): if sim_info.zone_id == target_zone_id: _start_event() else: _start_travel() elif services.current_zone_id() == target_zone_id: SimSpawner.spawn_sim(sim_info, spawn_action=lambda sim: _start_event()) else: if sim_info.zone_id != target_zone_id: sim_info.inject_into_inactive_zone(target_zone_id) _start_travel()
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_offspring_data(self): r = random.Random() r.seed(self._seed) offspring_count = pop_weighted([(p.weight*p.modifiers.get_multiplier(SingleSimResolver(self._sim_info)), p.size) for p in self.MULTIPLE_OFFSPRING_CHANCES], random=r) offspring_count = min(self._sim_info.household.free_slot_count + 1, offspring_count) self._offspring_data = [] for offspring_index in range(offspring_count): if offspring_index and r.random() < self.MONOZYGOTIC_OFFSPRING_CHANCE: gender = self._offspring_data[offspring_index - 1].gender genetics = self._offspring_data[offspring_index - 1].genetics else: gender = Gender.MALE if r.random() < 0.5 else Gender.FEMALE genetics = r.randint(1, MAX_UINT32) last_name = SimSpawner.get_family_name_for_gender(self._sim_info.account, self._sim_info.last_name, gender == Gender.FEMALE) traits = self._select_traits_for_offspring(gender) self._offspring_data.append(PregnancyOffspringData(gender, genetics, last_name=last_name, traits=traits))
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_empty_household(starting_funds: int=0, as_hidden_household: bool=False) -> Household: """create_empty_household(starting_funds=0, as_hidden_household=False) Create an empty household. :param starting_funds: The funds the Household will start with. :type starting_funds: int, optional :param as_hidden_household: If True, the created household will be hidden. :type as_hidden_household: bool, optional :return: The created Household :rtype: Household """ household = Household(SimSpawner._get_default_account(), starting_funds=starting_funds) if as_hidden_household: household.set_to_hidden() services.household_manager().add(household) return household
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
def _get_random_first_name(self, offspring_data): tries_left = 10 def is_valid(first_name): nonlocal tries_left if not first_name: return False tries_left -= 1 if tries_left and any(sim.first_name == first_name for sim in self._sim_info.household): return False if any(sim.first_name == first_name for sim in self._offspring_data): return False return True first_name = None while not is_valid(first_name): first_name = SimSpawner.get_random_first_name(self.account, offspring_data.is_female) return first_name
def baby_age_up(sim_info, client=DEFAULT): middle_bassinet = _replace_bassinet_for_age_up(sim_info) if middle_bassinet is not None: try: def run_age_up(kid): def age_up_exit_behavior(): new_bassinet = create_object(Baby.get_corresponding_definition(middle_bassinet.definition)) new_bassinet.location = middle_bassinet.location middle_bassinet.make_transient() kid.fade_opacity(1, 0) kid.visibility = VisibilityState(False) affordance = Baby.BABY_AGE_UP.age_up_affordance aop = AffordanceObjectPair(affordance, middle_bassinet, affordance, None, exit_functions=(age_up_exit_behavior,)) context = InteractionContext(kid, InteractionSource.SCRIPT, interactions.priority.Priority.Critical, insert_strategy=QueueInsertStrategy.NEXT) result = aop.test_and_execute(context) if result: result.interaction.add_liability(AGING_LIABILITY, AgingLiability(sim_info, Age.BABY)) else: logger.error('Failed to run baby age up interaction.', owner='jjacobson') return True if not SimSpawner.spawn_sim(sim_info, middle_bassinet.position, spawn_action=run_age_up): logger.error('Failed to spawn sim in process of baby age up. We are in an unrecoverable situation if this occurs.', owner='jjacobson') if client is DEFAULT: client = services.client_manager().get_client_by_household_id(sim_info.household_id) while client is not None: if sim_info not in client.selectable_sims: client.selectable_sims.add_selectable_sim_info(sim_info) else: client.on_sim_added_to_skewer(sim_info) client.selectable_sims.notify_dirty() except Exception as e: logger.exception('{} fail to age up with sim_info {}', middle_bassinet, sim_info, exc=e)
def _run_interaction_gen(self, timeline): SimSpawner.spawn_sim(self._sim_info)
def callback_spawn_sims(filter_results, callback_data): for f_result in filter_results: services.get_zone_situation_manager().add_debug_sim_id(f_result.id) SimSpawner.spawn_sim(f_result)