local OperationActivityData = {} local private = {} local EventSystem = require('Event/EventSystem') private.operationActivityData = {} --经过加工,将源数据转化为K-V结构 private.operationActivitySourceData = {} --源数据,一般为数组 private.operationActivityEntry = {} --http://confluence.taiyouxi.net/pages/viewpage.action?pageId=42733218 --客户端手写常量,遍历此表,去Proto结构中寻找并处理相应的数据 --key值为客户端自定义的值,调用的时候使用的字段名 --protoName为proto结构中的字段名,用来去proto中找数据 --primaryKey为表结构中的主键字段名 --isCacheSourceData 是否需要缓存服务器的源数组结构数据,用于遍历数组数据用,默认不开启 --注意双主键 需要配置第二个id local OperationActivitySheetName = { HotControlInfo = {protoName = "hotControlInfo", primaryKey = {"ActivityType", "ActivityID"}}, HotGenCondID = {protoName = "hotGenCondID", primaryKey = {"CondID"}}, CommonGiftReward = {protoName = "hotGiftInfo", primaryKey = {"ID"}}, --通用礼包奖励 --商店相关:由策划表改成服务器推送 StoreGoodsData = { protoName = "storeGoodsData", primaryKey = { "ID" }, isCacheSourceData = true }, StoreGoodsLimitBuyDetail = { protoName = "storeGoodsLimitBuyDetail", primaryKey = { "ID", "BuyLimit" }, isCacheSourceData = true }, StoreTypeData = { protoName = "storeTypeData", primaryKey = { "TabID" }, isCacheSourceData = true }, -- 聊天房间 CrossServerChatRoom = {protoName = "crossServerChatRoom", primaryKey = {"ID"}, isCacheSourceData = true}, TVTTestHero = {protoName = "testHero", primaryKey = {"HeroItemID"}, isCacheSourceData = true}, -- TVT 测试武将静态数据 HotTimeRefresh = {protoName = "hotTimeRefresh", primaryKey = {"ID"}, isCacheSourceData = true}, -- 热更TimeRefresh -- 阶段签到 StageSignIn = {protoName = "hot2StageSignIn", primaryKey = {"ActivityID", "StageID"}}, -- 霸业之始 HegemonyBackGround = {protoName = "hot3BackGround", primaryKey = {"ActivityID"}}, HegemonyParam = {protoName = "hot3Param", primaryKey = {"ActivityID", "StageID", "PageID", "NumID"}}, HegemonyTab = {protoName = "hot3Tab", primaryKey = {"ActivityID", "GroupID", "StageID", "PageID"}}, HegemonyPoints = {protoName = "hot3Points", primaryKey = {"ActivityID", "GroupID", "StageID"}}, -- 礼包 PushGiftData = {protoName = "hot5PushGift", primaryKey = {"ActivityID", "ID"}}, -- 大富翁 MonopolyPointType = {protoName = "hot7PointType", primaryKey = {"ActivityID", "PointID"}}, MonopolyPointReward = {protoName = "hot7PointReward", primaryKey = {"ActivityID","PointType"}}, MonopolyLoopReward = {protoName = "hot7LoopReward", primaryKey = {"ActivityID","LoopID"}}, -- 战令 HonorOrderConst = {protoName = "hot8Const", primaryKey = {"ActivityID", "ID"}}, -- 战令常量表 HonorOrderReward = {protoName = "hot8Reward", primaryKey = {"ActivityID", "HonorOrderID", "RewardID"}}, -- 战令等级奖励表 HonorOrderTargetPointDaily = {protoName = "hot8TargetPointDaily", primaryKey = {"ActivityID", "ID"}}, -- 战令每日挑战表 HonorOrderTargetPointCycle = {protoName = "hot8TargetPointCycle", primaryKey = {"ActivityID", "ID", "Type"}}, -- 战令周期挑战表 -- 饲育大师 HorseRearLevel = {protoName = "hot10RearLevel", primaryKey = {"ActivityID", "Level"}}, -- 养马等级表 HorseRearEvent = {protoName = "hot10RearEvent", primaryKey = {"ActivityID", "EventID"}}, -- 喂马事件表 -- 号令天下 CommandWorldRelation = {protoName = "hot11Integral", primaryKey = {"ActivityID", "ItemID"}}, --号令天下-道具货币对应关系 CommandWorldLevelReward = {protoName = "hot11LevelReward", primaryKey = {"ActivityID","Level"}}, --号令天下-宝箱等级奖励 CommandWorldLocalRanking = {protoName = "hot11LocalRanking", primaryKey = {"ActivityID","RankID"}}, --号令天下-本服排行奖励。 CommandWorldRankParam = {protoName = "hot11RankParam", primaryKey = {"ActivityID","RankType"}}, --号令天下-榜单参数 CommandWorldStore = {protoName = "hot11Store", primaryKey = {"ActivityID","ID"}}, --号令天下-商城 CommandWorldTaskReward = {protoName = "hot11TaskReward", primaryKey = {"ActivityID","ID"}}, --号令天下-任务奖励 CommandWorldTimAxis = {protoName = "hot11TimAxis", primaryKey = {"ActivityID"}}, --号令天下-时间轴 CommandWorldWarZoneRanking = {protoName = "hot11WarZoneRanking", primaryKey = {"ActivityID","RankID"}}, --号令天下-跨服排行奖励 CommandWorldWarZoneRanking = {protoName = "hot11WarZoneRanking", primaryKey = {"ActivityID","RankID"}}, --号令天下-跨服榜单 --幸运扭蛋 LuckyLotteryOptionalReward = {protoName = "hot15OptionalReward", primaryKey = {"ActivityID", "ID"}}, LuckyLotteryAccumulationReward = {protoName = "hot15AccumulationReward", primaryKey = {"ActivityID", "ID"}}, LuckyLotteryModeData = {protoName = "hot15BackGround", primaryKey = {"ActivityID"}}, LuckyLotteryDrawCost = {protoName = "hot15DrawExpend", primaryKey = {"ActivityID", "ID"}}, --新年活动 NewYearLoginReward = {protoName = "hot16LoginReward", primaryKey = {"ActivityID", "Day"}}, NewYearLuckyBag = {protoName = "hot16LuckyBag", primaryKey = {"ActivityID", "ID"}}, -- 大拍卖 WarZoneAuction = {protoName = "hot18WarZoneAuctionProduct", primaryKey = {"ActivityID", "AuctionID"}, isCacheSourceData = true}, -- 大拍卖(战区拍卖) -- 周年预热 AnniversaryPrepareReward = {protoName = "hot19Reward", primaryKey = {"ActivityID", "ID"}, isCacheSourceData = true}, -- 周年预热——进度奖励表 AnniversaryPrepareFireReward = {protoName = "hot19FireReward", primaryKey = {"ActivityID"}}, -- 周年预热——燃放奖励预览 -- 招财聚宝 TreasureBowlReward = {protoName = "hot20Reward", primaryKey = {"ActivityID", "ID"}}, -- 金兰之邀(组队充值) FriendRechargeBackGround2 = {protoName = "hot21BackGround2", primaryKey = {"ActivityID", "ModeType"}}, FriendRechargeReward = {protoName = "hot21Reward", primaryKey = {"ActivityID", "Level"}}, -- 红包雨 RedEnvelopeRainDailyRank = {protoName = "hot22DailyRank", primaryKey = {"ActivityID", "ID"}, isCacheSourceData = true}, -- 红包雨每日排行奖励显示 RedEnvelopeRainTotalRank = {protoName = "hot22TotalRank", primaryKey = {"ActivityID", "ID"}, isCacheSourceData = true}, -- 红包雨总排行奖励显示 RedEnvelopeRainReChargeReward = {protoName = "hot22ReChargeReward", primaryKey = {"ActivityID", "ID"}}, -- 红包雨充值转换 RedEnvelopeRainReward = {protoName = "hot22RedEnvelopeRainReward", primaryKey = {"ActivityID", "ServerNum", "ID"}, isCacheSourceData = true}, -- 红包雨红包上下限数据 -- 节日签到 FestivalLoginReward = {protoName = "hot23LoginReward", primaryKey = {"ActivityID", "Day"}}, --聚宝赠礼(周期累充) CycleRecharge = {protoName = "hot24CycleRechargeReward", primaryKey = {"ActivityID", "ID"}}, -- 转盘 TurntableItem = { protoName = "hot32Group", primaryKey = { "ActivityID", "ID" } }, TurntableBackGround = { protoName = "hot32BackGround", primaryKey = { "ActivityID" } }, TurntableTotalAward = { protoName = "hot32TotalAward", primaryKey = { "ActivityID", "ID" } }, TurntableRewardShow = { protoName = "hot32CasinoShow", primaryKey = { "ActivityID", "ShowID" } }, -- 神兽活动 GodBeastLevel = {protoName = "hot26RearLevel", primaryKey = {"ActivityID", "Level"}}, -- 神兽活动——等级表 GodBeastEvent = {protoName = "hot26RearEvent", primaryKey = {"ActivityID", "EventID"}}, -- 神兽活动——事件表 -- 日服金将复刻活动热更数据 GoldHeroReprintShowHero = {protoName = "hot10004HeroShow", primaryKey = {"ActivityID", "OrderID"}}, -- up武将 -- 版本更新活动 FunctionUpdateNotice = {protoName="hot27BackGround",primaryKey = {"ActivityID"}}, --周期累充活动 WeekCycleRecharge = {protoName = "hot30Reward", primaryKey = {"ActivityID", "StageID"}}, MonthCycleRecharge = {protoName = "hot31Reward", primaryKey = {"ActivityID", "StageID"}}, -- 渠道专属充值返利活动 DouYinRechargeReward = {protoName="hot33BackGround",primaryKey = {"ActivityID"}}, RecallGiftReward = {protoName="hot34Gift",primaryKey = {"ActivityID", "ID"}}, --主题月活动 SubjectMonth = {protoName="hot35BackGround",primaryKey = {"ActivityID"}}, } --此表作为通过ActivityType拆分具有相同结构的表,在使用上更为通用 --一般在OperationActivityCombineSheet中的表都含有一个主键ActivityType local OperationActivityCombineSheet = { --使用时的表名 DirectGiftData = { combineSheet = { --protoName为proto结构中的字段名,combineKeyValue一般为ActivityType {protoName = "hot4DirectGift", combineKeyValue = 4}, {protoName = "hot7DirectGift", combineKeyValue = 7}, {protoName = "hot9DirectGift", combineKeyValue = 9}, {protoName = "hot10DirectGift", combineKeyValue = 10}, {protoName = "hot11DirectGift", combineKeyValue = 11}, {protoName = "hot12DirectGift", combineKeyValue = 12}, {protoName = "hot13FreeBuy", combineKeyValue = 13}, {protoName = "hot15DirectGift", combineKeyValue = 15}, {protoName = "hot16DirectGift", combineKeyValue = 16}, {protoName = "hot26DirectGift", combineKeyValue = 26}, {protoName = "hot32DirectGift", combineKeyValue = 32}, {protoName = "hot10004DirectGift", combineKeyValue = 10004}, }, primaryKey = {"ActivityID", "HotPackageID"} }, ActivityBaseData = { combineSheet = { {protoName = "hot4BackGround", combineKeyValue = 4}, {protoName = "hot7BackGround", combineKeyValue = 7}, {protoName = "hot10BackGround", combineKeyValue = 10}, {protoName = "hot12BackGround", combineKeyValue = 12}, {protoName = "hot16BackGround", combineKeyValue = 16}, {protoName = "hot19BackGround", combineKeyValue = 19}, {protoName = "hot21BackGround", combineKeyValue = 21}, {protoName = "hot23BackGround", combineKeyValue = 23}, {protoName = "hot26BackGround", combineKeyValue = 26}, {protoName = "hot32BackGround", combineKeyValue = 32}, {protoName = "hot10004BackGround", combineKeyValue = 10004}, -- 日服金将复刻活动热更数据 {protoName = "hot35BackGround", combineKeyValue = 35}, }, primaryKey = {"ActivityID"} }, TaskRewardData = { combineSheet = { {protoName = "hot7TaskReward", combineKeyValue = 7}, {protoName = "hot10TaskReward", combineKeyValue = 10}, {protoName = "hot11TaskReward", combineKeyValue = 11}, {protoName = "hot16TaskReward", combineKeyValue = 16}, {protoName = "hot19TaskReward", combineKeyValue = 19}, {protoName = "hot21TaskReward", combineKeyValue = 21}, {protoName = "hot26TaskReward", combineKeyValue = 26}, }, primaryKey = {"ActivityID", "ID"} }, } --region -- **************** Local方法 ******************* -- local select = select local rawset = rawset local rawget = rawget local type = type local function GetDataByKey(self, ...) local count = select('#', ...) local data = rawget(private.operationActivityData, self) for i = 1, count do local key = select(i,...) if type(data) == "table" then data = data[key] end end return data end local function GetMethodName(primaryKey) local count = #primaryKey local name = string.format("GetDataBy%s", primaryKey[1]) if count > 1 then for i = 2, count do local key = primaryKey[i] name = string.format("%s_%s", name, key) end end return name end local function IpairsValue(tab, i) i = i + 1 local data = tab[i] if data then return i, tab[i] else return nil end end local baseMT = { __index = function(t, k) local data = rawget(t, k) if data then return t[k] end end, __newindex = function() error("Attempt to modify read-only table ") end } local commonDataMT = { __newindex = function() logging.error(LTAG.ERROR, "Attempt to modify read-only table") end } --endregion -- **************** Local方法 ******************* -- --region -- **************** OperationActivityEntryMT ******************* -- local OperationActivityEntryMT = {} OperationActivityEntryMT.__index = OperationActivityEntryMT --获取数据的个数 function OperationActivityEntryMT:GetDataCount() local data = rawget(private.operationActivityData, self) return #data end --获取某个实例ID对应的数据长度(较为常用) function OperationActivityEntryMT:GetDataLengthByActivityID(ActivityID) local data = rawget(private.operationActivityData, self) local activityData = data[ActivityID] or {} return #activityData end --迭代整个数组数据 function OperationActivityEntryMT:GetEnumerator() local data = rawget(private.operationActivitySourceData, self) if data then return IpairsValue, data, 0 end end --迭代某个实例ID对应的整个数组数据(较为常用) function OperationActivityEntryMT:GetEnumeratorByActivityID(ActivityID) local data = rawget(private.operationActivityData, self) local activityData = data[ActivityID] or {} return IpairsValue, activityData, 0 end --endregion -- **************** OperationActivityEntryMT ******************* -- function OperationActivityData.GetDataEntry() return private.operationActivityEntry end --通过上面的枚举处理服务器发过来的proto消息 function OperationActivityData.SetData(data) if IsServerDataNotNil(data) then for sheetName, constValue in pairs(OperationActivitySheetName) do local name = constValue.protoName if IsServerDataNotNil(data[name]) then private.ProcessDataAndFunc(data[name].items, sheetName, constValue.primaryKey, constValue.isCacheSourceData) end end for sheetName, constValue in pairs(OperationActivityCombineSheet) do private.ProcessCombineDataAndFunc(data, constValue.combineSheet, sheetName, constValue.primaryKey) end end end function private.ProcessCombineDataAndFunc(serverData, combineSheetData, sheetName, primaryKey) local funcTable = private.operationActivityEntry[sheetName] or {} for _, combineSheet in ipairs(combineSheetData) do local name = combineSheet.protoName if IsServerDataNotNil(serverData[name]) then local processData = {} local sheetData = serverData[name].items local count = #primaryKey if count == 1 then for i, v in ipairs(sheetData) do private.LocalizationContent(v) processData[v[primaryKey[1]]] = v end else for index, data in ipairs(sheetData) do private.InsertData(data, processData, 1, count, primaryKey) end end if funcTable[combineSheet.combineKeyValue] then rawset(private.operationActivityData, funcTable[combineSheet.combineKeyValue], nil) end local dataEntry = setmetatable({[GetMethodName(primaryKey)] = GetDataByKey}, OperationActivityEntryMT) rawset(private.operationActivityData, dataEntry, setmetatable(processData, baseMT)) funcTable[combineSheet.combineKeyValue] = dataEntry end end rawset(private.operationActivityEntry, sheetName, funcTable) end function private.ProcessDataAndFunc(sheetData, sheetName, primaryKey, isCacheSourceData) local processData = {} local count = #primaryKey if count == 1 then for i, v in ipairs(sheetData) do private.LocalizationContent(v) processData[v[primaryKey[1]]] = v end else for index, data in ipairs(sheetData) do private.InsertData(data, processData, 1,count, primaryKey) end end private.RemoveData(sheetName) local dataEntry = setmetatable({[GetMethodName(primaryKey)] = GetDataByKey}, OperationActivityEntryMT) rawset(private.operationActivityData, dataEntry, setmetatable(processData, baseMT)) if isCacheSourceData == true then rawset(private.operationActivitySourceData, dataEntry, sheetData) end rawset(private.operationActivityEntry, sheetName, dataEntry) end function private.InsertData(lineData, processData, index, keyCount, primaryKey) if index > keyCount then return elseif index == keyCount then local keyValue = lineData[primaryKey[index]] --本地化处理 private.LocalizationContent(lineData) processData[keyValue] = lineData else local keyValue = lineData[primaryKey[index]] local table = processData[keyValue] if table == nil then table = {} processData[keyValue] = table end private.InsertData(lineData, table, index + 1, keyCount, primaryKey) end end function private.RemoveData(sheetName) local dataEntry = private.operationActivityEntry[sheetName] if dataEntry then rawset(private.operationActivityData, dataEntry, nil) rawset(private.operationActivityEntry, sheetName, nil) end end --暂时在初始化的时机解析多语言的内容 --考虑每行数据的每个本地化文本字段都需要json解析,而且数据量大,后期需要考虑优化 function private.LocalizationContent(lineData) private.LocalizationLineData(lineData, "Name") private.LocalizationLineData(lineData, "ActivityName") private.LocalizationLineData(lineData, "PushTabName") private.LocalizationLineData(lineData, "DisplayFirstPath") private.LocalizationLineData(lineData, "DisplaySecondPath") private.LocalizationLineData(lineData, "DisplayIconPath") private.LocalizationLineData(lineData, "PredictionText") private.LocalizationLineData(lineData, "HotPackageName") --0元购礼包页签名 end function private.LocalizationLineData(lineData, property) local json = lineData[property] if json then lineData[property] = Localization.GetOperationActivityLabel(json) end end function OperationActivityData.ClearData() private.operationActivityData = {} private.operationActivityEntry = {} end return setmetatable(OperationActivityData, commonDataMT)