
local Failill = Class(function(self, inst)
    self.inst = inst
    self.maxtime = 3 * TUNING.TOTAL_DAY_TIME  +math.random(100) + 60
	self.time = self.maxtime
	self.diulei = 30
	self.resistance = 5 * TUNING.TOTAL_DAY_TIME
	self.medre = 0
	self.task = nil
	self.Illt = function()end
    --self.inst:ListenForEvent("percentusedchange", PercentChanged)
end)

function Failill:OnSave()
    return {time = self.time,
			resistance = self.resistance,
			medre = self.medre}
end

function Failill:OnLoad(data)
    if data.time then
        self.time = data.time
		self.resistance = data.resistance
		self.medre = data.medre
    end
end

function  Failill:SetResi(resistance)
	self.resistance = resistance
end

function Failill:GetResi()
	print(self.resistance)
	return self.resistance
end

function Failill:SetDiulei(diulei)
	self.diulei = diulei
end

function Failill:GetMedre()
	print(self.medre)
	return self.medre
end

function  Failill:GetTime()
	print(self.time)
	return self.time
end

function Failill:SetIll(fn)
	self.Illt = fn
end

function Failill:TestIll()
	if self.time <= 0 then 
	return true
	end
	return false
end

function Failill:DoIll()
	if self.inst.components.combat then 
		self.inst.components.health:DoDelta(-0.2 * self.diulei)
		self.inst:DoTaskInTime(0.3,function()self.inst.components.health:DoDelta(-0.3 * self.diulei)
		self.inst:DoTaskInTime(0.4,function()self.inst.components.health:DoDelta(-0.5 * self.diulei)end)end)
	end
	if self.inst.components.talker then
		self.inst.components.talker:Say(STRINGS.VERA.FAILILL,5,true)
	end
	self.Illt(self.inst)
	self.time = self.maxtime
end

function Failill:StartIll()
	self.task = self.inst:DoPeriodicTask(1,function()
	if self.resistance > 0 then
	self.resistance = self.resistance -1-self.medre
		if self.medre < 2 then
		self.medre = self.medre + 0.003
		end
	else
	self.time = self.time -1
	end
		if self:TestIll() then 
			self:DoIll()
		end
	end)
 end

function Failill:StopIll()
	self.task:Cancel()
end
 
return Failill
