require("TimedActions/ISBaseTimedAction")
require("TimedActions/ISReloadWeaponAction")
require("TimedActions/ISEjectMagazine")
require("TimedActions/ISInsertMagazine")
require("TimedActions/ISRackFirearm")

local customReloadAnims = {
    ["Base.L92_Carbine"] = "lever",
    ["Base.L94_Rifle"] = "lever",
    ["Base.LeverRifle"] = "lever",
    ["Base.LeverRifle2"] = "lever",
    ["Base.Tec9"] = "handgun2",
    ["Base.MAC10Unfolded"] = "handgun2",
    ["Base.MAC10Folded"] = "handgun2",
    ["Base.Vector45"] = "handgun2",
    ["Base.Vector9"] = "handgun2",
    ["Base.P90"] = "handgun2",
    ["Base.FAL"] = "FAL",
    ["Base.FALClassic"] = "FAL",
    ["Base.scar17"] = "FAL",
    ["Base.AssaultRifleM1"] = "M1Reload",
    ["Base.ShotgunSemi"] = "shotgunsemi",
    ["Base.ShotgunSemi2"] = "shotgunsemi",
    ["Base.Spas12"] = "shotgunsemi",
    ["Base.Spas12Folded"] = "shotgunsemi",
    ["Base.ShotgunSilent"] = "shotgunsemi",
    ["Base.MP153"] = "shotgunsemi",
    ["Base.MP153Sawn"] = "shotgunsemi",
    ["Base.MP5"] = "MP5",
    ["Base.MP5SD"] = "MP5",
    ["Base.MP5Unfolded"] = "MP5",
    ["Base.MP5Folded"] = "MP5",
    ["Base.UMP45"] = "MP5",
}

local function overrideReloadType(action)
    local gun = action.gun
    if gun then
        local reloadType = customReloadAnims[gun:getFullType()]
        if reloadType then
            action:setAnimVariable("WeaponReloadType", reloadType)
        end
    end
end

local origReloadStart = ISReloadWeaponAction.start
function ISReloadWeaponAction:start()
    origReloadStart(self)
    overrideReloadType(self)
end

local origEjectStart = ISEjectMagazine.start
function ISEjectMagazine:start()
    origEjectStart(self)
    overrideReloadType(self)
end

local origInsertStart = ISInsertMagazine.start
function ISInsertMagazine:start()
    origInsertStart(self)
    overrideReloadType(self)
end

local origRackStart = ISRackFirearm.start
function ISRackFirearm:start()
    origRackStart(self)
    overrideReloadType(self)
end
