コード例 #1
0
 def _create_update_message(self):
     msg = Situations_pb2.SituationMeterUpdate()
     msg.situation_id = self._situation.id
     msg.meter_id = self._meter_id
     msg.update_value = self._situation._get_effective_score_for_levels(
         self._situation._score)
     return msg
コード例 #2
0
 def _create_situation_goal_update_msg(self, pet, sickness, resolver):
     msg = Situations_pb2.SituationGoalsUpdate()
     msg.goal_status = UiSituationGoalStatus.COMPLETED
     msg.situation_id = self.id
     self._set_major_goal_data(pet, sickness, msg.major_goal)
     self._set_minor_goals_data(pet, msg.goals)
     self._handle_completed_goal(resolver, sickness, msg)
     return msg
コード例 #3
0
 def send_icon_update_to_client(self):
     msg = Situations_pb2.SituationIconUpdate()
     msg.situation_id = self.id
     build_icon_info_msg(self.get_pet().get_icon_info_data(), None,
                         msg.icon_info)
     msg.icon_info.control_id = ICON_CONTROL_ID
     op = distributor.ops.SituationIconUpdateOp(msg)
     Distributor.instance().add_op(self, op)
コード例 #4
0
def get_situation_ids(session_id: int = 0,
                      sim_id: OptionalTargetParam = None,
                      opt_target_id: int = None,
                      *situation_ids,
                      _connection=None):
    sim = get_optional_target(sim_id, _connection)
    if opt_target_id is None or opt_target_id == 0:
        target_sim_id = 0
    else:
        target_sim_id = opt_target_id
    household = sim.household
    instance_manager = services.get_instance_manager(
        sims4.resources.Types.SITUATION)
    situation_batch_msg = Situations_pb2.SituationIDBatch()
    situation_batch_msg.situation_session_id = session_id
    situation_batch_msg.scoring_enabled = household.situation_scoring_enabled
    valid_situations = []
    for situation_id in situation_ids:
        instance = instance_manager.get(situation_id)
        (result, mtx_id) = should_display_situation(instance, sim,
                                                    target_sim_id)
        while result or result.tooltip is not None:
            valid_situations.append((instance, mtx_id, result.tooltip))
    if not valid_situations:
        for instance in instance_manager.types.values():
            if instance.guid64 in situation_ids:
                pass
            (result,
             mtx_id) = should_display_situation(instance, sim, target_sim_id)
            while result or result.tooltip is not None:
                valid_situations.append((instance, mtx_id, result.tooltip))
    for (instance, mtx_id, tooltip) in valid_situations:
        highest_medal_earned = household.get_highest_medal_for_situation(
            instance.guid64)
        situation_batch_msg.highest_medal_earned.append(highest_medal_earned)
        situation_batch_msg.situation_resource_id.append(instance.guid64)
        situation_batch_msg.mtx_id.append(mtx_id)
        if tooltip is not None:
            tooltip = tooltip()
            situation_batch_msg.tooltip.append(tooltip)
        else:
            tooltip = Localization_pb2.LocalizedString()
            tooltip.hash = 0
            situation_batch_msg.tooltip.append(tooltip)
        situation_batch_msg.category_id.append(instance.category)
        try:
            situation_batch_msg.situation_name.extend([instance._display_name])
        except:
            del situation_batch_msg.situation_name[
                len(situation_batch_msg.situation_name) - 1]
            del situation_batch_msg.situation_resource_id[
                len(situation_batch_msg.situation_resource_id) - 1]
    shared_messages.add_message_if_selectable(
        sim, Consts_pb2.MSG_SITUATION_ID_BATCH, situation_batch_msg, True)
コード例 #5
0
def get_situation_data(session_id: int = 0,
                       sim_id: OptionalTargetParam = None,
                       *situation_ids,
                       _connection=None):
    sim = get_optional_target(sim_id, _connection)
    instance_manager = services.situation_manager()
    situation_batch_msg = Situations_pb2.SituationDataBatch()
    situation_batch_msg.situation_session_id = session_id
    for situation_id in situation_ids:
        with ProtocolBufferRollback(
                situation_batch_msg.situations) as situation_data:
            instance = instance_manager.get(situation_id)
            while instance is not None:
                shared_messages.build_icon_info_msg((instance._icon, None),
                                                    instance._display_name,
                                                    situation_data.icon_info)
                situation_data.icon_info.desc = instance.situation_description
                situation_data.cost = instance._cost
                situation_data.max_participants = instance.max_participants
                for medal in SituationMedal:
                    with ProtocolBufferRollback(
                            situation_data.rewards) as reward_msg:
                        level = instance.get_level_data(medal)
                        reward_msg.level = int(medal)
                        while level is not None and level.reward is not None:
                            reward_msg.display_name.extend(
                                [level.reward.reward_description])
                jobs = list(instance.get_tuned_jobs())
                jobs.sort(key=lambda job: job.guid64)
                if instance.job_display_ordering is not None:
                    for ordered_job in reversed(instance.job_display_ordering):
                        while ordered_job in jobs:
                            jobs.remove(ordered_job)
                            jobs.insert(0, ordered_job)
                for job in jobs:
                    while job.sim_count.upper_bound > 0:
                        with ProtocolBufferRollback(
                                situation_data.jobs) as job_msg:
                            job_msg.job_resource_id = job.guid64
                            shared_messages.build_icon_info_msg(
                                (job.icon, None), job.display_name,
                                job_msg.icon_info)
                            job_msg.icon_info.desc = job.job_description
                            job_msg.is_hireable = job.can_be_hired
                            job_msg.min_required = job.sim_count.lower_bound
                            job_msg.max_allowed = job.sim_count.upper_bound
                            job_msg.hire_cost = job.hire_cost
    shared_messages.add_message_if_selectable(
        sim, Consts_pb2.MSG_SITUATION_DATA_BATCH, situation_batch_msg, True)
コード例 #6
0
def get_sims_for_job(session_id,
                     sim_id,
                     situation_type,
                     job_type,
                     *job_assignments,
                     _connection=None):
    sim = get_optional_target(sim_id, _connection)
    situation_start_time = services.time_service().sim_now
    duration = situation_type.duration
    if duration > 0:
        situation_end_time = situation_start_time + date_and_time.create_time_span(
            0, 0, duration)
    else:
        situation_start_time = date_and_time.INVALID_DATE_AND_TIME
        situation_end_time = date_and_time.INVALID_DATE_AND_TIME
    results = services.sim_filter_service().submit_filter(
        job_type.filter,
        None,
        requesting_sim_info=sim.sim_info,
        start_time=situation_start_time,
        end_time=situation_end_time,
        allow_yielding=False)
    if job_type.additional_filter_for_user_selection:
        sim_constraints = {result.sim_info.id for result in results}
        results = services.sim_filter_service().submit_filter(
            job_type.additional_filter_for_user_selection,
            None,
            requesting_sim_info=sim.sim_info,
            start_time=situation_start_time,
            end_time=situation_end_time,
            sim_constraints=sim_constraints,
            allow_yielding=False)
    msg = Situations_pb2.SituationJobSims()
    msg.situation_session_id = session_id
    msg.job_resource_id = job_type.guid
    msg.requirements = job_type.requirement_text
    results.sort(key=lambda x: (x.sim_info.is_npc, x.sim_info.last_name))
    for result in results:
        msg.sim_ids.append(result.sim_info.id)
        with ProtocolBufferRollback(msg.sims) as situation_job_sim:
            situation_job_sim.sim_id = result.sim_info.id
            if result.sim_info.household.id == services.active_household_id():
                situation_job_sim.account_id = result.sim_info.account_id
            while result.conflicting_career_track_id:
                situation_job_sim.career_track_id = result.conflicting_career_track_id
    shared_messages.add_message_if_selectable(
        services.object_manager().get(sim.id),
        Consts_pb2.MSG_SITUATION_JOB_SIMS, msg, True)
コード例 #7
0
def get_prepopulated_job_for_sims(session_id,
                                  situation_type,
                                  sim_id: OptionalTargetParam = None,
                                  opt_target_id: int = None,
                                  _connection=None):
    sim = get_optional_target(sim_id, _connection)
    prepopulate = situation_type.get_prepopulated_job_for_sims(
        sim, opt_target_id)
    assign_msg = Situations_pb2.SituationAssignJob()
    assign_msg.situation_session_id = session_id
    if prepopulate is not None:
        for (sim_id, job_type_id) in prepopulate:
            assign_msg.sim_ids.append(sim_id)
            assign_msg.job_resource_ids.append(job_type_id)
    shared_messages.add_object_message(sim,
                                       Consts_pb2.MSG_SITUATION_ASSIGN_JOB,
                                       assign_msg, True)
コード例 #8
0
 def send_situation_start_ui(self,
                             actor,
                             target=None,
                             situations_available=None,
                             creation_time=None):
     msg = Situations_pb2.SituationPrepare()
     msg.situation_session_id = self.get_new_situation_creation_session()
     msg.creation_time = creation_time if creation_time is not None else 0
     msg.sim_id = actor.id
     if target is not None:
         msg.is_targeted = True
         msg.target_id = target.id
     if situations_available is not None:
         for situation in situations_available:
             msg.situation_resource_id.append(situation.guid64)
     shared_messages.add_message_if_selectable(
         actor, Consts_pb2.MSG_SITUATION_PREPARE, msg, True)
コード例 #9
0
 def _send_icon_update_to_client(self, sim):
     display_name = sim.household.holiday_tracker.get_active_holiday_display_name(
     )
     holiday_icon = sim.household.holiday_tracker.get_active_holiday_display_icon(
     )
     msg = Situations_pb2.SituationIconUpdate()
     msg.situation_id = self.id
     end_time = HolidayTuning.MAIN_HOLIDAY_START_TIME + HolidayTuning.HOLIDAY_DURATION(
     )
     build_icon_info_msg(
         IconInfoData(icon_resource=holiday_icon),
         display_name,
         msg.icon_info,
         desc=LocalizationHelperTuning.get_start_time_to_end_time(
             HolidayTuning.MAIN_HOLIDAY_START_TIME, end_time))
     msg.icon_info.control_id = 0
     op = distributor.ops.SituationIconUpdateOp(msg)
     Distributor.instance().add_op(self, op)
コード例 #10
0
 def send_goal_update_to_client(self, completed_goal=None):
     situation = self._situation
     if situation.is_running:
         msg = Situations_pb2.SituationGoalsUpdate()
         msg.goal_status = UiSituationGoalStatus.COMPLETED
         msg.situation_id = situation.id
         for goal in self.goals:
             with ProtocolBufferRollback(msg.goals) as goal_msg:
                 self._build_goal_message(goal_msg, goal)
                 if self._goal_preferences is not None:
                     (preference, reason) = self._goal_preferences[type(goal)]
                     goal_msg.goal_preference = preference
                     if reason is not None:
                         goal_msg.goal_preference_tooltip = reason
         if completed_goal is not None:
             msg.completed_goal_id = completed_goal.id
         op = distributor.ops.SituationGoalUpdateOp(msg)
         Distributor.instance().add_op(situation, op)
コード例 #11
0
 def send_goal_update_to_client(self,
                                completed_goal=None,
                                goal_preferences=None):
     situation = self._situation
     if situation.is_user_facing and situation.should_display_score and situation.is_running:
         msg = Situations_pb2.SituationGoalsUpdate()
         msg.situation_id = situation.id
         main_goal = self._realized_main_goal
         if main_goal is not None and situation._main_goal_visibility:
             self._build_goal_message(msg.major_goal, main_goal)
         highlight_first_incomplete_minor_goal = situation.highlight_first_incomplete_minor_goal
         if self._realized_minor_goals is None:
             situation_goals = []
         else:
             situation_goals = sorted(
                 self._realized_minor_goals.keys(),
                 key=lambda goal: self._realized_minor_goals[
                     goal].display_position)
         for goal in situation_goals:
             if not goal.visible_minor_goal:
                 continue
             with ProtocolBufferRollback(msg.goals) as goal_msg:
                 self._build_goal_message(goal_msg, goal)
                 if main_goal is not None:
                     if goal.id == main_goal.id:
                         if situation.main_goal_audio_sting is not None:
                             goal_msg.audio_sting.type = situation.main_goal_audio_sting.type
                             goal_msg.audio_sting.group = situation.main_goal_audio_sting.group
                             goal_msg.audio_sting.instance = situation.main_goal_audio_sting.instance
                 if highlight_first_incomplete_minor_goal:
                     goal_msg.highlight_goal = True
                     highlight_first_incomplete_minor_goal = False
         msg.goal_status = UiSituationGoalStatus.COMPLETED
         if completed_goal is not None:
             msg.completed_goal_id = completed_goal.id
             goal_status_override = completed_goal.goal_status_override
             if goal_status_override is not None:
                 msg.goal_status = goal_status_override
         op = distributor.ops.SituationGoalUpdateOp(msg)
         Distributor.instance().add_op(situation, op)
コード例 #12
0
ファイル: tunable.py プロジェクト: johndpope/sims4-ai-engine
 def craft_situation(interaction, targeted_situation_participant,
                     situations_available):
     msg = Situations_pb2.SituationPrepare()
     msg.situation_session_id = services.get_zone_situation_manager(
     ).get_new_situation_creation_session()
     msg.sim_id = interaction.sim.id
     if targeted_situation_participant is not None:
         target = interaction.get_participant(
             targeted_situation_participant)
         if target is not None:
             msg.is_targeted = True
             msg.target_id = target.id
         else:
             logger.error(
                 'None participant for: {} on interaction: {}'.format(
                     targeted_situation_participant, interaction),
                 owner='rmccord')
     if situations_available is not None:
         for situation in situations_available:
             msg.situation_resource_id.append(situation.guid64)
     shared_messages.add_message_if_selectable(
         interaction.sim, Consts_pb2.MSG_SITUATION_PREPARE, msg, True)
     return True
コード例 #13
0
 def _create_update_message(self):
     msg = Situations_pb2.SituationMeterUpdate()
     msg.situation_id = self._situation.id
     msg.meter_id = self._meter_id
     msg.update_value = int(self._stat_inst.get_value())
     return msg
コード例 #14
0
def get_valid_situation_locations(sim_id,
                                  situation_type,
                                  *guests,
                                  _connection=None):
    sim = get_optional_target(sim_id, _connection)
    if not sim:
        sims4.commands.output('Invalid Sim ID: {}'.format(sim_id), _connection)
        return
    sim_info = sim.sim_info
    possible_zones = []
    possible_zones.append(sim_info.household.home_zone_id)
    for guest_id in guests:
        guest_id = int(guest_id)
        guest_info = services.sim_info_manager().get(guest_id)
        while guest_info is not None:
            guest_zone_id = guest_info.household.home_zone_id
            if guest_zone_id is not None and guest_zone_id and guest_zone_id not in possible_zones:
                possible_zones.append(guest_zone_id)
    venue_service = services.current_zone().venue_service
    for venue_type in situation_type.venue_types:
        possible_zones.extend(
            venue_service.get_zones_for_venue_type(venue_type))
    venue_manager = services.get_instance_manager(sims4.resources.Types.VENUE)
    persistence_service = services.get_persistence_service()
    locations_msg = Situations_pb2.SituationLocations()
    cas_zones_msg = InteractionOps_pb2.CASAvailableZonesInfo()
    world_info_msg = cas_zones_msg.zones.add()
    for zone_id in possible_zones:
        zone_data = persistence_service.get_zone_proto_buff(zone_id)
        if zone_data is None:
            pass
        neighborhood_data = persistence_service.get_neighborhood_proto_buff(
            zone_data.neighborhood_id)
        if neighborhood_data is None:
            pass
        lot_data = None
        for lot_owner_data in neighborhood_data.lots:
            while zone_id == lot_owner_data.zone_instance_id:
                lot_data = lot_owner_data
                break
        while zone_data is not None and lot_data is not None:
            location_data = Dialog_pb2.LotInfoItem()
            location_data.zone_id = zone_data.zone_id
            location_data.name = zone_data.name
            location_data.world_id = zone_data.world_id
            location_data.lot_template_id = zone_data.lot_template_id
            location_data.lot_description_id = zone_data.lot_description_id
            venue_type_id = build_buy.get_current_venue(zone_id)
            venue_instance = venue_manager.get(venue_type_id)
            if venue_instance is not None:
                location_data.venue_type_name = venue_instance.display_name
            if lot_data.lot_owner:
                household_id = lot_data.lot_owner[0].household_id
                household = services.household_manager().get(household_id)
                if household is not None:
                    location_data.household_name = household.name
            locations_msg.situation_locations.append(location_data)
            with ProtocolBufferRollback(world_info_msg.zones) as zone_info_msg:
                zone_info_msg.id = zone_data.zone_id
                zone_info_msg.name = zone_data.name
                zone_info_msg.world_id = zone_data.world_id
                zone_info_msg.lot_template_id = zone_data.lot_template_id
                zone_info_msg.lot_description_id = zone_data.lot_description_id
    shared_messages.add_object_message_for_sim_id(
        sim.id, Consts_pb2.MSG_NS_AVAILABLE_ZONES_INFO, cas_zones_msg)
    shared_messages.add_object_message_for_sim_id(
        sim.id, Consts_pb2.MSG_SITUATION_LOCATIONS, locations_msg)