name = "Aim Test"
id = hero_id.any

function is_enabled()
    if not config.get_bool("enabled") then return false end
    return input.is_key_held(config.get_int("activation_key"))
end

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

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

    local mode = config.get_int("mode")
    local b = bone.head

    -- 0 = snap_to_target: instant flick with convergence
    if mode == 0 then
        if snap_to_target(target, { bone = b }) then
            print("snap_to_target: done")
        end

    -- 1 = aim_at_target: smooth aim until on target, then shoot
    elseif mode == 1 then
        if aim_at_target(target, { bone = b, speed = config.get_float("speed"), threshold = 0.0 }) then
            print("aim_at_target: on target")
            left_click()
        end

    -- 2 = lock_aim: persistent tracking through a combo
    elseif mode == 2 then
        print("lock_aim: locking")
        lock_aim(target, { bone = b, speed = config.get_float("speed") })
        sleep(500)
        press_ability(slot.ability1)
        sleep(300)
        press_ability(slot.ability2)
        sleep(200)
        unlock_aim()
        print("lock_aim: unlocked")
    end

    sleep(500)
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 = 10.0,        label = "Max FOV", min = 1.0, max = 30.0 },
    { key = "mode",           type = "combo",   default = 0,           label = "Mode", options = { "Snap", "Aim", "Lock" } },
    { key = "speed",          type = "float",   default = 0.5,         label = "Speed", min = 0.1, max = 1.0 },
}
