from mower.utils.graph import SceneGraphSolver
from mower.utils.recognize import Scene


class LightenLoadSolver(SceneGraphSolver):
    solver_name = "减轻负荷"

    def run(self):
        self.check = False
        super().run()

    def transition(self):
        if (scene := self.scene()) == Scene.ROGUE_SARKAZ_LIGHTEN_LOAD:
            self.ctap("rogue/Sarkaz_load/lose", 3)

        elif scene == Scene.ROGUE_SARKAZ_LOAD:
            if self.animation(interval=0.2):
                return
            if not self.find("rogue/Sarkaz_load/block"):
                self.scene_graph_step(Scene.ROGUE_MAIN)
                return
            if self.find("rogue/Sarkaz_load/concentrate"):
                self.check = True
            elif not self.check:
                self.ctap((1800, 180), 2)
                return
            if pos := self.find("rogue/Sarkaz_load/idea"):
                self.ctap(pos, 1)

        elif scene in self.waiting_scene:
            self.waiting_solver()
        else:
            return True
