147 lines
		
	
	
		
			5.5 KiB
		
	
	
	
		
			Lua
		
	
			
		
		
	
	
			147 lines
		
	
	
		
			5.5 KiB
		
	
	
	
		
			Lua
		
	
AutoRecoverManager = {}
 | 
						|
local this = AutoRecoverManager
 | 
						|
local GameSetting = ConfigManager.GetConfigData(ConfigName.GameSetting, 1)
 | 
						|
--- 注册物品及其获取恢复时间的方法
 | 
						|
local _TimeCheckFunc = {
 | 
						|
    [UpViewRechargeType.EliteCarbonTicket] = function()
 | 
						|
        local ownNumber = BagManager.GetItemCountById(UpViewRechargeType.EliteCarbonTicket)
 | 
						|
        return CarbonManager.remainTime
 | 
						|
    end,
 | 
						|
    -- [UpViewRechargeType.MonsterCampTicket] = function()
 | 
						|
    --     if MonsterCampManager.IsNeedSupply() then
 | 
						|
    --         local nextFreshTime = BagManager.bagDatas[UpViewRechargeType.MonsterCampTicket].nextFlushTime
 | 
						|
    --         local remationTime = nextFreshTime - PlayerManager.serverTime
 | 
						|
    --         return remationTime
 | 
						|
    --     else -- 数量已满返回 -1
 | 
						|
    --         return -1
 | 
						|
    --     end
 | 
						|
    -- end,
 | 
						|
    [UpViewRechargeType.AdventureAlianInvasionTicket] = function()
 | 
						|
        local curCount = BagManager.GetItemCountById(UpViewRechargeType.AdventureAlianInvasionTicket)
 | 
						|
        local maxCount = PrivilegeManager.GetPrivilegeNumber(9)
 | 
						|
        local itemData = BagManager.GetItemById(UpViewRechargeType.AdventureAlianInvasionTicket)
 | 
						|
        if not itemData then
 | 
						|
            return
 | 
						|
        end
 | 
						|
        if curCount < maxCount then
 | 
						|
            local nextFreshTime = itemData.nextFlushTime
 | 
						|
            local remationTime = nextFreshTime - PlayerManager.serverTime
 | 
						|
            if remationTime >= 0 then
 | 
						|
                return remationTime
 | 
						|
            end
 | 
						|
            -- 需要刷新数量
 | 
						|
            return -2
 | 
						|
        else -- 数量已满返回 -1
 | 
						|
            return -1
 | 
						|
        end
 | 
						|
    end,
 | 
						|
    [UpViewRechargeType.ActPower] = function()
 | 
						|
        local curCount = EndLessMapManager.GetLeftMapEnergy()
 | 
						|
        local itemData = BagManager.GetItemById(UpViewRechargeType.ActPower)
 | 
						|
        if not itemData then
 | 
						|
            return
 | 
						|
        end
 | 
						|
        
 | 
						|
            local nextFreshTime = itemData.nextFlushTime
 | 
						|
            local remationTime = nextFreshTime - PlayerManager.serverTime
 | 
						|
            --LogGreen("itemData.nextFlushTime:"..itemData.nextFlushTime.."       remationTime:"..remationTime)
 | 
						|
            if remationTime > 0 then
 | 
						|
                return remationTime
 | 
						|
            end
 | 
						|
            return -2
 | 
						|
    end,
 | 
						|
    [UpViewRechargeType.Energy] = function()
 | 
						|
        local curCount = BagManager.GetItemCountById(UpViewRechargeType.Energy)
 | 
						|
        local maxCount = PlayerManager.userLevelData[PlayerManager.level].MaxEnergy
 | 
						|
        if curCount < maxCount then
 | 
						|
            local nextFreshTime = BagManager.bagDatas[UpViewRechargeType.Energy].nextFlushTime
 | 
						|
            local remationTime = nextFreshTime - PlayerManager.serverTime   -- 下一次刷新的时间
 | 
						|
 | 
						|
            -- 计算从下一次刷新到恢复满得时间
 | 
						|
            local gameSetting = ConfigManager.GetConfigData(ConfigName.GameSetting, 1)
 | 
						|
            local recoverNum = gameSetting.EnergyRecoverSpeed[1]
 | 
						|
            local recoverTime = gameSetting.EnergyRecoverSpeed[2]
 | 
						|
            local fullTime = math.floor((maxCount - curCount) / recoverNum - 1) * recoverTime * 60
 | 
						|
 | 
						|
            return remationTime + fullTime
 | 
						|
        else -- 数量已满返回 -1
 | 
						|
            return -1
 | 
						|
        end
 | 
						|
    end,
 | 
						|
    [UpViewRechargeType.YunYouVle] = function()   --逍遥游云游值倒计时
 | 
						|
        local curCount = BagManager.GetItemCountById(UpViewRechargeType.YunYouVle)
 | 
						|
        local maxCount = PrivilegeManager.GetPrivilegeNumber(39)
 | 
						|
        local itemData = BagManager.GetItemById(UpViewRechargeType.YunYouVle)
 | 
						|
        if not itemData then
 | 
						|
            return
 | 
						|
        end
 | 
						|
        if curCount < maxCount then
 | 
						|
            local nextFreshTime = itemData.nextFlushTime
 | 
						|
            local remationTime = nextFreshTime - PlayerManager.serverTime   -- 下一次刷新的时间            
 | 
						|
            if remationTime > 0 then
 | 
						|
                return remationTime
 | 
						|
            end
 | 
						|
            -- 需要刷新数量
 | 
						|
            return -2
 | 
						|
        else -- 数量已满返回 -1
 | 
						|
            return -1
 | 
						|
        end
 | 
						|
    end,
 | 
						|
    
 | 
						|
}
 | 
						|
 | 
						|
 | 
						|
-- 
 | 
						|
 | 
						|
function this.Initialize()
 | 
						|
    local _ItemAdd = {}
 | 
						|
    for _, data in ipairs(GameSetting.ItemAdd) do
 | 
						|
        table.insert(_ItemAdd, data)
 | 
						|
    end
 | 
						|
    
 | 
						|
    Timer.New(function()
 | 
						|
        for i = 1, #_ItemAdd do
 | 
						|
            local data = _ItemAdd[i]
 | 
						|
            local itemId = data[1]
 | 
						|
            local deltaNum = data[2]
 | 
						|
            local deltaTime = data[3]
 | 
						|
            if this.IsAutoRecover(itemId) then
 | 
						|
                local leftTime = this.GetRecoverTime(itemId)
 | 
						|
                -- 已满不需要刷新
 | 
						|
                -- 
 | 
						|
                if leftTime == -2 then
 | 
						|
                    BagManager.bagDatas[itemId].num = BagManager.bagDatas[itemId].num + deltaNum
 | 
						|
                    BagManager.bagDatas[itemId].nextFlushTime = BagManager.bagDatas[itemId].nextFlushTime + deltaTime
 | 
						|
 | 
						|
                    Log("自动恢复物品数量刷新:"..itemId.."|"..BagManager.bagDatas[itemId].num.."|"..BagManager.bagDatas[itemId].nextFlushTime)
 | 
						|
                end
 | 
						|
            end
 | 
						|
        end
 | 
						|
    end, 1, -1, true):Start()
 | 
						|
end
 | 
						|
 | 
						|
-- 获取道具是否自动恢复
 | 
						|
function AutoRecoverManager.IsAutoRecover(itemId)
 | 
						|
    if not _TimeCheckFunc[itemId] then
 | 
						|
        return false
 | 
						|
    end
 | 
						|
    return true
 | 
						|
end
 | 
						|
 | 
						|
-- 获取道具恢复时间
 | 
						|
function AutoRecoverManager.GetRecoverTime(itemId)
 | 
						|
    if not _TimeCheckFunc[itemId] then
 | 
						|
        assert(false, Language[11392].. itemId)
 | 
						|
    end
 | 
						|
    return _TimeCheckFunc[itemId]()
 | 
						|
end
 | 
						|
 | 
						|
function AutoRecoverManager.CostRecoverItem(itemId, num, maxNum)
 | 
						|
    if this.IsAutoRecover(itemId) then
 | 
						|
        local curCount = BagManager.GetItemCountById(itemId)
 | 
						|
        if curCount >= maxNum then
 | 
						|
        end
 | 
						|
    end
 | 
						|
end
 | 
						|
 | 
						|
return this |