
--定义类
local shaqi = Class(function(self, inst)
	self.inst = inst
	self.current = 50
	self.max = 100
end)

function shaqi:DoDelta(delta)
	local oldval = self.current
	local val = self.current + delta
	if val >= self.max then
		self.current = self.max
	elseif val <= 0 then
		self.current = 0
	else
		self.current = val
	end
	local del = self.current - oldval
	self.inst:PushEvent("shaqi_delta", {val = self.current, oldval = oldval, delta = del})
end

--存档
function shaqi:OnSave()
	return 
	{
		current = self.current,
		max = self.max,
	}
end
function shaqi:OnLoad(data)
	if data then
		self.current = data.current
		self.max = data.max
	end
end


function shaqi:StartZen()
    --local manaResume = TUNING_SAMANSHA.MANA.SANITY
	local hungerResume = 5
	local shaqiRegen = hungerResume / 5
    if self.inst.components.hunger.current < hungerResume then
        return false--,"NOT_SANITY_ENOUGH"
    elseif self.current>=self.max then
        return false--,"MANA_ENOUGH"
    elseif not self.zenTask then
        self.zenTask = self.inst:DoPeriodicTask(1,function()
            if self.inst.components.hunger.current < hungerResume then
                --self.inst:PushEvent("notsanityenough")
				self.inst.components.talker:Say("玲可能也有点饿了!", 2.5,true)
            elseif self.current>=self.max then
                self.inst.components.talker:Say("也许已经到瓶顶了!", 2.5,true)
            else
                self:DoDelta(shaqiRegen)
                self.inst.components.hunger:DoDelta(-hungerResume)
                self.inst.components.health:DoDelta(4)
            end
        end)
        return true
    end
end

function shaqi:StopZen()
    if self.zenTask then
        self.zenTask:Cancel()
        self.zenTask=nil
    end
end



return shaqi