Commit 384bb077c785366a93be90ec5f6e5db08f6c0692
1 parent
ec87b4a5
挂机
Showing
5 changed files
with
187 additions
and
3 deletions
Show diff stats
src/ProtocolCode.lua
@@ -44,6 +44,12 @@ actionCodes = { | @@ -44,6 +44,12 @@ actionCodes = { | ||
44 | Hero_loveTaskRpc = 213, | 44 | Hero_loveTaskRpc = 213, |
45 | Hero_changeSkinRpc = 214, | 45 | Hero_changeSkinRpc = 214, |
46 | 46 | ||
47 | + Hang_startRpc = 251, | ||
48 | + Hang_checkRpc = 252, | ||
49 | + Hang_startBattleRpc = 253, | ||
50 | + Hang_endBattleRpc = 254, | ||
51 | + Hang_roleFormatRpc = 255, | ||
52 | + | ||
47 | } | 53 | } |
48 | 54 | ||
49 | rpcResponseBegin = 10000 | 55 | rpcResponseBegin = 10000 |
src/actions/AdvAction.lua
@@ -35,14 +35,14 @@ function _M.roleFormatRpc(agent , data) | @@ -35,14 +35,14 @@ function _M.roleFormatRpc(agent , data) | ||
35 | local role = agent.role | 35 | local role = agent.role |
36 | local msg = MsgPack.unpack(data) | 36 | local msg = MsgPack.unpack(data) |
37 | local advTeam = role:getProperty("advTeam") | 37 | local advTeam = role:getProperty("advTeam") |
38 | - for slot, heroId in ipairs(msg.heros) do | 38 | + for slot, heroId in pairs(msg.heros) do |
39 | if not role.heros[heroId] then | 39 | if not role.heros[heroId] then |
40 | return | 40 | return |
41 | end | 41 | end |
42 | end | 42 | end |
43 | table.clear(advTeam) | 43 | table.clear(advTeam) |
44 | advTeam.heros = {} | 44 | advTeam.heros = {} |
45 | - for slot, heroId in ipairs(msg.heros) do | 45 | + for slot, heroId in pairs(msg.heros) do |
46 | advTeam.heros[slot] = heroId | 46 | advTeam.heros[slot] = heroId |
47 | end | 47 | end |
48 | role:updateProperty({field = "advTeam", value = advTeam}) | 48 | role:updateProperty({field = "advTeam", value = advTeam}) |
@@ -0,0 +1,164 @@ | @@ -0,0 +1,164 @@ | ||
1 | +local ipairs = ipairs | ||
2 | +local table = table | ||
3 | +local math = math | ||
4 | +local next = next | ||
5 | +local string = string | ||
6 | +local redisproxy = redisproxy | ||
7 | +local MsgPack = MsgPack | ||
8 | +local getRandomName = getRandomName | ||
9 | +local mcast_util = mcast_util | ||
10 | +local string_format = string.format | ||
11 | +local tonumber = tonumber | ||
12 | +local require = require | ||
13 | +local table_insert = table.insert | ||
14 | +local tconcat = table.concat | ||
15 | +local table_unpack = table.unpack | ||
16 | + | ||
17 | +local _M = {} | ||
18 | + | ||
19 | +local function checkReward(role) | ||
20 | + local hangInfo = role:getProperty("hangInfo") | ||
21 | + if not hangInfo.carbonId or not hangInfo.coinTime or not hangInfo.itemTime then | ||
22 | + return | ||
23 | + end | ||
24 | + local carbonData = csvdb["idle_battleCsv"][hangInfo.carbonId] | ||
25 | + local nowTime = skynet.timex() | ||
26 | + | ||
27 | + local coinCount = math.floor((nowTime - hangInfo.coinTime) / 5) | ||
28 | + hangInfo.coinTime = hangInfo.coinTime + coinCount * 5 | ||
29 | + | ||
30 | + local itemCount = math.floor((nowTime - hangInfo.itemTime) / 60) | ||
31 | + hangInfo.itemTime = hangInfo.itemTime + itemCount * 60 | ||
32 | + | ||
33 | + local items = role:getProperty("hangBag") | ||
34 | + items[ItemId.Gold] = (items[ItemId.Gold] or 0) + coinCount * carbonData.money | ||
35 | + items[ItemId.Exp] = (items[ItemId.Exp] or 0) + coinCount * carbonData.exp | ||
36 | + | ||
37 | + local pool = {} | ||
38 | + for _, temp in pairs(carbonData.item:toArray()) do | ||
39 | + table.insert(pool, temp:toArray(true, "=")) | ||
40 | + end | ||
41 | + for i = 1, itemCount do | ||
42 | + local cur = pool[math.randWeight(pool, 3)] | ||
43 | + items[cur[1]] = (items[cur[1]] or 0) + cur[2] | ||
44 | + end | ||
45 | + | ||
46 | + if coinCount > 0 or itemCount > 0 then | ||
47 | + role:updateProperty({field = "hangBag", value = items}) | ||
48 | + role:updateProperty({field = "hangInfo", value = hangInfo}) | ||
49 | + end | ||
50 | +end | ||
51 | + | ||
52 | + | ||
53 | + | ||
54 | +--开始一个新的关卡 | ||
55 | +function _M.startRpc( agent, data ) | ||
56 | + local role = agent.role | ||
57 | + local msg = MsgPack.unpack(data) | ||
58 | + local carbonId = msg.carbonId | ||
59 | + local carbonData = csvdb["idle_battleCsv"][carbonId] | ||
60 | + if not carbonData then return end | ||
61 | + | ||
62 | + local hangPass = role:getProperty("hangPass") | ||
63 | + if carbonData.prepose ~= "" and carbonData.prepose ~= 0 and not hangPass[carbonData.prepose] then return end | ||
64 | + | ||
65 | + checkReward(role) | ||
66 | + | ||
67 | + local hangInfo = role:getProperty("hangInfo") | ||
68 | + table.clear(hangInfo) | ||
69 | + hangInfo.carbonId = carbonId | ||
70 | + local nowTime = skynet.timex() | ||
71 | + hangInfo.coinTime = nowTime | ||
72 | + hangInfo.itemTime = nowTime | ||
73 | + if not hangPass[carbonId] then | ||
74 | + hangInfo.bossTime = nowTime + 100 | ||
75 | + end | ||
76 | + role:updateProperty({field = "hangInfo", value = hangInfo}) | ||
77 | + | ||
78 | + SendPacket(actionCodes.Hang_startRpc, '') | ||
79 | + return true | ||
80 | +end | ||
81 | + | ||
82 | +-- 每隔1分钟检查一次 | ||
83 | +function _M.checkRpc(agent, data) | ||
84 | + local role = agent.role | ||
85 | + -- local msg = MsgPack.unpack(data) | ||
86 | + checkReward(role) | ||
87 | + SendPacket(actionCodes.Hang_checkRpc, MsgPack.pack({})) | ||
88 | + return true | ||
89 | +end | ||
90 | + | ||
91 | +function _M.startBattleRpc(agent, data) | ||
92 | + local role = agent.role | ||
93 | + local msg = MsgPack.unpack(data) | ||
94 | + local hangInfo = role:getProperty("hangInfo") | ||
95 | + if msg.carbonId ~= hangInfo.carbonId then return end | ||
96 | + local hangPass = role:getProperty("hangPass") | ||
97 | + if hangPass[hangInfo.carbonId] then return end | ||
98 | + local key = tostring(math.random()) | ||
99 | + hangInfo.key = key | ||
100 | + local nowTime = skynet.timex() | ||
101 | + hangInfo.bossTime = nowTime + 100 | ||
102 | + role:updateProperty({field = "hangInfo", value = hangInfo}) | ||
103 | + SendPacket(actionCodes.Hang_startBattleRpc, MsgPack.pack({key = key})) | ||
104 | + return true | ||
105 | +end | ||
106 | + | ||
107 | +function _M.endBattleRpc(agent, data) | ||
108 | + local role = agent.role | ||
109 | + local msg = MsgPack.unpack(data) | ||
110 | + local hangInfo = role:getProperty("hangInfo") | ||
111 | + if not msg.key or msg.key ~= hangInfo.key then return end | ||
112 | + if msg.carbonId ~= hangInfo.carbonId then return end | ||
113 | + local hangPass = role:getProperty("hangPass") | ||
114 | + if hangPass[hangInfo.carbonId] then return end | ||
115 | + local reward | ||
116 | + if msg.starNum and msg.starNum > 0 then --win | ||
117 | + hangPass[hangInfo.carbonId] = 1 | ||
118 | + role:updateProperty({field = "hangPass", value = hangPass}) | ||
119 | + hangInfo.bossTime = nil | ||
120 | + | ||
121 | + -- reward | ||
122 | + reward = {} | ||
123 | + local items = role:getProperty("hangBag") | ||
124 | + local carbonData = csvdb["idle_battleCsv"][carbonId] | ||
125 | + items[ItemId.Gold] = (items[ItemId.Gold] or 0) + carbonData.money_clear | ||
126 | + items[ItemId.Exp] = (items[ItemId.Exp] or 0) + carbonData.exp_clear | ||
127 | + reward[ItemId.Gold] = carbonData.money_clear | ||
128 | + reward[ItemId.Exp] = carbonData.exp_clear | ||
129 | + for itemId, count in pairs(carbonData.item_clear:toNumMap()) do | ||
130 | + items[itemId] = (items[itemId] or 0) + count | ||
131 | + reward[itemId] = count | ||
132 | + end | ||
133 | + end | ||
134 | + hangInfo.key = nil | ||
135 | + role:updateProperty({field = "hangInfo", value = hangInfo}) | ||
136 | + SendPacket(actionCodes.Hang_endBattleRpc, MsgPack.pack({ | ||
137 | + starNum = msg.starNum, | ||
138 | + reward = reward, | ||
139 | + })) | ||
140 | + return true | ||
141 | +end | ||
142 | + | ||
143 | +function _M.roleFormatRpc(agent , data) | ||
144 | + local role = agent.role | ||
145 | + local msg = MsgPack.unpack(data) | ||
146 | + local hangTeam = role:getProperty("hangTeam") | ||
147 | + for slot, heroId in pairs(msg.heros) do | ||
148 | + if not role.heros[heroId] then | ||
149 | + return | ||
150 | + end | ||
151 | + end | ||
152 | + table.clear(hangTeam) | ||
153 | + hangTeam.heros = {} | ||
154 | + for slot, heroId in pairs(msg.heros) do | ||
155 | + hangTeam.heros[slot] = heroId | ||
156 | + end | ||
157 | + hangTeam.leader = msg.leader | ||
158 | + | ||
159 | + role:updateProperty({field = "hangTeam", value = hangTeam}) | ||
160 | + SendPacket(actionCodes.Hang_roleFormatRpc, '') | ||
161 | + return true | ||
162 | +end | ||
163 | + | ||
164 | +return _M | ||
0 | \ No newline at end of file | 165 | \ No newline at end of file |
src/adv/AdvBattle.lua
@@ -38,7 +38,7 @@ function Battle:initPlayer() | @@ -38,7 +38,7 @@ function Battle:initPlayer() | ||
38 | end | 38 | end |
39 | end | 39 | end |
40 | player.hp = hp | 40 | player.hp = hp |
41 | - player.atk = player.hp * 0.1 --todo 系数是临时的 | 41 | + player.atk = tonumber(string.format("%0.0f", player.hp * 0.1)) --todo 系数是临时的 |
42 | player.miss = 0 | 42 | player.miss = 0 |
43 | player.hit = 100 | 43 | player.hit = 100 |
44 | self.adv.advTeam.player = player | 44 | self.adv.advTeam.player = player |
src/models/Role.lua
@@ -42,6 +42,13 @@ Role.schema = { | @@ -42,6 +42,13 @@ Role.schema = { | ||
42 | advInfo = {"table", {}}, -- 冒险关卡信息 | 42 | advInfo = {"table", {}}, -- 冒险关卡信息 |
43 | advTeam = {"table", {}}, -- 冒险玩家队伍信息 | 43 | advTeam = {"table", {}}, -- 冒险玩家队伍信息 |
44 | 44 | ||
45 | + --挂机相关 | ||
46 | + hangPass = {"table", {}}, -- 挂机通过的最大关卡 | ||
47 | + hangTeam = {"table", {}}, -- 挂机队伍 | ||
48 | + hangInfo = {"table", {}}, -- 当前挂机信息 | ||
49 | + hangBag = {"table", {}}, -- 背包 | ||
50 | + hangBagLimit = {"number", 10}, --背包上限 | ||
51 | + | ||
45 | } | 52 | } |
46 | 53 | ||
47 | 54 | ||
@@ -144,10 +151,17 @@ function Role:data() | @@ -144,10 +151,17 @@ function Role:data() | ||
144 | reDiamond = self:getProperty("reDiamond"), | 151 | reDiamond = self:getProperty("reDiamond"), |
145 | items = self:getProperty("items"):toNumMap(), | 152 | items = self:getProperty("items"):toNumMap(), |
146 | loveStatus = self:getProperty("loveStatus"):toNumMap(), | 153 | loveStatus = self:getProperty("loveStatus"):toNumMap(), |
154 | + | ||
147 | advPass = self:getProperty("advPass"), | 155 | advPass = self:getProperty("advPass"), |
148 | advInfo = self:getProperty("advInfo"), | 156 | advInfo = self:getProperty("advInfo"), |
149 | advItems = self:getProperty("advItems"):toNumMap(), | 157 | advItems = self:getProperty("advItems"):toNumMap(), |
150 | advTeam = self:getProperty("advTeam"), | 158 | advTeam = self:getProperty("advTeam"), |
159 | + | ||
160 | + hangPass = self:getProperty("hangPass"), | ||
161 | + hangTeam = self:getProperty("hangTeam"), | ||
162 | + hangInfo = self:getProperty("hangInfo"), | ||
163 | + hangBag = self:getProperty("hangBag"), | ||
164 | + hangBagLimit = self:getProperty("hangBagLimit"), | ||
151 | } | 165 | } |
152 | end | 166 | end |
153 | 167 |