def __call__(self, npc_infos): situation_manager = services.get_zone_situation_manager() player_lot_id = services.active_household_lot_id() active_lot_id = services.active_lot_id() for sim_info in npc_infos: npc = sim_info.get_sim_instance() if npc is None: pass greeted_status = situation_manager.get_npc_greeted_status_during_zone_fixup( sim_info) if active_lot_id == player_lot_id: logger.debug('Player lot greeted {} during zone fixup', sim_info, owner='sscholl') self.player_lot_greeted((sim_info, )) elif greeted_status == GreetedStatus.WAITING_TO_BE_GREETED: logger.debug( 'NPC lot waiting to be greeted {} during zone fixup', sim_info, owner='sscholl') self.npc_lot_ungreeted((sim_info, )) elif greeted_status == GreetedStatus.GREETED: logger.debug('NPC lot greeted {} during zone fixup', sim_info, owner='sscholl') self.npc_lot_greeted((sim_info, )) else: logger.debug('No option for {} during zone fixup', sim_info, owner='sscholl')
def __call__(self, sim_infos, host_sim_info=None): npc_infos = [] selectable_and_resident_infos = [] for sim_info in sim_infos: if sim_info.is_npc and not sim_info.lives_here: npc_infos.append(sim_info) else: selectable_and_resident_infos.append(sim_info) if npc_infos: player_lot_id = services.active_household_lot_id() active_lot_id = services.active_lot_id() if active_lot_id == player_lot_id: if self.player_sim_lot is not None: self.player_sim_lot(npc_infos, host_sim_info) if services.get_zone_situation_manager().is_player_greeted(): if self.npc_lot_greeted is not None: self.npc_lot_greeted(npc_infos, host_sim_info) if self.npc_lot_ungreeted is not None: self.npc_lot_ungreeted(npc_infos, host_sim_info) elif self.npc_lot_ungreeted is not None: self.npc_lot_ungreeted(npc_infos, host_sim_info) elif services.get_zone_situation_manager().is_player_greeted(): if self.npc_lot_greeted is not None: self.npc_lot_greeted(npc_infos, host_sim_info) if self.npc_lot_ungreeted is not None: self.npc_lot_ungreeted(npc_infos, host_sim_info) elif self.npc_lot_ungreeted is not None: self.npc_lot_ungreeted(npc_infos, host_sim_info) for sim_info in selectable_and_resident_infos: while sim_info.get_sim_instance() is None: op = distributor.ops.TravelBringToZone([sim_info.sim_id, 0, services.current_zone().id, 0]) distributor.system.Distributor.instance().add_op_with_no_owner(op)
def get_ambient_walkby_situation(cls): desire = cls._get_desired_ambient_walkby_situations() if desire is None: return lot_id = services.active_lot_id() weighted_situations = tuple((item.weight, item.situation) for item in desire.weighted_situations if item.situation.can_start_walkby(lot_id)) sitaution = random.weighted_random_item(weighted_situations) return sitaution
def request_club_invite(club_id: int, _connection=None): sim_info = services.active_sim_info() if sim_info is None: return club_service = services.get_club_service() if club_service is None: return club = club_service.get_club_by_id(club_id) if club is None: return if any(club_member.is_selectable for club_member in club.members): club.show_club_notification( sim_info, ClubTunables.CLUB_GATHERING_DIALOG_REQUEST_INVITE_ACTIVE_SIM) elif club in club_service.clubs_to_gatherings_map: club.show_club_notification( sim_info, ClubTunables.CLUB_GATHERING_DIALOG_REQUEST_INVITE_CURRENT_LOT) else: club_hangout_zone_id = club.get_hangout_zone_id() if club.hangout_setting == ClubHangoutSetting.HANGOUT_LOT: current_region = services.current_region() hangout_region = get_region_instance_from_zone_id( club_hangout_zone_id) if not current_region.is_region_compatible(hangout_region): club.show_club_notification( sim_info, ClubTunables. CLUB_GATHERING_DIALOG_REQUEST_INVITE_UNAVAILABLE, target_sim_id=club.leader.sim_id) return elif not club_hangout_zone_id: if services.active_lot_id() == services.active_household_lot_id(): def on_response(dialog): if dialog.accepted: club_service.start_gathering( club, host_sim_id=sim_info.sim_id, invited_sims=(sim_info, ), ignore_zone_validity=True) club.show_club_notification( sim_info, ClubTunables.CLUB_GATHERING_DIALOG_REQUEST_INVITE_NO_LOT, target_sim_id=club.leader.sim_id, on_response=on_response) else: club.show_club_notification( sim_info, ClubTunables. CLUB_GATHERING_DIALOG_REQUEST_INVITE_NO_LOT_NOT_HOME, target_sim_id=club.leader.sim_id) return club.show_club_gathering_dialog( sim_info, flavor_text=ClubTunables.CLUB_GATHERING_DIALOG_TEXT_REQUEST_INVITE, start_source=ClubGatheringStartSource.APPLY_FOR_INVITE)
def get_current_lot_id() -> int: """get_current_lot_id() Retrieve the decimal identifier of the current Lot. :return: The decimal identifier of the current Lot or -1 if a problem occurs. :rtype: int """ return services.active_lot_id() or -1
def get_zone_id_from_pick_location(self): lot_id = self.lot_id if lot_id is None: return plex_service = services.get_plex_service() if services.active_lot_id( ) == lot_id and plex_service.is_active_zone_a_plex(): return plex_service.get_plex_zone_at_position( self.location, self.level) persistence_service = services.get_persistence_service() return persistence_service.resolve_lot_id_into_zone_id( lot_id, ignore_neighborhood_id=self._ignore_neighborhood_id)
def get_ambient_walkby_situation(cls, sim_slots_available): lot_id = services.active_lot_id() def can_start_situation(situation): if services.game_clock_service().clock_speed == ClockSpeedMode.SUPER_SPEED3 and not situation.allowed_in_super_speed_3: return False return situation.can_start_walkby(lot_id, sim_slots_available) household = services.active_household() additional_walkbys = [] if household is not None: additional_walkbys.extend(household.holiday_tracker.get_additional_holiday_walkbys(predicate=can_start_situation)) return cls.walkby_desire_by_day_of_week.get_situation_and_params(predicate=can_start_situation, additional_situations=additional_walkbys)[0]
def can_schedule_situation(self, situation, limit_based_on_sims=False, number_of_sims_desired=0, **kwargs): if services.game_clock_service( ).clock_speed == clock.ClockSpeedMode.SUPER_SPEED3 and not situation.allowed_in_super_speed_3: return False if limit_based_on_sims and not situation.can_start_walkby( services.active_lot_id(), number_of_sims_desired): return False return situation.situation_meets_starting_requirements( **kwargs) and not services.get_zone_modifier_service( ).is_situation_prohibited(services.current_zone_id(), situation)
def __init__(self, owner, spawner_tags, *, bone_name, bone_offset, rows, columns, scale, priority): self._owner = owner self._bone_name = bone_name self._bone_offset = bone_offset self._scale = scale self._rows = rows self._columns = columns self._priority = priority random_indices = list(range(rows*columns)) random.shuffle(random_indices) self._random_index_gen = itertools.cycle(random_indices) self._footprint_polygon = None self._tags = frozenset(spawner_tags) lot_id = services.active_lot_id() if owner.is_on_active_lot() else 0 super().__init__(lot_id, owner.zone_id, routing_surface=owner.routing_surface)
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self._sim = self._context.sim if self._context.pick is not None: pick_position = self._context.pick.location self._pick_vector = pick_position - self._sim.position self._pick_vector /= self._pick_vector.magnitude() else: self._pick_vector = self._sim.forward if self._sim.is_on_active_lot(): plex_service = services.get_plex_service() if plex_service.is_active_zone_a_plex(): tags = (SpawnPoint.VISITOR_ARRIVAL_SPAWN_POINT_TAG,) else: tags = (SpawnPoint.ARRIVAL_SPAWN_POINT_TAG,) spawn_point = services.current_zone().get_spawn_point(lot_id=services.active_lot_id(), sim_spawner_tags=tags) self._origin_position = spawn_point.get_approximate_center() self._except_lot_id = services.active_lot_id() else: self._origin_position = self._sim.position self._except_lot_id = None self._routing_surface = routing.SurfaceIdentifier(services.current_zone_id(), 0, routing.SurfaceType.SURFACETYPE_WORLD) self._start_constraint = Circle(self._origin_position, self.constraint_radius, routing_surface=self._routing_surface, los_reference_point=None) self._start_constraint = self._start_constraint.intersect(self.get_water_constraint())
def run_away(self, pet_info): if self.missing_pet_id != 0 or self._running_away: return if not self._household.is_active_household or self._household.home_zone_id != services.current_zone_id(): return if self._cooldown_alarm is not None: return pet = pet_info.get_sim_instance() if pet is None: return spawn_point = services.current_zone().get_spawn_point(lot_id=services.active_lot_id()) routing_location = routing.Location(spawn_point.get_approximate_center(), sims4.math.Quaternion.ZERO(), spawn_point.routing_surface) if not routing.test_connectivity_pt_pt(pet.routing_location, routing_location, pet.routing_context): return if self._push_run_away_affordance(pet): if self.RUN_AWAY_NOTIFICATION is not None: dialog = self.RUN_AWAY_NOTIFICATION(pet_info, SingleSimResolver(pet_info)) dialog.show_dialog() self._running_away = True
def __call__(self, npc_infos): situation_manager = services.get_zone_situation_manager() player_lot_id = services.active_household_lot_id() active_lot_id = services.active_lot_id() for sim_info in npc_infos: npc = sim_info.get_sim_instance() if npc is None: pass greeted_status = situation_manager.get_npc_greeted_status_during_zone_fixup(sim_info) if active_lot_id == player_lot_id: logger.debug('Player lot greeted {} during zone fixup', sim_info, owner='sscholl') self.player_lot_greeted((sim_info,)) elif greeted_status == GreetedStatus.WAITING_TO_BE_GREETED: logger.debug('NPC lot waiting to be greeted {} during zone fixup', sim_info, owner='sscholl') self.npc_lot_ungreeted((sim_info,)) elif greeted_status == GreetedStatus.GREETED: logger.debug('NPC lot greeted {} during zone fixup', sim_info, owner='sscholl') self.npc_lot_greeted((sim_info,)) else: logger.debug('No option for {} during zone fixup', sim_info, owner='sscholl')
def __call__(self, sim_infos, host_sim_info=None): npc_infos = [] selectable_and_resident_infos = [] for sim_info in sim_infos: if sim_info.is_npc and not sim_info.lives_here: npc_infos.append(sim_info) else: selectable_and_resident_infos.append(sim_info) if npc_infos: player_lot_id = services.active_household_lot_id() active_lot_id = services.active_lot_id() if active_lot_id == player_lot_id: if self.player_sim_lot is not None: self.player_sim_lot(npc_infos, host_sim_info) if services.get_zone_situation_manager().is_player_greeted( ): if self.npc_lot_greeted is not None: self.npc_lot_greeted(npc_infos, host_sim_info) if self.npc_lot_ungreeted is not None: self.npc_lot_ungreeted(npc_infos, host_sim_info) elif self.npc_lot_ungreeted is not None: self.npc_lot_ungreeted(npc_infos, host_sim_info) elif services.get_zone_situation_manager().is_player_greeted(): if self.npc_lot_greeted is not None: self.npc_lot_greeted(npc_infos, host_sim_info) if self.npc_lot_ungreeted is not None: self.npc_lot_ungreeted(npc_infos, host_sim_info) elif self.npc_lot_ungreeted is not None: self.npc_lot_ungreeted(npc_infos, host_sim_info) for sim_info in selectable_and_resident_infos: while sim_info.get_sim_instance() is None: op = distributor.ops.TravelBringToZone( [sim_info.sim_id, 0, services.current_zone().id, 0]) distributor.system.Distributor.instance().add_op_with_no_owner( op)
def is_validity_overridden(self): return self._validity_household_id_override == services.active_household_id() and services.active_household_lot_id() == services.active_lot_id()
def __init__(self, owner, *, is_front): self._owner = owner self._is_front = is_front lot_id = services.active_lot_id() if owner.is_on_active_lot() else 0 super().__init__(lot_id, owner.zone_id, routing_surface=owner.routing_surface)
def get_active_lot_id(): return services.active_lot_id() or -1
def generate_street_civic_policy_data(*args, zone_id: int = None, **kwargs): service_info = [] street_service = services.street_service() if street_service is None: return service_info persistence_service = services.get_persistence_service() household_manager = services.household_manager() statistics_manager = services.get_instance_manager( sims4.resources.Types.STATISTIC) active_lot_id = services.active_lot_id() active_street = services.current_zone().street voting_open = street_service.voting_open for (street, instance) in street_service._provider_instances.items(): civic_policy_entry = [] enacted_policies = instance.get_enacted_policies(tuning=True) balloted_policies = instance.get_balloted_policies(tuning=True) up_for_repeal = instance.get_up_for_repeal_policies(tuning=True) for policy in instance.get_civic_policies(tuning=True): status_str = '' if policy in enacted_policies: status_str += 'Enacted ' if policy in balloted_policies: status_str += 'Balloted ' if policy in up_for_repeal: status_str += 'Up for Repeal' if status_str == '': status_str = 'Dormant' if policy.vote_count_statistic is None: votes = 'n/a' else: votes = instance.get_stat_value(policy.vote_count_statistic) entry = { 'civic_policy': str(policy), 'status': status_str, 'votes': votes } civic_policy_entry.append(entry) street_footprint = instance.get_street_footprint(add=False) has_eco_footprint = street_footprint is not None eco_footprint_state = 'None' eco_footprint_value = 'None' eco_footprint_convergence = 'None' if has_eco_footprint: eco_footprint_state = instance.current_eco_footprint_state.name eco_footprint_value = street_footprint.get_value( ) if has_eco_footprint else None eco_footprint_convergence = street_footprint.convergence_value lot_eco_footprint_entry = [] if street is not None: lot_id_to_zone_id_dict = get_lot_id_to_zone_ids_dict(street) for (lot_id, zone_ids) in lot_id_to_zone_id_dict.items(): is_played_lot = False for zone_id in zone_ids: household_id = persistence_service.get_household_id_from_zone_id( zone_id) if household_id: household = household_manager.get(household_id) if household is not None: if household.is_played_household: is_played_lot = True break footprint_value = EcoFootprintTunables.LOT_FOOTPRINT.default_value if active_lot_id == lot_id: lot = services.active_lot() footprint_value = lot.commodity_tracker.get_value( EcoFootprintTunables.LOT_FOOTPRINT) else: zone_data = persistence_service.get_zone_proto_buff( zone_ids[0]) if zone_data is not None: stat_tracker_data = zone_data.gameplay_zone_data.commodity_tracker for stat_data in stat_tracker_data.commodities: stat_cls = statistics_manager.get( stat_data.name_hash) if stat_cls is EcoFootprintTunables.LOT_FOOTPRINT: footprint_value = stat_data.value break else: house_desc_id = services.get_house_description_id( zone_data.lot_template_id, zone_data.lot_description_id, zone_data.active_plex) footprint_value = services.get_eco_footprint_value( house_desc_id) zone_data = persistence_service.get_zone_proto_buff( zone_ids[0]) lot_data = persistence_service.get_lot_data_from_zone_data( zone_data) lot_name = lot_data.lot_name if lot_name is '': lot_name = 'Unavailable' lot_desc_id = lot_data.lot_description_id if lot_data is not None else None entry = { 'lot_name': lot_name, 'lot_description_id': lot_desc_id, 'category': 'Played' if is_played_lot else 'Unplayed', 'footprint': footprint_value } lot_eco_footprint_entry.append(entry) entry = { 'street': str(street), 'voting_open': 'Yes' if voting_open else 'No', 'active': 'X' if street is active_street else '', 'civic_policies': civic_policy_entry, 'eco_footprint_state': eco_footprint_state, 'eco_footprint': eco_footprint_value, 'eco_footprint_convergence': eco_footprint_convergence, 'lot_eco_footprint': lot_eco_footprint_entry } service_info.append(entry) service_info = sorted(service_info, key=lambda entry: entry['street']) return service_info