local ProtocolZhanJiGame = class("ProtocolZhanJiGame", require("luaScript.Protocol.ProtocolZhanJi")) --[[ 子游戏战绩协议父类 构造的时候传入子游戏的ID,和战绩保存的文件名 获取最新战绩的时候调用类型和页数,大多数游戏是不需要传参数的 --]] local InterfaceKey = { idx = "gamb.idx", -- 获取战绩ID列表 } function ProtocolZhanJiGame:ctor(gameId, fileName) ProtocolZhanJiGame.super.ctor(self); self.zhanJiIdxs = {} self.otherIdxs = {} self.gameId = gameId self.fileName = fileName; self.shareUrl = "http://m.xiaopengol.com/replay.php" --分享战绩链接 self:loadFromFile() end function ProtocolZhanJiGame:init() ProtocolZhanJiGame.super.init(self) self:getIdxList() end -- 获取最新的战绩列表的key_list function ProtocolZhanJiGame:getIdxList(mode, page) local tt = { action = InterfaceKey.idx, -- 接口名 app = getAppId(), -- appId uid = app.user.loginInfo.uid, -- userId gameid = self.gameId, -- gameId mode = mode or 0, -- 玩法类型,黄十八使用到,默认为0既无特殊玩法 page = page or 1, -- 页码 } logD("ProtocolZhanJiGame:getIdxList()", table.tostring(tt)) httpPost(self.phpUrl, tt, function(status, response) self:getIdxlistResponse(status, response, page) end); end -- 获取战绩ID列表的回复 -- 并和本地数据进行比较,找出本地未下载的部分进行下载 function ProtocolZhanJiGame:getIdxlistResponse(status, response, page) logD("ProtocolZhanJiGame:getIdxlistResponse()", status, response) local ret, ttResult = checkPhpResponse(status, response) if not ret then logE("ProtocolZhanJiGame:getIdxlistResponse()", tostring(ttResult)) return end local page = ttResult.page local tpage = ttResult.tpage self.tpage = tpage; -- 只保存属于自己的战绩 local myUid = app.user.loginInfo.uid if not self.zhanJiIdxs[myUid] then self.zhanJiIdxs[myUid] = {} end local idxs = {} for k,pid in pairs(ttResult.idx) do table.insert(idxs, pid) end self.zhanJiIdxs[myUid] = idxs; if ttResult.url and ttResult.url~="" then self.shareUrl = ttResult.url end self:checkAndDownload(ttResult.idx); end -- 获取属于自己的战绩 function ProtocolZhanJiGame:getZhanJiList() -- 首先找到对应的 idx_list local myUid = app.user.loginInfo.uid if not self.zhanJiIdxs[myUid] then return {} end local function sortFuncEx(a,b) local numA = toNumber(a.endtime) local numB = toNumber(b.endtime) if numA ~= nil and numB ~= nil then return numA > numB else return a > b end end local zhanjiList = {} local idx_list = self.zhanJiIdxs[myUid] for _,pid in pairs(idx_list) do if self.zhanjiInfoList[pid] then table.insert(zhanjiList,self.zhanjiInfoList[pid]) end end table.sort(zhanjiList,sortFuncEx) return zhanjiList; end function ProtocolZhanJiGame:requestOtherZhanji(idx) local idxs = {} if idx then table.insert(idxs,idx) -- self.lastSearchIdx = idx table.insert(self.otherIdxs,idx) end if #self.otherIdxs==0 then return end self:checkAndDownload(idxs) end function ProtocolZhanJiGame:getZhanJiListOther() local zhanjiList = {} local function sortFuncEx(a,b) local numA = toNumber(a.endtime) local numB = toNumber(b.endtime) if numA ~= nil and numB ~= nil then return numA > numB else return a > b end end local idx_list = self.zhanJiIdxs[myUid] for _,pid in pairs(self.otherIdxs) do if self.zhanjiInfoList[pid] then table.insert(zhanjiList,self.zhanjiInfoList[pid]) end end table.sort(zhanjiList,sortFuncEx) return zhanjiList; end return ProtocolZhanJiGame;