
--[[
    *
    * Author: Fei Xiong
    * Date: 2016/10/19
    * Time: 3:32
    *
    * 妖力
    *
    *
--]]
local function oncurrent(self,current)
    self.inst.currentmana:set(current)
end
local Mana = Class(function(self, inst)
    self.inst = inst
    self.max = 200
    self.current = 50
    self:DoInit()
end,
nil,
{
    current = oncurrent
})

function Mana:OnSave()
    local data = {
        current = self.current,
    }
    return data
end

function Mana:OnLoad(data)
    self.current = data.current or self.max
end
--百分比
function Mana:GetPercent()
    return self.current / self.max
end

function Mana:DoInit()

end

function Mana:DoDelta(delta)
    self.current = math.clamp(self.current + delta, 0, self.max)
    return self.current
end

function Mana:StartZen()
    --local manaResume = TUNING_SAMANSHA.MANA.SANITY
	local hungerResume = 5
	local manaRegen = 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(manaRegen)
                self.inst.components.hunger:DoDelta(-hungerResume)
                self.inst.components.health:DoDelta(4)
            end
        end)
        return true
    end
end

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

return Mana