def soft_reset(game_object: GameObject, reset_reason: ResetReason = ResetReason.RESET_EXPECTED, hard_reset_on_exception: bool = False, source: Any = None, cause: Any = 'S4CL Soft Reset') -> bool: """soft_reset(game_object, reset_reason=ResetReason.RESET_EXPECTED, hard_reset_on_exception=False, source=None, cause=None) Perform a soft reset on an Object. :param game_object: An instance of an Object. :type game_object: GameObject :param reset_reason: The reason for the reset. Default is ResetReason.RESET_EXPECTED. :type reset_reason: ResetReason, optional :param hard_reset_on_exception: If set to True, a hard reset of the Object will be attempted upon an error occurring. If set to False, nothing will occur if the reset failed. Default is False. :type hard_reset_on_exception: bool, optional :param source: The source of the reset. Default is the GameObject. :type source: Any, optional :param cause: The cause of the reset. Default is 'S4CL Soft Reset'. :type cause: Any, optional :return: True, if the reset was successful. False, if not. :rtype: bool """ if game_object is None: return True # noinspection PyBroadException try: if game_object.parent is not None and game_object.parent.is_sim and not game_object.parent.posture_state.is_carrying( game_object): CarryingObject.snap_to_good_location_on_floor( game_object, starting_transform=game_object.parent.transform, starting_routing_surface=game_object.parent.routing_surface ) location = game_object.location game_object.on_reset_send_op(reset_reason) game_object.location = location game_object.resend_location() if game_object.routing_component is not None: game_object.routing_component.on_reset_internal_state( reset_reason) if game_object.idle_component is not None: game_object.idle_component._refresh_active_idle() if game_object.linked_object_component is not None: game_object.linked_object_component._relink(update_others=True) return True except: if hard_reset_on_exception: return CommonObjectSpawnUtils.hard_reset( game_object, reset_reason=reset_reason, source=source, cause=cause) return False
def release(self): target_object = self._target_object carry_component = target_object.get_component(CARRYABLE_COMPONENT) if carry_component is None: logger.error( 'Interaction ({0}) has a target ({1}) without a Carryable Component', self._interaction, target_object) return if target_object.parent is not self._parent: carry_component.reset_put_down_count() return if not carry_component.attempted_putdown or not carry_component.attempted_alternative_putdown or target_object.transient: new_context = self._interaction.context.clone_for_continuation( self._interaction) aop = target_object.get_put_down_aop(self._interaction, new_context) aop.test_and_execute(new_context) return if not CarryingObject.snap_to_good_location_on_floor(target_object): sim = self._interaction.sim if sim.household.id is not target_object.get_household_owner_id( ) or not sim.inventory_component.player_try_add_object( target_object): target_object.release_sim(sim) build_buy.move_object_to_household_inventory( target_object, failure_flags=HouseholdInventoryFlags.FORCE_OWNERSHIP)
def create_put_down_on_ground_constraint(sim, target, terrain_transform, cost=0): if cost is None or terrain_transform is None: return Nowhere() swipe_constraint = CarryingObject.get_carry_transition_position_constraint(terrain_transform.translation, sim.routing_surface) carry_constraint = create_carry_constraint(target, debug_name='CarryForPutDownOnGround') final_constraint = swipe_constraint.intersect(carry_constraint).intersect(STAND_OR_SIT_CONSTRAINT) return final_constraint.generate_constraint_with_cost(cost)
def on_reset_internal_state(self, reset_reason): if reset_reason == ResetReason.BEING_DESTROYED: self._registered_transition_controllers.clear() else: if not (self.parent is not None and self.parent.is_sim and self.parent.posture_state.is_carrying(self)): if not CarryingObject.snap_to_good_location_on_floor(self, self.parent.transform, self.parent.routing_surface): self.clear_parent(self.parent.transform, self.parent.routing_surface) self.location = self.location super().on_reset_internal_state(reset_reason)
def _custom_claim_callback(self): super()._custom_claim_callback() if self.put_down: return bar = self.target if bar.is_part: bar = bar.part_owner if self.dest_slot is not None: self.dest_slot.add_child(self.created_target) else: CarryingObject.snap_to_good_location_on_floor(self.created_target) self.put_down = True logger.debug('Push customer to pick up drink') def push_drink(): self._push_drink_pick_up() self.add_exit_function(push_drink)
def _custom_claim_callback(self): super()._custom_claim_callback() if self.put_down: return if self.dest_slot is not None: self.dest_slot.add_child(self.object_to_serve) else: CarryingObject.snap_to_good_location_on_floor(self.object_to_serve) self.put_down = True def push_consume(): logger.debug('Push customer to pick up the object.') self.object_to_serve.set_ready_to_serve() push_object_pick_up_and_consume( self, self.order_sim, self.object_to_serve, consume_affordance_override=self.consume_affordance_override) self.add_exit_function(push_consume)
def create_put_down_on_ground_constraint(sim, target, terrain_transform, cost=0): if cost is None or terrain_transform is None: return Nowhere() swipe_constraint = CarryingObject.get_carry_transition_position_constraint( terrain_transform.translation, sim.routing_surface) carry_constraint = create_carry_constraint( target, debug_name='CarryForPutDownOnGround') final_constraint = swipe_constraint.intersect(carry_constraint).intersect( STAND_OR_SIT_CONSTRAINT) return final_constraint.generate_constraint_with_cost(cost)
def _constraint_gen(cls, inst, sim, target, participant_type=ParticipantType.Actor): for constraint in super(TerrainSuperInteraction, cls)._constraint_gen( sim, target, participant_type=participant_type): yield constraint yield create_carry_constraint(target, debug_name='CarryForPutDown') if inst is not None and inst._carry_system_target._starting_transform is not None: yield CarryingObject.get_carry_transition_position_constraint( inst._carry_system_target._starting_transform.translation, sim.routing_surface)
def on_reset_internal_state(self, reset_reason): if reset_reason == ResetReason.BEING_DESTROYED: self._registered_transition_controllers.clear() else: if not (self.parent is not None and self.parent.is_sim and self.parent.posture_state.is_carrying(self)): if not CarryingObject.snap_to_good_location_on_floor( self, self.parent.transform, self.parent.routing_surface): self.clear_parent(self.parent.transform, self.parent.routing_surface) self.location = self.location super().on_reset_internal_state(reset_reason)
def create_recipe(recipe: TunableInstanceParam(Types.RECIPE), opt_sim: OptionalTargetParam = None, _connection=None): output = sims4.commands.Output(_connection) automation_output = sims4.commands.AutomationOutput(_connection) sim = get_optional_target(opt_sim, _connection) if sim is None: output('No sim for recipe creation') automation_output('CraftingCreateRecipe; Status:No Sim') return False craftable = DebugCreateCraftableInteraction.create_craftable(recipe, sim) if craftable is None: output('Failed To Create Craftable') automation_output( 'CraftingCreateRecipe; Status:Failed To Create Craftable') return False CarryingObject.snap_to_good_location_on_floor( craftable, starting_transform=sim.transform, starting_routing_surface=sim.routing_surface) automation_output( 'CraftingCreateRecipe; Status:Success, ObjectId:{}'.format( craftable.id)) return True
def release(self): target_object = self._interaction.target if target_object is None: return carry_component = target_object.get_component(CARRYABLE_COMPONENT) if carry_component is None: logger.error('Interaction ({0}) has a target ({1}) without a Carryable Component', self._interaction, self._interaction.target) return if target_object.parent is not self._parent: carry_component.reset_put_down_count() return if not carry_component.attempted_putdown or not carry_component.attempted_alternative_putdown or target_object.transient: new_context = self._interaction.context.clone_for_continuation(self._interaction) aop = target_object.get_put_down_aop(self._interaction, new_context) aop.test_and_execute(new_context) return if not CarryingObject.snap_to_good_location_on_floor(target_object): sim = self._interaction.sim if sim.household.id is not target_object.get_household_owner_id() or not sim.inventory_component.player_try_add_object(target_object): target_object.release_sim(sim) build_buy.move_object_to_household_inventory(target_object)
def _get_best_location(self, obj, target): routing_surface = getattr(self.target, 'provided_routing_surface', None) if routing_surface is None: routing_surface = target.routing_surface if self._transform is UNSET: if target.is_terrain: self._transform = target.transform else: (translation, orientation) = CarryingObject.get_good_location_on_floor( obj, starting_transform=target.transform, starting_routing_surface=routing_surface, additional_search_flags=FGLSearchFlag. STAY_IN_CURRENT_BLOCK) if translation is None: self._transform = None else: self._transform = Transform(translation, orientation) return (self._transform, routing_surface)
def _constraint_gen(cls, inst, sim, target, participant_type=ParticipantType.Actor): for constraint in super(TerrainSuperInteraction, cls)._constraint_gen(sim, target, participant_type=participant_type): yield constraint yield create_carry_constraint(target, debug_name='CarryForPutDown') if inst is not None and inst._carry_system_target._starting_transform is not None: yield CarryingObject.get_carry_transition_position_constraint(inst._carry_system_target._starting_transform.translation, sim.routing_surface)