def update_holiday(holiday_data: str, _connection=None): holiday_service = services.holiday_service() if holiday_service is None: return proto = GameplaySaveData_pb2.Holiday() text_format.Merge(holiday_data, proto) holiday_service.modify_holiday(proto)
def save_interactions(self): interaction_save_state = gameplay_serialization.SuperInteractionSaveState() sorted_sis = sorted(self._super_interactions, key=lambda si: 0 if self.sim.posture_state.is_source_interaction(si) else 1) for si in sorted_sis: if not si.saveable: continue with ProtocolBufferRollback(interaction_save_state.interactions) as si_save_data: si.fill_save_data(si_save_data) sim_queue = self.sim.queue transition_controller = sim_queue.transition_controller interaction = None if transition_controller is None else transition_controller.interaction if interaction is not None: is_transitioning = interaction.transition is not None and (interaction.transition.running and interaction.pipeline_progress < PipelineProgress.RUNNING) if is_transitioning: if interaction.saveable: transitioning_interaction = interaction_save_state.transitioning_interaction interaction.fill_save_data(transitioning_interaction.base_interaction_data) current_sim_posture = self.sim.posture_state if current_sim_posture is not None: transitioning_interaction.posture_aspect_body = current_sim_posture.body.guid64 transitioning_interaction.posture_carry_left = current_sim_posture.left.guid64 transitioning_interaction.posture_carry_right = current_sim_posture.right.guid64 for si in sim_queue.queued_super_interactions_gen(): if not si.saveable: continue if si is interaction: continue with ProtocolBufferRollback(interaction_save_state.queued_interactions) as si_save_data: si.fill_save_data(si_save_data) return interaction_save_state
def save(self, object_list=None, zone_data=None, open_street_data=None, store_travel_group_placed_objects=False, save_slot_data=None): self.update_zone_object_locators() proto_object_locators = GameplaySaveData_pb2.PersistableObjectLostAndFound( ) for entry in self._object_locators: if entry.object_data is None: logger.error( 'Trying to save a locator with no object data. \n zone_id: {}, open_street_id: {}, sim_id: {}, household_id: {}, \n time_before_lost: {}, time_stamp: {}', entry.zone_id, entry.open_street_id, entry.sim_id, entry.household_id, entry.time_before_lost, entry.time_stamp.absolute_ticks()) else: with ProtocolBufferRollback( proto_object_locators.locators) as locator: locator.object = entry.object_data.SerializeToString() locator.zone_id = entry.zone_id locator.open_street_id = entry.open_street_id locator.sim_id = entry.sim_id locator.household_id = entry.household_id locator.time_before_lost = entry.time_before_lost locator.time_stamp = entry.time_stamp.absolute_ticks() for (zone_id, objects) in self._clones_to_delete_by_zone.items(): for object_id in objects: with ProtocolBufferRollback( proto_object_locators.clones_to_delete) as clone: clone.zone_id = zone_id clone.object_id = object_id save_slot_data.gameplay_data.object_lost_and_found = proto_object_locators
def save(self, save_slot_data=None, **__): if self._season is None: return seasons_proto = GameplaySaveData_pb2.PersistableSeasonService() seasons_proto.current_season = self._season.value seasons_proto.season_start_time = self._season_content.start_time save_slot_data.gameplay_data.season_service = seasons_proto
def save(self, save_slot_data=None, **kwargs): data = GameplaySaveData_pb2.PersistableStyleService() for (gender, outfit_data) in self._style_outfit_data.items(): with ProtocolBufferRollback(data.outfit_infos) as outfit_info: outfit_info.outfit_info_data.mannequin_id = outfit_data.sim_id outfit_data.save_sim_info(outfit_info.outfit_info_data) save_slot_data.gameplay_data.style_service = data
def on_zone_unload(self): if not game_services.service_manager.is_traveling: return self._whim_goal_proto = GameplaySaveData_pb2.WhimsetTrackerData() self.save_whims_info_to_proto(self._whim_goal_proto, copy_existing=False) self.clean_up()
def update_club(club_data: str, _connection=None): club_service = _get_club_service(_connection) if club_service is None: return proto = GameplaySaveData_pb2.Club() text_format.Merge(club_data, proto) club_service.update_club_from_data(proto)
def save(self, save_slot_data=None, **__): global_policy_service_proto = GameplaySaveData_pb2.PersistableGlobalPolicyService( ) for global_policy in self._global_policies.values(): with ProtocolBufferRollback( global_policy_service_proto.global_policies ) as global_policy_proto: global_policy_proto.progress_state = global_policy.progress_state global_policy_proto.progress_value = global_policy.progress_value if global_policy.decay_handler is not None: global_policy_proto.decay_days = global_policy.decay_handler.when global_policy_proto.snippet = global_policy.guid64 for (bill_reduction_reason, bill_reduction_amt) in self._bill_reductions.items(): with ProtocolBufferRollback( global_policy_service_proto.bill_reductions ) as global_policy_bill_reduction: global_policy_bill_reduction.bill_reduction_reason = bill_reduction_reason global_policy_bill_reduction.bill_reduction_amount = bill_reduction_amt for effect_global_policy_id in self._utility_effects.keys(): with ProtocolBufferRollback( global_policy_service_proto.utility_effects ) as global_policy_utility: global_policy_utility.global_policy_snippet_guid64 = effect_global_policy_id save_slot_data.gameplay_data.global_policy_service = global_policy_service_proto
def save(self, save_slot_data=None, **__): narrative_proto = GameplaySaveData_pb2.PersistableNarrativeService() for narrative_instance in self._active_narratives.values(): with ProtocolBufferRollback(narrative_proto.narratives) as msg: narrative_instance.save(msg) for narrative in self._completed_narratives: narrative_proto.completed_narratives.append(narrative.guid64) save_slot_data.gameplay_data.narrative_service = narrative_proto
def save(self, save_slot_data=None, **kwargs): hidden_sim_service_proto = GameplaySaveData_pb2.PersistableHiddenSimService() for (sim_id, away_action) in self._hidden_sim_ids_dict.items(): with ProtocolBufferRollback(hidden_sim_service_proto.hidden_sim_data) as entry: entry.sim_id = sim_id if away_action is not None: entry.away_action = away_action.guid64 save_slot_data.gameplay_data.hidden_sim_service = hidden_sim_service_proto
def save(self, save_slot_data=None, **kwargs): self.timeout_real_sim_infos() adoption_service_proto = GameplaySaveData_pb2.PersistableAdoptionService() for (sim_id, creation_time) in self._creation_times.items(): with ProtocolBufferRollback(adoption_service_proto.adoptable_sim_data) as msg: msg.adoptable_sim_id = sim_id msg.creation_time = creation_time.absolute_ticks() save_slot_data.gameplay_data.adoption_service = adoption_service_proto
def save(self, open_street_data=None, **kwargs): if open_street_data is None: return open_street_data.ambient_service = gameplay_serialization.AmbientServiceData( ) for source in self._sources: with ProtocolBufferRollback( open_street_data.ambient_service.sources) as source_data: source.save(source_data)
def cache_whim_goal_proto(self, whim_tracker_proto, skip_load=False): if skip_load: return if self._sim_info.is_npc: return if self._sim_info.whim_tracker is None: return self._whim_goal_proto = GameplaySaveData_pb2.WhimsetTrackerData() self._whim_goal_proto.CopyFrom(whim_tracker_proto)
def add_holiday(holiday_data: str, season: SeasonType, day: int, _connection=None): holiday_service = services.holiday_service() if holiday_service is None: return proto = GameplaySaveData_pb2.Holiday() text_format.Merge(holiday_data, proto) holiday_service.add_a_holiday(proto, season, day)
def set_load_state_from_msg(self, effect_data): if effect_data is not None: effect_msg = GameplaySaveData_pb2.PersistableCivicPolicyStreetConditionalLayerEffectData( ) effect_msg.ParseFromString(effect_data) if effect_msg.start_tick == self.CHANGE_PENDING_SENTINEL_VALUE: self._change_pending = True self._last_change_start_time = DateAndTime(0) else: self._last_change_start_time = DateAndTime( effect_msg.start_tick)
def create_club(club_data: str, _connection=None): club_service = _get_club_service(_connection) if club_service is None: sims4.commands.automation_output('ClubCreate; Status:Failed', _connection) return proto = GameplaySaveData_pb2.Club() text_format.Merge(club_data, proto) club = club_service.create_club_from_new_data(proto) sims4.commands.automation_output( 'ClubCreate; Status:Success, Id:{}'.format(club.club_id), _connection)
def get_save_state_msg(self): if self._last_change_start_time is None: return effect_msg = GameplaySaveData_pb2.PersistableCivicPolicyStreetConditionalLayerEffectData( ) if self._change_pending: effect_msg.start_tick = self.CHANGE_PENDING_SENTINEL_VALUE else: effect_msg.start_tick = self._last_change_start_time.absolute_ticks( ) return effect_msg.SerializeToString()
def save(self, save_slot_data=None, **kwargs): holiday_service_proto = GameplaySaveData_pb2.PersistableHolidayService( ) for custom_holiday in self._holidays.values(): with ProtocolBufferRollback( holiday_service_proto.holidays) as holiday_data: custom_holiday.save_holiday(holiday_data) for calendar in self._holiday_times.values(): with ProtocolBufferRollback( holiday_service_proto.calendars) as calendar_msg: calendar.save(calendar_msg) save_slot_data.gameplay_data.holiday_service = holiday_service_proto
def load(self, zone_data=None, **kwargs): if zone_data is not None and zone_data.HasField( 'gameplay_zone_data' ) and zone_data.gameplay_zone_data.HasField('venue_data'): venue_data = zone_data.gameplay_zone_data.venue_data if venue_data.HasField('background_situation_id'): self._persisted_background_event_id = venue_data.background_situation_id if venue_data.HasField('special_event_id'): self._persisted_special_event_id = venue_data.special_event_id if venue_data.HasField('zone_director'): self._prior_zone_director_proto = gameplay_serialization.ZoneDirectorData( ) self._prior_zone_director_proto.CopyFrom( venue_data.zone_director) open_street_id = services.current_zone().open_street_id open_street_data = services.get_persistence_service( ).get_open_street_proto_buff(open_street_id) if open_street_data is not None and open_street_data.HasField( 'open_street_director'): self._prior_open_street_director_proto = gameplay_serialization.OpenStreetDirectorData( ) self._prior_open_street_director_proto.CopyFrom( open_street_data.open_street_director)
def save(self, save_slot_data=None, **__): lot_decoration_service_proto = GameplaySaveData_pb2.PersistableLotDecorationService( ) for neighborhood in self._neighborhood_deco_state.values(): for lot in neighborhood.lots: lot.save_deco_states_to_proto( lot_decoration_service_proto.lot_decorations) for (world_id, set_decorations) in self._world_decorations_set.items(): with ProtocolBufferRollback( lot_decoration_service_proto.world_decorations_set ) as world_setting: world_setting.world_id = world_id world_setting.set_decorations = set_decorations save_slot_data.gameplay_data.lot_decoration_service = lot_decoration_service_proto
def save(self, object_list=None, zone_data=None, open_street_data=None, store_travel_group_placed_objects=False, save_slot_data=None): service_data = GameplaySaveData_pb2.PersistableStreetService() for (street, provider) in self._provider_instances.items(): with ProtocolBufferRollback( service_data.street_data) as street_data: street_data.street_id = street.guid64 provider.save(street_data.civic_provider_data) provider.save_street_eco_footprint_data( street_data.street_eco_footprint_data) save_slot_data.gameplay_data.street_service = service_data
def save(self, object_list=None, zone_data=None, open_street_data=None, store_travel_group_placed_objects=False, save_slot_data=None): super().save(object_list, zone_data, open_street_data, store_travel_group_placed_objects, save_slot_data) culling_service = GameplaySaveData_pb2.PersistableCullingService() for (sim_id, time_stamp) in self._interacting_sims.items(): with ProtocolBufferRollback( culling_service.interacting_sims) as interacting_sim: interacting_sim.sim_id = sim_id interacting_sim.time_stamp = time_stamp.absolute_ticks() save_slot_data.gameplay_data.culling_service = culling_service
def save(self, open_street_data=None, **kwargs): if open_street_data is None: return open_street_data.conditional_layer_service = gameplay_serialization.ConditionalLayerServiceData( ) for (conditional_layer, layer_info) in self._layer_infos.items(): if not layer_info.objects_loaded and not conditional_layer.client_only: continue if conditional_layer.client_only and layer_info.last_request_type != ConditionalLayerRequestType.LOAD_LAYER: continue with ProtocolBufferRollback( open_street_data.conditional_layer_service.layer_infos ) as layer_data: layer_data.conditional_layer = conditional_layer.guid64 layer_data.object_ids.extend(list(layer_info.objects_loaded))
def load(self, policy_data): effects_to_load = dict() for effect in self._civic_policy_effects: effects_to_load[type(effect).guid64] = effect if policy_data is not None: if policy_data.policy_id == self.guid64: if policy_data.custom_data: policy_msg = GameplaySaveData_pb2.PersistableCivicPolicyStreetPolicyData( ) policy_msg.ParseFromString(policy_data.custom_data) self._enacted = policy_msg.enacted for effect_data in policy_msg.effect_data: effect = effects_to_load.get(effect_data.policy_id) if effect is not None: effect.set_load_state_from_msg( effect_data.custom_data) else: self._enacted = True
def save(self, save_slot_data=None, **kwargs): rabbit_hole_service_proto = GameplaySaveData_pb2.PersistableRabbitHoleService( ) for (sim_id, rabbit_holes) in self._rabbit_holes.items(): for rabbit_hole in rabbit_holes: with ProtocolBufferRollback( rabbit_hole_service_proto.rabbit_holes) as entry: entry.sim_id = sim_id entry.rabbit_hole_id = rabbit_hole.guid64 entry.rabbit_hole_instance_id = rabbit_hole.rabbit_hole_id rabbit_hole.save(entry) if rabbit_hole.linked_rabbit_holes: (linked_sim_ids, linked_rabbit_hole_ids) = zip( *rabbit_hole.linked_rabbit_holes) entry.linked_sim_ids.extend(linked_sim_ids) entry.linked_rabbit_hole_ids.extend( linked_rabbit_hole_ids) save_slot_data.gameplay_data.rabbit_hole_service = rabbit_hole_service_proto
def save(self, provider_data): effect_states = [] for effect in self._civic_policy_effects: effect_custom_data = effect.get_save_state_msg() if effect_custom_data is not None: effect_states.append((type(effect).guid64, effect_custom_data)) if not effect_states: super().save(provider_data) return policy_msg = GameplaySaveData_pb2.PersistableCivicPolicyStreetPolicyData( ) policy_msg.enacted = self.enacted for (effect_id, effect_custom_data) in effect_states: with ProtocolBufferRollback(policy_msg.effect_data) as effect_data: effect_data.policy_id = effect_id effect_data.custom_data = effect_custom_data with ProtocolBufferRollback(provider_data.policy_data) as policy_data: policy_data.policy_id = self.guid64 policy_data.custom_data = policy_msg.SerializeToString()
def save(self, zone_data=None, open_street_data=None, **kwargs): active_venue = self.active_venue if zone_data is not None: if active_venue is not None: venue_data = zone_data.gameplay_zone_data.venue_data if active_venue.active_background_event_id is not None: venue_data.background_situation_id = active_venue.active_background_event_id if active_venue.active_special_event_id is not None: venue_data.special_event_id = active_venue.active_special_event_id if self._zone_director is not None: zone_director_data = gameplay_serialization.ZoneDirectorData( ) self._zone_director.save(zone_director_data, open_street_data) venue_data.zone_director = zone_director_data else: if self._prior_open_street_director_proto is not None: open_street_data.open_street_director = self._prior_open_street_director_proto if self._prior_zone_director_proto is not None: venue_data.zone_director = self._prior_zone_director_proto
def save_data(self, household_msg): household_msg.object_preference_tracker = GameplaySaveData_pb2.ObjectPreferenceTracker( ) for (zone_preference_tuple, zone_preference_data ) in self._zone_object_preference_datas.items(): with ProtocolBufferRollback( household_msg.object_preference_tracker. zone_preference_datas) as save_zone_data: save_zone_data.zone_id = zone_preference_tuple[0] save_zone_data.preference_tag = zone_preference_tuple[1] for (sim_id, object_tuple) in zone_preference_data.items(): with ProtocolBufferRollback(save_zone_data.sim_preferences ) as save_sim_preference: (object_id, subroot_index) = object_tuple save_sim_preference.sim_id = sim_id save_sim_preference.object_id = object_id if subroot_index is None: save_sim_preference.subroot_index = -1 else: save_sim_preference.subroot_index = subroot_index
def save(self, save_slot_data=None, **__): organization_proto = GameplaySaveData_pb2.PersistableOrganizationService( ) for (org_id, members_list) in self._organization_members.items(): with ProtocolBufferRollback( organization_proto.organizations) as organization_msg: organization_msg.organization_id = org_id for member_id in members_list: with ProtocolBufferRollback( organization_msg.organization_members ) as organization_members_msg: organization_members_msg.organization_member_id = member_id for (drama_node_id, alarm_handle ) in self._schedule_cancelled_venue_event_alarm.items(): with ProtocolBufferRollback( organization_proto.schedule_cancelled_event_data ) as schedule_cancelled_event_msg: schedule_cancelled_event_msg.schedule_venue_event_time = alarm_handle.get_remaining_time( ).in_ticks() schedule_cancelled_event_msg.org_event_id = drama_node_id save_slot_data.gameplay_data.organization_service = organization_proto
def save(self, save_slot_data=None, **kwargs): if not self._has_started_up: return drama_schedule_proto = GameplaySaveData_pb2.PersistableDramaScheduleService() for drama_node_inst in self._scheduled_nodes.values(): with ProtocolBufferRollback(drama_schedule_proto.drama_nodes) as drama_node_msg: drama_node_inst.save(drama_node_msg) for drama_node_inst in self._active_nodes.values(): if drama_node_inst.persist_when_active: with ProtocolBufferRollback(drama_schedule_proto.running_nodes) as drama_node_msg: drama_node_inst.save(drama_node_msg) for (drama_node, time) in self._cooldown_nodes.items(): with ProtocolBufferRollback(drama_schedule_proto.cooldown_nodes) as cooldown_node: cooldown_node.node_type = drama_node.guid64 cooldown_node.completed_time = time.absolute_ticks() for (group, time) in self._cooldown_groups.items(): with ProtocolBufferRollback(drama_schedule_proto.cooldown_groups) as cooldown_group: cooldown_group.group = group cooldown_group.completed_time = time.absolute_ticks() drama_schedule_proto.drama_nodes_on_permanent_cooldown.extend(self._drama_nodes_on_permanent_cooldown) drama_schedule_proto.cooldown_groups_on_permanent_cooldown.extend(self._drama_node_groups_on_permanent_cooldown) drama_schedule_proto.startup_drama_node_buckets_used.extend(self._startup_buckets_used) save_slot_data.gameplay_data.drama_schedule_service = drama_schedule_proto