def set_front_door(obj_id:int, _connection=None): door = services.object_manager().get(obj_id) if door is not None and isinstance(door, objects.doors.door.Door) and door.is_door_portal: services.get_door_service().set_as_front_door(door) sims4.commands.output('Object {} set as front door'.format(str(door)), _connection) else: sims4.commands.output('Object {} is not a door, no door will be set'.format(str(door)), _connection)
def recalculate_front_door(_connection=None): services.get_door_service().fix_up_doors(force_refresh=True) door = services.get_door_service().get_front_door() if door is None: sims4.commands.output('No valid front door found', _connection) else: sims4.commands.output('Front door found. Door {} on position {}'.format(str(door), door.position), _connection)
def _constraint_gen(cls, inst, sim, target, *args, to_zone_id=DEFAULT, **kwargs): yield from super(__class__, inst if inst is not None else cls)._constraint_gen( sim, target, *args, **kwargs) yield services.current_zone().get_spawn_point_ignore_constraint() inst_or_cls = inst if inst is not None else cls home_zone_id = sim.sim_info.vacation_or_home_zone_id if to_zone_id is DEFAULT else to_zone_id if home_zone_id == services.current_zone_id(): if services.get_door_service().has_front_door(): yield inst_or_cls.front_door_constraint.create_constraint(sim) else: yield inst_or_cls.home_spawn_point_constraint.create_constraint( sim, lot_id=services.current_zone().lot.lot_id) yield STAND_CONSTRAINT elif sim.sim_info.is_child_or_older: persistence_service = services.get_persistence_service() zone_data = persistence_service.get_zone_proto_buff(home_zone_id) if zone_data is not None and zone_data.world_id == services.current_zone( ).world_id: home_lot_id = zone_data.lot_id yield inst_or_cls.home_spawn_point_constraint.create_constraint( sim, lot_id=home_lot_id) else: yield inst_or_cls.street_spawn_point_constraint.create_constraint( sim)
def start_situation(self): super().start_situation() if services.get_door_service().has_front_door(): self._change_state(self.has_front_door_situation_starting_state()) else: self._change_state( self.has_no_front_door_situation_starting_state())
def validate_front_door(_connection=None): active_lot = services.active_lot() if active_lot is None: return door = services.get_door_service().get_front_door() if door is None: sims4.commands.output('Lot has no front door set', _connection) else: sims4.commands.output('Front door found. Door {} on position {}'.format(str(door), door.position), _connection)
def on_activate(self, reader=None): super().on_activate(reader) if not services.get_door_service().has_front_door(): return for sim in self.owner.all_sims_in_situation_gen(): if sim.is_selectable: continue context = InteractionContext(sim, InteractionContext.SOURCE_SCRIPT, Priority.High, insert_strategy=QueueInsertStrategy.NEXT) sim.push_super_affordance(self._interaction_to_push, sim, context)
def assign_mailbox_owners(self): plex_service = services.get_plex_service() door_service = services.get_door_service() if not plex_service.is_active_zone_a_plex(): return if plex_service.get_plex_building_type( services.current_zone_id()) == PlexBuildingType.PENTHOUSE_PLEX: return plex_door_infos = door_service.get_plex_door_infos() if not plex_door_infos: return object_manager = services.object_manager() unclaimed_mailboxes = [] for mailbox in object_manager.get_objects_with_tags_gen( *self.MAILBOX_TAGS): mailbox.set_household_owner_id(None) unclaimed_mailboxes.append(mailbox) mailbox_handles = [ self._create_mailbox_handle(mailbox) for mailbox in unclaimed_mailboxes ] door_handles = self._create_plexdoor_handles(plex_door_infos) path_plan_context = routing.PathPlanContext() path_plan_context.set_key_mask(routing.FOOTPRINT_KEY_ON_LOT | routing.FOOTPRINT_KEY_OFF_LOT) routes = routing_utils.sorted_estimated_distances_between_multiple_handles( mailbox_handles, door_handles, path_plan_context) for estimated_distance in routes: mbox_handle = estimated_distance[0] door_handle = estimated_distance[1] mailbox = mbox_handle.obj door = door_handle.obj if mbox_handle.assigned: continue if door_handle.assigned: continue mapped_household_ids = set() household_id = door.household_owner_id if household_id != 0 and household_id not in mapped_household_ids: mapped_household_ids.add(household_id) self._apply_ownership(mailbox, household_id) door_handle.assigned = True mbox_handle.assigned = True logger.debug( 'mailbox {} paired with a door {} owned by household {}', mailbox, door, household_id) if not [dh for dh in door_handles if not dh.assigned]: break if not [mbh for mbh in mailbox_handles if not mbh.assigned]: break
def _get_ungreeted_overrides(self, context, **kwargs): zone_director = services.venue_service().get_zone_director() if not zone_director.forward_ungreeted_front_door_interactions_to_terrain: return if context.pick.pick_type not in PICK_UNGREETED: return if not context.pick.lot_id or context.pick.lot_id != services.active_lot( ).lot_id: return if not services.get_zone_situation_manager( ).is_player_waiting_to_be_greeted(): return front_door = services.get_door_service().get_front_door() if front_door is None: return yield from front_door.potential_interactions(context, **kwargs)
def get_default_position(self, position=None): front_door = services.get_door_service().get_front_door() if front_door is not None: default_position = front_door.position elif position is not None: default_position = min(self.corners, key=lambda p: (p - position).magnitude_squared()) else: plex_service = services.get_plex_service() if plex_service.get_plex_building_type( services.current_zone_id()) == PlexBuildingType.COASTAL: for corner_position in self.corners: if get_water_depth(corner_position.x, corner_position.z) <= 0: default_position = corner_position break else: logger.error( "Couldn't find a corner that was not below water on the current lot. This is probably an error case. We need a place to put down things like the mailbox, etc." ) default_position = self.corners[0] else: default_position = self.corners[0] delta = self.position - default_position if not sims4.math.vector3_almost_equal(delta, sims4.math.Vector3.ZERO()): default_position += vector_normalize(delta) if front_door is not None: plex_service = services.get_plex_service() if plex_service.is_active_zone_a_plex(): (front_position, back_position) = front_door.get_door_positions() if front_position is not None: front_zone_id = plex_service.get_plex_zone_at_position( front_position, front_door.level) else: front_zone_id = None if front_zone_id is not None: default_position = front_position elif back_position is not None: back_zone_id = plex_service.get_plex_zone_at_position( back_position, front_door.level) if back_zone_id is not None: default_position = back_position return default_position
def _set_loud_neighbor_and_door(self, neighbor_sim_id): neighbor_sim_info = services.sim_info_manager().get(neighbor_sim_id) if neighbor_sim_info is None: self._self_destruct() return self._neighbor_sim_id = neighbor_sim_id door_service = services.get_door_service() plex_door_infos = door_service.get_plex_door_infos() object_manager = services.object_manager() for door_info in plex_door_infos: door = object_manager.get(door_info.door_id) if door is not None: if door.household_owner_id == neighbor_sim_info.household_id: self._neighbor_door_id = door_info.door_id break else: logger.error('Could not find door object that belongs to {}', neighbor_sim_info.household.name) self._self_destruct()
def is_valid(self, sim_info=None, spawn_point_request_reason=SpawnPointRequestReason.DEFAULT): if sim_info is None: return False for plex_door_info in services.get_door_service().get_plex_door_infos(): if plex_door_info.door_id == self._owner.id: break else: logger.error('Failed to find plex door info for door {}', self._owner) return False if spawn_point_request_reason == SpawnPointRequestReason.SPAWN: if sim_info.prespawn_zone_id == plex_door_info.zone_id: return True return False elif spawn_point_request_reason == SpawnPointRequestReason.LEAVE: if sim_info.household.home_zone_id == plex_door_info.zone_id: return True else: return False return False return False
def _get_plex_postion_for_object_creation(self, start_position, level): plex_service = services.get_plex_service() is_active_zone_a_plex = plex_service.is_active_zone_a_plex() if not is_active_zone_a_plex: return if plex_service.get_plex_zone_at_position(start_position, level) is not None: return front_door = services.get_door_service().get_front_door() if front_door is not None: (front_position, back_position) = front_door.get_door_positions() front_zone_id = plex_service.get_plex_zone_at_position( front_position, front_door.level) if front_zone_id is not None: return front_position else: back_zone_id = plex_service.get_plex_zone_at_position( back_position, front_door.level) if back_zone_id is not None: return back_position
def get_door(self, sim, target=None): participant_sim = None if self.participant == ParticipantTypeActorTargetSim.Actor: participant_sim = sim elif self.participant == ParticipantTypeActorTargetSim.TargetSim: participant_sim = target if participant_sim is None or not participant_sim.is_sim: return door_service = services.get_door_service() plex_door_infos = door_service.get_plex_door_infos() home_zone_id = participant_sim.household.home_zone_id if home_zone_id == services.current_zone_id(): return door_service.get_front_door() state = DoorTuning.INACTIVE_APARTMENT_DOOR_STATE.enabled.state for plex_door_info in plex_door_infos: if plex_door_info.zone_id != home_zone_id: continue door = services.object_manager().get(plex_door_info.door_id) if door is not None: if door.get_state( state ) is DoorTuning.INACTIVE_APARTMENT_DOOR_STATE.enabled: return door
def start_situation(self): super().start_situation() if services.get_door_service().has_front_door(): self._change_state(self.front_door_repair_arrival()) else: self._change_state(self.no_front_door_repair_arrival())
def get_objects_gen(self, resolver): front_door = services.get_door_service().get_front_door() if front_door is not None: yield front_door
def get_door(self, sim, target=None): return services.get_door_service().get_front_door()
def _run_interaction_gen(self, timeline): services.get_door_service().set_as_front_door(self.target)
def on_remove(self): services.get_door_service().on_door_removed(self) self._destroy_back_spawn_point() super().on_remove()
def prepare_gen(self, timeline, *args, **kwargs): if not self.sim.can_sim_teleport_using_teleport_style(): return InteractionQueuePreparationStatus.FAILURE yield try: (starting_position, routing_surface_id) = self._get_position_and_surface( self.target, self.context) desired_level = self._get_level_of_target(self.target, self.context) if starting_position is not None: if routing_surface_id is not None: if desired_level is not None: if self.required_destination_surface is not None: zone_id = services.current_zone_id() routing_surface_id = routing.SurfaceIdentifier( zone_id or 0, desired_level, self.required_destination_surface) starting_location = routing.Location( starting_position, routing_surface=routing_surface_id) if self.destination_jig is not None: self._destination_jig_object = self._create_jig_object( ) if self._destination_jig_object is not None: ( position, orientation ) = TeleportHelper.get_fgl_at_destination_for_teleport( starting_location, self._destination_jig_object, destination_must_be_outside=self. destination_must_be_outside) if position is not None: if orientation is not None: self._destination_jig_object.move_to( translation=position, orientation=orientation, routing_surface=routing_surface_id) object_slots = self.destination_jig.get_slots_resource( 0) jig_slot_transform = object_slots.get_slot_transform_by_index( sims4.ObjectSlots.SLOT_ROUTING, 0) jig_slot_concat_transform = sims4.math.Transform.concatenate( sims4.math.Transform( position, orientation), jig_slot_transform) self._teleport_location = routing.Location( jig_slot_concat_transform. translation, orientation=jig_slot_concat_transform .orientation, routing_surface=routing_surface_id) else: ( position, orientation ) = TeleportHelper.get_fgl_at_destination_for_teleport( starting_location, self.sim, destination_must_be_outside=self. destination_must_be_outside) if position is None: if services.current_zone( ).lot.is_position_on_lot(starting_position): front_door = services.get_door_service( ).get_front_door() if front_door: routing_surface_id = front_door.routing_surface door_location = routing.Location( front_door.position, routing_surface=routing_surface_id) ( position, orientation ) = TeleportHelper.get_fgl_at_destination_for_teleport( door_location, self.sim, destination_must_be_outside=self. destination_must_be_outside, ignore_connectivity=True) if position is not None: if orientation is not None: self._teleport_location = routing.Location( position, orientation=orientation, routing_surface=routing_surface_id) except Exception as exception: logger.exception( 'Exception while getting teleport location for TeleportStyleSuperInteraction: ', exc=exception, level=sims4.log.LEVEL_ERROR) self._try_destroy_jig_object() if self._teleport_location is None: return InteractionQueuePreparationStatus.FAILURE yield result = yield from super().prepare_gen(timeline, **kwargs) return result yield
def on_enter(self): super().on_enter() door_service = services.get_door_service() door_service.fix_up_doors() return _ZoneSpinUpStateResult.DONE