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 _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_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 _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 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 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 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 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 _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 _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 _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 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 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)
def callback_spawn_sims(filter_results, callback_data): sim_infos = [result.sim_info for result in filter_results] for sim_info in sim_infos: services.get_zone_situation_manager().add_debug_sim_id(sim_info.id) SimSpawner.spawn_sim(sim_info)