Ejemplo n.º 1
0
 def sell_response(dialog):
     if not dialog.accepted:
         return
     value = int(self.get_live_drag_object_value(live_drag_object, self._live_drag_is_stack))
     live_drag_component.cancel_live_dragging(should_reset=False)
     object_tags = set()
     if self._live_drag_is_stack:
         (_, stack_items) = self._get_stack_items_from_drag_object(live_drag_object, remove=True, is_stack=True)
         for item in stack_items:
             item.current_value = 0
             item.set_stack_count(0)
             object_tags.update(item.get_tags())
             item.destroy(source=item, cause='Selling stack of live drag objects.')
     else:
         object_tags.update(live_drag_object.get_tags())
         if live_drag_object.is_in_inventory():
             self.remove_drag_object_and_get_next_item(live_drag_object)
         else:
             live_drag_object.remove_from_client()
     object_tags = frozenset(object_tags)
     live_drag_object.current_value = 0
     live_drag_object.destroy(source=live_drag_object, cause='Selling live drag object.')
     services.active_household().funds.add(value, Consts_pb2.TELEMETRY_OBJECT_SELL, self.active_sim, tags=object_tags)
     self._live_drag_objects = []
     self._live_drag_start_system = LiveDragLocation.INVALID
     self._live_drag_is_stack = False
     self._live_drag_sell_dialog_active = False
Ejemplo n.º 2
0
 def _award_insurance_money(self):
     client = services.client_manager().get_first_client()
     active_sim = client.active_sim
     if self._insurance_value > 0 and active_sim is not None:
         services.active_household().funds.add(self._insurance_value, Consts_pb2.TELEMETRY_INTERACTION_COST, None)
         dialog = self.FIRE_INSURANCE_CLAIM_NOTIFICATION(active_sim, SingleSimResolver(active_sim))
         dialog.show_dialog(additional_tokens=(self._insurance_value,))
         self._insurance_value = 0
Ejemplo n.º 3
0
 def on_loading_screen_animation_finished(self):
     logger.debug('on_loading_screen_animation_finished')
     services.game_clock_service().restore_saved_clock_speed()
     services.sim_info_manager().on_loading_screen_animation_finished()
     services.get_event_manager().process_events_for_household(
         test_events.TestEvent.SimTravel,
         services.active_household(),
         zone_id=self.id)
Ejemplo n.º 4
0
    def get_active_household() -> Union[Household, None]:
        """get_active_household()

        Retrieve the Household of the Active Sim.

        :return: The Household of the Active Sim or None if no household is found.
        :rtype: Union[Household, None]
        """
        return services.active_household()
Ejemplo n.º 5
0
 def clear_debt(self):
     if self.debt_source == DebtSource.SCHOOL_LOAN:
         host_sim_info = services.sim_info_manager().get(
             self._guest_list.host_sim_id)
         statistic = host_sim_info.get_statistic(
             LoanTunables.DEBT_STATISTIC, add=False)
         if statistic is None:
             return
         else:
             statistic.set_value(0)
     elif self.debt_source == DebtSource.BILLS:
         services.active_household().bills_manager.pay_bill(clear_bill=True)
     else:
         logger.error(
             'Attempting to use a debt source {} that is not handled',
             self.debt_source,
             owner='jjacobson')
         return
Ejemplo n.º 6
0
 def _lifestyle_brand_alarm_tick(self, *_):
     household = services.active_household()
     if household is None:
         return
     for sim_info in household.sim_info_gen():
         tracker = sim_info.lifestyle_brand_tracker
         if tracker is None:
             continue
         tracker.payout_lifestyle_brand()
Ejemplo n.º 7
0
 def _royalty_alarm_tick(self, *_):
     household = services.active_household()
     if household is None:
         return
     for sim_info in household.sim_info_gen():
         tracker = sim_info.royalty_tracker
         if tracker is None:
             continue
         tracker.update_royalties_and_get_paid()
Ejemplo n.º 8
0
 def end_vacation(self):
     active_household = services.active_household()
     current_zone_id = services.current_zone_id()
     current_region_id = get_region_description_id_from_zone_id(
         current_zone_id)
     rental_region_id = get_region_description_id_from_zone_id(
         self._zone_id)
     if current_region_id != rental_region_id or not active_household.any_member_belong_to_travel_group_id(
             self.id):
         at_home = current_zone_id == active_household.home_zone_id
         for sim_info in self:
             if active_household.id == sim_info.household_id and at_home:
                 if not sim_info.is_instanced(
                         allow_hidden_flags=ALL_HIDDEN_REASONS):
                     SimSpawner.spawn_sim(sim_info)
                     if sim_info.is_instanced(
                             allow_hidden_flags=ALL_HIDDEN_REASONS):
                         services.get_zone_situation_manager(
                         ).make_sim_leave_now_must_run(
                             sim_info.get_sim_instance(
                                 allow_hidden_flags=ALL_HIDDEN_REASONS))
                     else:
                         sim_info.inject_into_inactive_zone(
                             sim_info.household.home_zone_id)
             elif sim_info.is_instanced(
                     allow_hidden_flags=ALL_HIDDEN_REASONS):
                 services.get_zone_situation_manager(
                 ).make_sim_leave_now_must_run(
                     sim_info.get_sim_instance(
                         allow_hidden_flags=ALL_HIDDEN_REASONS))
             else:
                 sim_info.inject_into_inactive_zone(
                     sim_info.household.home_zone_id)
         services.travel_group_manager(
         ).destroy_travel_group_and_release_zone(self, return_objects=True)
         return
     for instanced_sim in active_household.instanced_sims_gen():
         instanced_sim.queue.cancel_all()
     travel_info = InteractionOps_pb2.TravelSimsToZone()
     travel_info.zone_id = active_household.home_zone_id
     active_sims_on_zone = [
         active_sim_info for active_sim_info in active_household
         if active_sim_info.zone_id == current_zone_id
     ]
     for sim_info in itertools.chain(self, active_sims_on_zone):
         if active_household.id == sim_info.household_id:
             if sim_info.sim_id not in travel_info.sim_ids:
                 travel_info.sim_ids.append(sim_info.sim_id)
         else:
             sim_info.inject_into_inactive_zone(
                 sim_info.household.home_zone_id)
     distributor.system.Distributor.instance().add_event(
         Consts_pb2.MSG_TRAVEL_SIMS_TO_ZONE, travel_info)
     services.game_clock_service().set_clock_speed(ClockSpeedMode.PAUSED)
     services.travel_group_manager().destroy_travel_group_and_release_zone(
         self)
Ejemplo n.º 9
0
 def return_lost_objects(self):
     returned_objects = defaultdict(list)
     current_zone = services.current_zone()
     current_zone_id = services.current_zone_id()
     current_open_street_id = current_zone.open_street_id
     active_household = services.active_household()
     for locator in list(self._object_locators):
         if locator.zone_id != current_zone_id:
             if locator.open_street_id != current_open_street_id:
                 elapsed_time = services.time_service(
                 ).sim_now - locator.time_stamp
                 if elapsed_time.in_minutes() < locator.time_before_lost:
                     continue
                 if locator.object_data is None:
                     self.remove_object(locator.object_id)
                 else:
                     (obj_returned,
                      owner) = self._return_lost_object(locator)
                     if obj_returned is not None:
                         if owner is not None:
                             if isinstance(owner, int):
                                 if owner == active_household.id:
                                     returned_objects[owner].append(
                                         obj_returned)
                                     if owner.household is active_household:
                                         returned_objects[owner].append(
                                             obj_returned)
                             elif owner.household is active_household:
                                 returned_objects[owner].append(
                                     obj_returned)
     if not returned_objects:
         return
     returned_objects_string = None
     household_manager = services.household_manager()
     for (owner, objects) in returned_objects.items():
         if isinstance(owner, int):
             household = household_manager.get(owner)
             header = ObjectLostAndFoundService.FAMILY_NAME_HEADER(
                 household.name)
             next_string = LocalizationHelperTuning.get_bulleted_list(
                 header,
                 *(LocalizationHelperTuning.get_object_name(obj)
                   for obj in objects))
         else:
             next_string = LocalizationHelperTuning.get_bulleted_list(
                 LocalizationHelperTuning.get_sim_name(owner),
                 *(LocalizationHelperTuning.get_object_name(obj)
                   for obj in objects))
         if returned_objects_string is None:
             returned_objects_string = next_string
         else:
             returned_objects_string = LocalizationHelperTuning.NEW_LINE_LIST_STRUCTURE(
                 returned_objects_string, next_string)
     dialog = ObjectLostAndFoundService.OBJECTS_RETURN_MESSAGE_DIALOG(
         services.active_sim_info())
     dialog.show_dialog(additional_tokens=(returned_objects_string, ))
Ejemplo n.º 10
0
 def extend_vacation(self, duration_days, cost=0):
     extension = clock.interval_in_sim_days(duration_days)
     self.end_timestamp = self.end_timestamp + extension
     self.setup_rented_zone_alarms()
     services.active_household().funds.try_remove(
         cost,
         reason=Consts_pb2.FUNDS_MONEY_VACATION,
         sim=services.get_active_sim())
     leader_sim_info = services.active_sim_info()
     if leader_sim_info not in self:
         leader_sim_info = self._sim_infos[0]
     with telemetry_helper.begin_hook(travel_group_telemetry_writer,
                                      TELEMETRY_HOOK_TRAVEL_GROUP_EXTEND,
                                      sim_info=leader_sim_info) as hook:
         hook.write_int(TELEMETRY_TRAVEL_GROUP_ID, self.id)
         hook.write_int(TELEMETRY_TRAVEL_GROUP_ZONE_ID, self.zone_id)
         hook.write_int(TELEMETRY_TRAVEL_GROUP_SIZE, len(self))
         hook.write_int(TELEMETRY_TRAVEL_GROUP_DURATION,
                        int(self.duration_time_span.in_minutes()))
Ejemplo n.º 11
0
 def on_enter(self):
     super().on_enter()
     for sim_info in services.sim_info_manager().values():
         if sim_info.do_first_sim_info_load_fixups:
             sim_info.apply_fixup_actions(
                 SimInfoFixupActionTiming.ON_FIRST_SIMINFO_LOAD)
     for sim_info in services.active_household():
         sim_info.apply_fixup_actions(
             SimInfoFixupActionTiming.ON_ADDED_TO_ACTIVE_HOUSEHOLD)
     return _ZoneSpinUpStateResult.DONE
Ejemplo n.º 12
0
 def on_activate(self, reader):
     super().on_activate(reader)
     if self.owner.neighor_saved_me_buff:
         if self.owner._fire_brigade_put_out_fire:
             for sim_info in services.active_household().instanced_sims_gen():
                 sim_info.add_buff_from_op(self.owner.neighor_saved_me_buff.buff_type, self.owner.neighor_saved_me_buff.buff_reason)
     if self.owner.visit_afterwards:
         for fire_brigade_volunteer in self.owner.get_fire_brigade_sim_infos():
             services.get_zone_situation_manager().create_visit_situation(fire_brigade_volunteer)
     self.owner._self_destruct()
Ejemplo n.º 13
0
 def get_value_with_markup(self, value) -> int:
     markup_multiplier = self.markup_multiplier
     if self.owner_household_id is not None:
         tracker = services.business_service().get_business_tracker_for_household(self.owner_household_id, self.business_type)
         markup_multiplier += tracker.additional_markup_multiplier
     else:
         active_household = services.active_household()
         if active_household is not None:
             markup_multiplier *= active_household.holiday_tracker.get_active_holiday_business_price_multiplier(self.business_type)
     return int(value*markup_multiplier)
 def _on_set_sim_role_state(self, sim, *args, **kwargs):
     super()._on_set_sim_role_state(sim, *args, **kwargs)
     relationship_tracker = sim.sim_info.relationship_tracker
     for sim_info in services.active_household():
         if relationship_tracker.has_bit(
                 sim_info.sim_id, RelationshipGlobalTuning.
                 NEIGHBOR_GIVEN_KEY_RELATIONSHIP_BIT):
             self._change_state(self.owner._hangout_state())
             return
     self._change_state(self.owner._knock_on_door_state())
Ejemplo n.º 15
0
 def on_add(self, *_, **__):
     self.owner.hover_tip = ui_protocols.UiObjectMetadata.HOVER_TIP_GARDENING
     active_household = services.active_household()
     if active_household is not None and services.current_zone_id(
     ) == active_household.zone_id and self.owner.is_on_active_lot():
         if hasattr(self, 'fruit_name'):
             return
         rebate_manager = active_household.rebate_manager
         rebate_manager.add_rebate_for_object(
             self.owner.id, RebateCategoryEnum.GAMEPLAY_OBJECT)
Ejemplo n.º 16
0
 def is_ungreeted_sim_disallowed(self):
     zone_id = services.current_zone_id()
     active_household = services.active_household()
     if active_household is not None and active_household.home_zone_id == zone_id:
         return False
     else:
         plex_service = services.get_plex_service()
         if plex_service.get_plex_building_type(zone_id) != PlexBuildingType.PENTHOUSE_PLEX:
             return False
     return True
Ejemplo n.º 17
0
 def trigger_sickness_distribution(self):
     active_household = services.active_household()
     for sim_info in active_household:
         if sim_info.sickness_tracker is None:
             continue
         resolver = SingleSimResolver(sim_info)
         if not self._should_sim_become_sick(resolver):
             continue
         sickness = self._choose_sickness_for_sim(
             resolver, criteria_func=lambda s: not s.distribute_manually)
         sickness.apply_to_sim_info(sim_info)
Ejemplo n.º 18
0
def autopay_bills(enable: bool = None, _connection=NO_CONTEXT):
    household = services.active_household()
    if household is None:
        sims4.commands.output('No active household.', _connection)
        return
    bills_manager = household.bills_manager
    autopay_bills = enable if enable is not None else not bills_manager.autopay_bills
    bills_manager.autopay_bills = autopay_bills
    sims4.commands.output(
        'Autopay Bills for household {} set to {}.'.format(
            household, autopay_bills), _connection)
 def _on_set_sim_job(self, sim, job_type):
     super()._on_set_sim_job(sim, job_type)
     if self.support_given_keys:
         relationship_tracker = sim.sim_info.relationship_tracker
         for sim_info in services.active_household():
             if relationship_tracker.has_bit(
                     sim_info.sim_id, RelationshipGlobalTuning.
                     NEIGHBOR_GIVEN_KEY_RELATIONSHIP_BIT):
                 services.current_zone(
                 ).venue_service.active_venue.summon_npcs(
                     (sim.sim_info, ), self.SUMMONING_PURPOSE)
Ejemplo n.º 20
0
 def create_welcome_wagon(self):
     situation_manager = services.get_zone_situation_manager()
     if not situation_manager.is_user_facing_situation_running():
         situation_manager.create_situation(
             self._welcome_wagon_situation,
             guest_list=self._guest_list.clone(),
             user_facing=True,
             scoring_enabled=False)
     active_household = services.active_household()
     active_household.needs_welcome_wagon = False
     self._self_destruct()
Ejemplo n.º 21
0
 def scheduled_start_action(self, scheduler, alarm_data, extra_data):
     if self.chance and random.random() < self.chance:
         return
     household_id = services.active_household().id
     self.start_action(household_id)
     blackout_end_time = alarm_data[1] - alarm_data[0]
     self._stop_schedule_entry = alarms.add_alarm(
         self,
         blackout_end_time,
         lambda _: self.scheduled_stop_action(household_id),
         cross_zone=True)
 def _send_update_message(self):
     household = services.active_household()
     if household is None:
         return
     street = world.street.get_street_instance_from_world_id(
         household.get_home_world_id())
     if street is None:
         return
     provider = self.get_provider(street)
     if provider is None:
         return
     provider.send_update_message()
Ejemplo n.º 23
0
 def _handle_curfew_message_callback(self, handle):
     active_lot = services.active_lot()
     if active_lot.lot_id != services.active_household_lot_id():
         from_sim = None
         for sim_info in services.active_household():
             if sim_info.is_young_adult_or_older:
                 if not sim_info.is_instanced():
                     from_sim = sim_info
                     break
         if from_sim is None:
             return
         for sim_info in services.active_household():
             if sim_info.get_sim_instance() is None:
                 continue
             resolver = DoubleSimResolver(sim_info, from_sim)
             if not CurfewService.CURFEW_WARNING_SIM_TESTS.run_tests(
                     resolver):
                 continue
             dialog = self.CURFEW_WARNING_TEXT_MESSAGE_DIALOG(
                 sim_info, target_sim_id=from_sim.id, resolver=resolver)
             dialog.show_dialog()
Ejemplo n.º 24
0
 def perform_auto_pick(cls, inst, choices):
     household = services.active_household()
     if household is None:
         return
     sim_ids = tuple(sim_info.id for sim_info in household.sim_info_gen())
     obj_rel_tuples_list = []
     for choice in choices:
         obj_rel_tuples_list.extend(
             cls._get_obj_rel_tuples_for_sims(choice, sim_ids))
     if not obj_rel_tuples_list:
         return
     return max(obj_rel_tuples_list, key=operator.itemgetter(1))[0]
 def timer_expired(self):
     for sim_info in services.active_household():
         resolver = DoubleSimResolver(sim_info,
                                      self.owner._neighbor_sim.sim_info)
         for loot_action in self._early_exit_loot:
             loot_action.apply_to_resolver(resolver)
     resolver = DoubleSimResolver(services.active_sim_info(),
                                  self.owner._neighbor_sim.sim_info)
     early_exit_notification = self._early_exit_notification(
         services.active_sim_info(), resolver=resolver)
     early_exit_notification.show_dialog()
     self.owner._self_destruct()
Ejemplo n.º 26
0
 def on_loading_screen_animation_finished(self):
     household = services.active_household()
     plex_service = services.get_plex_service()
     if household is not None and not household.has_home_zone_been_active(
     ) and plex_service.is_zone_an_apartment(
             household.home_zone_id, consider_penthouse_an_apartment=False):
         active_sim = services.get_active_sim()
         landlord_sim_info = self.get_landlord_sim_info()
         if active_sim is not None and landlord_sim_info is not None:
             dialog = LandlordTuning.LANDLORD_FIRST_PLAY_RENT_REMINDER_NOTIFICATION(
                 active_sim)
             dialog.show_dialog(icon_override=IconInfoData(
                 obj_instance=landlord_sim_info))
Ejemplo n.º 27
0
def payout_rebates(household_id: int = None, _connection=None):
    if household_id is None:
        household = services.active_household()
    else:
        household_manager = services.household_manager()
        household = household_manager.get(household_id)
    if household is None:
        return False
    rebate_manager = household.rebate_manager
    if rebate_manager is None:
        return False
    rebate_manager.payout_rebates()
    return True
 def get_filter_results_for_job(cls):
     active_sim_info = services.active_sim_info()
     neighbor_results = services.sim_filter_service().submit_filter(
         cls.neighbor_job_and_default_role_state.job.filter,
         callback=None,
         requesting_sim_info=active_sim_info,
         allow_yielding=False,
         blacklist_sim_ids={
             sim_info.sim_id
             for sim_info in services.active_household()
         },
         gsi_source_fn=cls.get_sim_filter_gsi_name)
     return neighbor_results
Ejemplo n.º 29
0
    def get_ambient_walkby_situation(cls, sim_slots_available):
        lot_id = services.active_lot_id()

        def can_start_situation(situation):
            if services.game_clock_service().clock_speed == ClockSpeedMode.SUPER_SPEED3 and not situation.allowed_in_super_speed_3:
                return False
            return situation.can_start_walkby(lot_id, sim_slots_available)

        household = services.active_household()
        additional_walkbys = []
        if household is not None:
            additional_walkbys.extend(household.holiday_tracker.get_additional_holiday_walkbys(predicate=can_start_situation))
        return cls.walkby_desire_by_day_of_week.get_situation_and_params(predicate=can_start_situation, additional_situations=additional_walkbys)[0]
Ejemplo n.º 30
0
def force_bills_due(_connection=None):
    household = services.active_household()
    if household is None:
        sims4.commands.output('No active household.', _connection)
        return
    bills_manager = household.bills_manager
    if bills_manager.current_payment_owed is None:
        previous_send_notification = bills_manager.bill_notifications_enabled
        bills_manager.bill_notifications_enabled = False
        bills_manager.allow_bill_delivery()
        if bills_manager.current_payment_owed is not None:
            bills_manager.trigger_bill_notifications_from_delivery()
        bills_manager.bill_notifications_enabled = previous_send_notification
Ejemplo n.º 31
0
 def get_random_target(self):
     object_manager = services.object_manager()
     if self.target_filter_tags is not None:
         found_objects = object_manager.get_objects_matching_tags(
             self.target_filter_tags, match_any=True)
         if len(found_objects) > 0:
             random_object = random.choice(list(found_objects))
             return random_object
         return
     else:
         household_sims = services.active_household().instanced_sims_gen()
         random_sim = random.choice(list(household_sims))
         return random_sim
Ejemplo n.º 32
0
 def create_career_event_situations_during_zone_spin_up(self):
     try:
         active_household = services.active_household()
         if active_household is None:
             return
         current_zone_id = services.current_zone_id()
         for sim_info in active_household:
             if sim_info.zone_id == current_zone_id:
                 career = sim_info.career_tracker.career_currently_within_hours
                 if career is not None:
                     career.create_career_event_situations_during_zone_spin_up()
     except:
         logger.exception('Exception raised while trying to restore career event.', owner='tingyul')
Ejemplo n.º 33
0
 def _test(self, resolver, skip_run_tests=False):
     homelot_id = services.active_household().home_zone_id
     if self.homelot_only and homelot_id != services.current_zone_id():
         return TestResult(
             False,
             'Cannot run because the current zone is not the home lot.')
     if self.host_sim_participant is not None:
         host_sim_info = self._get_resolver().get_participant(
             self.host_sim_participant)
         if host_sim_info is None:
             return TestResult(
                 False, 'Cannot run because there is no host sim info.')
     return super()._test(resolver, skip_run_tests=skip_run_tests)
def save_current_houshold(slot_id:int=0, slot_name='Unnamed', _connection=None):
    output = sims4.commands.Output(_connection)
    try:
        sim_info.save_active_household_command_start()
        save_slot_data_msg = services.get_persistence_service().get_save_slot_proto_buff()
        save_slot_data_msg.slot_id = slot_id
        active_household = services.active_household()
        if active_household is not None:
            save_slot_data_msg.active_household_id = active_household.id
        sims4.core_services.service_manager.save_all_services(None, persistence_error_types.ErrorCodes.CORE_SERICES_SAVE_FAILED, save_slot_data=save_slot_data_msg)
        save_game_buffer = services.get_persistence_service().get_save_game_data_proto()
        persistence_module.run_persistence_operation(persistence_module.PersistenceOpType.kPersistenceOpSaveHousehold, save_game_buffer, 0, None)
    except Exception as e:
        output('Exception thrown while executing command persistence.save_active_household.\n{}'.format(e))
        output('No household file generated. Please address all the exceptions.')
        raise
    finally:
        sim_info.save_active_household_command_stop()
    output('Exported active household to T:\\InGame\\Households\\{}.household'.format(active_household.name))
    return 1
Ejemplo n.º 35
0
 def on_added_to_inventory(self):
     household = services.active_household()
     if household is not None:
         household.collection_tracker.check_add_collection_item(household, self.owner.id, self.owner.definition.id)