示例#1
0
 def _get_role_state_overrides(self, sim, job_type, role_state_type,
                               role_affordance_target):
     if job_type is not self.owner._fruitcake_bearer_situation_job:
         return super()._get_role_state_overrides(sim, job_type,
                                                  role_state_type,
                                                  role_affordance_target)
     if self.owner._fruitcake_id is not None:
         target = services.current_zone().inventory_manager.get(
             self.owner._fruitcake_id)
     else:
         bearer_recipe = random.choice(self.owner._bearer_recipes)
         if bearer_recipe is None:
             logger.error(
                 'No recipes tuned for the fruitcake-bearer. Recipe                creation failed for {} situation',
                 self,
                 owner='shipark')
             return (role_state_type, None)
         target = DebugCreateCraftableInteraction.create_craftable(
             bearer_recipe,
             sim,
             owning_household_id_override=services.active_household_id(),
             place_in_crafter_inventory=True)
         if target is None:
             raise ValueError('No craftable created for {} on {}'.format(
                 self.owner._fruitcake_recipe, self))
         self.owner._fruitcake_id = target.id
     return (role_state_type, target)
示例#2
0
 def _get_role_state_overrides(self, sim, job_type, role_state_type,
                               role_affordance_target):
     target = self.owner.get_created_object()
     if target is None:
         if self._chosen_recipe is not None:
             target = DebugCreateCraftableInteraction.create_craftable(
                 self._chosen_recipe,
                 sim,
                 owning_household_id_override=services.active_household_id(
                 ),
                 place_in_crafter_inventory=True)
             if target is None:
                 raise ValueError(
                     'No craftable created for {} on {}'.format(
                         self._chosen_recipe, self))
         elif self._chosen_object is not None:
             target = self.owner._create_object_for_situation(
                 sim, self._chosen_object)
             if target is None:
                 raise ValueError('No object created for {} on {}'.format(
                     self._chosen_object, self))
         else:
             raise ValueError(
                 'No valid object to create for {}'.format(self))
         self.owner._created_object_id = target.id
     if target is not None:
         target.transient = True
     return (role_state_type, target)
 def _get_role_state_overrides(self, sim, job_type, role_state_type,
                               role_affordance_target):
     if self.owner._crafted_object_id != 0:
         target = services.current_zone().inventory_manager.get(
             self.owner._crafted_object_id)
     else:
         obj_def_to_craft = self.owner._object_definition_to_craft
         if obj_def_to_craft == 0:
             possible_recipes = self.owner._service_npc_type.recipe_picker_on_hire.recipes
             if possible_recipes is None:
                 raise ValueError('No recipe for {}'.format(self))
             recipe = random.choice(possible_recipes)
         else:
             recipe = services.recipe_manager().get(obj_def_to_craft)
             if recipe is None:
                 raise ValueError('No recipe for {}'.format(self))
         target = DebugCreateCraftableInteraction.create_craftable(
             recipe,
             self.owner._service_npc,
             owning_household_id_override=self.owner._hiring_household.id,
             place_in_crafter_inventory=True)
         if target is None:
             raise ValueError('No craftable created for {} on {}'.format(
                 recipe, self))
         self.owner._crafted_object_id = target.id
     return (role_state_type, target)
示例#4
0
def set_as_head(obj_id: RequiredTargetParam = None,
                scale: float = None,
                forward_rot: float = None,
                up_rot: float = None,
                _connection=None):
    sim = get_optional_target(None, _connection)
    if sim is None:
        return
    original_obj = obj_id.get_target()
    if original_obj is None:
        return
    if original_obj.is_sim:
        sims4.commands.output('Cannot set a Sim as your head.', _connection)
        return
    obj_definition_id = original_obj.definition.id
    if original_obj.crafting_component is not None:
        obj = DebugCreateCraftableInteraction.create_craftable(
            original_obj.crafting_component._crafting_process.recipe, sim)
    else:
        obj = objects.system.create_object(obj_definition_id)
    if obj is None:
        return
    if scale is None:
        head_width = 0.75
        default_object_width = head_width / 4
        polygon = obj.footprint_polygon
        if len(polygon) > 1:
            polygon2 = list(polygon)[1:]
            polygon2.append(polygon[-1])
            object_width_x = max(
                [abs(x - y).x for (x, y) in zip(polygon2, polygon)])
            object_width_z = max(
                [abs(x - y).z for (x, y) in zip(polygon2, polygon)])
            object_width = min((object_width_x, object_width_z))
        else:
            object_width = default_object_width
        new_scale = head_width / object_width
        obj.scale = new_scale
    else:
        obj.scale = scale
    forward_rot = 4 * sims4.math.PI / 3 if forward_rot is None else forward_rot
    up_rot = 3 * sims4.math.PI / 2 if up_rot is None else up_rot
    forward_orientation = sims4.math.Quaternion.from_axis_angle(
        forward_rot, sims4.math.FORWARD_AXIS)
    up_orientation = sims4.math.Quaternion.from_axis_angle(
        up_rot, sims4.math.UP_AXIS)
    orientation = sims4.math.Quaternion.concatenate(forward_orientation,
                                                    up_orientation)
    new_transform = sims4.math.Transform.IDENTITY()
    new_transform.orientation = orientation
    neck_hash = sims4.hash_util.hash32('b__neck__')
    if sim.current_object_set_as_head is not None and sim.current_object_set_as_head(
    ) is not None:
        sim.current_object_set_as_head().destroy(
            source=sim,
            cause='Destroying existing object set as head when setting new one.'
        )
    sim.current_object_set_as_head = weakref.ref(obj)
    obj.set_parent(sim, transform=new_transform, joint_name_or_hash=neck_hash)
 def on_service_sim_entered_situation(cls, service_sim, situation):
     if situation.role_affordance_target is None:
         recipe = services.recipe_manager().get(situation.object_definition_to_craft)
         if recipe is None:
             return False
         craftable = DebugCreateCraftableInteraction.create_craftable(recipe, service_sim, owning_household_id_override=situation.hiring_household.id, place_in_crafter_inventory=True)
         if craftable is None:
             return False
         situation.set_crafted_object_id(craftable.id)
     return True
 def _get_role_state_overrides(self, sim, job_type, role_state_type, role_affordance_target):
     if self.owner._crafted_object_id != 0:
         target = services.current_zone().inventory_manager.get(self.owner._crafted_object_id)
     else:
         recipe = services.recipe_manager().get(self.owner._object_definition_to_craft)
         if recipe is None:
             raise ValueError('No recipe for {}'.format(self))
         target = DebugCreateCraftableInteraction.create_craftable(recipe, self.owner._service_npc, owning_household_id_override=self.owner._hiring_household.id, place_in_crafter_inventory=True)
         if target is None:
             raise ValueError('No craftable created for {} on {}'.format(recipe, self))
         self.owner._crafted_object_id = target.id
     return (role_state_type, target)
示例#7
0
def create_multiple_objects(number, *obj_ids, _connection=None):
    manager = services.object_manager()
    sim = get_optional_target(None, _connection)
    search_flags = placement.FGLSearchFlagsDefault | placement.FGLSearchFlag.SHOULD_TEST_BUILDBUY
    if sim is not None:
        starting_position = sim.position
        routing_surface = sim.routing_surface
    else:
        lot = services.active_lot()
        starting_position = lot.position
        routing_surface = routing.SurfaceIdentifier(services.current_zone().id,
                                                    0,
                                                    routing.SURFACETYPE_WORLD)
    with postures.posture_graph.supress_posture_graph_build():
        for obj_id in obj_ids:
            obj_id = int(obj_id)
            original_obj = None
            if obj_id in manager:
                original_obj = manager.get(obj_id)
            if original_obj is None:
                return
            obj_definition_id = original_obj.definition.id
            created_obj_count = number
            while created_obj_count > 0:
                if original_obj.crafting_component is not None:
                    obj = DebugCreateCraftableInteraction.create_craftable(
                        original_obj.crafting_component._crafting_process.
                        recipe, sim)
                else:
                    obj = objects.system.create_object(obj_definition_id)
                if obj is not None:
                    fgl_context = placement.FindGoodLocationContext(
                        starting_position=starting_position,
                        object_id=obj.id,
                        search_flags=search_flags,
                        object_footprints=(obj.get_footprint(), ))
                    (position,
                     orientation) = placement.find_good_location(fgl_context)
                    if position is not None and orientation is not None:
                        obj.move_to(translation=position,
                                    orientation=orientation,
                                    routing_surface=routing_surface)
                    else:
                        obj.destroy(
                            source=obj,
                            cause=
                            'Failed to find good location for create_multiple_objects'
                        )
                created_obj_count -= 1
示例#8
0
 def on_service_sim_entered_situation(cls, service_sim, situation):
     if situation.role_affordance_target is None:
         recipe = services.recipe_manager().get(
             situation.object_definition_to_craft)
         if recipe is None:
             return False
         craftable = DebugCreateCraftableInteraction.create_craftable(
             recipe,
             service_sim,
             owning_household_id_override=situation.hiring_household.id,
             place_in_crafter_inventory=True)
         if craftable is None:
             return False
         situation.set_crafted_object_id(craftable.id)
     return True
示例#9
0
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