Commit 251d8e5ee3a1b0bccac7a645b0cad1fbc9229f55

Authored by zhangqijia
1 parent 06562145

fix: 挂机宝鉴,宝藏CD的bug

1. 开始新关卡,重置之前正在挖宝关卡的挂机时间,获取之前挖宝关卡的奖励
src/actions/GmAction.lua
... ... @@ -992,16 +992,19 @@ table.insert(helpDes, {"宝藏图鉴", "treasure", "list"} )
992 992 function _M.treasure(role, pms)
993 993 local pm1 = pms.pm1
994 994 if pm1 == "LIST" then
995   - local treasureList= role.dailyData:getTreasrueList(role)
996   - for id, val in pairs(treasureList) do
997   - print(string.format("%s:%d:%d:%d:%d", val.name, val.weight, val.treasure_value, val.expire_time or 0, val.cool_time or 0))
998   - end
  995 + local treasureList= role.dailyData:getProperty("treasureList")
  996 + dump(treasureList)
999 997 return "宝藏图鉴"
  998 + elseif pm1 == "FLUSH" then
  999 + local treasureList= role.dailyData:getTreasrueList(role)
  1000 + dump(treasureList)
  1001 + return "宝藏图鉴"
1000 1002 elseif pm1 == "CHECK" then
1001 1003 local treasureList = role.dailyData:checkTreasureList(role)
1002   - for id, val in pairs(treasureList) do
1003   - print(string.format("%s:%d:%d:%d:%d", val.name, val.weight, val.treasure_value, val.expire_time or 0, val.cool_time or 0))
  1004 + if treasureList == nil then
  1005 + return "未挖到宝藏"
1004 1006 end
  1007 + dump(treasureList)
1005 1008 return "挖宝成功"
1006 1009 elseif pm1 == "RESET" then
1007 1010 role.dailyData:resetTreasureList()
... ...
src/actions/HangAction.lua
... ... @@ -27,7 +27,7 @@ local function getHangTime(role)
27 27 return nowCoinTime - hangInfo.coinTime
28 28 end
29 29  
30   -local function checkReward(role, isTreasure)
  30 +local function checkReward(role, isTreasure, carbonId)
31 31 local hangInfo = role:getProperty("hangInfo")
32 32 if not hangInfo.carbonId or not hangInfo.coinTime or not hangInfo.itemTime then
33 33 return false
... ... @@ -56,7 +56,7 @@ local function checkReward(role, isTreasure)
56 56 coinCount = (coinCount + coinDoubleCount) * expCoef
57 57 items[ItemId.Gold] = math.floor((items[ItemId.Gold] or 0) + coinCount * (expCarbonData.money or 0))
58 58 items[ItemId.Exp] = math.floor((items[ItemId.Exp] or 0) + coinCount * (expCarbonData.exp or 0))
59   - items[ItemId.PlayerExp] = math.floor((items[ItemId.PlayerExp] or 0) + (coinCount * expCarbonData.playerExp or 0))
  59 + items[ItemId.PlayerExp] = math.floor((items[ItemId.PlayerExp] or 0) + coinCount * (expCarbonData.playerExp or 0))
60 60  
61 61 local pool = {}
62 62 for _, temp in pairs(carbonData.item:toArray()) do
... ... @@ -127,8 +127,9 @@ local function checkReward(role, isTreasure)
127 127  
128 128 --挂机得到的宝藏加入到挂机奖励
129 129 if isTreasure or false == true then
130   - local treasureList= role.dailyData:checkTreasureList(hangInfo.carbonId)
131   - if next(treasureList) ~= nil then
  130 + carbonId = carbonId or hangInfo.carbonId
  131 + local treasureList = role.dailyData:checkTreasureList(carbonId) or {}
  132 + if treasureList and next(treasureList) ~= nil then
132 133 for id, val in pairs(treasureList) do
133 134 local award = val.award:toNumMap()
134 135 for k,v in pairs(award) do
... ... @@ -171,7 +172,7 @@ function _M.startRpc( agent, data )
171 172 end
172 173 end
173 174  
174   - if checkReward(role) then
  175 + if checkReward(role, true, carbonId) then
175 176 role:updateProperty({field = "hangBag", value = role:getProperty("hangBag")})
176 177 end
177 178  
... ...
src/models/Daily.lua
... ... @@ -155,18 +155,20 @@ end
155 155 --资源
156 156 function Daily:checkTreasureBase(treasureList, treasureBase, removeId)
157 157 local tmptreasure = {}
  158 + local num = 0
158 159 for k, val in pairs(treasureList) do
159 160 if removeId and val.id == removeId then
160   - table.remove(treasureList, k)
  161 + treasureList[k] = nil
161 162 else
162 163 if treasureBase >= val.treasure_value then
163 164 treasureBase = treasureBase - val.treasure_value
164 165 tmptreasure[val.id] = val
  166 + num = num + 1
165 167 end
166 168 end
167 169  
168 170 end
169   - return tmptreasure
  171 + return tmptreasure, num
170 172 end
171 173  
172 174 --绑定通关关卡
... ... @@ -177,14 +179,9 @@ function Daily:checkChapters()
177 179 if next(treasureList) ~= nil then
178 180 for id, curInfo in pairs(treasureList) do
179 181 if curInfo["end_time"] then
180   - if skynet.timex() >= curInfo["end_time"] then
181   - curInfo = nil
  182 + if skynet.timex() < curInfo["end_time"] then
  183 + tmp_chapters[curInfo.chapter_id] = curInfo
182 184 end
183   - else
184   - curInfo = nil
185   - end
186   - if curInfo ~= nil then
187   - tmp_chapters[curInfo.chapter_id] = curInfo
188 185 end
189 186 end
190 187 end
... ... @@ -207,16 +204,26 @@ end
207 204 function Daily:checkTreasureWeight(treasureList, tmptreasure, treasureBase)
208 205 local removeId
209 206 local chapters = self:checkChapters()
  207 + local treasure
210 208 if next(chapters) == nil then return end
211 209  
212 210 while next(tmptreasure) do
213   - local tmp = self:checkTreasureBase(tmptreasure, treasureBase, removeId)
214   - local id = math.randWeight(tmp, "weight") --宝藏id
215   - if not id then
  211 + local tmp, num = self:checkTreasureBase(tmptreasure, treasureBase, removeId)
  212 +
  213 + if num == 0 then
216 214 break
  215 + elseif num == 1 then
  216 + for _, val in pairs(tmp) do
  217 + treasure = val
  218 + end
  219 + else
  220 + local id = math.randWeight(tmp, "weight") --宝藏id
  221 + if not id then
  222 + break
  223 + end
  224 + treasure = tmp[id]
217 225 end
218   -
219   - local treasure = tmp[id]
  226 +
220 227 if treasureBase >= treasure.treasure_value then
221 228 --扣除资源值
222 229 treasureBase = treasureBase - treasure.treasure_value
... ... @@ -229,8 +236,8 @@ function Daily:checkTreasureWeight(treasureList, tmptreasure, treasureBase)
229 236 end
230 237  
231 238 treasure.chapter_id = chapterId
232   - treasureList[id] = treasure
233   - removeId = id
  239 + treasureList[treasure.id] = treasure
  240 + removeId = treasure.id
234 241 end
235 242 end
236 243  
... ... @@ -249,49 +256,45 @@ function Daily:checkTreasureChapterId(curInfo, treasureList, chapterId)
249 256 if not curInfo["end_time"] then
250 257 curInfo["end_time"] = skynet.timex() + curInfo.working_time
251 258 else
252   - --宝藏冷却时间
253   - if not curInfo["expire_time"] then
254   - --已挖到
255   - if skynet.timex() >= curInfo["end_time"] then
256   - treasure = treasureList[curInfo.id]
257   - if curInfo.cool_time > 1 then
  259 + if skynet.timex() >= curInfo["end_time"] then
  260 + if curInfo.cool_time > 1 then
  261 + --宝藏冷却时间
  262 + if not curInfo["expire_time"] then
  263 + treasure = treasureList[curInfo.id]
258 264 curInfo["expire_time"] = skynet.timex() + curInfo.cool_time * oneDay
259 265 else
260   - curInfo["expire_time"] = skynet.timex()
  266 + --已经领取宝藏 检索宝藏冷却时间
  267 + if skynet.timex() >= curInfo["expire_time"] then
  268 + treasureList[curInfo.id] = nil
  269 + end
261 270 end
262   - if skynet.timex() >= curInfo["expire_time"] then
263   - table.remove(treasureList, curInfo.id)
264   - end
265   - end
266   - else
267   - --已经领取宝藏 检索宝藏冷却时间
268   - if skynet.timex() >= curInfo["expire_time"] then
269   - table.remove(treasureList, curInfo.id)
  271 + else
  272 + treasure = treasureList[curInfo.id]
  273 + treasureList[curInfo.id] = nil
270 274 end
271 275 end
272 276 end
273 277 else
274 278 --已经开始挖宝
275 279 if curInfo["end_time"] then
276   - if not curInfo["expire_time"] then --宝藏冷却时间
277   - if skynet.timex() >= curInfo["end_time"] then --已挖到
278   - treasure = treasureList[curInfo.id]
279   - if curInfo.cool_time > 1 then
  280 + if skynet.timex() >= curInfo["end_time"] then
  281 + if curInfo.cool_time > 1 then
  282 + --宝藏冷却时间
  283 + if not curInfo["expire_time"] then
  284 + treasure = treasureList[curInfo.id]
280 285 curInfo["expire_time"] = skynet.timex() + curInfo.cool_time * oneDay
281 286 else
282   - curInfo["expire_time"] = skynet.timex()
283   - end
284   - if skynet.timex() >= curInfo["expire_time"] then
285   - table.remove(treasureList, curInfo.id)
  287 + --已经领取宝藏 检索宝藏冷却时间
  288 + if skynet.timex() >= curInfo["expire_time"] then
  289 + treasureList[curInfo.id] = nil
  290 + end
286 291 end
287 292 else
288   - --未挖到直接删除
289   - table.remove(treasureList, curInfo.id)
290   - end
291   - else --已经领取宝藏 检索宝藏冷却时间
292   - if skynet.timex() >= curInfo["expire_time"] then
293   - table.remove(treasureList, curInfo.id)
  293 + treasure = treasureList[curInfo.id]
  294 + treasureList[curInfo.id] = nil
294 295 end
  296 + else
  297 + curInfo["end_time"] = nil
295 298 end
296 299 end
297 300 end
... ... @@ -310,7 +313,7 @@ function Daily:buyTreasure(treasureList)
310 313 boughtTreasurer[id] = val
311 314 end
312 315 end
313   - self:updateProperty({field = "treasureBase", value = treasureBase})
  316 + --self:updateProperty({field = "treasureBase", value = treasureBase})
314 317 return boughtTreasurer
315 318 end
316 319  
... ... @@ -322,7 +325,7 @@ end
322 325 --宝藏图鉴
323 326 function Daily:getTreasrueList()
324 327 local tmpcsv = csvdb["idle_treasureCsv"]
325   - local treasureList = self:getProperty("treasureList") --挖宝列表 过期删除 领取奖励删除 跨天更新
  328 + local treasureList = self:getProperty("treasureList") or {} --挖宝列表 过期删除 领取奖励删除 跨天更新
326 329 local tmptreasure = {}
327 330 local treasureBase = globalCsv.idle_treasure_base
328 331 for id, val in pairs(tmpcsv) do
... ... @@ -343,7 +346,7 @@ end
343 346  
344 347 --检索挖宝列表
345 348 function Daily:checkTreasureList(chapterId)
346   - local treasureList = self:getProperty("treasureList")
  349 + local treasureList = self:getProperty("treasureList") or {}
347 350 local tmptreasure = {}
348 351 for id, val in pairs(treasureList) do
349 352 local treasure = self:checkTreasureChapterId(val, treasureList, chapterId)
... ... @@ -353,6 +356,7 @@ function Daily:checkTreasureList(chapterId)
353 356 end
354 357  
355 358 if next(tmptreasure) == nil then
  359 + self:updateProperty({field = "treasureList", value = treasureList})
356 360 return nil
357 361 end
358 362 local boughtTreasurer = self:buyTreasure(tmptreasure)
... ...