def _send_destroy_message_to_client(self): msg_a = commodity_protocol.RelationshipDelete() msg_a.actor_sim_id = self._sim_id_a msg_a.target_id = self._sim_id_b op_a = GenericProtocolBufferOp( DistributorOps_pb2.Operation.SIM_RELATIONSHIP_DELETE, msg_a) distributor = Distributor.instance() distributor.add_op(self.find_sim_info_a(), op_a) if not self._is_object_rel: msg_b = commodity_protocol.RelationshipDelete() msg_b.actor_sim_id = self._sim_id_b msg_b.target_id = self._sim_id_a op_b = GenericProtocolBufferOp( DistributorOps_pb2.Operation.SIM_RELATIONSHIP_DELETE, msg_b) distributor.add_op(self.find_sim_info_b(), op_b)
def _send_skill_delete_message(self): if self.tracker.owner.is_npc: return skill_msg = Commodities_pb2.SkillDelete() skill_msg.skill_id = self.guid64 op = GenericProtocolBufferOp(Operation.SIM_SKILL_DELETE, skill_msg) Distributor.instance().add_op(self.tracker.owner, op)
def _send_relationship_data(self, sim_id): if self.relationship_track_visual is None: return relationship_to_send = self._get_relationship(sim_id) if not relationship_to_send: return sim_info = services.sim_info_manager().get(sim_id) if sim_info is None: return msg = commodity_protocol.RelationshipUpdate() msg.actor_sim_id = sim_id (msg.target_id.object_id, msg.target_id.manager_id) = self.owner.icon_info msg.target_instance_id = self.owner.id if self.icon_override is not None: build_icon_info_msg(IconInfoData(icon_resource=self.icon_override), None, msg.target_icon_override) with ProtocolBufferRollback(msg.tracks) as relationship_track_update: relationship_value = relationship_to_send.get_value() relationship_track_update.track_score = relationship_value relationship_track_update.track_bit_id = self.relationship_track_visual.relationship_track.get_bit_at_relationship_value( relationship_value).guid64 relationship_track_update.track_id = self.relationship_track_visual.relationship_track.guid64 relationship_track_update.track_popup_priority = self.relationship_track_visual.relationship_track.display_popup_priority relationship_track_update.visible_in_relationship_panel = self.relationship_track_visual.visible_in_relationship_panel send_relationship_op(sim_info, msg) if self._object_social_mixin is not None: self._object_social_mixin.send_social_update_message()
def _send_destroy_message_to_client(self): msg = commodity_protocol.RelationshipDelete() msg.actor_sim_id = self._sim_id msg.target_id = self._target_sim_id op = GenericProtocolBufferOp( DistributorOps_pb2.Operation.SIM_RELATIONSHIP_DELETE, msg) distributor = Distributor.instance() distributor.add_op(self.find_sim_info(), op)
def send_rank_change_update_message(self, previous_rank, current_rank): msg = Commodities_pb2.RankedStatisticRankChangedUpdate() msg.stat_id = self.guid64 msg.previous_rank = previous_rank msg.current_rank = current_rank send_sim_ranked_stat_change_rank_change_update_message( self.tracker.owner, msg) self.send_commodity_progress_msg()
def create_skill_update_msg(cls, sim_id, stat_value): if not cls.convert_to_user_value(stat_value) > 0: return skill_msg = Commodities_pb2.Skill_Update() skill_msg.skill_id = cls.guid64 skill_msg.curr_points = int(stat_value) skill_msg.sim_id = sim_id return skill_msg
def on_state_changed(self, state, old_value, new_value): super().on_state_changed(state, old_value, new_value) if new_value in self.NEGLECTED_STATES and not self._started_neglect_moment: start_baby_neglect(self) elif self.manager is not None and new_value in self.BABY_MOOD_MAPPING: mood = self.BABY_MOOD_MAPPING[new_value] mood_msg = Commodities_pb2.MoodUpdate() mood_msg.sim_id = self.id mood_msg.mood_key = mood.guid64 mood_msg.mood_intensity = 1 distributor.shared_messages.add_object_message( self, MSG_SIM_MOOD_UPDATE, mood_msg, False)
def _send_relationship_destroy(self, sim_id): if self.relationship_track_visual is None or self.relationship_track_visual.relationship_track is None: return sim_info = services.sim_info_manager().get(sim_id) if sim_info is None: return msg = commodity_protocol.RelationshipDelete() msg.actor_sim_id = sim_id msg.target_id = self.owner.id op = GenericProtocolBufferOp( DistributorOps_pb2.Operation.SIM_RELATIONSHIP_DELETE, msg) distributor = Distributor.instance() distributor.add_op(services.sim_info_manager().get(sim_id), op)
def _send_commodity_list_msg(self, commodity_list): list_msg = Commodities_pb2.CommodityListUpdate() list_msg.sim_id = self._sim_info.sim_id for commodity in commodity_list: if commodity.visible: stat = self._sim_info.commodity_tracker.get_statistic( commodity) if stat: if stat.is_visible_commodity(): with ProtocolBufferRollback( list_msg.commodities) as commodity_msg: stat.populate_commodity_update_msg( commodity_msg, is_rate_change=False) send_sim_commodity_list_update_message(self._sim_info, list_msg)
def create_and_send_commodity_update_msg(self, is_rate_change=True, allow_npc=False, from_add=False): ranked_stat_msg = Commodities_pb2.RankedStatisticProgressUpdate() ranked_stat_msg.stat_id = self.guid64 ranked_stat_msg.change_rate = self.get_change_rate() ranked_stat_msg.rank = self.rank_level difference = self.get_value() - self.points_to_current_rank() ranked_stat_msg.curr_rank_points = int( difference) if difference > 0 else 0 send_sim_ranked_stat_update_message(self.tracker.owner, ranked_stat_msg, allow_npc=allow_npc or self.send_stat_update_for_npcs)
def on_state_changed(self, state, old_value, new_value, from_init): super().on_state_changed(state, old_value, new_value, from_init) removal_moment = self.REMOVAL_MOMENT_STATES.get(new_value) if removal_moment is not None: if self._sim_info is not None: removal_moment.execute_removal_moment(self) else: self._pending_removal_moment = removal_moment return if self.manager is not None and new_value in self.BABY_MOOD_MAPPING: mood = self.BABY_MOOD_MAPPING[new_value] mood_msg = Commodities_pb2.MoodUpdate() mood_msg.sim_id = self.id mood_msg.mood_key = mood.guid64 mood_msg.mood_intensity = 1 distributor.shared_messages.add_object_message( self, MSG_SIM_MOOD_UPDATE, mood_msg, False)
def create_commmodity_update_msg(self, is_rate_change=True): if self.tracker is None or not self.tracker.owner.is_sim: return if not self.visible: return if not self.commodity_states: return if self.state_index is None: return if self._suppress_client_updates: return commodity_msg = Commodities_pb2.CommodityProgressUpdate() commodity_msg.commodity_id = self.guid64 commodity_msg.current_value = self.get_value() commodity_msg.rate_of_change = self.get_change_rate() commodity_msg.commodity_state_index = self.state_index commodity_msg.is_rate_change = is_rate_change return commodity_msg
def _build_object_relationship_update_proto(self, actor_sim_info, member_obj_def_id, deltas=None, name_override=None): msg = commodity_protocol.RelationshipUpdate() actor_sim_id = actor_sim_info.sim_id msg.actor_sim_id = actor_sim_id if name_override is not None: loc_custom_name = LocalizationHelperTuning.get_raw_text( name_override) build_icon_info_msg(IconInfoData(), loc_custom_name, msg.target_icon_override) if self._target_object_id == 0: target_object = None tag_set = services.relationship_service().get_mapped_tag_set_of_id( member_obj_def_id) definition_ids = services.relationship_service( ).get_ids_of_tag_set(tag_set) for definition_id in definition_ids: for obj in services.object_manager().objects: if definition_id == obj.definition.id: target_object = obj break if target_object is None: logger.error( 'Failed to find an object with requested object tag set in the world, so the initial object type relationship creation for sim {} will not complete.', actor_sim_info) return (msg.target_id.object_id, msg.target_id.manager_id) = target_object.icon_info msg.target_instance_id = target_object.id self._target_object_id = msg.target_id.object_id self._target_object_manager_id = msg.target_id.manager_id self._target_object_instance_id = msg.target_instance_id else: msg.target_id.object_id = self._target_object_id msg.target_id.manager_id = self._target_object_manager_id msg.target_instance_id = self._target_object_instance_id msg.last_update_time = self._last_update_time track_bits = self._build_relationship_track_proto(msg) self._build_relationship_bit_proto(actor_sim_id, track_bits, msg) return msg
def _send_relationship_data(self, sim_id): if self._relationship_track_visual is None: return relationship_to_send = self._get_relationship(sim_id) if not relationship_to_send: return sim_info = services.sim_info_manager().get(sim_id) if sim_info is None: return msg = commodity_protocol.RelationshipUpdate() msg.actor_sim_id = sim_id (msg.target_id.object_id, msg.target_id.manager_id) = self.owner.icon_info msg.target_instance_id = self.owner.id with ProtocolBufferRollback(msg.tracks) as relationship_track_update: relationship_value = relationship_to_send.get_value() relationship_track_update.track_score = relationship_value relationship_track_update.track_bit_id = self._relationship_track_visual.get_bit_at_relationship_value(relationship_value).guid64 relationship_track_update.track_id = self._relationship_track_visual.guid64 relationship_track_update.track_popup_priority = self._relationship_track_visual.display_popup_priority send_relationship_op(sim_info, msg)
def _build_relationship_update_proto(self, actor_sim_info, target_sim_id, deltas=None): msg = commodity_protocol.RelationshipUpdate() actor_sim_id = actor_sim_info.sim_id msg.actor_sim_id = actor_sim_id msg.target_id.object_id = target_sim_id msg.target_id.manager_id = services.sim_info_manager().id msg.last_update_time = self._last_update_time tracks = self._build_relationship_track_proto(msg) self._build_relationship_bit_proto(actor_sim_id, tracks, msg) sim_info_manager = services.sim_info_manager() target_sim_info = sim_info_manager.get(target_sim_id) owner = sim_info_manager.get(actor_sim_id) knowledge = self._get_uni_directional_rel_data(actor_sim_id).knowledge if knowledge is not None: if target_sim_info is not None: if target_sim_info.lod != SimInfoLODLevel.MINIMUM: if owner is not None: if owner.lod != SimInfoLODLevel.MINIMUM: if target_sim_info is not None: msg.num_traits = len( target_sim_info.trait_tracker. personality_traits) for trait in knowledge.known_traits: msg.known_trait_ids.append(trait.guid64) if knowledge.knows_career: msg.known_careertrack_ids.extend( knowledge.get_known_careertrack_ids()) if knowledge._known_stats is not None: for stat in knowledge._known_stats: msg.known_stat_ids.append(stat.guid64) if knowledge.knows_major: if knowledge.get_known_major() is not None: msg.known_major_id = knowledge.get_known_major( ).guid64 if target_sim_info is not None: if target_sim_info.spouse_sim_id is not None: msg.target_sim_significant_other_id = target_sim_info.spouse_sim_id return msg
def _build_relationship_update_proto(self, deltas=None): msg = commodity_protocol.RelationshipUpdate() msg.actor_sim_id = self._sim_id msg.target_id.object_id = self._target_sim_id msg.target_id.manager_id = services.sim_info_manager().id client_tracks = [ track for track in self._bit_track_tracker if track.display_priority > 0 ] client_tracks.sort(key=lambda track: track.display_priority) track_bits = set() for track in client_tracks: if track.visible_to_client: with ProtocolBufferRollback( msg.tracks) as relationship_track_update: relationship_track_update.track_score = track.get_value() relationship_track_update.track_bit_id = track.get_bit_for_client( ).guid64 relationship_track_update.track_id = track.guid64 relationship_track_update.track_popup_priority = track.display_popup_priority relationship_track_update.change_rate = track.get_change_rate( ) while deltas is not None: track_delta = deltas.get(track) while track_delta is not None: relationship_track_update.delta = track_delta track_bits.add(track.get_bit_for_client().guid64) for bit in self._bits.values(): if not bit.visible: pass if bit.guid64 in track_bits: pass msg.bit_ids.append(bit.guid64) if self._knowledge is not None: msg.num_traits = self._knowledge.num_traits for trait in self._knowledge.known_traits: msg.known_trait_ids.append(trait.guid64) target_sim_info = self.find_target_sim_info() if target_sim_info is not None and target_sim_info.spouse_sim_id is not None: msg.target_sim_significant_other_id = target_sim_info.spouse_sim_id return msg
def create_and_send_commodity_update_msg(self, is_rate_change=True, allow_npc=False, from_add=False): current_value = self.get_value() change_rate = self.get_change_rate() life_skill_msg = Commodities_pb2.LifeSkillUpdate() life_skill_msg.sim_id = self.tracker.owner.id life_skill_msg.life_skill_id = self.guid64 life_skill_msg.curr_value = current_value life_skill_msg.rate_of_change = change_rate life_skill_msg.is_from_add = from_add send_sim_life_skill_update_message(self.tracker.owner, life_skill_msg) if self._last_update_value is None: value_to_send = change_rate else: value_to_send = current_value - self._last_update_value self._last_update_value = current_value if value_to_send != 0 and not from_add: self.headline.send_headline_message(self.tracker.owner, value_to_send)
def create_skill_update_msg(cls, sim_id, stat_value): skill_msg = Commodities_pb2.Skill_Update() skill_msg.skill_id = cls.guid64 skill_msg.curr_points = int(stat_value) skill_msg.sim_id = sim_id return skill_msg
def create_and_send_life_skill_delete_msg(self): life_skill_msg = Commodities_pb2.LifeSkillDelete() life_skill_msg.sim_id = self.tracker.owner.id life_skill_msg.life_skill_id = self.guid64 send_sim_life_skill_delete_message(self.tracker.owner, life_skill_msg)
def _create_mood_update_msg(self): mood_msg = Commodities_pb2.MoodUpdate() mood_msg.sim_id = self.owner.id mood_msg.mood_key = self._active_mood.guid64 mood_msg.mood_intensity = self._active_mood_intensity return mood_msg