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,12 +22,12 @@ local function checkReward(role) | ||
22 | return | 22 | return |
23 | end | 23 | end |
24 | local carbonData = csvdb["idle_battleCsv"][hangInfo.carbonId] | 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 | hangInfo.coinTime = hangInfo.coinTime + coinCount * 5 | 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 | hangInfo.itemTime = hangInfo.itemTime + itemCount * 60 | 31 | hangInfo.itemTime = hangInfo.itemTime + itemCount * 60 |
32 | 32 | ||
33 | local items = role:getProperty("hangBag") | 33 | local items = role:getProperty("hangBag") |
@@ -44,8 +44,7 @@ local function checkReward(role) | @@ -44,8 +44,7 @@ local function checkReward(role) | ||
44 | end | 44 | end |
45 | 45 | ||
46 | if coinCount > 0 or itemCount > 0 then | 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 | end | 48 | end |
50 | end | 49 | end |
51 | 50 | ||
@@ -62,16 +61,23 @@ function _M.startRpc( agent, data ) | @@ -62,16 +61,23 @@ function _M.startRpc( agent, data ) | ||
62 | local hangPass = role:getProperty("hangPass") | 61 | local hangPass = role:getProperty("hangPass") |
63 | if carbonData.prepose ~= "" and carbonData.prepose ~= 0 and not hangPass[carbonData.prepose] then return end | 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 | local hangInfo = role:getProperty("hangInfo") | 68 | local hangInfo = role:getProperty("hangInfo") |
68 | - table.clear(hangInfo) | 69 | + local isNew = not hangInfo.carbonId |
69 | hangInfo.carbonId = carbonId | 70 | hangInfo.carbonId = carbonId |
70 | local nowTime = skynet.timex() | 71 | local nowTime = skynet.timex() |
71 | hangInfo.coinTime = nowTime | 72 | hangInfo.coinTime = nowTime |
72 | hangInfo.itemTime = nowTime | 73 | hangInfo.itemTime = nowTime |
74 | + if isNew then | ||
75 | + hangInfo.endTime = nowTime + 12 * 3600 | ||
76 | + end | ||
73 | if not hangPass[carbonId] then | 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 | end | 81 | end |
76 | role:updateProperty({field = "hangInfo", value = hangInfo}) | 82 | role:updateProperty({field = "hangInfo", value = hangInfo}) |
77 | 83 | ||
@@ -83,7 +89,10 @@ end | @@ -83,7 +89,10 @@ end | ||
83 | function _M.checkRpc(agent, data) | 89 | function _M.checkRpc(agent, data) |
84 | local role = agent.role | 90 | local role = agent.role |
85 | -- local msg = MsgPack.unpack(data) | 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 | SendPacket(actionCodes.Hang_checkRpc, MsgPack.pack({})) | 96 | SendPacket(actionCodes.Hang_checkRpc, MsgPack.pack({})) |
88 | return true | 97 | return true |
89 | end | 98 | end |
@@ -98,7 +107,6 @@ function _M.startBattleRpc(agent, data) | @@ -98,7 +107,6 @@ function _M.startBattleRpc(agent, data) | ||
98 | local key = tostring(math.random()) | 107 | local key = tostring(math.random()) |
99 | hangInfo.key = key | 108 | hangInfo.key = key |
100 | local nowTime = skynet.timex() | 109 | local nowTime = skynet.timex() |
101 | - hangInfo.bossTime = nowTime + 100 | ||
102 | role:updateProperty({field = "hangInfo", value = hangInfo}) | 110 | role:updateProperty({field = "hangInfo", value = hangInfo}) |
103 | SendPacket(actionCodes.Hang_startBattleRpc, MsgPack.pack({key = key})) | 111 | SendPacket(actionCodes.Hang_startBattleRpc, MsgPack.pack({key = key})) |
104 | return true | 112 | return true |
@@ -121,7 +129,7 @@ function _M.endBattleRpc(agent, data) | @@ -121,7 +129,7 @@ function _M.endBattleRpc(agent, data) | ||
121 | -- reward | 129 | -- reward |
122 | reward = {} | 130 | reward = {} |
123 | local items = role:getProperty("hangBag") | 131 | local items = role:getProperty("hangBag") |
124 | - local carbonData = csvdb["idle_battleCsv"][carbonId] | 132 | + local carbonData = csvdb["idle_battleCsv"][hangInfo.carbonId] |
125 | items[ItemId.Gold] = (items[ItemId.Gold] or 0) + carbonData.money_clear | 133 | items[ItemId.Gold] = (items[ItemId.Gold] or 0) + carbonData.money_clear |
126 | items[ItemId.Exp] = (items[ItemId.Exp] or 0) + carbonData.exp_clear | 134 | items[ItemId.Exp] = (items[ItemId.Exp] or 0) + carbonData.exp_clear |
127 | reward[ItemId.Gold] = carbonData.money_clear | 135 | reward[ItemId.Gold] = carbonData.money_clear |
@@ -161,4 +169,25 @@ function _M.roleFormatRpc(agent , data) | @@ -161,4 +169,25 @@ function _M.roleFormatRpc(agent , data) | ||
161 | return true | 169 | return true |
162 | end | 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 | return _M | 193 | return _M |
165 | \ No newline at end of file | 194 | \ No newline at end of file |