Exemplo n.º 1
0
 def potential_interactions(cls, target, context, **kwargs):
     for service_tuning_type in services.service_npc_manager().types:
         service_tuning = services.service_npc_manager().get(
             service_tuning_type)
         yield AffordanceObjectPair(cls,
                                    target,
                                    cls,
                                    None,
                                    service_tuning=service_tuning,
                                    **kwargs)
def cancel_service(service_npc_type, max_duration:int=240, _connection=None):
    service_npc_tuning = services.service_npc_manager().get(service_npc_type)
    if service_npc_tuning is not None:
        tgt_client = services.client_manager().get(_connection)
        if tgt_client is None:
            return False
        household = tgt_client.household
        services.current_zone().service_npc_service.cancel_service(household, service_npc_tuning)
        return True
    return False
def fake_perform_service(service_npc_type, _connection=None):
    service_npc_tuning = services.service_npc_manager().get(service_npc_type)
    if service_npc_tuning is not None:
        tgt_client = services.client_manager().get(_connection)
        if tgt_client is None:
            return False
        household = tgt_client.household
        service_npc_tuning.fake_perform(household)
        return True
    return False
Exemplo n.º 4
0
def fake_perform_service(service_npc_type: str, _connection=None):
    service_npc_tuning = services.service_npc_manager().get(service_npc_type)
    if service_npc_tuning is not None:
        tgt_client = services.client_manager().get(_connection)
        if tgt_client is None:
            return False
        else:
            household = tgt_client.household
            service_npc_tuning.fake_perform(household)
            return True
    return False
 def on_all_households_and_sim_infos_loaded(self, client):
     household = client.household
     if household is None:
         return
     if household.id != services.active_lot().owner_household_id:
         return
     all_hired_service_npcs = household.get_all_hired_service_npcs()
     for service_npc_resource_key in services.service_npc_manager().types:
         service_npc_tuning = services.service_npc_manager().get(service_npc_resource_key)
         while service_npc_tuning.auto_schedule_on_client_connect() or service_npc_tuning.guid64 in all_hired_service_npcs:
             is_recurring = False
             user_specified_data_id = None
             if service_npc_tuning.auto_schedule_on_client_connect():
                 is_recurring = True
             else:
                 service_npc_record = household.get_service_npc_record(service_npc_tuning.guid64, add_if_no_record=False)
                 if service_npc_record:
                     is_recurring = service_npc_record.recurring
                     user_specified_data_id = service_npc_record.user_specified_data_id
             self.request_service(household, service_npc_tuning, from_load=True, is_recurring=is_recurring, user_specified_data_id=user_specified_data_id)
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self._service_npc = None
     self._service_start_time = None
     reader = self._seed.custom_init_params_reader
     self._service_npc_type = services.service_npc_manager().get(reader.read_uint64('service_npc_type_id', 0))
     if self._service_npc_type is None:
         raise ValueError('Invalid service npc type for situation: {}'.format(self))
     self._hiring_household = services.household_manager().get(reader.read_uint64('household_id', 0))
     if self._hiring_household is None:
         raise ValueError('Invalid household for situation: {}'.format(self))
     self._object_definition_to_craft = reader.read_uint64('user_specified_data_id', 0)
     self._crafted_object_id = reader.read_uint64('crafted_object_id', 0)
Exemplo n.º 7
0
def cancel_service(service_npc_type: str,
                   max_duration: int = 240,
                   _connection=None):
    service_npc_tuning = services.service_npc_manager().get(service_npc_type)
    if service_npc_tuning is not None:
        tgt_client = services.client_manager().get(_connection)
        if tgt_client is None:
            return False
        else:
            household = tgt_client.household
            services.current_zone().service_npc_service.cancel_service(
                household, service_npc_tuning)
            return True
    return False
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     reader = self._seed.custom_init_params_reader
     self._service_npc_type = services.service_npc_manager().get(reader.read_uint64('service_npc_type_id', 0))
     if self._service_npc_type is None:
         raise ValueError('Invalid service npc type for situation: {}'.format(self))
     self._hiring_household = services.household_manager().get(reader.read_uint64('household_id', 0))
     if self._hiring_household is None:
         raise ValueError('Invalid household for situation: {}'.format(self))
     self._is_recurring = reader.read_bool('is_recurring', False)
     self._object_definition_to_craft = reader.read_uint64('user_specified_data_id', 0)
     self._crafted_object_id = reader.read_uint64('crafted_object_id', 0)
     self._service_start_time = services.time_service().sim_now
     self._had_preroll_work = True
     self._is_leaving = False
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self._locked_states = set()
     reader = self._seed.custom_init_params_reader
     self._service_npc_type = services.service_npc_manager().get(
         reader.read_uint64('service_npc_type_id', 0))
     if self._service_npc_type is None:
         raise ValueError(
             'Invalid service npc type for situation: {}'.format(self))
     self._hiring_household = services.household_manager().get(
         reader.read_uint64('household_id', 0))
     if self._hiring_household is None:
         raise ValueError(
             'Invalid household for situation: {}'.format(self))
     self._service_start_time = services.time_service().sim_now
def request_service(service_npc_type, household_id=None, _connection=None):
    service_npc_tuning = services.service_npc_manager().get(service_npc_type)
    if service_npc_tuning is not None:
        tgt_client = services.client_manager().get(_connection)
        if tgt_client is None:
            return False
        if household_id is None:
            household = tgt_client.household
        else:
            household_id = int(household_id)
            manager = services.household_manager()
            household = manager.get(household_id)
            if household is None:
                household = tgt_client.household
        services.current_zone().service_npc_service.request_service(household, service_npc_tuning)
        sims4.commands.output('Requesting service {0}'.format(service_npc_type), _connection)
        return True
    return False
Exemplo n.º 11
0
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     self._service_npc = None
     self._service_start_time = None
     reader = self._seed.custom_init_params_reader
     self._service_npc_type = services.service_npc_manager().get(
         reader.read_uint64('service_npc_type_id', 0))
     if self._service_npc_type is None:
         raise ValueError(
             'Invalid service npc type for situation: {}'.format(self))
     self._hiring_household = services.household_manager().get(
         reader.read_uint64('household_id', 0))
     if self._hiring_household is None:
         raise ValueError(
             'Invalid household for situation: {}'.format(self))
     self._object_definition_to_craft = reader.read_uint64(
         'user_specified_data_id', 0)
     self._crafted_object_id = reader.read_uint64('crafted_object_id', 0)
 def __init__(self, *args, **kwargs):
     super().__init__(*args, **kwargs)
     reader = self._seed.custom_init_params_reader
     self._service_npc_type = services.service_npc_manager().get(
         reader.read_uint64('service_npc_type_id', 0))
     if self._service_npc_type is None:
         raise ValueError(
             'Invalid service npc type for situation: {}'.format(self))
     self._hiring_household = services.household_manager().get(
         reader.read_uint64('household_id', 0))
     if self._hiring_household is None:
         raise ValueError(
             'Invalid household for situation: {}'.format(self))
     self._is_recurring = reader.read_bool('is_recurring', False)
     self._object_definition_to_craft = reader.read_uint64(
         'user_specified_data_id', 0)
     self._crafted_object_id = reader.read_uint64('crafted_object_id', 0)
     self._service_start_time = services.time_service().sim_now
     self._had_preroll_work = True
     self._is_leaving = False
Exemplo n.º 13
0
def request_service(service_npc_type: str,
                    household_id=None,
                    _connection=None):
    service_npc_tuning = services.service_npc_manager().get(service_npc_type)
    if service_npc_tuning is not None:
        tgt_client = services.client_manager().get(_connection)
        if tgt_client is None:
            return False
        else:
            if household_id is None:
                household = tgt_client.household
            else:
                household_id = int(household_id)
                manager = services.household_manager()
                household = manager.get(household_id)
                if household is None:
                    household = tgt_client.household
            services.current_zone().service_npc_service.request_service(
                household, service_npc_tuning)
            sims4.commands.output(
                'Requesting service {0}'.format(service_npc_type), _connection)
            return True
    return False
class EcoInspectorSituation(SituationComplexCommon):
    INSTANCE_TUNABLES = {'inspector_job_and_role_state': TunableSituationJobAndRoleState(description='\n            The job and role state for the eco-inspector.\n            ', tuning_group=GroupNames.ROLES), 'eco_inspect_state': _EcoInspectState.TunableFactory(description='\n           Inspection + Vacuuming state\n            ', display_name='1. Eco Inspect', tuning_group=SituationComplexCommon.SITUATION_STATE_GROUP), 'expelling_smog_state': _ExpellingSmogState.TunableFactory(description='\n           Expelling state\n            ', display_name='2. Expelling Smog', tuning_group=SituationComplexCommon.SITUATION_STATE_GROUP), 'leaving_state': _LeavingState.TunableFactory(description='\n            Inspector is leaving after Vacuuming.\n            ', display_name='3. Leaving State', tuning_group=SituationComplexCommon.SITUATION_STATE_GROUP), 'expel_smog': TunableInteractionOfInterest(description='\n            Social: listen to move to expelling_smog state\n            '), 'delta_expel': Tunable(description='\n            How much to increase the pollution level by?  \n            ', tunable_type=float, default=0.0), 'leave': TunableInteractionOfInterest(description='\n            Listen for this enter the leave state.\n            '), 'expel_smog_notification': OptionalTunable(description='\n            A TNS that is displayed after expelling smog.\n            ', tunable=UiDialogNotification.TunableFactory()), 'arrival_notification': OptionalTunable(description='\n            A TNS that is displayed pm arrival of the eco-inspector.\n            ', tunable=UiDialogNotification.TunableFactory()), 'leave_notification': OptionalTunable(description='\n            A TNS that after the eco-inspector leaves.\n            ', tunable=UiDialogNotification.TunableFactory()), 'service_npc_hireable': TunableReference(description='\n            Service NPC for the eco-inspector.\n            ', manager=services.service_npc_manager(), pack_safe=True), 'fake_perform_pollution_limit': Tunable(description='\n            Limit down to which to change pollution.  \n            ', tunable_type=float, default=0.0), 'fake_perform_vacuum_delta': TunableRange(description='\n            How much to decrease the pollution level by?  \n            ', tunable_type=float, default=1.0, minimum=0.1)}

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        self._service_npc = None
        self._service_start_time = None
        reader = self._seed.custom_init_params_reader
        self._service_npc_type = self.service_npc_hireable
        self._hiring_household = services.household_manager().get(reader.read_uint64('household_id', 0))
        if self._hiring_household is None:
            raise ValueError('Invalid household for situation: {}'.format(self))
        self.initial_street_value = EcoInspectorSituation.get_footprint_commodity_value()

    @staticmethod
    def get_footprint_commodity_value():
        street_service = services.street_service()
        policy_provider = street_service.get_provider(services.current_street())
        return policy_provider.commodity_tracker.get_value(eco_footprint_tuning.EcoFootprintTunables.STREET_FOOTPRINT, add=True)

    @staticmethod
    def set_footprint_commodity_value(value):
        street_service = services.street_service()
        policy_provider = street_service.get_provider(services.current_street())
        policy_provider.commodity_tracker.set_value(eco_footprint_tuning.EcoFootprintTunables.STREET_FOOTPRINT, value)
        policy_provider.distribute_neighborhood_update()

    @classmethod
    def _states(cls):
        return (SituationStateData(1, _WaitState), SituationStateData(2, _EcoInspectState, factory=cls.eco_inspect_state), SituationStateData(3, _ExpellingSmogState, factory=cls.expelling_smog_state), SituationStateData(4, _LeavingState, factory=cls.leaving_state))

    @classmethod
    def _get_tuned_job_and_default_role_state_tuples(cls):
        return [(cls.inspector_job_and_role_state.job, cls.inspector_job_and_role_state.role_state)]

    @classmethod
    def default_job(cls):
        return cls.inspector_job_and_role_state.job

    @classmethod
    def fake_perform_job(cls):
        _inspector = EcoInspectorSituation
        _commodity_val = _inspector.get_footprint_commodity_value()
        if _commodity_val < cls.fake_perform_pollution_limit:
            return
        no_steps = math.ceil((_commodity_val - cls.fake_perform_pollution_limit)/cls.fake_perform_vacuum_delta)
        _inspector.set_footprint_commodity_value(_commodity_val - no_steps*cls.fake_perform_vacuum_delta)

    def _save_custom_situation(self, writer):
        super()._save_custom_situation(writer)
        writer.write_uint64('household_id', self._hiring_household.id)

    def _on_add_sim_to_situation(self, sim, job_type, role_state_type_override=None):
        super()._on_add_sim_to_situation(sim, job_type, role_state_type_override=role_state_type_override)
        if self.inspector_person() is not None:
            self._change_state(self.eco_inspect_state())

    def inspector_person(self):
        sim = next(self.all_sims_in_job_gen(self.inspector_job_and_role_state.job), None)
        return sim

    def _on_set_sim_job(self, sim, job_type):
        super()._on_set_sim_job(sim, job_type)
        self._service_npc = sim
        services.current_zone().service_npc_service.cancel_service(self._hiring_household, self._service_npc_type)

    def start_situation(self):
        super().start_situation()
        self._change_state(_WaitState())
Exemplo n.º 15
0
 def on_all_households_and_sim_infos_loaded(self, client):
     household = client.household
     if household is None:
         return
     household_manager = services.household_manager()
     if household_manager is None:
         return
     service_npc_manager = services.service_npc_manager()
     for npc_household in household_manager.values():
         npc_household.load_fixup_service_npcs()
         preferred_npc_data = npc_household.get_all_prefered_sim_id_service_id(
         )
         if preferred_npc_data is None:
             continue
         for (sim_id, service_type) in preferred_npc_data:
             service_npc_tuning = service_npc_manager.get(service_type)
             if service_npc_tuning is not None:
                 self.register_service_npc(sim_id, service_npc_tuning)
     if household.id != services.active_lot().owner_household_id:
         return
     business_manager = services.business_service(
     ).get_business_manager_for_zone()
     if business_manager is not None and business_manager.business_type != BusinessType.INVALID:
         return
     all_hired_service_npcs = household.get_all_hired_service_npcs()
     for service_npc_resource_key in services.service_npc_manager().types:
         service_npc_tuning = services.service_npc_manager().get(
             service_npc_resource_key)
         if not service_npc_tuning.auto_schedule_on_client_connect():
             if service_npc_tuning.guid64 in all_hired_service_npcs:
                 is_recurring = False
                 user_specified_data_id = None
                 if service_npc_tuning.auto_schedule_on_client_connect():
                     is_recurring = True
                 else:
                     service_npc_record = household.get_service_npc_record(
                         service_npc_tuning.guid64, add_if_no_record=False)
                     if service_npc_record:
                         is_recurring = service_npc_record.recurring
                         user_specified_data_id = service_npc_record.user_specified_data_id
                 self.request_service(
                     household,
                     service_npc_tuning,
                     from_load=True,
                     is_recurring=is_recurring,
                     user_specified_data_id=user_specified_data_id)
         is_recurring = False
         user_specified_data_id = None
         if service_npc_tuning.auto_schedule_on_client_connect():
             is_recurring = True
         else:
             service_npc_record = household.get_service_npc_record(
                 service_npc_tuning.guid64, add_if_no_record=False)
             if service_npc_record:
                 is_recurring = service_npc_record.recurring
                 user_specified_data_id = service_npc_record.user_specified_data_id
         self.request_service(household,
                              service_npc_tuning,
                              from_load=True,
                              is_recurring=is_recurring,
                              user_specified_data_id=user_specified_data_id)
Exemplo n.º 16
0
 def potential_interactions(cls, target, context, **kwargs):
     for service_tuning_type in services.service_npc_manager().types:
         service_tuning = services.service_npc_manager().get(service_tuning_type)
         yield AffordanceObjectPair(cls, target, cls, None, service_tuning=service_tuning, **kwargs)
Exemplo n.º 17
0
class ServiceNpcRequest(XevtTriggeredElement):
    __qualname__ = 'ServiceNpcRequest'
    MINUTES_ADD_TO_SERVICE_ARRIVAL = 5
    HIRE = 1
    CANCEL = 2
    FACTORY_TUNABLES = {
        'description':
        '\n        Request a service NPC as part of an interaction. Note for timing field:\n        Only beginning and end will work because xevents will trigger\n        immediately on the server for service requests\n        ',
        'request_type':
        TunableVariant(
            description=
            '\n                Specify the type of service NPC Request. You can hire, dismiss,\n                fire, or cancel a service npc.',
            hire=TunableTuple(
                description=
                '\n                A reference to the tuned service npc instance that will be\n                requested at the specified time.',
                locked_args={'request_type': HIRE},
                service=TunableReference(services.service_npc_manager())),
            cancel=TunableTuple(
                locked_args={'request_type': CANCEL},
                service=TunableReference(services.service_npc_manager()),
                description=
                'A reference to the tuned service that will be cancelled. This only really applies to recurring services where a cancelled service will never have any service npcs show up again until re-requested.'
            ),
            default='hire'),
        'notification':
        OptionalTunable(
            description=
            '\n                When enabled, display a notification when the service npc is \n                successfully hired/cancelled.\n                If hired, last token is DateAndTime when service npc will\n                arrive. (usually this is 1)\n                ',
            tunable=NotificationElement.TunableFactory(
                locked_args={
                    'timing': XevtTriggeredElement.LOCKED_AT_BEGINNING
                }))
    }

    def __init__(self,
                 interaction,
                 *args,
                 request_type,
                 notification,
                 sequence=(),
                 **kwargs):
        super().__init__(interaction,
                         request_type=request_type,
                         notification=notification,
                         sequence=sequence,
                         *args,
                         **kwargs)
        self._request_type = request_type
        self.notification = notification
        self._household = interaction.sim.household
        self._service_npc_user_specified_data_id = None
        self._recurring = False
        self._read_interaction_parameters(**interaction.interaction_parameters)

    def _read_interaction_parameters(self,
                                     service_npc_user_specified_data_id=None,
                                     service_npc_recurring_request=False,
                                     **kwargs):
        self._service_npc_user_specified_data_id = service_npc_user_specified_data_id
        self._recurring = service_npc_recurring_request

    def _do_behavior(self):
        request_type = self._request_type.request_type
        service_npc = self._request_type.service
        if service_npc is None:
            return
        service_npc_service = services.current_zone().service_npc_service
        if request_type == self.HIRE:
            finishing_time = service_npc_service.request_service(
                self._household,
                service_npc,
                user_specified_data_id=self.
                _service_npc_user_specified_data_id,
                is_recurring=self._recurring)
            if self.notification is not None and finishing_time is not None:
                finishing_time = finishing_time + create_time_span(
                    minutes=self.MINUTES_ADD_TO_SERVICE_ARRIVAL)
                notification_element = self.notification(self.interaction)
                notification_element.show_notification(
                    additional_tokens=(finishing_time, ))
        elif request_type == self.CANCEL:
            service_npc_service.cancel_service(self._household, service_npc)
            if self.notification is not None:
                notification_element = self.notification(self.interaction)
                notification_element._do_behavior()