Commit 5af8b4aa5c114da0d9effe6f11dd3b37ba4c29af
1 parent
384bb077
挂机down
Showing
3 changed files
with
42 additions
and
12 deletions
Show diff stats
src/GlobalVar.lua
src/ProtocolCode.lua
src/actions/HangAction.lua
... | ... | @@ -22,12 +22,12 @@ local function checkReward(role) |
22 | 22 | return |
23 | 23 | end |
24 | 24 | local carbonData = csvdb["idle_battleCsv"][hangInfo.carbonId] |
25 | - local nowTime = skynet.timex() | |
25 | + local nowTime = math.min(skynet.timex(), hangInfo.endTime or 0) | |
26 | 26 | |
27 | - local coinCount = math.floor((nowTime - hangInfo.coinTime) / 5) | |
27 | + local coinCount = math.max(0, math.floor((nowTime - hangInfo.coinTime) / 5)) | |
28 | 28 | hangInfo.coinTime = hangInfo.coinTime + coinCount * 5 |
29 | 29 | |
30 | - local itemCount = math.floor((nowTime - hangInfo.itemTime) / 60) | |
30 | + local itemCount = math.max(0, math.floor((nowTime - hangInfo.itemTime) / 60)) | |
31 | 31 | hangInfo.itemTime = hangInfo.itemTime + itemCount * 60 |
32 | 32 | |
33 | 33 | local items = role:getProperty("hangBag") |
... | ... | @@ -44,8 +44,7 @@ local function checkReward(role) |
44 | 44 | end |
45 | 45 | |
46 | 46 | if coinCount > 0 or itemCount > 0 then |
47 | - role:updateProperty({field = "hangBag", value = items}) | |
48 | - role:updateProperty({field = "hangInfo", value = hangInfo}) | |
47 | + return true | |
49 | 48 | end |
50 | 49 | end |
51 | 50 | |
... | ... | @@ -62,16 +61,23 @@ function _M.startRpc( agent, data ) |
62 | 61 | local hangPass = role:getProperty("hangPass") |
63 | 62 | if carbonData.prepose ~= "" and carbonData.prepose ~= 0 and not hangPass[carbonData.prepose] then return end |
64 | 63 | |
65 | - checkReward(role) | |
64 | + if checkReward(role) then | |
65 | + role:updateProperty({field = "hangBag", value = role:getProperty("hangBag")}) | |
66 | + end | |
66 | 67 | |
67 | 68 | local hangInfo = role:getProperty("hangInfo") |
68 | - table.clear(hangInfo) | |
69 | + local isNew = not hangInfo.carbonId | |
69 | 70 | hangInfo.carbonId = carbonId |
70 | 71 | local nowTime = skynet.timex() |
71 | 72 | hangInfo.coinTime = nowTime |
72 | 73 | hangInfo.itemTime = nowTime |
74 | + if isNew then | |
75 | + hangInfo.endTime = nowTime + 12 * 3600 | |
76 | + end | |
73 | 77 | if not hangPass[carbonId] then |
74 | - hangInfo.bossTime = nowTime + 100 | |
78 | + hangInfo.bossTime = nowTime + carbonData.idle_time | |
79 | + else | |
80 | + hangInfo.bossTime = nil | |
75 | 81 | end |
76 | 82 | role:updateProperty({field = "hangInfo", value = hangInfo}) |
77 | 83 | |
... | ... | @@ -83,7 +89,10 @@ end |
83 | 89 | function _M.checkRpc(agent, data) |
84 | 90 | local role = agent.role |
85 | 91 | -- local msg = MsgPack.unpack(data) |
86 | - checkReward(role) | |
92 | + if checkReward(role) then | |
93 | + role:updateProperty({field = "hangBag", value = role:getProperty("hangBag")}) | |
94 | + role:updateProperty({field = "hangInfo", value = role:getProperty("hangInfo")}) | |
95 | + end | |
87 | 96 | SendPacket(actionCodes.Hang_checkRpc, MsgPack.pack({})) |
88 | 97 | return true |
89 | 98 | end |
... | ... | @@ -98,7 +107,6 @@ function _M.startBattleRpc(agent, data) |
98 | 107 | local key = tostring(math.random()) |
99 | 108 | hangInfo.key = key |
100 | 109 | local nowTime = skynet.timex() |
101 | - hangInfo.bossTime = nowTime + 100 | |
102 | 110 | role:updateProperty({field = "hangInfo", value = hangInfo}) |
103 | 111 | SendPacket(actionCodes.Hang_startBattleRpc, MsgPack.pack({key = key})) |
104 | 112 | return true |
... | ... | @@ -121,7 +129,7 @@ function _M.endBattleRpc(agent, data) |
121 | 129 | -- reward |
122 | 130 | reward = {} |
123 | 131 | local items = role:getProperty("hangBag") |
124 | - local carbonData = csvdb["idle_battleCsv"][carbonId] | |
132 | + local carbonData = csvdb["idle_battleCsv"][hangInfo.carbonId] | |
125 | 133 | items[ItemId.Gold] = (items[ItemId.Gold] or 0) + carbonData.money_clear |
126 | 134 | items[ItemId.Exp] = (items[ItemId.Exp] or 0) + carbonData.exp_clear |
127 | 135 | reward[ItemId.Gold] = carbonData.money_clear |
... | ... | @@ -161,4 +169,25 @@ function _M.roleFormatRpc(agent , data) |
161 | 169 | return true |
162 | 170 | end |
163 | 171 | |
172 | +function _M.getRewardRpc(agent , data) | |
173 | + local role = agent.role | |
174 | + checkReward(role) | |
175 | + local items = role:getProperty("hangBag") | |
176 | + if not next(items) then return end | |
177 | + local reward = role:award(items, {}) | |
178 | + table.clear(items) | |
179 | + local hangInfo = role:getProperty("hangInfo") | |
180 | + local nowTime = skynet.timex() | |
181 | + hangInfo.endTime = nowTime + 12 * 3600 | |
182 | + hangInfo.coinTime = nowTime | |
183 | + hangInfo.itemTime = nowTime | |
184 | + role:updateProperty({field = "hangBag", value = items}) | |
185 | + role:updateProperty({field = "hangInfo", value = hangInfo}) | |
186 | + | |
187 | + SendPacket(actionCodes.Hang_getRewardRpc, MsgPack.pack({ | |
188 | + reward = reward | |
189 | + })) | |
190 | + return true | |
191 | +end | |
192 | + | |
164 | 193 | return _M |
165 | 194 | \ No newline at end of file | ... | ... |