require "TimedActions/ISBaseTimedAction"
ISStartPanzerRepairAction = ISBaseTimedAction:derive("ISStartPanzerRepairAction");

function ISStartPanzerRepairAction:isValid()
    if self.vehicle:getSpeed2D() > 0 and GetAbilityLevel(self.vehicle, "Repair") < 10 then
        self.character:Say(getText("IGUI_PanzerCrew_BattleRepair_Stop"))
        return false
    end
    return true
end

function ISStartPanzerRepairAction:update()
end

function ISStartPanzerRepairAction:start()
    self.character:playSound("RepairSound")

end

function ISStartPanzerRepairAction:stop()
    ISBaseTimedAction.stop(self);
end

function ISStartPanzerRepairAction:perform()
    ISBaseTimedAction.perform(self);
    local PanzerType = GetPanzerType(self.vehicle)
    if PanzerType then

        local CrewLaungage = PanzerList[PanzerType].CrewLaungage
        if self.character:getModData().CrewLaungage then
            CrewLaungage = self.character:getModData().CrewLaungage
        end
        self.character:playSound(CrewLaungage .. "RepairComplete")
    end
    for i = 1, self.vehicle:getPartCount() do
        local part = self.vehicle:getPartByIndex(i - 1)
        local ConditionNow = part:getCondition()
        Panzer:sendVehicleCommandWrapper(self.character, part, "setPartCondition", {
            condition = ConditionNow + 10
        })

    end
    self.character:playSound("track_repair_1")
end

function ISStartPanzerRepairAction:new(character, vehicle)
    local o = {}
    setmetatable(o, self)
    self.__index = self
    o.character = character;
    o.vehicle = vehicle;
    o.stopOnWalk = false;
    local caidan = ZombRand(1, 100)
    o.stopOnRun = true;
    o.maxTime = 1050 - GetAbilityLevel(vehicle, "Repair") * 50;
    return o;
end

