def object_manager():
    global _cached_object_manager
    if _enable_cache_count:
        if _cached_object_manager is None:
            _cached_object_manager = services.object_manager()
        return _cached_object_manager
    return services.object_manager()
    def save_and_destroy_sim(self, on_reset, sim_info):
        if services.current_zone().is_zone_shutting_down:
            return
        from_zone_id = self.from_zone_id
        to_zone_id = self.to_zone_id
        callback = self.on_complete_callback
        context = self.on_complete_context

        def notify_travel_service():
            if services.travel_service().has_pending_travel(sim_info.account):
                travel_service.on_travel_interaction_succeeded(sim_info, from_zone_id, to_zone_id, callback, context)
            if not sim_info.is_npc:
                services.client_manager().get_first_client().send_selectable_sims_update()

        try:
            logger.debug('Saving sim during TravelInteraction for {}', sim_info)
            sim_info.inject_into_inactive_zone(self.to_zone_id)
            save_success = sim_info.save_sim()
            while not save_success:
                logger.error('Failure saving during TravelInteraction for {}', sim_info)
        finally:
            logger.debug('Destroying sim {}', sim_info)
            self.force_save_and_destroy_sim = False
            if on_reset:
                if self.sim is not None:
                    services.object_manager().remove(self.sim)
                notify_travel_service()
            elif self.sim is not None:
                self.sim.schedule_destroy_asap(source=self, cause='Destroying sim on travel.')
 def _remove_from_cache(self, user_directed=True, autonomy=True):
     user_directed &= self._cached
     autonomy &= self._cached_for_autonomy
     services.object_manager().crafting_cache.remove_type(self.crafting_station_type, user_directed=user_directed, autonomy=autonomy)
     if autonomy:
         self._cached_for_autonomy = False
     if user_directed:
         self._cached = False
 def _add_to_cache(self, user_directed=True, autonomy=True):
     user_directed &= not self._cached
     autonomy &= not self._cached_for_autonomy
     services.object_manager().crafting_cache.add_type(self.crafting_station_type, user_directed=user_directed, autonomy=autonomy)
     if autonomy:
         self._cached_for_autonomy = True
     if user_directed:
         self._cached = True
 def _added(self, obj, send_ui=True, object_with_inventory=None):
     obj.inventoryitem_component.set_inventory_type(self._inventory_type, object_with_inventory)
     if obj.id in services.object_manager():
         services.object_manager().move_to_inventory(obj, self.inventory_manager)
         obj.clear_parent(self.INVENTORY_TRANSFORM, None)
         for state_trigger in self._inventory_state_triggers:
             state_trigger.on_object_added(obj)
     if send_ui:
         self._added_ui_update(obj)
def clone_obj_to_inv(obj_id, inventory_owner_id, count:int=1, _connection=None):
    obj_to_create = services.object_manager().get(obj_id)
    target_object = services.object_manager().get(inventory_owner_id)
    if obj_to_create is None or target_object is None:
        sims4.commands.output('{} or {} not found in object manager'.format(obj_id, inventory_owner_id), _connection)
        return
    inventory = target_object.inventory_component
    if inventory is None:
        sims4.commands.output("{} doesn't have an inventory".format(str(target_object)), _connection)
        return
    for _ in range(count):
        obj_instance = objects.system.create_object(obj_to_create.definition)
        while obj_instance:
            inventory.player_try_add_object(obj_instance)
 def objects_to_score_gen(self, motives:set=singletons.DEFAULT):
     if motives is singletons.DEFAULT:
         motives = self.all_commodities
     if not self.object_list:
         autonomy_rule = self.sim.get_off_lot_autonomy_rule_type() if self.off_lot_autonomy_rule_override is None else self.off_lot_autonomy_rule_override
         off_lot_radius = self.sim.get_off_lot_autonomy_radius()
         sim_is_on_active_lot = self.sim.is_on_active_lot(tolerance=self.sim.get_off_lot_autonomy_tolerance())
         for obj in services.object_manager().advertising_objects_gen(motives):
             if self.ignored_object_list and obj in self.ignored_object_list:
                 pass
             if not self.sim.autonomy_component.get_autonomous_availability_of_object(obj, autonomy_rule, off_lot_radius, sim_is_on_active_lot):
                 pass
             yield obj
         for obj in self.sim.inventory_component:
             if self.ignored_object_list and obj in self.ignored_object_list:
                 pass
             yield obj
     elif not motives:
         for obj in self.object_list:
             if self.ignored_object_list and obj in self.ignored_object_list:
                 pass
             yield obj
     else:
         for obj in self.object_list:
             while obj.commodity_flags & motives:
                 if self.ignored_object_list and obj in self.ignored_object_list:
                     pass
                 yield obj
Exemple #8
0
def create_and_place_baby(sim_info, **kwargs):
    bassinet = create_object(Baby.get_default_baby_def(), obj_id=sim_info.sim_id)
    bassinet.set_sim_info(sim_info, **kwargs)

    def try_to_place_bassinet(position, **kwargs):
        fgl_context = placement.FindGoodLocationContext(starting_position=position, object_id=sim_info.sim_id, search_flags=placement.FGLSearchFlagsDefault | placement.FGLSearchFlag.SHOULD_TEST_BUILDBUY, object_footprints=(bassinet.get_footprint(),), **kwargs)
        (translation, orientation) = placement.find_good_location(fgl_context)
        if translation is not None and orientation is not None:
            bassinet.move_to(translation=translation, orientation=orientation)
            return True
        return False

    lot = services.active_lot()
    for tag in Baby.BABY_PLACEMENT_TAGS:
        for (attempt, obj) in enumerate(services.object_manager().get_objects_with_tag_gen(tag)):
            position = obj.position
            if lot.is_position_on_lot(position) and try_to_place_bassinet(position, max_distance=10):
                return
            while attempt >= Baby.MAX_PLACEMENT_ATTEMPTS:
                break
    position = lot.get_default_position()
    if not try_to_place_bassinet(position):
        bassinet.update_ownership(sim_info, make_sim_owner=False)
        build_buy.move_object_to_household_inventory(bassinet)
        if sim_info.is_selectable:
            failed_placement_notification = Baby.FAILED_PLACEMENT_NOTIFICATION(sim_info, SingleSimResolver(sim_info))
            failed_placement_notification.show_dialog()
 def on_role_activate(self, role_affordance_target=None):
     if self.portal_disallowance_tags:
         object_manager = services.object_manager()
         for portal in object_manager.portal_cache_gen():
             while portal.state_component and portal.get_state(FrontDoorTuning.FRONT_DOOR_ENABLED_STATE.state) == FrontDoorTuning.FRONT_DOOR_ENABLED_STATE:
                 self._add_disallowed_portal(portal)
         object_manager.register_portal_added_callback(self._add_disallowed_portal)
         object_manager.register_front_door_candidates_changed_callback(self._on_front_door_candidates_changed)
     for buff_ref in self.buffs:
         if buff_ref is None:
             logger.warn('{} has empty buff in buff list. Please fix tuning.', self)
         if buff_ref.buff_type is None:
             logger.warn('{} has an buff type not set. Please fix tuning.', self)
         self._buff_handles.append(self.sim.add_buff(buff_ref.buff_type, buff_reason=buff_ref.buff_reason))
     if self.off_lot_autonomy_buff is not None and self.off_lot_autonomy_buff.buff_type is not None:
         self._off_lot_autonomy_buff_handle = self.sim.add_buff(self.off_lot_autonomy_buff.buff_type, buff_reason=self.off_lot_autonomy_buff.buff_reason)
     flags = set()
     for affordance in self.role_specific_affordances:
         flags |= affordance.commodity_flags
     if flags:
         self.sim.add_dynamic_commodity_flags(self, flags)
     if self.on_activate is not None:
         self.on_activate(self, role_affordance_target)
     if not self.allow_npc_routing_on_active_lot:
         self.sim.inc_lot_routing_restriction_ref_count()
def set_front_door(obj_id, _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:
        door.set_as_front_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 load_front_door(front_door_id):
    front_door = services.object_manager().get(front_door_id)
    if front_door is not None:
        front_door.set_as_front_door()
    else:
        logger.warn('Front door object id saved was not found in manager, finding a new front door')
        find_and_set_front_door()
 def on_enter(self):
     super().on_enter()
     services.current_zone().lot.publish_shared_inventory_items()
     active_household_id = services.active_household_id()
     for script_object in services.object_manager().get_all():
         script_object.finalize(active_household_id=active_household_id)
     return _ZoneSpinUpStateResult.DONE
 def load(self, crafting_process_message):
     recipe_manager = services.get_instance_manager(sims4.resources.Types.RECIPE)
     self.recipe = recipe_manager.get(crafting_process_message.recipe_id)
     for phase in self.recipe.phases.values():
         if phase.id == crafting_process_message.phase_id:
             self.phase = phase
         else:
             while phase.id == crafting_process_message.previous_phase_id:
                 self._previous_phase = phase
     current_ico = services.object_manager().get(crafting_process_message.current_ico)
     if current_ico is None:
         current_ico = services.inventory_manager().get(crafting_process_message.current_ico)
     if current_ico is not None:
         self._current_ico_ref = current_ico.ref()
     if crafting_process_message.crafter_sim_id != 0:
         self._crafter_sim_id = crafting_process_message.crafter_sim_id
         self.add_order(self._crafter_sim_id, self.recipe)
     if crafting_process_message.HasField('inscription'):
         self.inscription = crafting_process_message.inscription
     if crafting_process_message.HasField('crafted_value'):
         self.crafted_value = crafting_process_message.crafted_value
     statistic_component = self.get_component(objects.components.types.STATISTIC_COMPONENT)
     statistic_tracker = statistic_component.get_statistic_tracker()
     if statistic_tracker is not None:
         statistic_tracker.load(crafting_process_message.statistic_tracker.statistics)
def c_api_add_sims(session_id, zone_id, sim_ids, callback, add_to_skewer):
    zone = services._zone_manager.get(zone_id)
    if zone is None:
        return LOADSIMS_FAILED_ERROR_CODE
    client = zone.client_manager.get(session_id)
    load_sims_on_client_connect = True
    if client is None and load_sims_on_client_connect:
        services.sim_info_manager().add_sims_to_zone(sim_ids)
    else:
        object_manager = services.object_manager()
        for sim_id in sim_ids:
            if sim_id in object_manager:
                logger.error(
                    'Attempt to add a sim who is already in the zone.  Native likely has a logic error.',
                    owner='mduke')
            ret = sims.sim_spawner.SimSpawner.load_sim(sim_id)
            while not ret:
                logger.error(
                    'Sim failed to load while spinning up sim_id: {}.',
                    sim_id,
                    owner='mduke')
                return LOADSIMS_FAILED_ERROR_CODE
        if add_to_skewer:
            for sim_id in sim_ids:
                sim_info = services.sim_info_manager(zone_id).get(sim_id)
                while sim_info is not None:
                    if client.household_id == sim_info.household_id:
                        client.add_selectable_sim_info(sim_info)
    return SUCCESS_CODE
 def cleanup_objects(cls, lot=None):
     if lot is None:
         logger.error('Lot is None when trying to run lot cleanup.', owner='jjacobson')
         return
     cls.objects_to_destroy = set()
     for cleanup in GlobalLotTuningAndCleanup.OBJECT_CLEANUP_TUNING:
         items_to_cleanup = cleanup.count(lot)
         if items_to_cleanup == 0:
             pass
         items_cleaned_up = 0
         for obj in services.object_manager().values():
             if items_cleaned_up >= items_to_cleanup:
                 break
             if obj.is_sim:
                 pass
             resolver = SingleObjectResolver(obj)
             run_action = False
             for possible_action in cleanup.possible_actions:
                 while possible_action.tests.run_tests(resolver):
                     while True:
                         for action in possible_action.actions:
                             action(obj, lot)
                             run_action = True
             while run_action:
                 items_cleaned_up += 1
     for obj in cls.objects_to_destroy:
         obj.destroy(source=lot, cause='Cleaning up the lot')
     cls.objects_to_destroy = None
Exemple #16
0
def _replace_bassinet(sim_info, bassinet=None):
    bassinet = bassinet if bassinet is not None else services.object_manager().get(sim_info.sim_id)
    if bassinet is not None:
        empty_bassinet = create_object(Baby.get_corresponding_definition(bassinet.definition))
        empty_bassinet.location = bassinet.location
        bassinet.destroy(source=sim_info, cause='Replaced bassinet with empty version')
        return empty_bassinet
Exemple #17
0
def _check_bring_baby_back_from_daycare(household, travel_sim_infos, current_zone):
    if household.is_npc_household:
        return
    if not household.number_of_babies:
        return
    for sim_info in household.teen_or_older_info_gen():
        while sim_info not in travel_sim_infos and sim_info.zone_id == household.home_zone_id:
            sim = sim_info.get_sim_instance()
            if sim is not None and not sim.is_hidden():
                return
    returned_babies = []
    obj_mgr = services.object_manager()
    for baby_info in household.baby_info_gen():
        bassinet = obj_mgr.get(baby_info.sim_id)
        while bassinet is not None:
            if not bassinet._ignore_daycare:
                bassinet.enable_baby_state()
                returned_babies.append(bassinet)
            else:
                bassinet._ignore_daycare = False
    if returned_babies:
        if len(returned_babies) == 1:
            dialog = Baby.BRING_BABY_BACK_FROM_DAYCARE_NOTIFICATION_SINGLE_BABY(sim_info, SingleSimResolver(returned_babies[0]))
        else:
            dialog = Baby.BRING_BABY_BACK_FROM_DAYCARE_NOTIFICATION_MULTIPLE_BABIES(sim_info, SingleSimResolver(sim_info))
        dialog.show_dialog()
def select_career(sim_id:int=None, career_instance_id:int=None, track_id:int=None, level:int=None, company_name_hash:int=None, reason:int=CareerOps.JOIN_CAREER, _connection=None):
    if sim_id is None or (career_instance_id is None or track_id is None) or level is None:
        logger.error('Not all of the data needed for the careers.select command was passed.')
        return False
    career_manager = services.get_instance_manager(sims4.resources.Types.CAREER)
    career_type = career_manager.get(career_instance_id)
    if career_type is None:
        logger.error('invalid career Id sent to careers.select')
        return False
    sim = services.object_manager().get(sim_id)
    if sim_id is None:
        logger.error('invalid sim Id passed to careers.select')
        return False
    career_track_manager = services.get_instance_manager(sims4.resources.Types.CAREER_TRACK)
    career_track = career_track_manager.get(track_id)
    if career_track is None:
        logger.error('invalid career track Id passed to careers.select')
        return False
    if reason is None:
        logger.error('invalid career selection reason passed to careers.select')
        return False
    career_tracker = sim.sim_info.career_tracker
    if reason == CareerOps.JOIN_CAREER:
        current_career = career_tracker.get_career_by_uid(career_instance_id)
        if current_career is not None:
            current_career.set_new_career_track(track_id)
        else:
            career_tracker.add_career(career_type(sim.sim_info, company_name=company_name_hash), show_confirmation_dialog=True)
    if reason == CareerOps.QUIT_CAREER:
        career_tracker.remove_career(career_instance_id)
Exemple #19
0
def _assign_to_bassinet(sim_info):
    object_manager = services.object_manager()
    bassinet = object_manager.get(sim_info.sim_id)
    if assign_bassinet_for_baby(sim_info):
        return
    if not (bassinet is None and build_buy.object_exists_in_household_inventory(sim_info.id, sim_info.household_id)):
        create_and_place_baby(sim_info)
Exemple #20
0
 def _set_zone_objects_household_owner_id(self, household_id):
     for obj in services.object_manager(self.id).get_all():
         while obj.is_on_active_lot():
             obj.set_household_owner_id(household_id)
     for (_, inventory) in self.lot.get_all_object_inventories_gen():
         for inv_obj in inventory:
             inv_obj.set_household_owner_id(household_id)
 def on_finalize_load(self):
     obj_manager = services.object_manager()
     for puddle_id in self._puddle_load_ids:
         puddle = obj_manager.get(puddle_id)
         while puddle is not None:
             self._puddle_refs.add(puddle)
     self._puddle_load_ids = []
def get_sims_for_job(session_id, sim_id, situation_type, job_type, *job_assignments, _connection=None):
    sim = get_optional_target(sim_id, _connection)
    situation_start_time = services.time_service().sim_now
    duration = situation_type.duration
    if duration > 0:
        situation_end_time = situation_start_time + date_and_time.create_time_span(0, 0, duration)
    else:
        situation_start_time = date_and_time.INVALID_DATE_AND_TIME
        situation_end_time = date_and_time.INVALID_DATE_AND_TIME
    results = services.sim_filter_service().submit_filter(job_type.filter, None, requesting_sim_info=sim.sim_info, start_time=situation_start_time, end_time=situation_end_time, allow_yielding=False)
    if job_type.additional_filter_for_user_selection:
        sim_constraints = {result.sim_info.id for result in results}
        results = services.sim_filter_service().submit_filter(job_type.additional_filter_for_user_selection, None, requesting_sim_info=sim.sim_info, start_time=situation_start_time, end_time=situation_end_time, sim_constraints=sim_constraints, allow_yielding=False)
    msg = Situations_pb2.SituationJobSims()
    msg.situation_session_id = session_id
    msg.job_resource_id = job_type.guid
    msg.requirements = job_type.requirement_text
    results.sort(key=lambda x: (x.sim_info.is_npc, x.sim_info.last_name))
    for result in results:
        msg.sim_ids.append(result.sim_info.id)
        with ProtocolBufferRollback(msg.sims) as situation_job_sim:
            situation_job_sim.sim_id = result.sim_info.id
            if result.sim_info.household.id == services.active_household_id():
                situation_job_sim.account_id = result.sim_info.account_id
            while result.conflicting_career_track_id:
                situation_job_sim.career_track_id = result.conflicting_career_track_id
    shared_messages.add_message_if_selectable(services.object_manager().get(sim.id), Consts_pb2.MSG_SITUATION_JOB_SIMS, msg, True)
 def on_client_connect(self, client):
     for created_obj_id in self._spawned_object_ids:
         spawned_object = services.object_manager().get(created_obj_id)
         while spawned_object is not None:
             self._spawned_objects.add(spawned_object)
     self._spawned_object_ids = []
     SpawnerInitializer.create(client.zone_id)
def display_outcomes(sim_id:int=None, _connection=None):
    sim = services.object_manager().get(sim_id)
    client = services.client_manager().get(_connection)
    if not sim:
        sim = _active_sim(client)
    for si in sim.si_state.sis_actor_gen():
        sims4.commands.output('Outcome for {} = {}'.format(si.affordance, si.outcome_result), _connection)
def push_walk_away(sim_id:int=None, _connection=None):
    if sim_id is None:
        client = services.client_manager().get(_connection)
        sim = _active_sim(client)
    else:
        sim = services.object_manager().get(sim_id)
    push_backoff(sim)
 def activate_sprinkler_system(self):
     object_manager = services.object_manager()
     self._sprinkler_system_objects.update(object_manager.get_objects_with_tag_gen(self.SPRINKLER_BOX_OBJECT_TAG))
     if not self._sprinkler_system_objects:
         return
     time_span = date_and_time.create_time_span(minutes=self.SPRINKLER_ACTIVATION_TIME)
     repeating_time_span = date_and_time.create_time_span(minutes=self.SPRINKLER_RUN_TIME)
     self._sprinkler_alarm = alarms.add_alarm(self, time_span, self._sprinkler_alarm_callback, repeating=True, repeating_time_span=repeating_time_span)
 def activate_fire_alarms(self):
     object_manager = services.object_manager()
     self._fire_alarm_objects = set(object_manager.get_objects_of_type_gen(self.FIRE_ALARM_OBJECT_DEF))
     if not self._fire_alarm_objects:
         return
     time_span = date_and_time.create_time_span(minutes=self.FIRE_ALARM_CYCLE_TIME)
     repeating_time_span = date_and_time.create_time_span(minutes=self.FIRE_ALARM_CYCLE_TIME)
     self._fire_alarm_alarm = alarms.add_alarm(self, time_span, self._fire_alarm_callback, repeating=True, repeating_time_span=repeating_time_span)
def cleanup_gardening_objects(_connection=None):
    for obj in services.object_manager().get_all_objects_with_component_gen(GARDENING_COMPONENT):
        if not isinstance(obj.gardening_component, GardeningFruitComponent):
            pass
        while obj.parent is None and not obj.is_in_inventory() and not obj.is_on_active_lot():
            sims4.commands.output('Destroyed object {} on open street was found without a parent at position {}, parent_type {}.'.format(obj, obj.position, obj.parent_type), _connection)
            obj.destroy(source=obj, cause='Fruit/Flower with no parent on open street')
    sims4.commands.output('Gardening cleanup complete', _connection)
 def get_valid_drop_object_ids(self):
     drop_target_ids = []
     for test_obj in services.object_manager().values():
         while not test_obj.is_hidden() and self.is_valid_drop_target(test_obj):
             drop_target_ids.append(test_obj.id)
     if self.owner.inventoryitem_component is not None:
         return (drop_target_ids, self.owner.inventoryitem_component.get_stack_id())
     return (drop_target_ids, None)
Exemple #30
0
def assign_bassinet_for_baby(sim_info):
    object_manager = services.object_manager()
    for bassinet in object_manager.get_objects_of_type_gen(*Baby.BABY_BASSINET_DEFINITION_MAP.values()):
        while not bassinet.transient:
            set_baby_sim_info_with_switch_id(bassinet, sim_info)
            bassinet.destroy(source=sim_info, cause='Assigned bassinet for baby.')
            return True
    return False
def destroy_unentitled_craftables():
    entitlement_map = {}
    objects_to_destroy = list()
    for obj in itertools.chain(services.object_manager().values(),
                               services.inventory_manager().values()):
        crafting_component = obj.crafting_component
        while crafting_component is not None:
            recipe = crafting_component.get_recipe()
            if recipe is not None and recipe.entitlement:
                if recipe.entitlement in entitlement_map:
                    entitled = entitlement_map[recipe.entitlement]
                else:
                    entitled = mtx.has_entitlement(recipe.entitlement)
                    entitlement_map[recipe.entitlement] = entitled
                if not entitled:
                    objects_to_destroy.append(obj)
    for obj in objects_to_destroy:
        obj.destroy(source=obj, cause='Destroying unentitled craftables.')
 def _load_and_push_interaction(self, interaction_data):
     interaction = services.get_instance_manager(sims4.resources.Types.INTERACTION).get(interaction_data.interaction)
     if interaction is None:
         return ExecuteResult.NONE
     logger.debug('_load_and_push_interaction :{} on sim:{}', interaction, self.sim, owner='sscholl')
     target = services.object_manager().get(interaction_data.target_id)
     if target is None:
         target = services.current_zone().inventory_manager.get(interaction_data.target_id)
     if target is not None and interaction_data.HasField('target_part_group_index'):
         target = target.parts[interaction_data.target_part_group_index]
     source = InteractionSource(interaction_data.source)
     priority = Priority(interaction_data.priority)
     context = interactions.context.InteractionContext(self.sim, source, priority, restored_from_load=True)
     load_data = InteractionLoadData()
     if interaction_data.HasField('start_time'):
         load_data.start_time = DateAndTime(interaction_data.start_time)
     execute_result = self.sim.push_super_affordance(interaction, target, context, skip_safe_tests=True, skip_test_on_execute=True, load_data=load_data)
     return execute_result
Exemple #33
0
 def get_all_retail_objects(cls):
     retail_manager = services.business_service(
     ).get_retail_manager_for_zone()
     if retail_manager is None:
         return set()
     lot_owner_household_id = cls._get_lot_owner_household_id()
     output_set = set()
     for obj in services.object_manager().valid_objects():
         if not obj.is_on_active_lot():
             continue
         if not cls._is_obj_owned_by_lot_owner(obj, lot_owner_household_id):
             continue
         if obj.has_component(objects.components.types.RETAIL_COMPONENT):
             output_set.add(obj)
         if obj.has_component(objects.components.types.INVENTORY_COMPONENT):
             if obj.inventory_component.inventory_type in RetailUtils.RETAIL_INVENTORY_TYPES:
                 output_set |= set(obj.inventory_component)
     return output_set
Exemple #34
0
def cleanup_gardening_objects(_connection=None):
    for obj in services.object_manager().get_all_objects_with_component_gen(
            GARDENING_COMPONENT):
        gardening_component = obj.get_component(types.GARDENING_COMPONENT)
        if not isinstance(gardening_component, GardeningFruitComponent):
            continue
        if obj.parent is None:
            if not obj.is_in_inventory():
                if not obj.is_on_active_lot():
                    sims4.commands.output(
                        'Destroyed object {} on open street was found without a parent at position {}, parent_type {}.'
                        .format(obj, obj.position,
                                obj.parent_type), _connection)
                    obj.destroy(
                        source=obj,
                        cause='Fruit/Flower with no parent on open street')
    sims4.commands.output('Gardening cleanup complete', _connection)
    return True
 def _load_bowling_lane(self):
     reader = self._seed.custom_init_params_reader
     if reader is None:
         return
     bowling_lane_id = reader.read_uint64(BOWLING_LANE_TOKEN, None)
     if bowling_lane_id is None:
         logger.error('Failed to find bowling lane id from {} reader.',
                      self)
         return
     self._bowling_lane = services.object_manager().get(bowling_lane_id)
     if self._bowling_lane is None:
         logger.error(
             'Failed to find bowling lane id {} from object manager.',
             bowling_lane_id)
         return
     self._bowling_lane_chosen = True
     services.venue_service().get_zone_director(
     ).set_situation_bowling_lane(self.id, self._bowling_lane)
 def _build_constraint(self, context):
     all_objects = list(services.object_manager().values())
     random.shuffle(all_objects)
     for obj in all_objects:
         if not obj.is_sim:
             if not obj.is_on_active_lot():
                 continue
             resolver = SingleObjectResolver(obj)
             if not self.object_tests.run_tests(resolver):
                 continue
             constraint = self.circle_constraint_around_chosen_object.create_constraint(
                 context.sim, obj)
             if constraint.valid:
                 return constraint
     logger.warn(
         'No objects were found for this interaction to route the Sim near. Interaction = {}',
         type(self))
     return Anywhere()
 def clear_restriction(self, object_id, subroot_index):
     if object_id not in self.object_to_sim:
         return
     if subroot_index is None:
         sims_to_clear = self.object_to_sim[object_id].values()
         del self.object_to_sim[object_id]
     elif subroot_index in self.object_to_sim[object_id]:
         sims_to_clear = (self.object_to_sim[object_id][subroot_index], )
         del self.object_to_sim[object_id][subroot_index]
         if not self.object_to_sim[object_id]:
             del self.object_to_sim[object_id]
     else:
         sims_to_clear = tuple()
     for sim_id in sims_to_clear:
         del self._sim_to_object[sim_id]
     game_object = services.object_manager().get(object_id)
     if game_object is not None:
         game_object.update_object_tooltip()
Exemple #38
0
 def _populate_take_photo_op(self, sims, interaction, take_photo_proto):
     take_photo_proto.camera_mode = self._get_camera_mode()
     take_photo_proto.zoom_capability = self.zoom_capability
     take_photo_proto.camera_quality = self.camera_quality
     take_photo_proto.hide_photographer = self.hide_photographer
     take_photo_proto.success_chance = self.success_chance.get_chance(
         interaction.get_resolver())
     take_photo_proto.camera_position_bone_name = self.camera_position_bone_name
     offset = self._get_offset(interaction)
     take_photo_proto.camera_position_offset.x = offset.x
     take_photo_proto.camera_position_offset.y = offset.y
     take_photo_proto.camera_position_offset.z = offset.z
     take_photo_proto.rotate_target = self.enable_rotate_target(interaction)
     take_photo_proto.filters_disabled = self.filters_disabled
     take_photo_proto.single_shot_mode = self.single_shot_mode
     take_photo_proto.painting_size = self._get_photo_size()
     take_photo_proto.num_photos_per_session = self.number_of_photos_override if self.number_of_photos_override is not None else Photography.NUM_PHOTOS_PER_SESSION
     take_photo_proto.sim_mood_asm_param_name = sims[
         0].get_mood_animation_param_name()
     if self.objects_to_hide_tags is not None:
         objects_to_hide = list(
             obj.id
             for obj in services.object_manager().get_objects_with_tags_gen(
                 *self.objects_to_hide_tags.tags))
         take_photo_proto.objects_to_hide.extend(objects_to_hide)
     bone_object = interaction.get_participant(
         self.camera_position_bone_object)
     if bone_object is not None:
         take_photo_proto.camera_position_bone_object = bone_object.id
     for (index, sim) in enumerate(sims):
         with ProtocolBufferRollback(
                 take_photo_proto.sim_photo_infos) as entry:
             entry.participant_sim_id = sim.sim_id
             entry.participant_sim_position.x = sim.position.x
             entry.participant_sim_position.y = sim.position.y
             entry.participant_sim_position.z = sim.position.z
             if self.photo_pose is not None:
                 if self.photo_pose.asm is not None:
                     entry.animation_pose.asm = get_protobuff_for_key(
                         self.photo_pose.asm)
                     entry.animation_pose.state_name = self.photo_pose.state_name
                     actor_name = self._get_actor_name(index)
                     if actor_name is not None:
                         entry.animation_pose.actor_name = actor_name
def select_career(sim_id: int = None,
                  career_instance_id: int = None,
                  track_id: int = None,
                  level: int = None,
                  company_name_hash: int = None,
                  reason: int = CareerOps.JOIN_CAREER,
                  _connection=None):
    if sim_id is None or (career_instance_id is None
                          or track_id is None) or level is None:
        logger.error(
            'Not all of the data needed for the careers.select command was passed.'
        )
        return False
    career_manager = services.get_instance_manager(
        sims4.resources.Types.CAREER)
    career_type = career_manager.get(career_instance_id)
    if career_type is None:
        logger.error('invalid career Id sent to careers.select')
        return False
    sim = services.object_manager().get(sim_id)
    if sim_id is None:
        logger.error('invalid sim Id passed to careers.select')
        return False
    career_track_manager = services.get_instance_manager(
        sims4.resources.Types.CAREER_TRACK)
    career_track = career_track_manager.get(track_id)
    if career_track is None:
        logger.error('invalid career track Id passed to careers.select')
        return False
    if reason is None:
        logger.error(
            'invalid career selection reason passed to careers.select')
        return False
    career_tracker = sim.sim_info.career_tracker
    if reason == CareerOps.JOIN_CAREER:
        current_career = career_tracker.get_career_by_uid(career_instance_id)
        if current_career is not None:
            current_career.set_new_career_track(track_id)
        else:
            career_tracker.add_career(career_type(
                sim.sim_info, company_name=company_name_hash),
                                      show_confirmation_dialog=True)
    if reason == CareerOps.QUIT_CAREER:
        career_tracker.remove_career(career_instance_id)
    def get_instance_for_all_game_objects_generator(
        include_object_callback: Callable[[GameObject], bool]=None
    ) -> Iterator[GameObject]:
        """get_instance_for_all_objects_generator(include_object_callback=None)

        Retrieve an instance for each and every Object in the game world.

        :param include_object_callback: If the result of this callback is True, the Object will be included in the\
         results. If set to None, All Objects will be included.
        :type include_object_callback: Callable[[GameObject], bool], optional
        :return: An iterable of all Objects matching the `include_object_callback` filter.
        :rtype: Iterator[GameObject]
        """
        for game_object in services.object_manager().get_all():
            if game_object is None:
                continue
            if include_object_callback is not None and not include_object_callback(game_object):
                continue
            yield game_object
Exemple #41
0
def display_queue(sim_id:int=None, _connection=None):
    output = Output(_connection)
    if sim_id is None:
        client = services.client_manager().get(_connection)
        sim = _active_sim(client)
    else:
        sim = services.object_manager().get(sim_id)
        if sim is None:
            output('Invalid Sim id {0:08x}'.format(sim_id))
            return False
    output('Super Interaction State: (num = {0})'.format(len(sim.si_state)))
    for si in sim.si_state.sis_actor_gen():
        output(' * {}'.format(str(si)))
        for subi in si.queued_sub_interactions_gen():
            output('    - {}'.format(str(subi)))
    output('Interaction Queue State: (num = {0})'.format(len(sim.queue)))
    for si in sim.queue:
        output(' * {}'.format(str(si)))
    output('Running: %s' % sim.queue.running)
Exemple #42
0
 def _build_object_relationship_update_proto(self,
                                             actor_sim_info,
                                             member_obj_def_id,
                                             deltas=None,
                                             name_override=None):
     msg = commodity_protocol.RelationshipUpdate()
     actor_sim_id = actor_sim_info.sim_id
     msg.actor_sim_id = actor_sim_id
     if name_override is not None:
         loc_custom_name = LocalizationHelperTuning.get_raw_text(
             name_override)
         build_icon_info_msg(IconInfoData(), loc_custom_name,
                             msg.target_icon_override)
     if self._target_object_id == 0:
         target_object = None
         tag_set = services.relationship_service().get_mapped_tag_set_of_id(
             member_obj_def_id)
         definition_ids = services.relationship_service(
         ).get_ids_of_tag_set(tag_set)
         for definition_id in definition_ids:
             for obj in services.object_manager().objects:
                 if definition_id == obj.definition.id:
                     target_object = obj
                     break
         if target_object is None:
             logger.error(
                 'Failed to find an object with requested object tag set in the world,                             so the initial object type relationship creation for sim {} will not complete.',
                 actor_sim_info)
             return
         (msg.target_id.object_id,
          msg.target_id.manager_id) = target_object.icon_info
         msg.target_instance_id = target_object.id
         self._target_object_id = msg.target_id.object_id
         self._target_object_manager_id = msg.target_id.manager_id
         self._target_object_instance_id = msg.target_instance_id
     else:
         msg.target_id.object_id = self._target_object_id
         msg.target_id.manager_id = self._target_object_manager_id
         msg.target_instance_id = self._target_object_instance_id
     msg.last_update_time = self._last_update_time
     track_bits = self._build_relationship_track_proto(msg)
     self._build_relationship_bit_proto(actor_sim_id, track_bits, msg)
     return msg
def order_for_table(sim_orders: str, _connection=None):
    zone_director = get_restaurant_zone_director()
    if zone_director is None:
        sims4.commands.output('Current venue is not restaurant', _connection)
        return False
    proto = Restaurant_pb2.SimOrders()
    text_format.Merge(sim_orders, proto)
    orders = [(order.sim_id, order.recipe_id) for order in proto.sim_orders]
    sim = services.object_manager().get(orders[0][0])
    if sim is None:
        sims4.commands.output(
            "Trying to order for a Sim that isn't on the lot", _connection)
        return False
    zone_director.order_for_table(orders)
    groups = zone_director.get_dining_groups_by_sim(sim)
    group = groups.pop()
    group.hold_ordered_cost(
        proto.meal_cost if has_field(proto, 'meal_cost') else 0)
    return True
 def _remove_invalid_attractors(self):
     for attractor_tuning in self.attractors:
         attractor_IDs_to_remove = []
         for attractor_id in self._attractor_ids[attractor_tuning]:
             attractor = services.object_manager().get(attractor_id)
             if not attractor:
                 attractor_IDs_to_remove.append(attractor_id)
             elif not any(attractor.position == loc[0]
                          and attractor.orientation == loc[1]
                          for loc in self.
                          _valid_attractor_positions[attractor_tuning]):
                 attractor.destroy()
                 attractor_IDs_to_remove.append(attractor_id)
             else:
                 self._valid_attractor_positions[attractor_tuning].remove(
                     (attractor.position, attractor.orientation))
         self._attractor_ids[attractor_tuning] = list(
             x for x in self._attractor_ids[attractor_tuning]
             if x not in attractor_IDs_to_remove)
Exemple #45
0
def dump_object(obj_id, _connection=None):
    manager = services.object_manager()
    obj = None
    if obj_id in manager:
        obj = manager.get(obj_id)
    else:
        sims4.commands.output(
            'DUMP_OBJECT: Object ID not in the object manager.', _connection)
    if obj is not None:
        sims4.commands.output(
            'Object {} ({})'.format(obj_id, obj.__class__.__name__),
            _connection)
        for (key, value) in vars(obj).items():
            sims4.commands.output('\t{} = {}'.format(key, value), _connection)
            while isinstance(value, Component):
                while True:
                    for (key, value) in vars(value).items():
                        sims4.commands.output('\t\t{} = {}'.format(key, value),
                                              _connection)
Exemple #46
0
def add_censor(obj_id, mode: str = None, _connection=None):
    manager = services.object_manager()
    obj = None
    if obj_id in manager:
        obj = manager.get(obj_id)
    else:
        sims4.commands.output(
            'ADD_CENSOR: Object ID not in the object manager.', _connection)
    if obj is not None:
        mode = mode.upper()
        if mode.startswith('CENSOR_'):
            mode = mode[7:]
        if mode in CensorState:
            handle = obj.censorgrid_component.add_censor(CensorState[mode])
            sims4.commands.output(
                'Censor created with handle: {}'.format(handle), _connection)
        else:
            sims4.commands.output('Unknown censor mode name: ' + mode,
                                  _connection)
def route_failure(sim, interaction, failure_reason, failure_object_id):
    global ROUTE_FAILURE_OVERRIDE_MAP
    if not sim.should_route_fail:
        return
    overrides = None
    if ROUTE_FAILURE_OVERRIDE_MAP is None:
        ROUTE_FAILURE_OVERRIDE_MAP = {TransitionFailureReasons.BLOCKING_OBJECT: RouteFailureTunables.route_fail_overrides_object, TransitionFailureReasons.RESERVATION: RouteFailureTunables.route_fail_overrides_reservation, TransitionFailureReasons.BUILD_BUY: RouteFailureTunables.route_fail_overrides_build, TransitionFailureReasons.NO_DESTINATION_NODE: RouteFailureTunables.route_fail_overrides_no_dest_node, TransitionFailureReasons.NO_PATH_FOUND: RouteFailureTunables.route_fail_overrides_no_path_found, TransitionFailureReasons.NO_VALID_INTERSECTION: RouteFailureTunables.route_fail_overrides_no_valid_intersection, TransitionFailureReasons.NO_GOALS_GENERATED: RouteFailureTunables.route_fail_overrides_no_goals_generated, TransitionFailureReasons.NO_CONNECTIVITY_TO_GOALS: RouteFailureTunables.route_fail_overrides_no_connectivity, TransitionFailureReasons.PATH_PLAN_FAILED: RouteFailureTunables.route_fail_overrides_path_plan_fail}
    if failure_reason is not None and failure_reason in ROUTE_FAILURE_OVERRIDE_MAP:
        overrides = ROUTE_FAILURE_OVERRIDE_MAP[failure_reason]()
        if failure_object_id is not None:
            fail_obj = services.object_manager().get(failure_object_id)
            if fail_obj is not None:
                overrides.balloon_target_override = fail_obj
    route_fail_anim = RouteFailureTunables.route_fail_animation(sim.posture.source_interaction, overrides=overrides, sequence=())
    supported_postures = route_fail_anim.get_supported_postures()
    if supported_postures:
        return build_element((route_fail_anim, flush_all_animations))
    balloon_requests = TunableBalloon.get_balloon_requests(interaction, route_fail_anim.overrides)
    return balloon_requests
Exemple #48
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     reader = self._seed.custom_init_params_reader
     self.targets = None
     self._retry_count = 0
     self.interaction_override = self._seed.extra_kwargs.get(
         'interaction', None)
     self.basic_extra = self._seed.extra_kwargs.get('basic_extra', ())
     if reader is None:
         self._target_id = self._seed.extra_kwargs.get(
             'default_target_id', None)
     else:
         self._target_id = reader.read_uint64(OBJECT_TOKEN, None)
     if self._target_id is not None:
         target = services.object_manager().get(self._target_id)
         if target.parts:
             self.targets = set(target.parts)
         else:
             self.targets = set((target, ))
def complete_goal(goal_name, target_sim_id=None, _connection=None):
    if target_sim_id is None or target_sim_id == 0:
        target_sim = None
    else:
        target_sim = services.object_manager().get(int(target_sim_id, base=0))
    situations = services.get_zone_situation_manager().running_situations()
    success = False
    for situation in situations:
        success = situation.debug_force_complete_named_goal(
            goal_name, target_sim)
        while success:
            break
    if success:
        sims4.commands.output('Success: Goal {} Completed'.format(goal_name),
                              _connection)
    else:
        sims4.commands.output(
            'FAILURE: Goal {} NOT Completed'.format(goal_name), _connection)
    return success
 def get_objects(self, resolver, *args, **kwargs):
     owner = resolver.get_participant(self.participant, *args, **kwargs)
     if owner is None:
         return ()
     if not owner.is_sim:
         return ()
     stored_object_component = owner.sim_info.get_component(
         types.STORED_OBJECT_INFO_COMPONENT)
     if stored_object_component is None:
         return ()
     else:
         obj_id = stored_object_component.get_stored_object_info_id(
             self.stored_object_type)
         stored_object = services.object_manager().get(obj_id)
         if stored_object is None:
             stored_object = services.inventory_manager().get(obj_id)
         if stored_object is not None:
             return (stored_object, )
     return ()
Exemple #51
0
def debugvis_mood_toggle(_connection=None):
    def _on_object_add(obj):
        if obj.is_sim:
            for _connection in _all_mood_visualization_enabled:
                debugvis_mood_start(opt_sim=obj, _connection=_connection)

    def _on_object_remove(obj):
        if obj.is_sim:
            for _connection in _all_mood_visualization_enabled:
                debugvis_mood_stop(opt_sim=obj, _connection=_connection)

    def _on_client_remove(client):
        if client.id in _all_mood_visualization_enabled:
            debugvis_mood_toggle(_connection=client.id)

    enable = _connection not in _all_mood_visualization_enabled
    old_registered = True if _all_mood_visualization_enabled else False
    om = services.object_manager()
    infom = services.sim_info_manager()
    cm = services.client_manager()
    if enable:
        _all_mood_visualization_enabled.add(_connection)
        for sim in infom.instanced_sims_gen():
            debugvis_mood_start(opt_sim=sim, _connection=_connection)
    else:
        _all_mood_visualization_enabled.remove(_connection)
        for sim in infom.instanced_sims_gen():
            debugvis_mood_stop(opt_sim=sim, _connection=_connection)
    new_registered = True if _all_mood_visualization_enabled else False
    if not old_registered and new_registered:
        om.register_callback(indexed_manager.CallbackTypes.ON_OBJECT_ADD,
                             _on_object_add)
        om.register_callback(indexed_manager.CallbackTypes.ON_OBJECT_REMOVE,
                             _on_object_remove)
        cm.register_callback(indexed_manager.CallbackTypes.ON_OBJECT_REMOVE,
                             _on_client_remove)
    elif old_registered and not new_registered:
        om.unregister_callback(indexed_manager.CallbackTypes.ON_OBJECT_ADD,
                               _on_object_add)
        om.unregister_callback(indexed_manager.CallbackTypes.ON_OBJECT_REMOVE,
                               _on_object_remove)
        cm.unregister_callback(indexed_manager.CallbackTypes.ON_OBJECT_REMOVE,
                               _on_client_remove)
 def get_restriction(self,
                     sim_info,
                     game_object,
                     preference_tag,
                     full_object=False,
                     allow_test=True):
     sim_id = sim_info.sim_id
     zone_preference_tuple = (services.current_zone_id(), preference_tag)
     if zone_preference_tuple not in self._zone_object_preference_datas:
         return AutonomyPreferenceType.ALLOWED
     object_id = game_object.id
     subroot_index = self.get_preferable_subroot_index(game_object)
     zone_preference_data = self._zone_object_preference_datas[
         zone_preference_tuple]
     if sim_id in zone_preference_data:
         (owned_object_id,
          owned_subroot_index) = zone_preference_data[sim_id]
         if owned_object_id not in services.object_manager():
             zone_preference_data.clear_restriction(owned_object_id, None)
         else:
             if owned_object_id == object_id and (
                     full_object or subroot_index == owned_subroot_index):
                 return AutonomyPreferenceType.USE_ONLY
             if allow_test and self._is_ignore_disallowed(
                     sim_info, preference_tag):
                 return AutonomyPreferenceType.ALLOWED
             return AutonomyPreferenceType.DISALLOWED
     if object_id in zone_preference_data.object_to_sim:
         if full_object:
             if None not in zone_preference_data.object_to_sim[object_id]:
                 return AutonomyPreferenceType.ALLOWED
                 if subroot_index not in zone_preference_data.object_to_sim[
                         object_id]:
                     return AutonomyPreferenceType.ALLOWED
         elif subroot_index not in zone_preference_data.object_to_sim[
                 object_id]:
             return AutonomyPreferenceType.ALLOWED
     else:
         return AutonomyPreferenceType.ALLOWED
     if allow_test and self._is_ignore_disallowed(sim_info, preference_tag):
         return AutonomyPreferenceType.ALLOWED
     return AutonomyPreferenceType.DISALLOWED
Exemple #53
0
 def clean_objects_left_in_destination_world(self):
     zone = services.current_zone()
     current_zone_id = zone.id
     open_street_id = zone.open_street_id
     travel_group_manager = services.travel_group_manager()
     clean_up_data_indexes_to_remove = []
     object_manager = services.object_manager()
     save_game_protocol_buffer = services.get_persistence_service(
     ).get_save_game_data_proto()
     for (clean_up_index, clean_up_save_data) in enumerate(
             save_game_protocol_buffer.destination_clean_up_data):
         if clean_up_save_data.travel_group_id in travel_group_manager:
             continue
         if clean_up_save_data.household_id != 0:
             continue
         object_indexes_to_delete = []
         for (index, object_clean_up_data) in enumerate(
                 clean_up_save_data.object_clean_up_data_list):
             if not object_clean_up_data.zone_id == current_zone_id:
                 if object_clean_up_data.world_id == open_street_id:
                     obj = object_manager.get(
                         object_clean_up_data.object_data.object_id)
                     if obj is not None:
                         obj.destroy(source=self,
                                     cause='Destination world clean up.')
                     object_indexes_to_delete.append(index)
             obj = object_manager.get(
                 object_clean_up_data.object_data.object_id)
             if obj is not None:
                 obj.destroy(source=self,
                             cause='Destination world clean up.')
             object_indexes_to_delete.append(index)
         if len(object_indexes_to_delete) == len(
                 clean_up_save_data.object_clean_up_data_list):
             clean_up_save_data.ClearField('object_clean_up_data_list')
         else:
             for index in reversed(object_indexes_to_delete):
                 del clean_up_save_data.object_clean_up_data_list[index]
         if len(clean_up_save_data.object_clean_up_data_list) == 0:
             clean_up_data_indexes_to_remove.append(clean_up_index)
     for index in reversed(clean_up_data_indexes_to_remove):
         del save_game_protocol_buffer.destination_clean_up_data[index]
def get_video_object_info(obj_id: int, _connection=None):
    manager = services.object_manager()
    obj = None
    if obj_id in manager:
        obj = manager.get(obj_id)
    else:
        sims4.commands.output(
            'Object ID {} not present in the object manager.'.format(obj_id),
            _connection)
    if obj is not None:
        sims4.commands.output(
            'Object {} ({})'.format(obj_id, obj.__class__.__name__),
            _connection)
        v = obj.get_component(types.VIDEO_COMPONENT)
        if v is not None:
            sims4.commands.output('  ' + repr(v), _connection)
        else:
            sims4.commands.output(
                '  Object does not have video playback capabilities.',
                _connection)
 def _create_situation_geometry(self):
     seed = self._seed
     default_target_id = seed.extra_kwargs.get('default_target_id', None)
     if default_target_id is not None:
         self._target_object = services.object_manager().get(
             default_target_id)
     if self._target_object is None:
         default_location = seed.extra_kwargs.get('default_location', None)
         if default_location is not None:
             self._target_object = TerrainPoint(default_location)
         else:
             logger.error('Failed to determine target for {}', self)
             self._self_destruct()
             return
     else:
         leader_sim = self.initiating_sim_info.get_sim_instance()
         if leader_sim is None:
             logger.error('No leader sim for {}', self)
             self._self_destruct()
             return
 def on_cleanup_zone_objects(self):
     super().on_cleanup_zone_objects()
     next_temple_id = self.open_street_director.get_next_temple_id()
     if next_temple_id is not None:
         self._reset_temple_data()
     if self._temple_id is None:
         if next_temple_id is None:
             logger.error(
                 "No temple_id was loaded for this temple and the Open Street Director doesn't have an ID for us. This temple will not function correctly."
             )
             return
         self._temple_id = next_temple_id
         self._prepare_temple_data()
         object_manager = services.object_manager()
         self._setup_gates(object_manager)
         self._setup_traps(object_manager)
         self._setup_rooms_visibility()
         self.open_street_director.set_temple_in_progress()
         self._require_setup = True
     self._apply_enter_lot_loot()
 def transfer_active_household_inventory(self, source_household, target_household):
     inventory_available = build_buy.is_household_inventory_available(target_household.id)
     source_household_msg = services.get_persistence_service().get_household_proto_buff(source_household.id)
     target_household_msg = services.get_persistence_service().get_household_proto_buff(target_household.id)
     object_manager = services.object_manager()
     object_ids = build_buy.get_object_ids_in_household_inventory(source_household.id)
     for object_id in object_ids:
         object_data_raw = _buildbuy.get_object_data_in_household_inventory(object_id, source_household.id)
         if object_data_raw is None:
             continue
         obj = self._create_object_from_raw_inv_data(object_id, object_data_raw)
         self._transfer_object(target_household, obj, inventory_available, target_household_msg)
     for object_data in source_household_msg.inventory.objects:
         if object_data.object_id in object_ids:
             continue
         obj = object_manager.get(object_data.object_id)
         if obj is None:
             obj = self._create_object_from_object_data(object_data.object_id, object_data)
         if obj is not None:
             self._transfer_object(target_household, obj, inventory_available, target_household_msg)
Exemple #58
0
 def on_role_activate(self, role_affordance_target=None, situation=None, **affordance_override_kwargs):
     if self.portal_disallowance_tags:
         self._refresh_all_door_portal_allowance()
         object_manager = services.object_manager()
         object_manager.register_portal_added_callback(self._refresh_door_portal_allowance)
         object_manager.register_front_door_candidates_changed_callback(self._refresh_all_door_portal_allowance)
     for buff_ref in self.buffs:
         if buff_ref is None:
             logger.warn('{} has empty buff in buff list. Please fix tuning.', self)
         else:
             self._buff_handles.append(self.sim.add_buff(buff_ref.buff_type, buff_reason=buff_ref.buff_reason))
     if self.off_lot_autonomy_buff is not None:
         if self.off_lot_autonomy_buff.buff_type is not None:
             self._off_lot_autonomy_buff_handle = self.sim.add_buff(self.off_lot_autonomy_buff.buff_type, buff_reason=self.off_lot_autonomy_buff.buff_reason)
     self._apply_commodity_flag(self.role_specific_affordances, self.sim.add_dynamic_commodity_flags)
     self._apply_commodity_flag(self.preroll_affordances, self.sim.add_dynamic_preroll_commodity_flags)
     if self.on_activate is not None:
         self.on_activate(self, role_affordance_target, situation=situation, **affordance_override_kwargs)
     if not self.allow_npc_routing_on_active_lot:
         self.sim.inc_lot_routing_restriction_ref_count()
Exemple #59
0
def buildbuy_session_end(zone_id):
    with sims4.zone_utils.global_zone_lock(zone_id):
        for obj in services.object_manager(zone_id).get_all():
            obj.on_buildbuy_exit()
        posture_graph_service = services.current_zone().posture_graph_service
        posture_graph_service.on_exit_buildbuy()
        pythonutils.try_highwater_gc()
        venue_type = get_current_venue(zone_id)
        logger.assert_raise(
            venue_type is not None,
            ' Venue Type is None in buildbuy session end for zone id:{}',
            zone_id,
            owner='sscholl')
        if venue_type is not None:
            venue_tuning = services.venue_manager().get(venue_type)
            services.current_zone(
            ).venue_service.set_venue_and_schedule_events(venue_tuning)
        services.current_zone().on_build_buy_exit()
        from objects.doors.front_door import find_and_set_front_door
        find_and_set_front_door()
 def drive_vehicles_on_travel(self):
     object_manager = services.object_manager()
     for traveled_sim_id in self._sims_traveled_to_zone:
         sim_info = self.get(traveled_sim_id)
         vehicle_id = sim_info._vehicle_id
         sim_info._vehicle_id = None
         if vehicle_id is None:
             continue
         sim = sim_info.get_sim_instance()
         if sim is None:
             continue
         vehicle = object_manager.get(vehicle_id)
         if vehicle is None:
             logger.error('{} traveled on a vehicle, but it does not exist.', sim, owner='rmccord')
         else:
             parented_vehicle = sim.parented_vehicle
             if parented_vehicle is not None:
                 continue
             sim.set_allow_route_instantly_when_hitting_marks(True)
             vehicle.vehicle_component.push_drive_affordance(sim)