PrivilegeManager = {} local this = PrivilegeManager function this.Initialize() this._PrivilegeInfoList = {} --接收到的后端的特权列表 this._PrivilegeTypeList = {} --从前端特权表中读取的数据,以表中列PrivilegeType为键 end -- 初始化数据 function PrivilegeManager.InitPrivilegeData(data) this._PrivilegeInfoList = {} for i = 1, #data do --[[data:从后端接受到的数据 data是个列表 列表元素的结构id与priviledge的id对应 usedTimes使用次数 endTime 有效时间]] this._PrivilegeInfoList[data[i].id] = { id = data[i].id, usedTimes = data[i].usedTimes, endTime = data[i].effectTime } LogGreen(string.format("特权ID = %s, 使用了的次数 = %s, 结束时间 = %s", data[i].id, data[i].usedTimes, data[i].effectTime)) end this._PrivilegeTypeList = {} local configList = ConfigManager.GetConfig(ConfigName.PrivilegeTypeConfig) for _, config in ConfigPairs(configList) do if not this._PrivilegeTypeList[config.PrivilegeType] then this._PrivilegeTypeList[config.PrivilegeType] = {} end table.insert(this._PrivilegeTypeList[config.PrivilegeType], config) end Game.GlobalEvent:DispatchEvent(GameEvent.Privilege.OnPrivilegeZeroUpdate) end --刷新从后端接收的到的特权表--零点推送用 function PrivilegeManager.FiveAMRefreshLocalData(privilegeList) this.InitPrivilegeData(privilegeList) CheckRedPointStatus(RedPointType.FightLevelDailyReward) end --刷新从后端接收的到的特权表--购买时用 function PrivilegeManager.OnPrivilegeUpdate(data) --LogGreen("后端特权推送:") for i = 1, #data do this._PrivilegeInfoList[data[i].id] = { id = data[i].id, usedTimes = data[i].usedTimes, endTime = data[i].effectTime } LogGreen(string.format("特权ID = %s, 使用了的次数 = %s, 结束时间 = %s", data[i].id, data[i].usedTimes, data[i].effectTime)) -- 发送特权解锁事件 Game.GlobalEvent:DispatchEvent(GameEvent.Privilege.OnPrivilegeUpdate, data[i].id) end end -- 获取服务器数据 function PrivilegeManager.GetSerData(privilegeId) local data = this._PrivilegeInfoList[privilegeId] return data end -- 用于比较副本id的大小 local function _CarbonIdCompare(cId1, cId2) local len1 = string.len(cId1) local diff1 = tonumber(string.sub(cId1, len1, len1)) local id1 = tonumber(string.sub(cId1, 1, len1-1)) local len2 = string.len(cId2) local diff2 = tonumber(string.sub(cId2, len2, len2)) local id2 = tonumber(string.sub(cId2, 1, len2-1)) if diff1 == diff2 then return id1 - id2 end return diff1 - diff2 end -- 判断 cdv2 是否 在cdv1条件下可以解锁 --- type 解锁类型 --- condition 解锁条件 --- value 当前值 local function _CompareCondition(type, condition, value) assert(type, Language[11399]) assert(condition, Language[11400]) if type == 1 then -- 玩家等级解锁 value = value or PlayerManager.level return value >= condition elseif type == 2 then -- 关卡解锁 if value then return _CarbonIdCompare(value, condition) >= 0 else return FightPointPassManager.GetFightStateById(condition) == FIGHT_POINT_STATE.PASS end elseif type == 3 then -- vip等级解锁 value = value or VipManager.GetVipLevel() return value >= condition elseif type == 4 then -- 充值解锁(无论多少金额) return true elseif type == 5 then -- 特殊类型 return true elseif type == 6 then -- 总好感度等级解锁 local _, tlv, _ = LikabilityManager.GetTotalHeroLikeLv(-1) value = value or tlv return value >= condition elseif type == 7 then -- 充值金额解锁 value = value or VipManager.GetChargedNum() return value >= condition elseif type==8 then --开启周卡解锁 return MonthCardManager.GetMonthCardIsOpen(MONTH_CARD_TYPE.MONTHCARD) elseif type==9 then --神尊等级解锁 return GetShenzunLv() >= condition elseif type==10 then --名望特权等级 -- LogError("DynamicActivityManager.curLevel=="..DynamicActivityManager.curLevel.." condition=="..condition) return DynamicActivityManager.curLevel >= condition elseif type==11 then if condition==0 then return true else local id = 2200 + condition+1 LogError("condition===="..condition.." id=="..id) local isBuy = OperatingManager.IsBuyGift(id) if isBuy then LogError("已购买") end return isBuy end elseif type==12 then return GetTaiChuPriLv() >= condition else return false end end --获取特权次数或者收益相关值(纯前端读表) --- value 自定义比较值,为空时使用玩家自己的默认值进行比较, function PrivilegeManager.GetPrivilegeNumberById(privilegeId, value) local privilegeData = ConfigManager.GetConfigData(ConfigName.PrivilegeTypeConfig, privilegeId) local unlockType = privilegeData.UnlockType -- 特殊类型特殊处理 if unlockType == 4 or unlockType == 5 then -- 4类型没有服务器数据不解锁 local serData = this.GetSerData(privilegeId) if not serData then return 0 end -- 判断是否有持续时间 -- 有结束时间,但不在时间范围内 if serData.endTime ~= 0 and serData.endTime < GetTimeStamp() then return 0 end end -- 没有条件直接 直接永远存在 if not privilegeData.Condition then return -1 end -- 判断解锁条件 local tValue = 0 for i = 1, #privilegeData.Condition do local condition = privilegeData.Condition[i] -- 没有条件了 if not condition then break end -- 按照类型比较解锁条件 if not _CompareCondition(unlockType, condition[1], value) then break end -- 保存当前值 tValue = condition[2] -- if privilegeId==4 or privilegeId==33 then -- LogError("tValue==========="..tValue) -- end end -- 根据类型返回相应得数值 if privilegeData.IfFloat == 1 then return tValue elseif privilegeData.IfFloat == 2 then return tValue / 10000 else return tValue / 100 end end --获取特权次数或者收益相关值(纯前端读表) --- value 自定义比较值,为空时使用玩家自己的默认值进行比较, function PrivilegeManager.GetPrivilegeNumber(privilegeType, conValue) local privilegeList = this._PrivilegeTypeList[privilegeType] if not privilegeList then return 0 end local value = 0 -- if privilegeType==4 or privilegeType==33 then -- LogError("privilegeType==========="..privilegeType) -- end for _, config in ipairs(privilegeList) do local privilegeId = config.Id -- if privilegeType==4 or privilegeType==33 then -- LogError("id=============="..privilegeId) -- end local v = this.GetPrivilegeNumberById(privilegeId, conValue) -- -1表示一直存在,无限次数 if v < 0 then return v end -- 所有值相同类型值相加 value = value + v end -- if privilegeType==4 or privilegeType==33 then -- LogError("value=============="..value) -- end return value end --获取某权益已用次数 function PrivilegeManager.GetPrivilegeUsedTimes(privilegeType) local privilegeList = this._PrivilegeTypeList[privilegeType] if not privilegeList then return 0 end local usedTimes = 0 for _, config in ipairs(privilegeList) do local privilegeId = config.Id local serData = this._PrivilegeInfoList[privilegeId] if serData then usedTimes = usedTimes + serData.usedTimes -- LogBlue(string.format("privilegeId:%s, usedTimes:%s",tostring(privilegeId),tostring(serData.usedTimes))) end end return usedTimes end --获取某权益已用次数 function PrivilegeManager.GetPrivilegeUsedTimesById(privilegeId) local serData = this._PrivilegeInfoList[privilegeId] if serData then return serData.usedTimes end return 0 end function PrivilegeManager.SetPrivilegeUsedTimesById(privilegeId,times) local serData = this._PrivilegeInfoList[privilegeId] if serData then serData.usedTimes=serData.usedTimes+times end -- return usedTimes end function PrivilegeManager.SetPrivilegeUsedTimes(privilegeType,times) local privilegeList = this._PrivilegeTypeList[privilegeType] if not privilegeList then return 0 end local usedTimes = 0 for _, config in ipairs(privilegeList) do local privilegeId = config.Id local serData = this._PrivilegeInfoList[privilegeId] if serData then serData.usedTimes=serData.usedTimes+times end end -- return usedTimes end --function PrivilegeManager.GetYiYuan --获取特权次数相关剩余值(前后端数值计算) function PrivilegeManager.GetPrivilegeRemainValue(privilegeType) local originalValue = this.GetPrivilegeNumber(privilegeType) local usedTimes = this.GetPrivilegeUsedTimes(privilegeType) local remainNum = originalValue - usedTimes -- 剩余次数不会小于0,修正 if remainNum < 0 then remainNum = 0 end return remainNum end --刷新已用次数 function PrivilegeManager.RefreshPrivilegeUsedTimes(privilegeType, times) local privilegeList = this._PrivilegeTypeList[privilegeType] if not privilegeList then return end for _, config in ipairs(privilegeList) do local privilegeId = config.Id local serData = this._PrivilegeInfoList[privilegeId] if serData then local maxTimes = this.GetPrivilegeNumberById(privilegeId) local curTimes = serData.usedTimes local finalTimes = curTimes + times times = finalTimes - maxTimes if times <= 0 then this._PrivilegeInfoList[privilegeId].usedTimes = finalTimes break else this._PrivilegeInfoList[privilegeId].usedTimes = maxTimes end end end end --前端重置特权次数 function PrivilegeManager.RefreshStarPrivilege(privilegeType) local privilegeList = this._PrivilegeTypeList[privilegeType] if not privilegeList then return end for _, config in ipairs(privilegeList) do local privilegeId = config.Id local serData = this._PrivilegeInfoList[privilegeId] if serData then this._PrivilegeInfoList[privilegeId].usedTimes = 0 end end end --前端移除某特权 function PrivilegeManager.RemovePrivilege(privilegeType,_privilegeId) local privilegeList = this._PrivilegeTypeList[privilegeType] if not privilegeList then return end for _, config in ipairs(privilegeList) do local privilegeId = config.Id local serData = this._PrivilegeInfoList[privilegeId] if serData and privilegeId == _privilegeId then this._PrivilegeInfoList[privilegeId] = nil end end end --获取某权益是否解锁的状态 function PrivilegeManager.GetPrivilegeOpenStatus(privilegeType, value) -- 判断条件是否符合 local num = this.GetPrivilegeNumber(privilegeType, value) return num ~= 0 end --获取某权益是否解锁的状态 function PrivilegeManager.GetPrivilegeOpenStatusById(privilegeId, value) -- 判断条件是否符合 local num = this.GetPrivilegeNumberById(privilegeId, value) return num ~= 0 end --获取谋权益几级解锁 function PrivilegeManager.GetPrivilegeOpenTip(privilegeType) local privilegeList = this._PrivilegeTypeList[privilegeType] if not privilegeList or #privilegeList == 0 then return Language[11401]..tostring(privilegeType) end --当存在多解锁类型时 -- if #privilegeList>1 then -- local infoList={} --解锁2倍速的处理 -- for i,v in ipairs(privilegeList) do -- if (v.UnlockType==1) and privilegeType==PRIVILEGE_TYPE.DoubleTimesFight then -- for _, con in ipairs(v.Condition) do -- if con[2] > 0 then -- table.insert(infoList, con[1]) -- end -- end -- end -- end -- if privilegeType==PRIVILEGE_TYPE.DoubleTimesFight then -- local lvOpenTimeScaleConFig = ConfigManager.TryGetConfigDataByDoubleKey(ConfigName.PrivilegeTypeConfig,"PrivilegeType",PRIVILEGE_TYPE.DoubleTimesFight,"UnlockType",1) -- -- local fightConfig = ConfigManager.GetConfigData(ConfigName.MainLevelConfig, infoList[1]) -- -- return string.format("通关 %s 关卡解锁或玩家特权等级达到 %s 级解锁",GetLanguageStrById(fightConfig.Name),infoList[2]) -- return string.format(Language[11406],lvOpenTimeScaleConFig.Condition[1][1]) -- end -- end local privilegeData = privilegeList[1] -- 没有条件直接返回0 if not privilegeData.Condition then return Language[11403] end if privilegeData.Type ~= 1 then return Language[11404] end local condition = privilegeData.Condition local v = nil for _, con in ipairs(condition) do if con[2] > 0 then v = con[1] end end if not v then return Language[11405] end if privilegeData.UnlockType == 1 then return string.format(Language[11406], v) elseif privilegeData.UnlockType == 2 then local fightConfig = ConfigManager.GetConfigData(ConfigName.MainLevelConfig, v) return string.format(Language[11407], GetLanguageStrById(fightConfig.Name)) elseif privilegeData.UnlockType == 3 then return string.format(Language[11408], v) end end --功能解锁是否在当前等级 --function PrivilegeManager.IsPrivilegeOpenedCurrentLevel(privilegeId, level) function PrivilegeManager.IsPrivilegeOpenedCurrentValue(privilegeId, value) local privilegeData = ConfigManager.GetConfigData(ConfigName.PrivilegeTypeConfig, privilegeId) assert(privilegeData, string.format("ConfigName.PrivilegeTypeConfig not find Id:%s", privilegeId)) if not privilegeData.Condition then return false end if privilegeData.Condition[1][1] == value then return end end -- 通过vip等级获取相应等级会解锁的特权信息 -- return { -- [1] = { -- content = "", -- value = 0 } -- [2] = ... --} function PrivilegeManager.GetTipsByVipLv(vipLv) local list = {} local configList = ConfigManager.GetAllConfigsDataByKey(ConfigName.PrivilegeTypeConfig, "UnlockType", 3) for _, config in ipairs(configList) do if config.isShowName == 1 then for _, condition in ipairs(config.Condition) do if condition[1] == vipLv then local tValue = condition[2] -- 根据类型返回相应得数值 if config.IfFloat == 1 then tValue = tValue elseif config.IfFloat == 2 then tValue = tValue / 10000 else tValue = tValue / 100 end -- 如果是功能解锁,且解锁 if config.Type == 1 and tValue ~= 0 then tValue = "" end table.insert(list, {content = GetLanguageStrById(config.Name), value = tValue,id = config.Id, IfFloat = config.IfFloat}) break end end end end return list end ---获取神尊特权加成 function PrivilegeManager.GetShenZunAddByLv(_shenzunLv) local list = {} local configList = ConfigManager.GetAllConfigsDataByKey(ConfigName.PrivilegeTypeConfig, "UnlockType", 9) for _, config in ipairs(configList) do if config.isShowName == 1 then for _, condition in ipairs(config.Condition) do if condition[1] == _shenzunLv then local tValue = condition[2] -- 根据类型返回相应得数值 if config.IfFloat == 1 then tValue = tValue elseif config.IfFloat == 2 then tValue = tValue / 10000 else tValue = tValue / 100 end -- 如果是功能解锁,且解锁 if config.Type == 1 and tValue ~= 0 then tValue = "" end table.insert(list, {content = GetLanguageStrById(config.Name), value = tValue,id = config.Id, IfFloat = config.IfFloat}) break end end end end return list end ---获取神尊特权加成 function PrivilegeManager.GetMingWangAddByLv(_shenzunLv) local list = {} local configList = ConfigManager.GetAllConfigsDataByKey(ConfigName.PrivilegeTypeConfig, "UnlockType", 10) for _, config in ipairs(configList) do if config.isShowName == 1 then for _, condition in ipairs(config.Condition) do if condition[1] == _shenzunLv then local tValue = condition[2] -- 根据类型返回相应得数值 if config.IfFloat == 1 then tValue = tValue elseif config.IfFloat == 2 then tValue = tValue / 10000 else tValue = tValue / 100 end -- 如果是功能解锁,且解锁 if config.Type == 1 and tValue ~= 0 then tValue = "" end table.insert(list, {content = GetLanguageStrById(config.Name), value = tValue,id = config.Id, IfFloat = config.IfFloat}) break end end end end return list end -- 获取特权剩余时间(非计时特权返回0) function PrivilegeManager.GetPrivilegeLeftTime(privilegeType) local isActive = this.GetPrivilegeOpenStatus(privilegeType) if isActive then local privilegeList = this._PrivilegeTypeList[privilegeType] if not privilegeList or #privilegeList == 0 then return 0 end for _, pId in ipairs(privilegeList) do local serData = this.GetSerData(pId) if serData and serData > 0 then local leftTime = serData.endTime - GetTimeStamp() if leftTime > 0 then return leftTime end end end end return 0 end -- 获取特权剩余时间(非计时特权返回0) function PrivilegeManager.GetPrivilegeLeftTimeById(privilegeId) local serData = this.GetSerData(privilegeId) if serData and serData.endTime > 0 then local leftTime = serData.endTime - GetTimeStamp() if leftTime > 0 then return leftTime end end return 0 end ------- 部分特殊特权处理 ----------------------- -- 检测是否是特殊特权 --function PrivilegeManager.CheckIsSpecialPrivilege(privilegeId) -- for _, spId in pairs(SPECIAL_PRIVILEGE) do -- if spId == privilegeId then -- return true -- end -- end -- Log("特权id == " .. privilegeId .. ", 不是特殊特权,请检查!") -- return false --end -- 开放某些特权 --function PrivilegeManager.OpenSpecialPrivilege(privilegeId) -- -- 检测是否是特殊特权 -- if not this.CheckIsSpecialPrivilege(privilegeId) then -- return -- end -- -- 检测特权是否存在 -- local serData = this._PrivilegeInfoList[privilegeId] -- if serData then return end -- this._PrivilegeInfoList[privilegeId] = { -- id = privilegeId, -- usedTimes = 0, -- endTime = 0 -- } --end -- 获取特权状态(true 开启,false 未开启) --function PrivilegeManager.GetSpecialPrivilegeStatus(privilegeId) -- -- 检测是否是特殊特权 -- if not this.CheckIsSpecialPrivilege(privilegeId) then -- return false -- end -- -- -- local serData = this._PrivilegeInfoList[privilegeId] -- if serData then -- return true -- end -- return false --end return this