Esempio n. 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
 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)
 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