def load_zone(self): zone_data_proto = self._get_zone_proto() self.neighborhood_id = zone_data_proto.neighborhood_id self.open_street_id = zone_data_proto.world_id self.service_manager.load_all_services(zone_data=zone_data_proto) self._first_visit_to_zone = not protocol_buffer_utils.has_field( zone_data_proto.gameplay_zone_data, 'venue_type_id_on_save') open_street_data = services.get_persistence_service( ).get_open_street_proto_buff(self.open_street_id) if open_street_data is not None: self._time_of_last_open_street_save = DateAndTime( open_street_data.sim_time_on_save) spawn_points = {} if zone_data_proto.spawn_point_ids: for (index, spawn_point_id) in enumerate(zone_data_proto.spawn_point_ids): spawn_point = self._spawner_data[index] spawn_point.spawn_point_id = spawn_point_id spawn_points[spawn_point_id] = spawn_point else: for (index, spawn_point) in enumerate(self._spawner_data.values()): spawn_point_id = id_generator.generate_object_id() spawn_point.spawn_point_id = spawn_point_id spawn_points[spawn_point_id] = spawn_point self._spawner_data = spawn_points self.lot.load(zone_data_proto.gameplay_zone_data) for spawn_point in self._spawner_data.values(): while spawn_point.has_tag( SpawnPoint. ARRIVAL_SPAWN_POINT_TAG) and spawn_point.lot_id == self.lot.lot_id: self._active_lot_arrival_spawn_point = spawn_point return True
def add_a_holiday(self, holiday_proto, season, day): holiday_id = generate_object_id() new_holiday = CustomHoliday(holiday_id, None) self._holidays[holiday_id] = new_holiday new_holiday.load_holiday(holiday_proto) for holiday_time in self._holiday_times.values(): holiday_time.add_holiday(season, day, holiday_id) self._schedule_holiday(holiday_id)
def move_object_to_household_inventory( obj, failure_flags=0, object_location_type=ObjectOriginLocation.ON_LOT): placement_flags = get_object_placement_flags(obj.definition.id) if PlacementFlags.NON_INVENTORYABLE in placement_flags: obj.destroy( cause="Can't add non inventoriable objects to household inventory." ) return False else: household_id = obj.get_household_owner_id() active_household = services.active_household() household = services.household_manager().get(household_id) if household_id is None or household is None: if failure_flags & HouseholdInventoryFlags.FORCE_OWNERSHIP: household_id = active_household.id household = active_household obj.set_household_owner_id(household_id) else: if failure_flags & HouseholdInventoryFlags.DESTROY_OBJECT: obj.destroy( cause= "Can't add unowned objects to household inventory.") return False return False return False obj.on_hovertip_requested() obj.new_in_inventory = True obj.remove_reference_from_parent() stack_count = obj.stack_count() obj.set_stack_count(1) if is_household_inventory_available(household_id): zone_id = services.current_zone_id() try: _buildbuy.add_object_to_household_inventory( obj.id, household_id, zone_id, household.account.id, object_location_type, stack_count) except KeyError as e: logger.error('Failed to add {} to {} inventory. Exception: {}', obj, household, e, owner='manus') return False else: household_msg = services.get_persistence_service( ).get_household_proto_buff(household_id) if household_msg is not None: for i in range(stack_count): object_data = obj.save_object(household_msg.inventory.objects) if object_data is not None: if i != 0: object_data.id = id_generator.generate_object_id() obj.destroy(cause='Add to household inventory') else: return False return True
def score_and_schedule_nodes_gen(self, nodes_to_score, nodes_to_schedule, specific_time=None, time_modifier=TimeSpan.ZERO, timeline=None, gsi_data=None, **additional_drama_node_kwargs): active_household = services.active_household() if active_household is None: return self._update_cooldowns() sim_resolvers = tuple(SingleSimResolver(sim_info) for sim_info in active_household.sim_info_gen()) possible_nodes = [] chosen_node_types = set() for drama_node in nodes_to_score: if not self._is_node_on_cooldown(drama_node) or gsi_data is not None: gsi_data.rejected_nodes.append(GSIRejectedDramaNodeScoringData(drama_node, '{} is on cooldown.', drama_node)) for resolver in sim_resolvers: uid = id_generator.generate_object_id() drama_node_inst = drama_node(uid) result = drama_node_inst.setup(resolver, gsi_data=gsi_data, **additional_drama_node_kwargs) if timeline is not None: yield timeline.run_child(elements.SleepElement(date_and_time.TimeSpan(0))) if not result: drama_node_inst.cleanup() else: score = drama_node_inst.score() if score == 0: if gsi_data is not None: gsi_data.rejected_nodes.append(GSIRejectedDramaNodeScoringData(drama_node, 'Scoring generated a score of 0.', score=score, receiver=drama_node_inst.get_receiver_sim_info(), sender=drama_node_inst.get_sender_sim_info())) drama_node_inst.cleanup() else: if gsi_data is not None: gsi_data.potential_nodes.append(GSIDramaNodeScoringData(drama_node, score, drama_node_inst.get_score_details(), drama_node_inst.get_receiver_sim_info(), drama_node_inst.get_sender_sim_info())) possible_nodes.append((score, drama_node_inst)) if not possible_nodes: return while nodes_to_schedule > 0: while possible_nodes: chosen_node = random.pop_weighted(possible_nodes) if type(chosen_node) in chosen_node_types: if gsi_data is not None: gsi_data.rejected_nodes.append(GSIRejectedDramaNodeScoringData(type(drama_node_inst), 'Could not schedule drama node because a drama node of this type was already scheduled.', score=chosen_node.score(), score_details=chosen_node.get_score_details(), receiver=chosen_node.get_receiver_sim_info(), sender=chosen_node.get_sender_sim_info())) chosen_node.cleanup() else: result = chosen_node.schedule(None, specific_time=specific_time, time_modifier=time_modifier) if timeline is not None: yield timeline.run_child(elements.SleepElement(date_and_time.TimeSpan(0))) if not result: if gsi_data is not None: gsi_data.rejected_nodes.append(GSIRejectedDramaNodeScoringData(type(chosen_node), 'Could not schedule drama node because there are no valid times.', score=chosen_node.score(), score_details=chosen_node.get_score_details(), receiver=chosen_node.get_receiver_sim_info(), sender=chosen_node.get_sender_sim_info())) chosen_node.cleanup() else: if gsi_data is not None: gsi_data.chosen_nodes.append(GSIDramaNodeScoringData(type(chosen_node), chosen_node.score(), chosen_node.get_score_details(), chosen_node.get_receiver_sim_info(), chosen_node.get_sender_sim_info())) self._scheduled_nodes[chosen_node.uid] = chosen_node if chosen_node.cooldown is not None and chosen_node.cooldown.cooldown_option == CooldownOption.ON_SCHEDULE: self.start_cooldown(type(chosen_node)) if is_drama_node_log_enabled(): log_drama_node_scoring(chosen_node, DramaNodeLogActions.SCHEDULED) nodes_to_schedule -= 1 chosen_node_types.add(type(chosen_node)) for (score, drama_node_inst) in possible_nodes: drama_node_inst.cleanup()
def __init__(self, lot_id, zone_id, spawn_point_id=None, routing_surface=None): self.lot_id = lot_id if routing_surface is None: routing_surface = routing.SurfaceIdentifier(zone_id, 0, routing.SurfaceType.SURFACETYPE_WORLD) self._routing_surface = routing_surface if spawn_point_id is None: self._spawn_point_id = id_generator.generate_object_id() else: self._spawn_point_id = spawn_point_id self.attractor_point_ids = set()
def _transfer_object(self, target_household, obj, inventory_available, target_household_msg): obj.set_household_owner_id(target_household.id) if inventory_available: build_buy.move_object_to_household_inventory(obj) else: if target_household_msg is not None: object_data = obj.save_object(target_household_msg.inventory.objects) if object_data is not None: object_data.object_id = id_generator.generate_object_id() obj.destroy(cause='Merge/Transfer to New Household Inventory')
def set_household_relationships_by_tags(cls, tag_to_sim_info, household): for member_relationship_data in cls._household_relationship: source_sim_info = tag_to_sim_info.get(member_relationship_data.x) target_sim_info = tag_to_sim_info.get(member_relationship_data.y) if not source_sim_info is None: if target_sim_info is None: continue if member_relationship_data.is_spouse: source_sim_info.update_spouse_sim_id(target_sim_info.id) target_sim_info.update_spouse_sim_id(source_sim_info.id) if member_relationship_data.is_parentless_sibling: parent_id = source_sim_info.genealogy.get_family_relation( FamilyRelationshipIndex.MOTHER) or ( target_sim_info.genealogy.get_family_relation( FamilyRelationshipIndex.MOTHER) or id_generator.generate_object_id()) source_sim_info.genealogy.set_family_relation( FamilyRelationshipIndex.MOTHER, parent_id) target_sim_info.genealogy.set_family_relation( FamilyRelationshipIndex.MOTHER, parent_id) if member_relationship_data.family_relationship is not None: target_sim_info.set_and_propagate_family_relation( member_relationship_data.family_relationship, source_sim_info) household.set_default_relationships() for member_relationship_data in cls._household_relationship: source_sim_info = tag_to_sim_info.get(member_relationship_data.x) target_sim_info = tag_to_sim_info.get(member_relationship_data.y) if not source_sim_info is None: if target_sim_info is None: continue for bit_to_add in member_relationship_data.relationship_bits: bit_triggered_track = bit_to_add.triggered_track if bit_triggered_track is not None: bit_track_node = bit_to_add.triggered_track.get_bit_track_node_for_bit( bit_to_add) else: bit_track_node = None if bit_track_node is not None: if bit_track_node.remove_value > bit_track_node.add_value: rand_score = random.randint( bit_track_node.add_value, bit_track_node.remove_value) else: rand_score = random.randint( bit_track_node.remove_value, bit_track_node.add_value) source_sim_info.relationship_tracker.add_relationship_score( target_sim_info.id, rand_score, bit_triggered_track) else: source_sim_info.relationship_tracker.add_relationship_bit( target_sim_info.id, bit_to_add, force_add=True)
def bind_familiar(self, familiar_type, pet_familiar=None): if pet_familiar is None: name = SimSpawner.get_random_first_name(Gender.MALE, sim_name_type_override=FamiliarTracker.FAMILIAR_DATA[familiar_type].familiar_type.name_list) pet_familiar_id = None else: name = None pet_familiar_id = pet_familiar.sim_id services.relationship_service().add_relationship_bit(self._owner.sim_id, pet_familiar.sim_id, FamiliarTracker.PET_FAMILIAR_BIT) familiar_uid = id_generator.generate_object_id() new_familiar = FamiliarInfo(familiar_uid, familiar_type, name, pet_familiar_id) self._familiars[new_familiar.uid] = new_familiar return new_familiar.uid
def __init__(self, *args, provider=None, provider_required=False, **kwargs): super().__init__(*args, **kwargs) self.tag = 0 self.provider_ref = weakref.ref( provider) if provider is not None else None self.event_id = id_generator.generate_object_id() self.event_data = None self._processed = False self._provider_required = provider_required
def schedule_node(self, drama_node, resolver, specific_time=None, drama_inst=None, setup_kwargs={}, **constructor_kwargs): if drama_inst is not None: drama_node_inst = drama_inst else: uid = id_generator.generate_object_id() drama_node_inst = drama_node(uid, **constructor_kwargs) if not drama_node_inst.schedule(resolver, specific_time=specific_time, **setup_kwargs): return if is_drama_node_log_enabled(): log_drama_node_scoring(drama_node_inst, DramaNodeLogActions.SCHEDULED) self._scheduled_nodes[drama_node_inst.uid] = drama_node_inst if drama_node.cooldown is not None and drama_node.cooldown.cooldown_option == CooldownOption.ON_SCHEDULE: self.start_cooldown(drama_node) return drama_node_inst.uid
def run_node(self, drama_node, resolver, **kwargs): uid = id_generator.generate_object_id() drama_node_inst = drama_node(uid) if not drama_node_inst.setup(resolver, **kwargs): return False drama_node_inst.debug_set_selected_time(services.time_service().sim_now) result = drama_node_inst.run() if result == DramaNodeRunOutcome.SUCCESS_NODE_INCOMPLETE: self._active_nodes[uid] = drama_node_inst elif result == DramaNodeRunOutcome.RESCHEDULED: self._scheduled_nodes[uid] = drama_node_inst elif is_drama_node_log_enabled(): log_drama_node_scoring(drama_node_inst, DramaNodeLogActions.COMPLETED) return True
def __init__(self, sim_id, rabbit_hole_id=None, starting_phase=RabbitHolePhase.STARTING, picked_skill=None): self.rabbit_hole_id = rabbit_hole_id or id_generator.generate_object_id( ) self.sim_id = sim_id self.alarm_handle = None self.callbacks = CallableList() self.linked_rabbit_holes = [] self.picked_skill = picked_skill self.ignore_travel_cancel_callbacks = False self.current_phase = starting_phase self._selected_affordance = None self.time_remaining_on_load = None
def __init__(self, actor, path, track_override=None, callback_fn=None): super().__init__() self.actor = actor self._transition_controller = actor.transition_controller self.path = path self.id = id_generator.generate_object_id() self.start_time = None self.update_walkstyle = False self.track_override = track_override self._callback_fn = callback_fn self._time_to_shave = 0 self.wait_time = 0 self.finished = False self._time_offset = 0.0 self._running_nodes = None self.canceled = False self._sleep_element = None
def create_situation(self, situation_type, guest_list=None, user_facing=True, duration_override=None, custom_init_writer=None, zone_id=0, scoring_enabled=True, spawn_sims_during_zone_spin_up=False): if guest_list is None: guest_list = SituationGuestList() hire_cost = guest_list.get_hire_cost() reserved_funds = None if guest_list.host_sim is not None: reserved_funds = guest_list.host_sim.family_funds.try_remove( situation_type.cost() + hire_cost, Consts_pb2.TELEMETRY_EVENT_COST, guest_list.host_sim) if reserved_funds is None: return reserved_funds.apply() situation_id = id_generator.generate_object_id() self._send_create_situation_telemetry(situation_type, situation_id, guest_list, hire_cost, zone_id) if zone_id != 0 and services.current_zone().id != zone_id: return self._create_departing_seed_and_travel( situation_type, situation_id, guest_list, user_facing, duration_override, custom_init_writer, zone_id, scoring_enabled=scoring_enabled) situation_seed = SituationSeed( situation_type, SeedPurpose.NORMAL, situation_id, guest_list, user_facing=user_facing, duration_override=duration_override, scoring_enabled=scoring_enabled, spawn_sims_during_zone_spin_up=spawn_sims_during_zone_spin_up) if custom_init_writer is not None: situation_seed.setup_for_custom_init_params(custom_init_writer) return self.create_situation_from_seed(situation_seed)
def _ensure_parental_lineage_exists(self, source_sim_info, clone_sim_info): with genealogy_caching(): if any(source_sim_info.genealogy.get_parent_sim_ids_gen()): return mom_id = id_generator.generate_object_id() source_sim_info.genealogy.set_family_relation( FamilyRelationshipIndex.MOTHER, mom_id) clone_sim_info.genealogy.set_family_relation( FamilyRelationshipIndex.MOTHER, mom_id) sim_info_manager = services.sim_info_manager() for child_sim_id in source_sim_info.genealogy.get_children_sim_ids_gen( ): child_sim_info = sim_info_manager.get(child_sim_id) if child_sim_info is not None: grandparent_relation = FamilyRelationshipIndex.MOTHERS_MOM if source_sim_info.is_female else FamilyRelationshipIndex.FATHERS_MOM child_sim_info.genealogy.set_family_relation( grandparent_relation, mom_id)
def add(self, obj): new_id = obj.id or id_generator.generate_object_id() if new_id in self._objects: existing_obj = self.get(new_id) logger.callstack( 'ID collision detected. ID:{}, New Object:{}, Existing Object:{}', new_id, obj, existing_obj, level=sims4.log.LEVEL_ERROR, owner='tingyul') raise ObjectIDError self.call_pre_add(obj) self._objects[new_id] = obj obj.manager = self obj.id = new_id self.call_on_add(obj) return new_id
def add(self, obj): if capture_load_times: time_stamp = time.time() new_id = obj.id or id_generator.generate_object_id() if new_id in self._objects: existing_obj = self.get(new_id) raise ObjectIDError('ID collision detected. ID:{}, New Object:{}, Existing Object:{}'.format(new_id, obj, existing_obj)) self.call_pre_add(obj, new_id) self._objects[new_id] = obj obj.manager = self obj.id = new_id self.call_on_add(obj) if capture_load_times: if hasattr(obj, 'definition'): time_elapsed = time.time() - time_stamp if obj.definition not in object_load_times: object_load_times[obj.definition] = ObjectLoadData() object_load_times[obj.definition].time_spent_adding += time_elapsed object_load_times[obj.definition].adds += 1 return new_id
def __init__(self, *args, sim_id: int = 0, gender: Gender = Gender.MALE, age: Age = Age.ADULT, species: SpeciesExtended = SpeciesExtended.HUMAN, first_name: str = '', last_name: str = '', breed_name: str = '', full_name_key=0, breed_name_key=0, physique: str = '', skin_tone=1, **kwargs): super().__init__(*args, **kwargs) self.sim_id = sim_id or id_generator.generate_object_id() self.primitives = distributor.ops.DistributionSet(self) self.manager = None self._base = BaseSimInfo(sim_id, first_name, last_name, breed_name, full_name_key, breed_name_key, age, gender, species, skin_tone, physique) self._base.voice_pitch = 0.0 self._base.voice_actor = 0 self._base.voice_effect = 0 self._base.facial_attributes = '' self._base.custom_texture = 0 self._base.pelt_layers = '' self._species = SpeciesExtended.get_species(species) self.on_base_characteristic_changed = CallableList() self.on_outfit_changed = CallableList() self.on_outfit_generated = CallableList() self._set_current_outfit_without_distribution( (OutfitCategory.EVERYDAY, 0)) self._previous_outfit = (OutfitCategory.EVERYDAY, 0) self._preload_outfit_list = [] self.on_preload_outfits_changed = CallableList() self.appearance_tracker = AppearanceTracker(self) self.visible_to_client = False
def create_situation(self, situation_type, guest_list=None, user_facing=True, duration_override=None, custom_init_writer=None, zone_id=0, scoring_enabled=True, spawn_sims_during_zone_spin_up=False, creation_source=None, travel_request_kwargs=frozendict(), linked_sim_id=GLOBAL_SITUATION_LINKED_SIM_ID, scheduled_time=None, **extra_kwargs): zone = services.current_zone() if zone.is_zone_shutting_down: return current_zone_id = services.current_zone_id() situation_type = services.narrative_service( ).get_possible_replacement_situation(situation_type) if services.get_zone_modifier_service().is_situation_prohibited( zone_id if zone_id else current_zone_id, situation_type): return if guest_list is None: guest_list = SituationGuestList() hire_cost = guest_list.get_hire_cost() host_sim_info = guest_list.host_sim_info if host_sim_info is not None and not host_sim_info.household.funds.try_remove( situation_type.cost() + hire_cost, Consts_pb2.TELEMETRY_EVENT_COST, host_sim_info): return situation_id = id_generator.generate_object_id() self._send_create_situation_telemetry(situation_type, situation_id, guest_list, hire_cost, zone_id) if zone_id and zone_id != current_zone_id and scheduled_time is None: return self._create_situation_and_travel( situation_type, situation_id, guest_list, user_facing, duration_override, custom_init_writer, zone_id, scoring_enabled=scoring_enabled, creation_source=creation_source, linked_sim_id=linked_sim_id, travel_request_kwargs=travel_request_kwargs) situation_seed = SituationSeed( situation_type, SeedPurpose.NORMAL, situation_id, guest_list, user_facing=user_facing, duration_override=duration_override, zone_id=zone_id, scoring_enabled=scoring_enabled, spawn_sims_during_zone_spin_up=spawn_sims_during_zone_spin_up, creation_source=creation_source, linked_sim_id=linked_sim_id, **extra_kwargs) if custom_init_writer is not None: situation_seed.setup_for_custom_init_params(custom_init_writer) return_id = None if scheduled_time is not None: uid = services.drama_scheduler_service().schedule_node( self.DEFAULT_PLAYER_PLANNED_DRAMA_NODE, SingleSimResolver(guest_list.host_sim.sim_info), specific_time=scheduled_time, situation_seed=situation_seed) return_id = situation_id if uid is not None else None else: return_id = self.create_situation_from_seed(situation_seed) return return_id
def start_ensemble(self): self._guid = id_generator.generate_object_id() if self.visible: op = StartEnsemble(self._guid) Distributor.instance().add_op_with_no_owner(op)