diff --git a/src/ProtocolCode.lua b/src/ProtocolCode.lua index 077cf00..708cb74 100644 --- a/src/ProtocolCode.lua +++ b/src/ProtocolCode.lua @@ -79,6 +79,11 @@ actionCodes = { Diner_expediteSellRpc = 310, Diner_getGreenhouseRpc = 311, + Tower_roleFormatRpc = 350, + Tower_startBattleRpc = 351, + Tower_endBattleRpc = 352, + Tower_rankRpc = 353, + Car_makePotionRpc = 400, Car_equipUpRpc = 401, Car_runeUpRpc = 402, diff --git a/src/actions/TowerAction.lua b/src/actions/TowerAction.lua new file mode 100644 index 0000000..184c89f --- /dev/null +++ b/src/actions/TowerAction.lua @@ -0,0 +1,107 @@ +local ipairs = ipairs +local table = table +local math = math +local redisproxy = redisproxy +local MsgPack = MsgPack + + +local _M = {} + + +function _M.roleFormatRpc(agent , data) + local role = agent.role + local msg = MsgPack.unpack(data) + local towerTeam = role:getProperty("towerF") + for slot, heroId in pairs(msg.heros) do + if not role.heros[heroId] then + return + end + end + table.clear(towerTeam) + towerTeam.heros = {} + for slot, heroId in pairs(msg.heros) do + towerTeam.heros[slot] = heroId + end + towerTeam.leader = msg.leader + + role:updateProperty({field = "towerF", value = towerTeam}) + SendPacket(actionCodes.Tower_roleFormatRpc, '') + return true +end + + +local function getUpdateTime(lastCount, lastTime) + local nextCount, nextTime = lastCount, skynet.timex() + if lastTime then + local addCount = math.floor((skynet.timex() - lastTime) / (globalCsv.tower_count_up * 60)) + nextCount = math.min(lastCount + addCount, globalCsv.tower_count_limit) + nextTime = lastTime + addCount * (globalCsv.tower_count_up * 60) + end + return nextCount, nextTime +end + +function _M.startBattleRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + local id = msg.id + + local towerInfo = role:getProperty("towerInfo") + + if towerInfo.l ~= id then return end -- 层数不对 + + if not csvdb["tower_battleCsv"][id] then return end + local curCount, nextTime = getUpdateTime(towerInfo.c, towerInfo.t) + if curCount < 1 then return end -- 没有次数返回 + + --搞起来 + towerInfo.c = curCount - 1 + towerInfo.t = nextTime + local key = tostring(math.random()) + towerInfo.k = key + + role:updateProperty({field = "towerInfo", value = towerInfo}) + + SendPacket(actionCodes.Tower_startBattleRpc, '') + return true +end + +function _M.endBattleRpc(agent, data) + local role = agent.role + local msg = MsgPack.unpack(data) + local id = msg.id + local key = msg.key + local passTime = msg.passTime + + local towerInfo = role:getProperty("towerInfo") + if towerInfo.l ~= id or not towerInfo.k or towerInfo.k ~= key then return end + local curTower = csvdb["tower_battleCsv"][id] + if not curTower then return end + + local curCount, nextTime = getUpdateTime(towerInfo.c, towerInfo.t) + + + local reward + if msg.starNum and msg.starNum > 0 then --win + curCount = math.min(curCount + 1, globalCsv.tower_count_limit) -- 返还次数 + towerInfo.l = towerInfo.l + 1 + reward = role:award(curTower.reward) + end + + towerInfo.c = curCount + towerInfo.t = nextTime + towerInfo.k = nil + role:updateProperty({field = "towerInfo", value = towerInfo}) + SendPacket(actionCodes.Tower_endBattleRpc, MsgPack.pack({reward = reward})) + return true +end + + +function _M.rankRpc(agent , data) + local role = agent.role + + local rankList = {} + SendPacket(actionCodes.Tower_rankRpc, MsgPack.pack({rankList = rankList})) + return true +end + +return _M \ No newline at end of file diff --git a/src/models/Role.lua b/src/models/Role.lua index dd80291..c1bc8f7 100644 --- a/src/models/Role.lua +++ b/src/models/Role.lua @@ -60,6 +60,9 @@ Role.schema = { equips = {"table", {}}, -- 装备简化下, 目前的设计足够支撑 -- {t = {l = c}} -- 接口设计好 底层扩展就重写~ boxL = {"table", {}}, -- boxList 正开启的箱子 -- {[1] = {id = 1010, gem = 101, time = 1313}} + + towerInfo = {"table", {c = globalCsv.tower_count_limit}}, -- 当天爬塔消耗的次数 -- {t = time, c = count, l = layer, k = battleKey} + towerF = {"table", {}}, -- 爬塔阵容 } @@ -185,6 +188,8 @@ function Role:data() storyB = self:getProperty("storyB"), equips = self:getProperty("equips"), boxL = self:getProperty("boxL"), + towerInfo = self:getProperty("towerInfo"), + towerF = self:getProperty("towerF"), } end -- libgit2 0.21.2