Пример #1
0
    def get_instance(cls, household_id):
        if cls.instance is not None:
            return cls.instance

        Logger.log("selection group: no instance, {}".format(household_id))

        # restore state
        try:
            file_handler = open(HOME_DIR + '/selection_group.json')
        except BaseException:
            file_handler = None

        if file_handler is None or not file_handler.readable():
            return cls(household_id)

        state = file_handler.read()
        file_handler.close()

        Logger.log('restored state: {}'.format(state))

        # deserialize
        instance = cls.deserialize(state)  # pylint: disable=no-member

        if instance.household_id != household_id:
            return cls(household_id)

        return instance
Пример #2
0
    def _run_interaction_gen(self, timeline):
        Logger.log("running make selectable interaction...")
        try:
            super()._run_interaction_gen(timeline)

            sim_info = self.target.sim_info

            if self.context.target_sim_id is not None:
                sim_info = (services.sim_info_manager()
                            .get(self.context.target_sim_id))

            Logger.log("got sim info {} {}"
                       .format(sim_info.first_name, sim_info.last_name))

            SelectionGroupService \
                .get(services.active_household_id()) \
                .make_sim_selectable(sim_info)

            Logger.log("sim is now selectable!")

            services.get_first_client().set_active_sim_by_id(sim_info.id)

            Logger.log("sim is now active!")

            return True

        except BaseException:
            Logger.log(traceback.format_exc())
Пример #3
0
def set_active_sim(first_name='', last_name='', _connection=None):
    output = commands.CheatOutput(_connection)

    try:
        if _connection is None:
            output('SetActiveSim; Status:ParamError')
            return False

        tgt_client = services.client_manager().get(_connection)

        if tgt_client is None:
            output('SetActiveSim; Status:ClientError no client')
            return False

        sim_info = (services.sim_info_manager().get_sim_info_by_name(
            first_name, last_name))

        if sim_info is None:
            output('SetActiveSim; Status:SimError no sim with this name found')
            return False

        SelectionGroupService \
            .get(services.active_household_id()) \
            .make_sim_selectable(sim_info)

        if tgt_client.set_active_sim_by_id(sim_info.id):
            output('SetActiveSim; Status:Success')
            return True

        output('SetActiveSim; Status:NoChange')
        return True
    except BaseException as exception:
        output('Error: {}'.format(exception))
        Logger.log(traceback.format_exc())
Пример #4
0
def canys_zone_on_loading_screen_animation_finished(original, self):
    Logger.log('do_on_loading_screen_animation_finished')

    try:
        GameEvents.emit_loading_screen_animation_finished(self)

        return original(self)
    except BaseException:
        Logger.log(traceback.format_exc())
Пример #5
0
def tn_sim_on_add(original, self):
    Logger.log('do_on_add')
    try:
        result = original(self)

        GameEvents.emit_add_sim(self)

        return result
    except BaseException:
        Logger.log(traceback.format_exc())
Пример #6
0
    def cleanup_sims(self):
        for sim_info_id in self.selectable_sims:
            sim_info = services.sim_info_manager().get(sim_info_id)

            if sim_info.household_id == self.household_id:
                return

            Logger.log(
                "{} is not in household, removing to avoid teardown issues".
                format(sim_info))

            self.remove_sim(sim_info)
Пример #7
0
def canys_sim_info_is_enabled_in_skewer(original, self):
    try:
        selection_group = SelectionGroupService.get(
            services.active_household_id(), True)

        if selection_group and selection_group.is_household_npc(self):
            return False

        return original(self)
    except BaseException:
        Logger.log(traceback.format_exc())
        return True
Пример #8
0
def tn_zone_do_zone_spin_up(original, self, household_id, active_sim_id):
    try:
        result = original(self, household_id, active_sim_id)

        def callback():
            Logger.log('do_zone_spin_up')
            GameEvents.emit_zone_spin_up(self, household_id, active_sim_id)

        self.register_callback(ZoneState.RUNNING, callback)

        return result
    except BaseException:
        Logger.log(traceback.format_exc())
Пример #9
0
    def test(cls, inst, *args, target=DEFAULT, context=None, **kwargs) -> TestResult:  # pylint: disable=no-self-argument
        inst_or_cls = inst if inst is not None else cls

        Logger.log("testing SimMakeNotSelectableInteraction, context: {} {}"
                   .format(args, kwargs))

        if target:
            info_target = target.sim_info

        Logger.log('info_target: {}'.format(info_target))

        if context is not None and context.target_sim_id is not None:
            target_id = context.target_sim_id
            info_target = services.sim_info_manager().get(target_id)

        Logger.log('info_target: {}'.format(info_target))

        if cls.must_be_selectable(info_target):
            return TestResult(False, "sim is in active household and has to be selectable")

        sim_is_selectable = (SelectionGroupService
                             .get(0).is_selectable(info_target.id))

        Logger.log("sim_is_selectable: {}".format(sim_is_selectable))

        if not sim_is_selectable:
            return TestResult(False, "sim is not selectable", inst)

        if target is None or target.sim_info.id != info_target.id:
            return TestResult.TRUE

        return (super(SimMakeNotSelectableInteraction, inst_or_cls)
                .test(*args, target=target, context=context, **kwargs))
Пример #10
0
    def on_zone_teardown(self, _zone, _client):
        Logger.log('on_zone_teardown: tearing down SelectionGroupService')

        if not self.zone_is_setup:
            Logger.log("SelectionGroupService is already teared down")
            return

        self.persist_state()
        self.cleanup_sims()

        GameEvents.remove_zone_teardown(self.on_zone_teardown)

        self.zone_is_setup = False
        self.__class__.instance = None
Пример #11
0
    def cleanup_sims(self):
        for sim_info_id in self.selectable_sims:
            sim_info = services.sim_info_manager().get(sim_info_id)

            if sim_info is None:
                Logger.log("sim with id {} does not exist and shouldn't apear here"
                           .format(sim_info_id))
                continue

            if sim_info.household_id == self.household_id:
                continue

            Logger.log("{} is not in household, removing to avoid teardown issues".format(sim_info))

            self.remove_sim(sim_info)
Пример #12
0
    def setup_zone(self):
        if len(self.household_npcs) > 0:
            self.client.send_selectable_sims_update()

        for sim_info_id in self.selectable_sims:
            try:
                sim_info = services.sim_info_manager().get(sim_info_id)

                self.make_sim_selectable(sim_info)
            except BaseException:
                Logger.log("Error while adding sim to skewer: {}".format(sim_info_id))
                Logger.log(traceback.format_exc())

        self.client.selectable_sims.add_watcher(self, self.update_selectable_sims)
        self.update_selectable_sims()
        self.zone_is_setup = True
Пример #13
0
    def inject_into_relationship_panel(cls, sim):
        affordance_manager = services.affordance_manager()
        injected_interactions = []

        for interaction_id in cls.sim_interactions:
            interaction_class = affordance_manager.get(interaction_id)

            if interaction_class is None:
                Logger.log(
                    'interaction {} not found in affordance_manager'.format(
                        interaction_id))
                continue

            injected_interactions.append(interaction_class)

        sim._relation_panel_affordances = (sim._relation_panel_affordances +
                                           tuple(injected_interactions))
Пример #14
0
    def test(cls, inst, *args, target=DEFAULT, context=None, **kwargs) -> TestResult:  # pylint: disable=no-self-argument
        try:
            inst_or_cls = inst if inst is not None else cls
            roommate_service = services.get_roommate_service()

            if roommate_service is None:
                return TestResult.NONE

            Logger.log("testing SimRemoveRoomMateInteraction, context: {} {}"
                       .format(args, kwargs))

            if target:
                info_target = target.sim_info

            if context.target_sim_id is not None:
                target_id = context.target_sim_id
                info_target = services.sim_info_manager().get(target_id)

            household_id = context.sim.sim_info.household_id

            Logger.log('info_target: {}'.format(info_target))

            if context.sim.sim_info.id == info_target.id:
                return TestResult(False, "sim can not be it's own roommate", inst)

            if not roommate_service.is_sim_info_roommate(info_target, household_id):
                return TestResult(False, "sim is not a roommate of current household", inst)

            return (super(SimRemoveRoomMateInteraction, inst_or_cls)
                    .test(*args, target=target, context=context, **kwargs))
        except BaseException:
            Logger.log(traceback.format_exc())
Пример #15
0
    def test(cls, inst, *args, target=DEFAULT, context=None, **kwargs) -> TestResult:  # pylint: disable=no-self-argument
        try:
            inst_or_cls = inst if inst is not None else cls
            selection_group = SelectionGroupService.get(services.active_household_id())

            Logger.log("testing SimHouseholdNpcOffInteraction, context: {} {}"
                       .format(args, kwargs))

            if target:
                info_target = target.sim_info

            if context.target_sim_id is not None:
                target_id = context.target_sim_id
                info_target = services.sim_info_manager().get(target_id)

            Logger.log('info_target: {}'.format(info_target))

            if not selection_group.is_household_npc(info_target):
                return TestResult(False, "sim is not a household npc", inst)

            if info_target.household_id != services.active_household_id():
                return TestResult(False, "sim is not a member of the active household", inst)

            return (super(SimHouseholdNpcOffInteraction, inst_or_cls)
                    .test(*args, target=target, context=context, **kwargs))
        except BaseException:
            Logger.log(traceback.format_exc())
Пример #16
0
    def _run_interaction_gen(self, timeline):
        try:
            Logger.log("running remove roommate interaction...")

            super()._run_interaction_gen(timeline)

            sim_info = self.target.sim_info

            if self.context.target_sim_id is not None:
                sim_info = (services.sim_info_manager()
                            .get(self.context.target_sim_id))

            Logger.log("got sim info {} {}"
                       .format(sim_info.first_name, sim_info.last_name))

            services.get_roommate_service().remove_roommate(sim_info)

            Logger.log("sim is now not a roommate anymore!")

            return True

        except BaseException:
            Logger.log(traceback.format_exc())
Пример #17
0
    def _run_interaction_gen(self, timeline):
        try:
            Logger.log("running turn into roommate interaction...")

            super()._run_interaction_gen(timeline)

            sim_info = self.target.sim_info
            home_zone_id = self.get_sim_info_home_zone_id(self.context.sim.sim_info)

            if self.context.target_sim_id is not None:
                sim_info = (services.sim_info_manager()
                            .get(self.context.target_sim_id))

            Logger.log("got sim info {} {}"
                       .format(sim_info.first_name, sim_info.last_name))

            services.get_roommate_service().add_roommate(sim_info, home_zone_id)

            Logger.log("sim is now a roommate!")

            return True

        except BaseException:
            Logger.log(traceback.format_exc())
Пример #18
0
    def _run_interaction_gen(self, timeline):
        try:
            Logger.log("running household npc off interaction...")

            super()._run_interaction_gen(timeline)

            sim_info = self.target.sim_info

            if self.context.target_sim_id is not None:
                sim_info = (services.sim_info_manager()
                            .get(self.context.target_sim_id))

            Logger.log("got sim info {} {}"
                       .format(sim_info.first_name, sim_info.last_name))

            selection_group = SelectionGroupService.get(services.active_household_id())
            selection_group.remove_household_npc(sim_info)

            Logger.log("sim is now a normal household member!")

            return True

        except BaseException:
            Logger.log(traceback.format_exc())
Пример #19
0
    active_lot_household = services.current_zone(
    ).get_active_lot_owner_household()
    selection_group = SelectionGroupService.get(services.active_household_id())

    if active_lot_household is None:
        return original(self)

    for sim_info in active_lot_household.sim_infos:
        if sim_info.id not in selection_group.selectable_sims:
            continue

        return True

    return original(self)


@inject_method_to(SimInventoryComponent, 'allow_ui')
def tn_sim_inventory_component_allow_ui(original, self):
    if self.owner.is_selected:
        return True

    return original(self)


Logger.log('starting control_any_sim')


@GameEvents.on_loading_screen_animation_finished
def canys_validate_version(_zone):
    IntegrityService.check_integrety(control_any_sim.__version__)
Пример #20
0
def tn_init_services(_zone, household_id, _active_sim_id):
    try:
        SelectionGroupService.get(household_id)
    except BaseException:
        Logger.log(traceback.format_exc())
Пример #21
0
    def on_active_sim_changed(self, _old_sim, _new_sim):

        if self.client is None:
            Logger.log("active sim changed but we have no client, yet?")
            return

        sim_info = self.client.active_sim_info

        if sim_info is None:
            Logger.log("sim selection changed but no sim is selected")
            return

        if sim_info.household_id == self.household_id:
            return

        try:
            sim_info.request_lod(SimInfoLODLevel.ACTIVE)

            Logger.log("sim {} lod is now: {}".format(sim_info, sim_info.lod))

            sim_info.away_action_tracker.refresh(on_travel_away=True)
            sim_info.relationship_tracker.clean_and_send_remaining_relationship_info(
            )
            sim_info.publish_all_commodities()

            sim_instance = sim_info.get_sim_instance(
                allow_hidden_flags=ALL_HIDDEN_REASONS)

            if sim_instance is not None:
                inventory = sim_instance.get_component(INVENTORY_COMPONENT)
                inventory.publish_inventory_items()
            else:
                Logger.log('there is no sim instance for {}'.format(sim_info))

        except BaseException:
            Logger.log(
                "Error while updating newly active sim: {}".format(sim_info))
            Logger.log(traceback.format_exc())
Пример #22
0
    def is_selectable(self, sim_id):
        test = sim_id in self.selectable_sims

        Logger.log("is sim {} in selectable list: {}".format(sim_id, test))

        return test
Пример #23
0
    def test(cls, inst, *args, target=DEFAULT, context=None, **kwargs) -> TestResult:  # pylint: disable=no-self-argument
        try:
            inst_or_cls = inst if inst is not None else cls

            Logger.log("testing SimMakeSelectableInteraction, context: {} {}"
                       .format(args, kwargs))

            if target:
                info_target = target.sim_info

            Logger.log('info_target: {}'.format(info_target))

            if context is not None and context.target_sim_id is not None:
                target_id = context.target_sim_id
                info_target = services.sim_info_manager().get(target_id)

            Logger.log('info_target: {}'.format(info_target))

            sim_is_selectable = (SelectionGroupService
                                 .get(0).is_selectable(info_target.id))

            Logger.log("sim_is_selectable: {}".format(sim_is_selectable))

            if sim_is_selectable:
                fail = TestResult(False, "sim is already selectable", inst)
                Logger.log('fail result: {}'.format(repr(fail)))
                return fail

            if target is None or target.sim_info.id != info_target.id:
                return TestResult.TRUE

            return (super(SimMakeSelectableInteraction, inst_or_cls)
                    .test(*args, target=target, context=context, **kwargs))

        except BaseException:
            Logger.log(traceback.format_exc())
Пример #24
0
 def callback():
     Logger.log('do_zone_spin_up')
     GameEvents.emit_zone_spin_up(self, household_id, active_sim_id)
Пример #25
0
    def emit_zone_teardown(cls, current_zone, client):
        Logger.log("registered zone teardown handlers: {}".format(len(cls.zone_teardown_handlers)))

        for handler in cls.zone_teardown_handlers:
            handler(current_zone, client)