Commit 1199daf93d7c3ac2618479aab6a38ab04f339653

Authored by zhangqijia
1 parent a1fd1815

fix: 挂机图鉴, 增加宝藏CD检查

1. 开始挖宝藏有结束时间,无过期时间
2. 用户获取宝藏后,宝藏才进入CD状态
Showing 2 changed files with 59 additions and 29 deletions   Show diff stats
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)
  30 +local function checkReward(role, isTreasure)
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
... ... @@ -126,11 +126,15 @@ local function checkReward(role)
126 126 end
127 127  
128 128 --挂机得到的宝藏加入到挂机奖励
129   - local treasureList= role.dailyData:checkTreasureList(hangInfo.carbonId)
130   - for id, val in pairs(treasureList) do
131   - local award = val.award:toNumMap()
132   - for k,v in pairs(award) do
133   - items[k] = (award[k] or 0) + v
  129 + if isTreasure or false == true then
  130 + local treasureList= role.dailyData:checkTreasureList(hangInfo.carbonId)
  131 + if next(treasureList) ~= nil then
  132 + for id, val in pairs(treasureList) do
  133 + local award = val.award:toNumMap()
  134 + for k,v in pairs(award) do
  135 + items[k] = (award[k] or 0) + v
  136 + end
  137 + end
134 138 end
135 139 end
136 140  
... ... @@ -418,7 +422,7 @@ end
418 422 function _M.getRewardRpc(agent , data)
419 423 local role = agent.role
420 424 local hangTime = getHangTime(role)
421   - checkReward(role)
  425 + checkReward(role, true)
422 426 local items = role:getProperty("hangBag")
423 427 if not next(items) then return end
424 428 local reward, change = role:award(items, {log = {desc = "hangReward"}})
... ...
src/models/Daily.lua
... ... @@ -128,13 +128,13 @@ function Daily:checkTreasureExpired(treasureAttr, treasureList)
128 128 -- check finish
129 129 if curInfo["expire_time"] then
130 130 if curInfo.cool_time > 1 then
131   - if skynet.timex() > curInfo["expire_time"] then --已过期
  131 + if skynet.timex() >= curInfo["expire_time"] then --已过期
132 132 treasureList[treasureAttr.id] = nil
133 133 elseif skynet.timex() > curInfo["expire_time"] - curInfo.cool_time * oneDay then --未冷却
134 134 curInfo = nil
135 135 end
136 136 else
137   - if skynet.timex() > curInfo["expire_time"] then
  137 + if skynet.timex() >= curInfo["expire_time"] then
138 138 treasureList[treasureAttr.id] = nil
139 139 end
140 140 end
... ... @@ -168,7 +168,6 @@ function Daily:checkTreasureWeight(treasureList, tmptreasure, treasureBase)
168 168 local removeId
169 169 while next(tmptreasure) do
170 170 local tmp = self:checkTreasureBase(tmptreasure, treasureBase, removeId)
171   - print(treasureBase)
172 171 local id = math.randWeight(tmp, "weight") --宝藏id
173 172 if not id then
174 173 break
... ... @@ -202,28 +201,55 @@ function Daily:checkTreasureChapterId(curInfo, treasureList, chapterId)
202 201 return treasure
203 202 end
204 203  
205   - if chapterId == curInfo.chapter_id then --开始挖宝关卡ID=挂机关卡ID
206   - if not curInfo["expire_time"] then
207   - if curInfo.cool_time > 1 then
208   - curInfo["expire_time"] = skynet.timex() + curInfo.working_time + curInfo.cool_time * oneDay
209   - else
210   - curInfo["expire_time"] = skynet.timex() + curInfo.working_time
211   - end
  204 + --开始挖宝关卡ID=挂机关卡ID
  205 + if chapterId == curInfo.chapter_id then
  206 + --开始挖宝
  207 + if not curInfo["end_time"] then
  208 + curInfo["end_time"] = skynet.timex() + curInfo.working_time
212 209 else
213   - if skynet.timex() > curInfo["expire_time"] then --已过期
214   - treasure = table.remove(treasureList, curInfo.id)
215   - elseif skynet.timex() > curInfo["expire_time"] - curInfo.cool_time * oneDay then --未冷却
216   - treasure = curInfo
  210 + --宝藏冷却时间
  211 + if not curInfo["expire_time"] then
  212 + --已挖到
  213 + if skynet.timex() >= curInfo["end_time"] then
  214 + treasure = treasureList[curInfo.id]
  215 + if curInfo.cool_time > 1 then
  216 + curInfo["expire_time"] = skynet.timex() + curInfo.cool_time * oneDay
  217 + else
  218 + curInfo["expire_time"] = skynet.timex()
  219 + end
  220 + if skynet.timex() >= curInfo["expire_time"] then
  221 + table.remove(treasureList, curInfo.id)
  222 + end
  223 + end
  224 + else
  225 + --已经领取宝藏 检索宝藏冷却时间
  226 + if skynet.timex() >= curInfo["expire_time"] then
  227 + table.remove(treasureList, curInfo.id)
  228 + end
217 229 end
218 230 end
219 231 else
220   - if curInfo["expire_time"] then
221   - if skynet.timex() > curInfo["expire_time"] then --已过期
222   - treasure = table.remove(treasureList, curInfo.id)
223   - elseif skynet.timex() > curInfo["expire_time"] - curInfo.cool_time * oneDay then --未冷却
224   - treasure = curInfo
225   - else
226   - curInfo["expire_time"] = nil
  232 + --已经开始挖宝
  233 + if curInfo["end_time"] then
  234 + if not curInfo["expire_time"] then --宝藏冷却时间
  235 + if skynet.timex() >= curInfo["end_time"] then --已挖到
  236 + treasure = treasureList[curInfo.id]
  237 + if curInfo.cool_time > 1 then
  238 + curInfo["expire_time"] = skynet.timex() + curInfo.cool_time * oneDay
  239 + else
  240 + curInfo["expire_time"] = skynet.timex()
  241 + end
  242 + if skynet.timex() >= curInfo["expire_time"] then
  243 + table.remove(treasureList, curInfo.id)
  244 + end
  245 + else
  246 + --未挖到直接删除
  247 + table.remove(treasureList, curInfo.id)
  248 + end
  249 + else --已经领取宝藏 检索宝藏冷却时间
  250 + if skynet.timex() >= curInfo["expire_time"] then
  251 + table.remove(treasureList, curInfo.id)
  252 + end
227 253 end
228 254 end
229 255 end
... ... @@ -236,7 +262,7 @@ function Daily:buyTreasure(treasureList)
236 262 for id, val in pairs(treasureList) do
237 263 treasureBase = treasureBase - val.treasure_value
238 264 if treasureBase < 0 then
239   - treasureBase = treasureBase + val.treasure_value
  265 + treasureBase = treasureBase + val.treasure_value
240 266 print("资源余额不足")
241 267 return
242 268 else
... ...