def _load_item(self, definition_id, obj_data):
     if self._should_create_object(definition_id):
         self._create_inventory_object(definition_id, obj_data)
     else:
         if self._shelved_objects is None:
             self._shelved_objects = FileSerialization_pb2.ObjectList()
         self._shelved_objects.objects.append(obj_data)
Exemple #2
0
def c_api_buildbuy_get_save_object_data(zone_id: int, obj_id: int):
    obj = services.get_zone(zone_id).find_object(obj_id)
    if obj is None:
        return
    object_list = file_serialization.ObjectList()
    save_data = obj.save_object(object_list.objects, from_bb=True)
    return save_data
Exemple #3
0
def c_api_buildbuy_get_save_object_data(zone_id, obj_id):
    with sims4.zone_utils.global_zone_lock(zone_id):
        obj = services.get_zone(zone_id).find_object(obj_id)
        if obj is None:
            return
        object_list = file_serialization.ObjectList()
        save_data = obj.save_object(object_list.objects)
    return save_data
Exemple #4
0
 def save_data(self):
     household_msg = services.get_persistence_service(
     ).get_household_proto_buff(self.id)
     if household_msg is None:
         household_msg = services.get_persistence_service(
         ).add_household_proto_buff()
     inventory = serialization.ObjectList()
     inventory.CopyFrom(household_msg.inventory)
     household_msg.Clear()
     household_msg.account_id = self.account.id
     household_msg.household_id = self.id
     household_msg.name = self.name
     household_msg.description = self.description
     household_msg.home_zone = self.home_zone_id
     household_msg.last_modified_time = self.last_modified_time
     household_msg.money = self.funds.money
     household_msg.hidden = self.hidden
     household_msg.creator_id = self.creator_id
     household_msg.creator_name = self.creator_name
     if self.creator_uuid is not None:
         household_msg.creator_uuid = self.creator_uuid
     household_msg.inventory = inventory
     household_msg.reward_inventory = self._reward_inventory
     household_msg.gameplay_data.build_buy_unlock_list = ResourceKey_pb2.ResourceKeyList(
     )
     for unlock in self.build_buy_unlocks:
         if isinstance(unlock, int):
             unlock = sims4.resources.Key(Types.OBJCATALOG, unlock, 0)
         key_proto = sims4.resources.get_protobuff_for_key(unlock)
         household_msg.gameplay_data.build_buy_unlock_list.resource_keys.append(
             key_proto)
     household_msg.gameplay_data.situation_scoring_enabled = self._situation_scoring_enabled
     if self.sim_in_household(self._last_active_sim_id):
         household_msg.last_played = self._last_active_sim_id
     household_msg.is_npc = self.is_persistent_npc
     household_msg.gameplay_data.billable_household_value = self.household_net_worth(
         billable=True)
     household_msg.gameplay_data.ClearField(
         'highest_earned_situation_medals')
     for (situation_id,
          medal) in self._highest_earned_situation_medals.items():
         with ProtocolBufferRollback(
                 household_msg.gameplay_data.highest_earned_situation_medals
         ) as situation_medal:
             situation_medal.situation_id = situation_id
             situation_medal.medal = medal
     self.bills_manager.save_data(household_msg)
     self.collection_tracker.save_data(household_msg)
     if self._service_npc_record is not None:
         for service_record in self._service_npc_record.values():
             with ProtocolBufferRollback(household_msg.gameplay_data.
                                         service_npc_records) as record_msg:
                 service_record.save_npc_record(record_msg)
     id_list = serialization.IdList()
     for sim_info in self:
         id_list.ids.append(sim_info.id)
     household_msg.sims = id_list
     return True
Exemple #5
0
 def save_items(self):
     if self.is_shared_inventory:
         return
     object_list = FileSerialization_pb2.ObjectList()
     for obj in self:
         obj.save_object(object_list.objects,
                         item_location=self.default_item_location,
                         container_id=self.owner.id)
     self._on_save_items(object_list)
     return object_list
Exemple #6
0
 def update_zone_object_locators(self):
     current_zone = services.current_zone()
     current_zone_id = services.current_zone_id()
     object_manager = current_zone.object_manager
     current_open_street_id = current_zone.open_street_id
     for locator in list(self._object_locators):
         if locator.zone_id != current_zone_id:
             continue
         obj = object_manager.get(locator.object_id)
         if obj is not None:
             locator.open_street_id = ObjectLostAndFoundService.STREET_UNKNOWN if current_zone.lot.is_position_on_lot(
                 obj.position) else current_open_street_id
             object_list = FileSerialization_pb2.ObjectList()
             open_street_object_locators = FileSerialization_pb2.ObjectList(
             )
             locator.object_data = ObjectManager.save_game_object(
                 obj, object_list, open_street_object_locators)
             if locator.object_data is None:
                 self.remove_object(locator.object_id)
                 self.remove_object(locator.object_id)
         else:
             self.remove_object(locator.object_id)
Exemple #7
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)
Exemple #8
0
 def _reload_definition(self, key):
     if paths.SUPPORT_RELOADING_RESOURCES:
         sims4.resources.purge_cache()
         if isinstance(key, tuple):
             (def_id, state) = key
         else:
             def_id = key
             state = 0
         definition = self._load_definition_and_tuning(def_id, state)
         if definition is not None:
             if def_id in self._dependencies:
                 list_copy = list(self._dependencies.get(def_id))
                 self._dependencies[def_id].clear()
                 for gameobject in list_copy:
                     if gameobject.is_sim:
                         continue
                     loc_type = gameobject.item_location
                     object_list = file_serialization.ObjectList()
                     save_data = gameobject.save_object(object_list.objects)
                     try:
                         gameobject.manager.remove(gameobject)
                     except:
                         logger.exception('exception in removing game object {}', gameobject)
                         continue
                     try:
                         dup = objects.system.create_object(definition, obj_id=gameobject.id, loc_type=loc_type, disable_object_commodity_callbacks=True)
                         dup.load_object(save_data, inline_finalize=True)
                         if gameobject.location is not None:
                             dup.location = gameobject.location
                         inventory = dup.get_inventory()
                         if inventory is not None:
                             inventory.system_add_object(dup)
                         logger.error('reloading game object with ID {}', dup.id)
                     except:
                         logger.exception('exception in reinitializing game object {}', gameobject)
         return definition
Exemple #9
0
 def save(self,
          object_list=None,
          zone_data=None,
          open_street_data=None,
          store_travel_group_placed_objects=False,
          **kwargs):
     if object_list is None:
         return
     open_street_objects = file_serialization.ObjectList()
     total_beds = 0
     double_bed_exist = False
     kid_bed_exist = False
     alternative_sleeping_spots = 0
     university_roommate_beds = 0
     if store_travel_group_placed_objects:
         objects_to_save_for_clean_up = []
     roommate_bed_tags = set()
     roommate_service = services.get_roommate_service()
     if roommate_service is not None:
         roommate_bed_tags = roommate_service.BED_TAGS
     for game_object in self._objects.values():
         if self._should_save_object_on_lot(game_object):
             save_result = ObjectManager.save_game_object(
                 game_object, object_list, open_street_objects)
             if not save_result:
                 continue
             if zone_data is None:
                 continue
             if store_travel_group_placed_objects and save_result.owner_id != 0:
                 placement_flags = build_buy.get_object_placement_flags(
                     game_object.definition.id)
                 if build_buy.PlacementFlags.NON_INVENTORYABLE not in placement_flags:
                     objects_to_save_for_clean_up.append(save_result)
             if not game_object.definition.has_build_buy_tag(
                     *self._all_bed_tags):
                 continue
             if game_object.definition.has_build_buy_tag(
                     *self.BED_TAGS.double_beds):
                 double_bed_exist = True
                 total_beds += 1
             elif game_object.definition.has_build_buy_tag(
                     *self.BED_TAGS.kid_beds):
                 total_beds += 1
                 kid_bed_exist = True
             elif game_object.definition.has_build_buy_tag(
                     *self.BED_TAGS.other_sleeping_spots):
                 alternative_sleeping_spots += 1
             elif game_object.definition.has_build_buy_tag(
                     *self.BED_TAGS.beds):
                 total_beds += 1
             if len(roommate_bed_tags) > 0:
                 if game_object.definition.has_build_buy_tag(
                         *roommate_bed_tags):
                     university_roommate_beds += 1
     if open_street_data is not None:
         open_street_data.objects = open_street_objects
     if zone_data is not None:
         bed_info_data = gameplay_serialization.ZoneBedInfoData()
         bed_info_data.num_beds = total_beds
         bed_info_data.double_bed_exist = double_bed_exist
         bed_info_data.kid_bed_exist = kid_bed_exist
         bed_info_data.alternative_sleeping_spots = alternative_sleeping_spots
         if roommate_service is not None:
             household_and_roommate_cap = roommate_service.HOUSEHOLD_AND_ROOMMATE_CAP
             bed_info_data.university_roommate_beds = min(
                 household_and_roommate_cap, university_roommate_beds)
         zone_data.gameplay_zone_data.bed_info_data = bed_info_data
         if store_travel_group_placed_objects:
             current_zone = services.current_zone()
             save_game_protocol_buffer = services.get_persistence_service(
             ).get_save_game_data_proto()
             self._clear_clean_up_data_for_zone(current_zone,
                                                save_game_protocol_buffer)
             self._save_clean_up_destination_data(
                 current_zone, objects_to_save_for_clean_up,
                 save_game_protocol_buffer)
     lot = services.current_zone().lot
     for (inventory_type, inventory) in lot.get_all_object_inventories_gen(
             shared_only=True):
         for game_object in inventory:
             game_object.save_object(object_list.objects,
                                     ItemLocation.OBJECT_INVENTORY,
                                     inventory_type)
Exemple #10
0
 def clone(self, **kwargs):
     clone = objects.system.create_object(self.definition, **kwargs)
     object_list = file_serialization.ObjectList()
     save_data = self.save_object(object_list.objects)
     clone.load_object(save_data)
     return clone