name = "Bebop"
id = hero_id.bebop

function is_enabled()
    return config.get_bool("enabled")
        and input.is_key_held(config.get_int("activation_key"))
end

function on_tick()
    local target = targeting.find_closest_by_fov(config.get_float("max_fov"), 70.0)
    if not target or not target:is_targetable() then return end

    local lp = local_player()
    if not lp then return end

    -- hook (ability 3)
    local hook = lp:get_ability(slot.ability3)
    if not hook or not hook.learned then return end
    if not lp:is_ability_ready(slot.ability3) then return end

    snap_to_target(target, { bone = bone.spine_1, projectile_velocity = 3100 })
    press_ability(slot.ability3)

    if not wait_for_cooling_down(slot.ability3, 5000) then return end
    if not wait_until_in_range(target, 4.0, 4000) then return end

    -- bomb (ability 2)
    local bomb = lp:get_ability(slot.ability2)
    if config.get_bool("bomb") and bomb and bomb.learned and lp:is_ability_ready(slot.ability2) then
        snap_to_target(target, { bone = bone.spine_1 })
        sleep(100)
        press_ability(slot.ability2)
        sleep(100)
        left_click()

        -- echo shard
        if config.get_bool("echoshard") and lp:has_item("upgrade_ability_power_shard") then
            input.press_key(item_slot_to_key(config.get_int("echoshard_slot")))
            sleep(100)

            if lp:is_ability_ready(slot.ability2) then
                snap_to_target(target, { bone = bone.spine_1 })
                sleep(100)
                press_ability(slot.ability2)
                sleep(100)
                left_click()
            end
        end
    end

    -- uppercut (ability 1)
    local uppercut = lp:get_ability(slot.ability1)
    if config.get_bool("uppercut") and uppercut and uppercut.learned and lp:is_ability_ready(slot.ability1) then
        snap_to_target(target, { bone = bone.spine_1 })
        sleep(100)
        press_ability(slot.ability1)
    end
end

settings = {
    { key = "enabled",        type = "bool",    default = false,       label = "Enabled" },
    { key = "activation_key", type = "keybind", default = VK.XBUTTON2, label = "Activation Key" },
    { key = "max_fov",        type = "float",   default = 5.0,         label = "Max FOV", min = 1.0, max = 15.0 },
    { key = "bomb",           type = "bool",    default = true,        label = "Bomb" },
    { key = "uppercut",       type = "bool",    default = true,        label = "Uppercut" },
    { key = "echoshard",      type = "bool",    default = false,       label = "Echo Shard" },
    { key = "echoshard_slot", type = "item_slot", default = 0,           label = "Echo Shard Slot", depends_on = "echoshard", depends_value = 1 },
}
