# Path: Chains/firefox.py
# class FIREFOX(Enum):
#     HIGH = 0
#     EDGE = 1
#     HORIZONTAL = 2
#     RANDOM = 3
#     # Added SAFERANDOM option so Smashbot wouldn't random a straight horizontal upB and SD below the stage
#     SAFERANDOM = 4


import melee
import Chains
import random
from melee.enums import Action, Button, Character
from Tactics.tactic import Tactic
from Chains.firefox import FIREFOX
        # Tech if we need to
        #   Calculate when we will land
        if smashbot_state.position.y > -4 and not smashbot_state.on_ground and \
                Action.DAMAGE_HIGH_1.value <= smashbot_state.action.value <= Action.DAMAGE_FLY_ROLL.value:
            framesuntillanding = 0
            speed = smashbot_state.speed_y_attack + smashbot_state.speed_y_self
            height = smashbot_state.position.y
            gravity = self.framedata.characterdata[smashbot_state.character]["Gravity"]
            termvelocity = self.framedata.characterdata[smashbot_state.character]["TerminalVelocity"]
            while height > 0:
                height += speed
                speed -= gravity
                speed = max(speed, -termvelocity)
                framesuntillanding += 1
                # Shortcut if we get too far
                if framesuntillanding > 120:
                    break
            # Do the tech
            if framesuntillanding < 4:
                self.pickchain(Chains.Tech)
                return

        # Meteor cancel 8 frames after hitlag ended
        # TODO: Don't SDI an up input if we want to meteor cancel
        if smashbot_state.speed_y_attack < 0 and smashbot_state.action_frame == 8:
            if smashbot_state.jumps_left > 0:
                if gamestate.custom["meteor_jump_lockout"] == 0:
                    self.pickchain(Chains.Jump, [int(smashbot_state.position.x < 0)])
                    return
            elif gamestate.custom["meteor_ff_lockout"] == 0:

# Path: Chains/firefox.py
# class FIREFOX(Enum):
#     HIGH = 0
#     EDGE = 1
#     HORIZONTAL = 2
#     RANDOM = 3
#     # Added SAFERANDOM option so Smashbot wouldn't random a straight horizontal upB and SD below the stage
#     SAFERANDOM = 4


# Path: Tactics/mitigate.py
import melee
import Chains
import random
from melee.enums import Action, Button, Character
from Tactics.tactic import Tactic
from Chains.firefox import FIREFOX

        # Tech if we need to
        #   Calculate when we will land
        if smashbot_state.position.y > -4 and not smashbot_state.on_ground and \
                Action.DAMAGE_HIGH_1.value <= smashbot_state.action.value <= Action.DAMAGE_FLY_ROLL.value:
            framesuntillanding = 0
            speed = smashbot_state.speed_y_attack + smashbot_state.speed_y_self
            height = smashbot_state.position.y
            gravity = self.framedata.characterdata[smashbot_state.character]["Gravity"]
            termvelocity = self.framedata.characterdata[smashbot_state.character]["TerminalVelocity"]
            while height > 0:
                height += speed
                speed -= gravity
                speed = max(speed, -termvelocity)
                framesuntillanding += 1
                # Shortcut if we get too far
                if framesuntillanding > 120:
                    break
            # Do the tech
            if framesuntillanding < 4:
                self.pickchain(Chains.Tech)
                return

        # Meteor cancel 8 frames after hitlag ended
        # TODO: Don't SDI an up input if we want to meteor cancel
        if smashbot_state.speed_y_attack < 0 and smashbot_state.action_frame == 8:
            if smashbot_state.jumps_left > 0:
                if gamestate.custom["meteor_jump_lockout"] == 0:
                    self.pickchain(Chains.Jump, [int(smashbot_state.position.x < 0)])
                    return
            elif gamestate.custom["meteor_ff_lockout"] == 0:

                self.pickchain(Chains.Firefox, [FIREFOX.SAFERANDOM])