Пример #1
0
    def test(cls, inst, *args, target=DEFAULT, context=None, **kwargs) -> TestResult:  # pylint: disable=no-self-argument
        try:
            inst_or_cls = inst if inst is not None else cls
            selection_group = SelectionGroupService.get(services.active_household_id())

            Logger.log("testing SimHouseholdNpcOffInteraction, context: {} {}"
                       .format(args, kwargs))

            if target:
                info_target = target.sim_info

            if context.target_sim_id is not None:
                target_id = context.target_sim_id
                info_target = services.sim_info_manager().get(target_id)

            Logger.log('info_target: {}'.format(info_target))

            if not selection_group.is_household_npc(info_target):
                return TestResult(False, "sim is not a household npc", inst)

            if info_target.household_id != services.active_household_id():
                return TestResult(False, "sim is not a member of the active household", inst)

            return (super(SimHouseholdNpcOffInteraction, inst_or_cls)
                    .test(*args, target=target, context=context, **kwargs))
        except BaseException:
            Logger.log(traceback.format_exc())
Пример #2
0
 def save_zone(self, save_slot_data=None):
     zone_data_msg = self._get_zone_proto()
     zone_data_msg.ClearField('gameplay_zone_data')
     gameplay_zone_data = zone_data_msg.gameplay_zone_data
     gameplay_zone_data.lot_owner_household_id_on_save = self.lot.owner_household_id
     gameplay_zone_data.venue_type_id_on_save = self.venue_service.venue.guid64 if self.venue_service.venue is not None else 0
     gameplay_zone_data.active_household_id_on_save = services.active_household_id(
     )
     self.lot.save(gameplay_zone_data)
     if self.lot.front_door_id:
         zone_data_msg.front_door_id = self.lot.front_door_id
     num_spawn_points = len(self._spawner_data)
     spawn_point_ids = [0] * num_spawn_points
     for (spawn_point_id, spawn_point) in self._spawner_data.items():
         spawn_point_ids[spawn_point.spawn_point_index] = spawn_point_id
     zone_data_msg.ClearField('spawn_point_ids')
     zone_data_msg.spawn_point_ids.extend(spawn_point_ids)
     zone_objects_message = serialization.ZoneObjectData()
     object_list = serialization.ObjectList()
     zone_objects_message.zone_id = self.id
     persistence_service = services.get_persistence_service()
     open_street_data = persistence_service.get_open_street_proto_buff(
         self.open_street_id)
     if open_street_data is not None:
         open_street_data.Clear()
         add_proto_to_persistence = False
     else:
         open_street_data = serialization.OpenStreetsData()
         add_proto_to_persistence = True
     open_street_data.world_id = self.open_street_id
     open_street_data.nbh_id = self.neighborhood_id
     open_street_data.sim_time_on_save = services.time_service(
     ).sim_timeline.now.absolute_ticks()
     open_street_data.active_household_id_on_save = services.active_household_id(
     )
     open_street_data.active_zone_id_on_save = self.id
     self.service_manager.save_all_services(
         persistence_service,
         persistence_error_types.ErrorCodes.ZONE_SERVICES_SAVE_FAILED,
         object_list=object_list,
         zone_data=zone_data_msg,
         open_street_data=open_street_data,
         save_slot_data=save_slot_data)
     zone_objects_message.objects = object_list
     if add_proto_to_persistence:
         services.get_persistence_service().add_open_street_proto_buff(
             open_street_data)
     persistence_module.run_persistence_operation(
         persistence_module.PersistenceOpType.kPersistenceOpSaveZoneObjects,
         zone_objects_message, 0, None)
Пример #3
0
def tn_sim_info_is_npc(_original, self):
    if services.active_sim_info() == self:
        return False

    if services.active_household_id() == self.household_id:
        selection_group = SelectionGroupService.get(
            services.active_household_id(), True)

        if not selection_group:
            return False

        return selection_group.is_household_npc(self)

    return True
Пример #4
0
 def resolve_live_drag_household_permission(self):
     owning_household_id = self.owner.get_household_owner_id()
     active_household_id = services.active_household_id()
     if active_household_id is not None and owning_household_id is not None and owning_household_id != active_household_id:
         self.update_permission(LiveDragPermission.HOUSEHOLD, False)
     else:
         self.update_permission(LiveDragPermission.HOUSEHOLD, True)
 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 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)
Пример #7
0
 def _off_lot_churn_callback(self, alarm_handle):
     trackers = self.get_business_trackers_for_household(
         services.active_household_id())
     if not trackers:
         return
     for tracker in trackers:
         tracker.run_off_lot_simulation()
Пример #8
0
def purchase_to_inventory(inventory_obj,
                          def_id: str = None,
                          mailman_purchase: bool = False,
                          _connection=None):
    definition_manager = services.definition_manager()
    definition = definition_manager.get(def_id)
    if definition is None:
        return False
    client = services.client_manager().get(_connection)
    if client is None:
        return False
    household = client.household
    price = definition.price
    if household.funds.money < price:
        return False
    if mailman_purchase:
        obj = services.active_lot().create_object_in_hidden_inventory(
            definition)
    else:
        inventory = inventory_obj.get_target().inventory_component
        if inventory is None:
            return False
        obj = create_object(definition)
        if obj is None:
            return False
        if not inventory.player_try_add_object(obj):
            obj.destroy(source=inventory,
                        cause='Failed to purchase object into inventory')
            return False
    obj.set_household_owner_id(household.id)
    obj.try_post_bb_fixup(force_fixup=True,
                          active_household_id=services.active_household_id())
    household.funds.remove(price, Consts_pb2.TELEMETRY_OBJECT_BUY)
    return True
def purchase_to_inventory(inventory_obj, def_id:str=None, mailman_purchase:bool=False, _connection=None):
    definition_manager = services.definition_manager()
    definition = definition_manager.get(def_id)
    if definition is None:
        return False
    client = services.client_manager().get(_connection)
    if client is None:
        return False
    household = client.household
    price = definition.price
    if household.funds.money < price:
        return False
    if mailman_purchase:
        obj = services.active_lot().create_object_in_hidden_inventory(definition)
    else:
        inventory = inventory_obj.get_target().inventory_component
        if inventory is None:
            return False
        obj = create_object(definition)
        if obj is None:
            return False
        if not inventory.player_try_add_object(obj):
            obj.destroy(source=inventory, cause='Failed to purchase object into inventory')
            return False
    obj.set_household_owner_id(household.id)
    obj.try_post_bb_fixup(force_fixup=True, active_household_id=services.active_household_id())
    household.funds.remove(price, Consts_pb2.TELEMETRY_OBJECT_BUY)
    return True
Пример #10
0
 def should_close_after_load(self):
     current_zone = services.current_zone()
     if current_zone.active_household_changed_between_save_and_load() and services.active_household_id() == self._owner_household_id:
         return True
     if current_zone.id == self._zone_id:
         return self.should_automatically_close() and current_zone.time_has_passed_in_world_since_zone_save()
     return self.should_automatically_close()
Пример #11
0
 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
Пример #12
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)
Пример #13
0
    def prune_distant_relatives(self):
        with genealogy_caching():
            open_list = []
            closed_list = set()
            prune_list = set()
            active_household_id = services.active_household_id()
            for sim_info in self:
                while not sim_info.is_dead:
                    heapq.heappush(open_list,
                                   (-self.ANCESTRY_PURGE_DEPTH, sim_info.id))

            def visit(sim_info, depth):
                if sim_info not in closed_list:
                    closed_list.add(sim_info)
                    heapq.heappush(open_list, (depth, sim_info.id))
                    if depth > 0:
                        if sim_info.household_id != active_household_id and not sim_info.is_instanced(
                                allow_hidden_flags=ALL_HIDDEN_REASONS):
                            prune_list.add(sim_info)

            sim_info_manager = services.sim_info_manager()
            while open_list:
                (depth, sim_info_id) = heapq.heappop(open_list)
                sim_info = sim_info_manager.get(sim_info_id)
                while sim_info is not None:
                    while True:
                        for relative_id in sim_info.genealogy.get_immediate_family_sim_ids_gen(
                        ):
                            relative = sim_info_manager.get(relative_id)
                            while relative is not None:
                                visit(relative, depth + 1)
        for sim_info in prune_list:
            sim_info.household.remove_sim_info(sim_info)
            sim_info_manager.remove_permanently(sim_info)
            services.get_persistence_service().del_sim_proto_buff(sim_info.id)
Пример #14
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)
 def _should_create_object(self, definition_id):
     if self.owner.household.id == services.active_household_id():
         return True
     elif InventoryItemComponent.should_item_be_removed_from_inventory(
             definition_id):
         return False
     return True
Пример #16
0
 def on_choice_selected(self, choice_tag, **kwargs):
     mother = choice_tag
     if mother is None:
         return
     father = self.target
     transferable_states = {}
     for state in self._combine_data.states_to_combine:
         mother_state = mother.get_state(state)
         father_state = father.get_state(state)
         transferable_states[state] = [mother_state, father_state]
         for combine_data in self._combine_data.combination_mapping:
             if combine_data.father_state == father_state and combine_data.mother_state == mother_state:
                 transferable_states[state].append(
                     combine_data.resulting_state)
     if not transferable_states:
         logger.error(
             'CollectionPickerInteraction: {} and {} collectibles have no transferable states',
             mother,
             father,
             owner='camilogarcia')
         return
     states_to_transfer = []
     for states in transferable_states.values():
         states_to_transfer.append(sims4.random.random.choice(states))
     target_match = len(states_to_transfer)
     possible_outcomes = []
     for collectable in self._collectible_data:
         match = 0
         for target_states in collectable.collectable_item.cls._components.state._tuned_values.states:
             if target_states.default_value in states_to_transfer:
                 match += 1
         if match == target_match:
             possible_outcomes.append(collectable.collectable_item)
     if not possible_outcomes:
         logger.error(
             'CollectionPickerInteraction: No possible result when combining  {} and {}',
             mother,
             father,
             owner='camilogarcia')
         return
     definition_to_create = sims4.random.random.choice(possible_outcomes)
     obj = create_object(definition_to_create)
     if obj is None:
         logger.error(
             'CollectionPickerInteraction: Failed to create object when combining  {} and {}',
             mother,
             father,
             owner='camilogarcia')
         return
     obj.update_ownership(self.sim.sim_info)
     if not self.sim.inventory_component.player_try_add_object(obj):
         obj.set_household_owner_id(services.active_household_id())
         if not build_buy.move_object_to_household_inventory(
                 obj,
                 object_location_type=ObjectOriginLocation.SIM_INVENTORY):
             logger.error(
                 'CollectionPickerInteraction: Failed to add object {} to household inventory.',
                 obj,
                 owner='rmccord')
     self._push_continuation(obj)
Пример #17
0
    def _run_interaction_gen(self, timeline):
        Logger.log("running make selectable interaction...")
        try:
            super()._run_interaction_gen(timeline)

            sim_info = self.target.sim_info

            if self.context.target_sim_id is not None:
                sim_info = (services.sim_info_manager()
                            .get(self.context.target_sim_id))

            Logger.log("got sim info {} {}"
                       .format(sim_info.first_name, sim_info.last_name))

            SelectionGroupService \
                .get(services.active_household_id()) \
                .make_sim_selectable(sim_info)

            Logger.log("sim is now selectable!")

            services.get_first_client().set_active_sim_by_id(sim_info.id)

            Logger.log("sim is now active!")

            return True

        except BaseException:
            Logger.log(traceback.format_exc())
Пример #18
0
def set_active_sim(first_name='', last_name='', _connection=None):
    output = commands.CheatOutput(_connection)

    try:
        if _connection is None:
            output('SetActiveSim; Status:ParamError')
            return False

        tgt_client = services.client_manager().get(_connection)

        if tgt_client is None:
            output('SetActiveSim; Status:ClientError no client')
            return False

        sim_info = (services.sim_info_manager().get_sim_info_by_name(
            first_name, last_name))

        if sim_info is None:
            output('SetActiveSim; Status:SimError no sim with this name found')
            return False

        SelectionGroupService \
            .get(services.active_household_id()) \
            .make_sim_selectable(sim_info)

        if tgt_client.set_active_sim_by_id(sim_info.id):
            output('SetActiveSim; Status:Success')
            return True

        output('SetActiveSim; Status:NoChange')
        return True
    except BaseException as exception:
        output('Error: {}'.format(exception))
        Logger.log(traceback.format_exc())
Пример #19
0
 def on_exit(self):
     active_household_id = services.active_household_id()
     sim_info_manager = services.sim_info_manager()
     for script_object in sim_info_manager.instanced_sims_gen(
             allow_hidden_flags=ALL_HIDDEN_REASONS):
         script_object.finalize(active_household_id=active_household_id)
     super().on_exit()
Пример #20
0
def transfer_entire_inventory(source, recipient):
    if source is None or recipient is None:
        raise ValueError('Attempt to transfer items from {} to {}.'.format(source, recipient))
    lot = services.active_lot()
    if isinstance(source, InventoryType):
        source_inventory = lot.get_object_inventory(source)
    else:
        source_inventory = source.inventory_component
    if source_inventory is None:
        raise ValueError('Failed to find inventory component for source of inventory transfer: {}'.format(source))
    recipient_is_inventory_type = isinstance(recipient, InventoryType)
    if recipient_is_inventory_type:
        recipient_inventory = lot.get_object_inventory(recipient)
    else:
        recipient_inventory = recipient.inventory_component
    if recipient_inventory is None:
        raise ValueError('Attempt to transfer items to an object that has no inventory component: {}'.format(recipient))
    for obj in list(source_inventory):
        if not source_inventory.try_remove_object_by_id(obj.id, force_remove_stack=True):
            logger.warn('Failed to remove object {} from {} inventory', obj, source)
        if recipient_inventory.can_add(obj):
            if not recipient_is_inventory_type and recipient.is_sim:
                obj.update_ownership(recipient)
            recipient_inventory.system_add_object(obj, None if recipient_is_inventory_type else recipient)
        else:
            obj.set_household_owner_id(services.active_household_id())
            build_buy.move_object_to_household_inventory(obj, object_location_type=ObjectOriginLocation.SIM_INVENTORY)
Пример #21
0
 def update_household_objects_ownership(self):
     zone_data_proto = self._get_zone_proto()
     if zone_data_proto is None:
         return
     venue_instance = self.venue_service.venue
     if venue_instance is None or not venue_instance.venue_requires_front_door:
         return
     if self.lot.owner_household_id == 0:
         self._set_zone_objects_household_owner_id(None)
     elif self.lot.owner_household_id == services.active_household_id():
         gameplay_zone_data = zone_data_proto.gameplay_zone_data
         if not protocol_buffer_utils.has_field(
                 gameplay_zone_data,
                 'active_household_id_on_save') or gameplay_zone_data.lot_owner_household_id_on_save != services.active_household_id(
                 ):
             self._set_zone_objects_household_owner_id(
                 services.active_household_id())
Пример #22
0
def tn_sim_info_is_selected(_original, self):
    active_household_id = services.active_household_id()
    client = (services.client_manager().get_client_by_household_id(
        active_household_id))

    if client is not None:
        return self is client.active_sim

    return False
Пример #23
0
 def _apply_ownership(self, mailbox, household_id):
     mailbox.set_household_owner_id(household_id)
     for tuning in self.OWNER_STATES:
         if mailbox.definition in tuning.definitions:
             owner_state_value = tuning.active_state_value if household_id == services.active_household_id(
             ) else tuning.default_state_value
             mailbox.set_state(owner_state_value.state,
                               owner_state_value,
                               immediate=True)
Пример #24
0
 def _setup_created_object(self, created_object):
     if self.aggregate_object_owner & AggregateObjectOwnership.SAME_AS_TARGET:
         if self.target is not None:
             created_object.set_household_owner_id(
                 self.target.get_household_owner_id())
     elif self.aggregate_object_owner & AggregateObjectOwnership.ACTIVE_HOUSEHOLD:
         active_household_id = services.active_household_id()
         if active_household_id is not None:
             created_object.set_household_owner_id(active_household_id)
 def load_data(self, household_msg):
     self._collections.clear()
     if self.owner.all_sims_skip_load():
         return
     msg_type = UI_pb2.CollectibleItemUpdate.TYPE_DISCOVERY
     active_household_id = services.active_household_id()
     for collection in household_msg.gameplay_data.collection_data:
         self._collections[collection.collectible_def_id] = collection.collection_id
         while active_household_id == household_msg.household_id:
             self.send_collection_msg(msg_type, collection.collection_id, household_msg.household_id, collection.collectible_def_id)
Пример #26
0
 def set_active_household_live_drag_permission(self):
     owning_household_id = self.owner.get_household_owner_id()
     active_household_id = services.active_household_id()
     if active_household_id is not None and owning_household_id is not None and owning_household_id != active_household_id:
         self._household_permission = False
     else:
         self._household_permission = True
     if self.can_live_drag and not self._household_permission:
         self.set_can_live_drag(False)
     return self._household_permission
Пример #27
0
 def print_item_counts(self):
     active_sim_info = services.active_sim_info()
     self._show_dialog(
         "Items in {} {}'s inventory: {}\n"
         "Items in household inventory: {}".format(
             active_sim_info.first_name, active_sim_info.last_name,
             len(services.get_active_sim().inventory_component),
             len(
                 build_buy.get_object_ids_in_household_inventory(
                     services.active_household_id()))))
Пример #28
0
 def _add_expenditures_and_do_post_bb_fixup(self):
     if self.objects_to_fixup_post_bb is not None:
         household = self.lot.get_household()
         rebate_manager = household.rebate_manager if household is not None else None
         active_household_id = services.active_household_id()
         for obj in self.objects_to_fixup_post_bb:
             if rebate_manager is not None:
                 rebate_manager.add_rebate_for_object(obj)
             obj.try_post_bb_fixup(active_household_id=active_household_id)
         self.objects_to_fixup_post_bb = None
Пример #29
0
 def active_household_changed_between_save_and_load(self):
     zone_data_proto = self._get_zone_proto()
     if zone_data_proto is None:
         return False
     gameplay_zone_data = zone_data_proto.gameplay_zone_data
     if not protocol_buffer_utils.has_field(gameplay_zone_data,
                                            'active_household_id_on_save'):
         return False
     return gameplay_zone_data.active_household_id_on_save != services.active_household_id(
     )
 def _on_save_items(self, object_list):
     if self._shelved_objects is None:
         return
     if not self.owner.is_player_sim:
         return
     if self.owner.household.id == services.active_household_id():
         return
     logger.info('Merging Inventory {} (size: {}) with saved inventory {}.',
                 self, len(self), self.get_shelved_object_count())
     for shelved_obj in self._shelved_objects.objects:
         object_list.objects.append(shelved_obj)
Пример #31
0
def canys_sim_info_is_enabled_in_skewer(original, self):
    try:
        selection_group = SelectionGroupService.get(
            services.active_household_id(), True)

        if selection_group and selection_group.is_household_npc(self):
            return False

        return original(self)
    except BaseException:
        Logger.log(traceback.format_exc())
        return True
Пример #32
0
 def load_data(self, household_msg):
     self._collections.clear()
     if self.owner.all_sims_skip_load():
         return
     msg_type = UI_pb2.CollectibleItemUpdate.TYPE_DISCOVERY
     active_household_id = services.active_household_id()
     for collection in household_msg.gameplay_data.collection_data:
         self._collections[
             collection.collectible_def_id] = collection.collection_id
         while active_household_id == household_msg.household_id:
             self.send_collection_msg(msg_type, collection.collection_id,
                                      household_msg.household_id,
                                      collection.collectible_def_id)
Пример #33
0
    def _fill_and_send_save_game_protobufs_gen(self, timeline, slot_id, slot_name, auto_save_slot_id=None):
        self.save_error_code = persistence_error_types.ErrorCodes.SETTING_SAVE_SLOT_DATA_FAILED
        save_slot_data_msg = self.get_save_slot_proto_buff()
        save_slot_data_msg.slot_id = slot_id
        save_slot_data_msg.slot_name = slot_name
        if services.active_household_id() is not None:
            save_slot_data_msg.active_household_id = services.active_household_id()
        sims4.core_services.service_manager.save_all_services(self, persistence_error_types.ErrorCodes.CORE_SERICES_SAVE_FAILED, save_slot_data=save_slot_data_msg)
        self.save_error_code = persistence_error_types.ErrorCodes.SAVE_CAMERA_DATA_FAILED
        camera.serialize(save_slot_data=save_slot_data_msg)

        def on_save_complete(slot_id, success):
            wakeable_element.trigger_soft_stop()

        self.save_error_code = persistence_error_types.ErrorCodes.SAVE_TO_SLOT_FAILED
        wakeable_element = element_utils.soft_sleep_forever()
        persistence_module.run_persistence_operation(persistence_module.PersistenceOpType.kPersistenceOpSave, self._save_game_data_proto, slot_id, on_save_complete)
        yield element_utils.run_child(timeline, wakeable_element)
        if auto_save_slot_id is not None:
            self.save_error_code = persistence_error_types.ErrorCodes.AUTOSAVE_TO_SLOT_FAILED
            wakeable_element = element_utils.soft_sleep_forever()
            persistence_module.run_persistence_operation(persistence_module.PersistenceOpType.kPersistenceOpSave, self._save_game_data_proto, auto_save_slot_id, on_save_complete)
            yield element_utils.run_child(timeline, wakeable_element)
        self.save_error_code = persistence_error_types.ErrorCodes.NO_ERROR
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)
Пример #35
0
def tn_zone_director_residential_base_is_any_sim_always_greeted(
        original, self):
    active_lot_household = services.current_zone(
    ).get_active_lot_owner_household()
    selection_group = SelectionGroupService.get(services.active_household_id())

    if active_lot_household is None:
        return original(self)

    for sim_info in active_lot_household.sim_infos:
        if sim_info.id not in selection_group.selectable_sims:
            continue

        return True

    return original(self)
def purchase_picker_response(inventory_target, mailman_purchase:bool=False, *def_ids_and_amounts, _connection=None):
    total_price = 0
    current_purchased = 0
    objects_to_buy = []
    definition_manager = services.definition_manager()
    for (def_id, amount) in zip(def_ids_and_amounts[::2], def_ids_and_amounts[1::2]):
        definition = definition_manager.get(def_id)
        if definition is None:
            sims4.commands.output('inventory.purchase_picker_response: Definition not found with id {}'.format(def_id), _connection)
            return False
        purchase_price = definition.price*amount
        total_price += purchase_price
        objects_to_buy.append((definition, amount))
    client = services.client_manager().get(_connection)
    if client is None:
        sims4.commands.output('inventory.purchase_picker_response: No client found to make purchase.', _connection)
        return False
    household = client.household
    if household.funds.money < total_price:
        sims4.commands.output('inventory.purchase_picker_response: Insufficient funds for household to purchase items.', _connection)
        return False
    if mailman_purchase:
        inventory = services.active_lot().get_hidden_inventory()
    else:
        inventory_owner = inventory_target.get_target()
        inventory = inventory_owner.inventory_component
    if inventory is None:
        sims4.commands.output('inventory.purchase_picker_response: Inventory not found for items to be purchased into.', _connection)
        return False
    for (definition, amount) in objects_to_buy:
        obj = create_object(definition)
        if obj is None:
            sims4.commands.output('inventory.purchase_picker_response: Failed to create object with definition {}.'.format(definition), _connection)
        obj.set_stack_count(amount)
        if not inventory.player_try_add_object(obj):
            sims4.commands.output('inventory.purchase_picker_response: Failed to add object into inventory: {}'.format(obj), _connection)
            obj.destroy(source=inventory, cause='inventory.purchase_picker_response: Failed to add object into inventory.')
        obj.set_household_owner_id(household.id)
        obj.try_post_bb_fixup(force_fixup=True, active_household_id=services.active_household_id())
        purchase_price = definition.price*amount
        current_purchased += purchase_price
    household.funds.remove(current_purchased, Consts_pb2.TELEMETRY_OBJECT_BUY)
    return True
 def on_choice_selected(self, choice_tag, **kwargs):
     mother = choice_tag
     if mother is None:
         return
     father = self.target
     transferable_states = {}
     for state in self._combine_data.states_to_combine:
         mother_state = mother.get_state(state)
         father_state = father.get_state(state)
         transferable_states[state] = [mother_state, father_state]
         for combine_data in self._combine_data.combination_mapping:
             while combine_data.father_state == father_state and combine_data.mother_state == mother_state:
                 transferable_states[state].append(combine_data.resulting_state)
     if not transferable_states:
         logger.error('CollectionPickerInteraction: {} and {} collectibles have no transferable states', mother, father, owner='camilogarcia')
         return
     states_to_transfer = []
     for states in transferable_states.values():
         states_to_transfer.append(sims4.random.random.choice(states))
     target_match = len(states_to_transfer)
     possible_outcomes = []
     for collectable in self._collectible_data:
         match = 0
         for target_states in collectable.collectable_item.cls._components.state._tuned_values.states:
             while target_states.default_value in states_to_transfer:
                 match += 1
         while match == target_match:
             possible_outcomes.append(collectable.collectable_item)
     if not possible_outcomes:
         logger.error('CollectionPickerInteraction: No possible result when combining  {} and {}', mother, father, owner='camilogarcia')
         return
     definition_to_create = sims4.random.random.choice(possible_outcomes)
     obj = create_object(definition_to_create)
     if obj is None:
         logger.error('CollectionPickerInteraction: Failed to create object when combining  {} and {}', mother, father, owner='camilogarcia')
         return
     obj.update_ownership(self.sim.sim_info)
     if not self.sim.inventory_component.player_try_add_object(obj):
         obj.set_household_owner_id(services.active_household_id())
         build_buy.move_object_to_household_inventory(obj, object_location_type=ObjectOriginLocation.SIM_INVENTORY)
     self._push_continuation(obj)
Пример #38
0
 def load_data(self, householdProto):
     for utility in householdProto.gameplay_data.delinquent_utilities:
         self._utility_delinquency[utility] = True
         while utility == Utilities.POWER:
             self._stop_all_power_utilities()
     for additional_bill_cost in householdProto.gameplay_data.additional_bill_costs:
         self.add_additional_bill_cost(additional_bill_cost.bill_source, additional_bill_cost.cost)
     self._can_deliver_bill = householdProto.gameplay_data.can_deliver_bill
     self._put_bill_in_hidden_inventory = householdProto.gameplay_data.put_bill_in_hidden_inventory
     if self._put_bill_in_hidden_inventory:
         self._place_bill_in_mailbox()
     self._current_payment_owed = householdProto.gameplay_data.current_payment_owed
     if self._current_payment_owed == 0:
         self._current_payment_owed = None
     self._bill_timer = householdProto.gameplay_data.bill_timer
     self._shutoff_timer = householdProto.gameplay_data.shutoff_timer
     self._warning_timer = householdProto.gameplay_data.warning_timer
     active_household_id = services.active_household_id()
     if active_household_id is not None and self._household.id == active_household_id:
         self._set_up_timers()
     elif self._bill_timer_handle is not None:
         alarms.cancel_alarm(self._bill_timer_handle)
         self._bill_timer_handle = None
 def active_household_has_sell_permission(self):
     owning_household_id = self.owner.get_household_owner_id()
     active_household_id = services.active_household_id()
     return owning_household_id == active_household_id
Пример #40
0
 def on_all_households_and_sim_infos_loaded(self):
     active_household_id = services.active_household_id()
     if active_household_id is not None and self._household.id == active_household_id:
         self._set_up_timers()