示例#1
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
示例#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 __init__(self, account, starting_funds=singletons.DEFAULT):
     self.account = account
     self.id = 0
     self.name = ''
     self.description = ''
     self.home_zone_id = 0
     self.last_modified_time = 0
     self._watchers = {}
     self._autonomy_settings = autonomy.settings.AutonomySettings()
     self._sim_infos = []
     if starting_funds is singletons.DEFAULT:
         starting_funds = self.DEFAULT_STARTING_FUNDS
     self._funds = sims.funds.FamilyFunds(self, starting_funds)
     self._remote_connected = False
     self.bills_manager = bills.Bills(self)
     self._cheats_enabled = False
     self._has_cheated = False
     self.owned_object_count = 0
     self._service_npc_record = None
     self._collection_tracker = CollectionTracker(self)
     self._telemetry_tracker = HouseholdTelemetryTracker(self)
     self._last_active_sim_id = 0
     self._reward_inventory = serialization.RewardPartList()
     self.is_persistent_npc = True
     self._cached_billable_household_value = 0
     self._highest_earned_situation_medals = {}
     self._situation_scoring_enabled = True
     self.hidden = False
     self.creator_id = 0
     self.creator_name = ''
     self.creator_uuid = None
     self.primitives = ()
     self._adopting_sim_ids = set()
     self._build_buy_unlocks = set()
     self._aging_update_alarm = None
示例#4
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
 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)
 def load_sim_outfits_from_persistence_proto(self, sim_id, outfit_list):
     self._initialize_outfits()
     if outfit_list is not None:
         for outfit_data in outfit_list.outfits:
             new_outfit = {}
             new_outfit['sim_id'] = sim_id
             new_outfit['outfit_id'] = outfit_data.outfit_id
             new_outfit['type'] = outfit_data.category
             part_list = serialization.IdList()
             part_list.MergeFrom(outfit_data.parts)
             new_outfit['parts'] = part_list.ids
             body_types_list = serialization.BodyTypesList()
             body_types_list.MergeFrom(outfit_data.body_types_list)
             new_outfit['body_types'] = body_types_list.body_types
             new_outfit['match_hair_style'] = outfit_data.match_hair_style
             self.add_outfit(OutfitCategory(outfit_data.category), new_outfit)
示例#7
0
 def load(self, **_):
     self._clear()
     save_slot_data_msg = services.get_persistence_service(
     ).get_save_slot_proto_buff()
     if not save_slot_data_msg.gameplay_data.HasField(
             'object_lost_and_found'):
         return
     object_lost_and_found = save_slot_data_msg.gameplay_data.object_lost_and_found
     for object_locators in object_lost_and_found.locators:
         object_data = FileSerialization_pb2.ObjectData()
         object_data.ParseFromString(object_locators.object)
         if object_data is None:
             logger.error(
                 'Trying to load a locator with no object data. \n                zone_id: {}, open_street_id: {}, sim_id: {}, household_id: {}, \n                time_before_lost: {}, time_stamp: {}',
                 object_locators.zone_id, object_locators.open_street_id,
                 object_locators.sim_id, object_locators.household_id,
                 object_locators.time_before_lost,
                 object_locators.time_stamp.absolute_ticks())
         else:
             locator = self._raw_add_object_data(
                 object_locators.zone_id, object_locators.open_street_id,
                 object_data.object_id, object_locators.sim_id,
                 object_locators.household_id,
                 object_locators.time_before_lost,
                 DateAndTime(object_locators.time_stamp))
             locator.object_data = object_data
     for clone in object_lost_and_found.clones_to_delete:
         self.add_clone_id(clone.zone_id, clone.open_street_id,
                           clone.object_id)
示例#8
0
 def __init__(self):
     super().__init__()
     self._save_locks = []
     self._save_game_data_proto = serialization.SaveGameData()
     self.save_timeline = None
     self.save_error_code = persistence_error_types.ErrorCodes.NO_ERROR
     self._read_write_locked = False
示例#9
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
 def save_sim_outfits(self):
     outfit_list_msg = serialization.OutfitList()
     for outfit_category in OutfitCategory:
         while self.outfits_in_category(outfit_category) is not None:
             while True:
                 for (index, outfit_dict) in enumerate(self.outfits_in_category(outfit_category)):
                     with ProtocolBufferRollback(outfit_list_msg.outfits) as outfit_msg:
                         outfit_msg.outfit_id = outfit_dict['outfit_id']
                         outfit_msg.category = outfit_category
                         outfit_msg.outfit_index = index
                         outfit_msg.created = services.time_service().sim_now.absolute_ticks()
                         outfit_msg.parts = serialization.IdList()
                         for part in outfit_dict['parts']:
                             outfit_msg.parts.ids.append(part)
                         for body_type in outfit_dict['body_types']:
                             outfit_msg.body_types_list.body_types.append(body_type)
                         outfit_msg.match_hair_style = outfit_dict['match_hair_style']
     return outfit_list_msg
示例#11
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
示例#12
0
 def load_data(self, householdProto):
     self.name = householdProto.name
     self.description = householdProto.description
     self.id = householdProto.household_id
     self.home_zone_id = householdProto.home_zone
     self.last_modified_time = householdProto.last_modified_time
     self._funds = sims.funds.FamilyFunds(self, householdProto.money)
     self._rebate_manager = sims.rebate_manager.RebateManager(self)
     self.is_persistent_npc = householdProto.is_npc
     self.hidden = householdProto.hidden
     self.creator_id = householdProto.creator_id
     self.creator_name = householdProto.creator_name
     self.creator_uuid = householdProto.creator_uuid
     if householdProto.sims.ids:
         for sim_id in householdProto.sims.ids:
             try:
                 sim_info = services.sim_info_manager().get(sim_id)
                 if sim_info is None:
                     sim_info = sims.sim_info.SimInfo(sim_id=sim_id,
                                                      account=self.account)
                 sim_proto = services.get_persistence_service(
                 ).get_sim_proto_buff(sim_id)
                 sim_info.load_sim_info(sim_proto)
                 while not self.sim_in_household(sim_id):
                     self.add_sim_info(sim_info, process_events=False)
             except Exception:
                 logger.exception('Sim {} failed to load', sim_id)
     self.bills_manager.load_data(householdProto)
     self.collection_tracker.load_data(householdProto)
     for record_msg in householdProto.gameplay_data.service_npc_records:
         record = self.get_service_npc_record(record_msg.service_type,
                                              add_if_no_record=True)
         record.load_npc_record(record_msg)
     for situation_medal in householdProto.gameplay_data.highest_earned_situation_medals:
         self._highest_earned_situation_medals[
             situation_medal.situation_id] = situation_medal.medal
     self._last_active_sim_id = householdProto.last_played
     self._reward_inventory = serialization.RewardPartList()
     self._reward_inventory.CopyFrom(householdProto.reward_inventory)
     old_unlocks = set(list(householdProto.gameplay_data.build_buy_unlocks))
     self._build_buy_unlocks = set()
     for unlock in old_unlocks:
         key = sims4.resources.Key(Types.OBJCATALOG, unlock, 0)
         self._build_buy_unlocks.add(key)
     if hasattr(householdProto.gameplay_data, 'build_buy_unlock_list'):
         for key_proto in householdProto.gameplay_data.build_buy_unlock_list.resource_keys:
             key = sims4.resources.Key(key_proto.type, key_proto.instance,
                                       key_proto.group)
             self._build_buy_unlocks.add(key)
     if hasattr(householdProto.gameplay_data, 'situation_scoring_enabled'):
         self._situation_scoring_enabled = householdProto.gameplay_data.situation_scoring_enabled
     self._cached_billable_household_value = householdProto.gameplay_data.billable_household_value
示例#13
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)
 def __init__(self):
     super().__init__()
     self._save_locks = []
     self._read_write_locked = False
     self._save_game_data_proto = serialization.SaveGameData()
     self.save_timeline = None
     self._unlocked_callbacks = CallableList()
     self.once_per_session_telemetry_sent = False
     self.save_error_code = persistence_error_types.ErrorCodes.NO_ERROR
     self._zone_data_pb_cache = {}
     self._world_id_to_region_id_cache = {}
     self._sim_data_pb_cache = None
     self._household_pb_cache = None
     self._world_ids = frozenset()
示例#15
0
def load_zone(_connection=None):
    try:
        zone = services.current_zone()
        name = str(hex(zone.id)).replace("0x", "")
        zone_objects_pb = serialization.ZoneObjectData()
        zone_objects_message = open(get_file_matching_name(name)[0],
                                    "rb").read()
        output("msg", dir(zone_objects_pb))
        zone_objects_pb.ParseFromString(zone_objects_message)
        output("msg", zone_objects_pb)
        output("msg", zone_objects_message)
        persistence_module.run_persistence_operation(
            persistence_module.PersistenceOpType.kPersistenceOpLoadZoneObjects,
            zone_objects_pb, 0, None)
    except Exception as e:
        output("er", e)
 def get_neighborhood_proto(self, street, add=True):
     zone_ids = get_zone_ids_from_street(street)
     if not zone_ids:
         return (None, None)
     persistence_service = services.get_persistence_service()
     zone_id = zone_ids[0]
     zone_data = persistence_service.get_zone_proto_buff(zone_id)
     neighborhood_proto = persistence_service.get_neighborhood_proto_buf_from_zone_id(
         zone_id)
     if not neighborhood_proto:
         return (None, None)
     for street_data in neighborhood_proto.street_data:
         if street_data.world_id == zone_data.world_id:
             return (neighborhood_proto, street_data)
     if not add:
         return (None, None)
     street_data = FileSerialization_pb2.StreetInfoData()
     street_data.world_id = zone_data.world_id
     neighborhood_proto.street_data.append(street_data)
     return (neighborhood_proto, neighborhood_proto.street_data[-1])
示例#17
0
def send_travel_view_household_info(_connection=None):
    msg = UI_pb2.TravelViewHouseholdsInfo()
    for household in tuple(services.household_manager().values()):
        with ProtocolBufferRollback(msg.household_locations) as household_location_data:
            household_location_data.household_id = household.id
            household_location_data.household_name = household.name
            household_location_data.home_zone_id = household.home_zone_id
            household_location_data.is_played = household.is_player_household
            for sim_info in household:
                with ProtocolBufferRollback(household_location_data.sim_info_status) as sim_info_location_status:
                    sim_info_location_status.sim_id = sim_info.id
                    sim_info_location_status.age = sim_info.age
                    sim_info_location_status.is_at_home = sim_info.is_at_home
                    sim_info_location_status.zone_id = sim_info.zone_id
    distributor = Distributor.instance()
    distributor.add_op_with_no_owner(GenericProtocolBufferOp(Operation.TRAVEL_VIEW_HOUSEHOLDS_INFO, msg))
    travel_group_list_msg = FileSerialization_pb2.TravelGroupList()
    for travel_group in tuple(services.travel_group_manager().values()):
        with ProtocolBufferRollback(travel_group_list_msg.travel_groups) as travel_group_data:
            travel_group.save_data(travel_group_data)
    distributor.add_op_with_no_owner(GenericProtocolBufferOp(Operation.TRAVEL_GROUP_LIST, travel_group_list_msg))
示例#18
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
示例#19
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)
示例#20
0
 def create_sim_infos(cls,
                      sim_creators,
                      household=None,
                      starting_funds=DEFAULT,
                      tgt_client=None,
                      account=None,
                      generate_deterministic_sim=False,
                      zone_id=None,
                      creation_source: str = 'Unknown'):
     sim_info_list = []
     if account is None:
         account = cls._get_default_account()
     if household is None:
         household = sims.household.Household(account,
                                              starting_funds=starting_funds)
     sim_creation_dictionaries = tuple(
         sim_creator.build_creation_dictionary()
         for sim_creator in sim_creators)
     new_sim_data = generate_household(
         sim_creation_dictionaries=sim_creation_dictionaries,
         household_name=household.name,
         generate_deterministic_sim=generate_deterministic_sim)
     zone = services.current_zone()
     world_id = zone.world_id
     if zone_id is None:
         zone_id = zone.id
     language = cls._get_language_for_locale(account)
     family_name = cls._get_random_family_name(language)
     if household.id == 0:
         household.id = new_sim_data['id']
         services.household_manager().add(household)
         household.name = family_name
     for (index, sim_data) in enumerate(new_sim_data['sims']):
         sim_proto = serialization.SimData()
         sim_proto.ParseFromString(sim_data)
         first_name = sim_creators[index].first_name
         if not first_name and not sim_creators[index].full_name_key:
             first_name = cls._get_random_first_name(
                 language, sim_proto.gender == Gender.FEMALE)
         last_name = sim_creators[index].last_name
         if not last_name and not sim_creators[index].full_name_key:
             last_name = cls._get_family_name_for_gender(
                 language, family_name, sim_proto.gender == Gender.FEMALE)
         sim_proto.first_name = first_name
         sim_proto.last_name = last_name
         sim_proto.full_name_key = sim_creators[index].full_name_key
         sim_proto.age = sim_creators[index].age
         sim_proto.zone_id = zone_id
         sim_proto.world_id = world_id
         sim_proto.household_id = household.id
         sim_proto.gameplay_data.creation_source = creation_source
         sim_info = sims.sim_info.SimInfo(sim_proto.sim_id, account=account)
         sim_info.load_sim_info(sim_proto)
         if sim_creators[index].resource_key:
             sim_info.load_from_resource(sim_creators[index].resource_key)
             if not sim_info.first_name:
                 sim_info.first_name = sim_proto.first_name
             if not sim_info.last_name:
                 sim_info.last_name = sim_proto.last_name
             if not sim_info.full_name_key:
                 sim_info.full_name_key = sim_proto.full_name_key
         household.add_sim_info(sim_info)
         sim_info.assign_to_household(household)
         sim_info.save_sim()
         sim_info_list.append(sim_info)
         if tgt_client is not None and household is tgt_client.household:
             logger.info('Added {} Sims to the current client',
                         len(sim_creators))
             tgt_client.set_next_sim()
         else:
             logger.info('Added {} Sims to household ID {}.',
                         len(sim_creators), household.id)
         logger.info('Create Sims, sim_number={}; succeeded',
                     len(sim_creators))
     household.save_data()
     return (sim_info_list, household)
示例#21
0
def get_object_in_household_inventory(object_id, household_id):
    def make_object(object_data):
        def_id = get_vetted_object_defn_guid(object_id, object_data.guid)
        definition = services.definition_manager().get(
            def_id, obj_state=object_data.state_index)

        class HouseholdInventoryObject(definition.cls):
            @property
            def persistence_group(self):
                return objects.persistence_groups.PersistenceGroups.NONE

            @persistence_group.setter
            def persistence_group(self, value):
                pass

            def save_object(
                    self,
                    object_list,
                    *args,
                    item_location=objects.object_enums.ItemLocation.ON_LOT,
                    container_id=0,
                    **kwargs):
                pass

            @property
            def is_valid_posture_graph_object(self):
                return False

        try:
            obj = objects.system.create_object(
                object_data.guid,
                cls_override=HouseholdInventoryObject,
                obj_id=object_id,
                obj_state=object_data.state_index,
                loc_type=ItemLocation.HOUSEHOLD_INVENTORY,
                content_source=ContentSource.HOUSEHOLD_INVENTORY_PROXY)
            obj.append_tags(objects.object_manager.ObjectManager.
                            HOUSEHOLD_INVENTORY_OBJECT_TAGS)
            obj.attributes = object_data.SerializeToString()
            obj.set_household_owner_id(household_id)
        except ObjectIDError as exc:
            obj = services.object_manager().get(object_id)
            if obj is None:
                logger.error(
                    'Failed to create or find proxy object for Household Inventory object {}\n{}',
                    object_id, exc)
        return obj

    if is_household_inventory_available(household_id):
        object_data_raw = _buildbuy.get_object_data_in_household_inventory(
            object_id, household_id)
        if object_data_raw is None:
            return
        object_data = FileSerialization_pb2.ObjectData()
        object_data.ParseFromString(object_data_raw)
        if object_data is not None:
            return make_object(object_data)
    else:
        household_msg = services.get_persistence_service(
        ).get_household_proto_buff(household_id)
        if household_msg is not None:
            if household_msg.inventory:
                for object_data in household_msg.inventory:
                    if object_data.object_id == object_id:
                        return make_object(object_data)
示例#22
0
 def create_sim_infos(cls,
                      sim_creators,
                      household=None,
                      starting_funds=DEFAULT,
                      tgt_client=None,
                      account=None,
                      generate_deterministic_sim=False,
                      zone_id=None,
                      sim_name_type=SimNameType.DEFAULT,
                      creation_source: str = 'Unknown - create_sim_infos',
                      skip_adding_to_household=False,
                      is_debug=False):
     sim_info_list = []
     if account is None:
         account = cls._get_default_account()
     if household is None:
         if not skip_adding_to_household:
             household = sims.household.Household(
                 account, starting_funds=starting_funds)
     sim_creation_dictionaries = tuple(
         sim_creator.build_creation_dictionary()
         for sim_creator in sim_creators)
     new_sim_data = generate_household(
         sim_creation_dictionaries=sim_creation_dictionaries,
         household_name=household.name,
         generate_deterministic_sim=generate_deterministic_sim)
     zone = services.current_zone()
     world_id = zone.world_id
     if zone_id is None:
         zone_id = zone.id
     elif zone_id != 0:
         world_id = services.get_persistence_service(
         ).get_world_id_from_zone(zone_id)
     language = cls._get_language_for_locale(account.locale)
     family_name = cls._get_random_last_name(language,
                                             sim_name_type=sim_name_type)
     if household.id == 0:
         if not skip_adding_to_household:
             household.id = new_sim_data['id']
             services.household_manager().add(household)
             household.name = family_name
     for (index, sim_data) in enumerate(new_sim_data['sims']):
         sim_proto = serialization.SimData()
         sim_proto.ParseFromString(sim_data)
         first_name = sim_creators[index].first_name
         if not first_name:
             if not sim_creators[index].first_name_key:
                 if not sim_creators[index].full_name_key:
                     if sim_name_type == SimNameType.DEFAULT:
                         first_name = cls.get_random_first_name(
                             sim_proto.gender, sim_proto.extended_species)
                     else:
                         first_name = cls._get_random_first_name(
                             language,
                             sim_proto.gender == Gender.FEMALE,
                             sim_name_type=sim_name_type)
         last_name = sim_creators[index].last_name
         last_name_key = sim_creators[index].last_name_key
         if not last_name:
             if not last_name_key:
                 if last_name_key is not UNSET:
                     if not sim_creators[index].full_name_key:
                         if sim_name_type == SimNameType.DEFAULT:
                             last_name = cls.get_last_name(
                                 family_name, sim_proto.gender,
                                 sim_proto.extended_species)
                         else:
                             last_name = cls._get_family_name_for_gender(
                                 language,
                                 family_name,
                                 sim_proto.gender == Gender.FEMALE,
                                 sim_name_type=sim_name_type)
         sim_proto.first_name = first_name
         sim_proto.last_name = last_name
         sim_proto.first_name_key = sim_creators[index].first_name_key
         if last_name_key is not UNSET:
             sim_proto.last_name_key = last_name_key
         sim_proto.full_name_key = sim_creators[index].full_name_key
         sim_proto.age = sim_creators[index].age
         sim_proto.extended_species = sim_creators[index].species
         sim_proto.breed_name_key = sim_creators[index].breed_name_key
         sim_proto.zone_id = zone_id
         sim_proto.world_id = world_id
         sim_proto.household_id = household.id
         SimInfoCreationSource.save_creation_source(creation_source,
                                                    sim_proto)
         trait_ids = [
             trait.guid64 for trait in sim_creators[index].traits
             if trait.persistable
         ]
         sim_proto.attributes.trait_tracker.trait_ids.extend(trait_ids)
         sim_info = sims.sim_info.SimInfo(sim_id=sim_proto.sim_id,
                                          account=account)
         sim_info.load_sim_info(sim_proto)
         breed_tag = breed_tuning.get_breed_tag_from_tag_set(
             sim_creators[index].tag_set)
         if breed_tag != Tag.INVALID:
             breed_tuning.try_conform_sim_info_to_breed(sim_info, breed_tag)
         if sim_creators[index].resource_key:
             sim_info.load_from_resource(sim_creators[index].resource_key)
             if not sim_info.first_name:
                 sim_info.first_name = sim_proto.first_name
             if not sim_info.last_name:
                 sim_info.last_name = sim_proto.last_name
             if not sim_info.first_name_key:
                 sim_info.first_name_key = sim_proto.first_name_key
             if not sim_info.last_name_key:
                 sim_info.last_name_key = sim_proto.last_name_key
             if not sim_info.full_name_key:
                 sim_info.full_name_key = sim_proto.full_name_key
             if not sim_info.breed_name_key:
                 sim_info.breed_name_key = sim_proto.breed_name_key
         if not skip_adding_to_household:
             sim_info.assign_to_household(household)
             sim_info.save_sim()
             household.add_sim_info(sim_info)
             if tgt_client is not None and household is tgt_client.household:
                 logger.info('Added {} Sims to the current client',
                             len(sim_creators))
                 if tgt_client.active_sim is None:
                     tgt_client.set_next_sim()
             else:
                 logger.info('Added {} Sims to household ID {}.',
                             len(sim_creators), household.id)
         logger.info('Create Sims, sim_number={}; succeeded',
                     len(sim_creators))
         sim_info.push_to_relgraph()
         if gsi_handlers.sim_info_lifetime_handlers.archiver.enabled:
             gsi_handlers.sim_info_lifetime_handlers.archive_sim_info_event(
                 sim_info, 'new sim info')
         services.sim_info_manager().on_sim_info_created()
         sim_info_list.append(sim_info)
     if not skip_adding_to_household:
         household.save_data()
     if is_debug:
         services.get_zone_situation_manager().add_debug_sim_id(sim_info.id)
     return (sim_info_list, household)
示例#23
0
 def add_cas_part_to_reward_inventory(self, cas_part):
     reward_part_data = serialization.RewardPartData()
     reward_part_data.part_id = cas_part
     reward_part_data.is_new_reward = True
     self._reward_inventory.reward_parts.append(reward_part_data)
示例#24
0
 def _create_object_from_raw_inv_data(self, object_id, raw_inv_data):
     object_data = FileSerialization_pb2.ObjectData()
     object_data.ParseFromString(raw_inv_data)
     return self._create_object_from_object_data(object_id, object_data)
示例#25
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