Commit 276b1da94cc71fb1ad9b4079541e498a78e147e6
1 parent
3b0526d2
爬塔接口
Showing
3 changed files
with
117 additions
and
0 deletions
Show diff stats
src/ProtocolCode.lua
@@ -79,6 +79,11 @@ actionCodes = { | @@ -79,6 +79,11 @@ actionCodes = { | ||
79 | Diner_expediteSellRpc = 310, | 79 | Diner_expediteSellRpc = 310, |
80 | Diner_getGreenhouseRpc = 311, | 80 | Diner_getGreenhouseRpc = 311, |
81 | 81 | ||
82 | + Tower_roleFormatRpc = 350, | ||
83 | + Tower_startBattleRpc = 351, | ||
84 | + Tower_endBattleRpc = 352, | ||
85 | + Tower_rankRpc = 353, | ||
86 | + | ||
82 | Car_makePotionRpc = 400, | 87 | Car_makePotionRpc = 400, |
83 | Car_equipUpRpc = 401, | 88 | Car_equipUpRpc = 401, |
84 | Car_runeUpRpc = 402, | 89 | Car_runeUpRpc = 402, |
@@ -0,0 +1,107 @@ | @@ -0,0 +1,107 @@ | ||
1 | +local ipairs = ipairs | ||
2 | +local table = table | ||
3 | +local math = math | ||
4 | +local redisproxy = redisproxy | ||
5 | +local MsgPack = MsgPack | ||
6 | + | ||
7 | + | ||
8 | +local _M = {} | ||
9 | + | ||
10 | + | ||
11 | +function _M.roleFormatRpc(agent , data) | ||
12 | + local role = agent.role | ||
13 | + local msg = MsgPack.unpack(data) | ||
14 | + local towerTeam = role:getProperty("towerF") | ||
15 | + for slot, heroId in pairs(msg.heros) do | ||
16 | + if not role.heros[heroId] then | ||
17 | + return | ||
18 | + end | ||
19 | + end | ||
20 | + table.clear(towerTeam) | ||
21 | + towerTeam.heros = {} | ||
22 | + for slot, heroId in pairs(msg.heros) do | ||
23 | + towerTeam.heros[slot] = heroId | ||
24 | + end | ||
25 | + towerTeam.leader = msg.leader | ||
26 | + | ||
27 | + role:updateProperty({field = "towerF", value = towerTeam}) | ||
28 | + SendPacket(actionCodes.Tower_roleFormatRpc, '') | ||
29 | + return true | ||
30 | +end | ||
31 | + | ||
32 | + | ||
33 | +local function getUpdateTime(lastCount, lastTime) | ||
34 | + local nextCount, nextTime = lastCount, skynet.timex() | ||
35 | + if lastTime then | ||
36 | + local addCount = math.floor((skynet.timex() - lastTime) / (globalCsv.tower_count_up * 60)) | ||
37 | + nextCount = math.min(lastCount + addCount, globalCsv.tower_count_limit) | ||
38 | + nextTime = lastTime + addCount * (globalCsv.tower_count_up * 60) | ||
39 | + end | ||
40 | + return nextCount, nextTime | ||
41 | +end | ||
42 | + | ||
43 | +function _M.startBattleRpc(agent, data) | ||
44 | + local role = agent.role | ||
45 | + local msg = MsgPack.unpack(data) | ||
46 | + local id = msg.id | ||
47 | + | ||
48 | + local towerInfo = role:getProperty("towerInfo") | ||
49 | + | ||
50 | + if towerInfo.l ~= id then return end -- 层数不对 | ||
51 | + | ||
52 | + if not csvdb["tower_battleCsv"][id] then return end | ||
53 | + local curCount, nextTime = getUpdateTime(towerInfo.c, towerInfo.t) | ||
54 | + if curCount < 1 then return end -- 没有次数返回 | ||
55 | + | ||
56 | + --搞起来 | ||
57 | + towerInfo.c = curCount - 1 | ||
58 | + towerInfo.t = nextTime | ||
59 | + local key = tostring(math.random()) | ||
60 | + towerInfo.k = key | ||
61 | + | ||
62 | + role:updateProperty({field = "towerInfo", value = towerInfo}) | ||
63 | + | ||
64 | + SendPacket(actionCodes.Tower_startBattleRpc, '') | ||
65 | + return true | ||
66 | +end | ||
67 | + | ||
68 | +function _M.endBattleRpc(agent, data) | ||
69 | + local role = agent.role | ||
70 | + local msg = MsgPack.unpack(data) | ||
71 | + local id = msg.id | ||
72 | + local key = msg.key | ||
73 | + local passTime = msg.passTime | ||
74 | + | ||
75 | + local towerInfo = role:getProperty("towerInfo") | ||
76 | + if towerInfo.l ~= id or not towerInfo.k or towerInfo.k ~= key then return end | ||
77 | + local curTower = csvdb["tower_battleCsv"][id] | ||
78 | + if not curTower then return end | ||
79 | + | ||
80 | + local curCount, nextTime = getUpdateTime(towerInfo.c, towerInfo.t) | ||
81 | + | ||
82 | + | ||
83 | + local reward | ||
84 | + if msg.starNum and msg.starNum > 0 then --win | ||
85 | + curCount = math.min(curCount + 1, globalCsv.tower_count_limit) -- 返还次数 | ||
86 | + towerInfo.l = towerInfo.l + 1 | ||
87 | + reward = role:award(curTower.reward) | ||
88 | + end | ||
89 | + | ||
90 | + towerInfo.c = curCount | ||
91 | + towerInfo.t = nextTime | ||
92 | + towerInfo.k = nil | ||
93 | + role:updateProperty({field = "towerInfo", value = towerInfo}) | ||
94 | + SendPacket(actionCodes.Tower_endBattleRpc, MsgPack.pack({reward = reward})) | ||
95 | + return true | ||
96 | +end | ||
97 | + | ||
98 | + | ||
99 | +function _M.rankRpc(agent , data) | ||
100 | + local role = agent.role | ||
101 | + | ||
102 | + local rankList = {} | ||
103 | + SendPacket(actionCodes.Tower_rankRpc, MsgPack.pack({rankList = rankList})) | ||
104 | + return true | ||
105 | +end | ||
106 | + | ||
107 | +return _M | ||
0 | \ No newline at end of file | 108 | \ No newline at end of file |
src/models/Role.lua
@@ -60,6 +60,9 @@ Role.schema = { | @@ -60,6 +60,9 @@ Role.schema = { | ||
60 | equips = {"table", {}}, -- 装备简化下, 目前的设计足够支撑 -- {t = {l = c}} -- 接口设计好 底层扩展就重写~ | 60 | equips = {"table", {}}, -- 装备简化下, 目前的设计足够支撑 -- {t = {l = c}} -- 接口设计好 底层扩展就重写~ |
61 | 61 | ||
62 | boxL = {"table", {}}, -- boxList 正开启的箱子 -- {[1] = {id = 1010, gem = 101, time = 1313}} | 62 | boxL = {"table", {}}, -- boxList 正开启的箱子 -- {[1] = {id = 1010, gem = 101, time = 1313}} |
63 | + | ||
64 | + towerInfo = {"table", {c = globalCsv.tower_count_limit}}, -- 当天爬塔消耗的次数 -- {t = time, c = count, l = layer, k = battleKey} | ||
65 | + towerF = {"table", {}}, -- 爬塔阵容 | ||
63 | } | 66 | } |
64 | 67 | ||
65 | 68 | ||
@@ -185,6 +188,8 @@ function Role:data() | @@ -185,6 +188,8 @@ function Role:data() | ||
185 | storyB = self:getProperty("storyB"), | 188 | storyB = self:getProperty("storyB"), |
186 | equips = self:getProperty("equips"), | 189 | equips = self:getProperty("equips"), |
187 | boxL = self:getProperty("boxL"), | 190 | boxL = self:getProperty("boxL"), |
191 | + towerInfo = self:getProperty("towerInfo"), | ||
192 | + towerF = self:getProperty("towerF"), | ||
188 | 193 | ||
189 | } | 194 | } |
190 | end | 195 | end |