Commit 2bc706ab9583b23ebb8a352766dd7147f293d981
1 parent
b8b1c164
兑换活动重置,累充功能
Showing
6 changed files
with
157 additions
and
26 deletions
Show diff stats
src/ProtocolCode.lua
... | ... | @@ -221,6 +221,8 @@ actionCodes = { |
221 | 221 | Activity_actCalendaTaskRpc = 655, |
222 | 222 | Activity_actPaySignRpc = 656, |
223 | 223 | Activity_exchangeRpc = 657, |
224 | + Activity_gachakonRpc = 658, | |
225 | + Activity_hangDropRpc = 659, | |
224 | 226 | |
225 | 227 | Radio_startQuestRpc = 700, |
226 | 228 | Radio_finishQuestRpc = 701, | ... | ... |
src/actions/ActivityAction.lua
... | ... | @@ -277,7 +277,8 @@ function _M.exchangeRpc(agent, data) |
277 | 277 | local exchangeData = curData[actid] or {} |
278 | 278 | local curCount = exchangeData[id] or 0 |
279 | 279 | local actCfg = exchangeCfg[id] |
280 | - if curCount >= actCfg then return 4 end | |
280 | + local limitArr = actCfg.limit:toArray(true, "=") | |
281 | + if curCount >= limitArr[2] then return 4 end | |
281 | 282 | |
282 | 283 | local costs = actCfg.goods:toNumMap() |
283 | 284 | if not role:checkItemEnough(costs) then return 5 end |
... | ... | @@ -299,32 +300,120 @@ function _M.gachakonRpc(agent, data) |
299 | 300 | local role = agent.role |
300 | 301 | local msg = MsgPack.unpack(data) |
301 | 302 | local actid = msg.actid |
303 | + local count = msg.count | |
304 | + | |
305 | + if count > 10 then return end | |
306 | + | |
302 | 307 | if not role.activity:isOpenById(actid) then return 1 end |
303 | 308 | |
309 | + local actCtrlData = csvdb["activity_ctrlCsv"][actid] | |
310 | + if not actCtrlData then return 2 end | |
311 | + local cost = actCtrlData.condition2:toNumMap() | |
312 | + | |
304 | 313 | local actCfg = csvdb["activity_capsuleToysCsv"][actid] |
305 | - if not actCfg then return 2 end | |
314 | + if not actCfg then return 3 end | |
315 | + | |
316 | + for k, v in pairs(cost) do | |
317 | + cost[k] = v * count | |
318 | + end | |
319 | + | |
320 | + if not role:checkItemEnough(cost) then return 4 end | |
306 | 321 | |
307 | 322 | local gachakonInfo = role.activity:getActData("Gachakon") or {} |
308 | 323 | local tmpCfg = clone(actCfg) |
309 | - local flag = 0 | |
310 | - for id, cfg in pairs(tmpCfg) do | |
311 | - local num = gachakonInfo[id] or 0 | |
312 | - cfg.amount = cfg.amount >= num and cfg.amount - num or 0 | |
313 | - cfg.weight = cfg.weight * cfg.amount | |
314 | - if cfg.weight > 0 then | |
315 | - flag = 1 | |
324 | + local award = {} | |
325 | + local remain = 0 | |
326 | + local reset = false | |
327 | + for i = 1, count do | |
328 | + local flag = 0 | |
329 | + for id, cfg in pairs(tmpCfg) do | |
330 | + local num = gachakonInfo[id] or 0 | |
331 | + cfg.amount = cfg.amount >= num and cfg.amount - num or 0 | |
332 | + cfg.weight = cfg.weight * cfg.amount | |
333 | + if cfg.weight > 0 then | |
334 | + flag = 1 | |
335 | + end | |
336 | + end | |
337 | + if flag == 0 then | |
338 | + reset = true | |
339 | + break | |
340 | + end | |
341 | + local id = math.randWeight(tmpCfg, "weight") | |
342 | + gachakonInfo[id] = (gachakonInfo[id] or 0) + 1 | |
343 | + local curAward = tmpCfg[id].award:toNumMap() | |
344 | + for k, v in pairs(curAward) do | |
345 | + award[k] = (award[k] or 0) + v | |
316 | 346 | end |
347 | + remain = remain + 1 | |
317 | 348 | end |
318 | - if flag == 0 then return 3 end | |
319 | 349 | |
320 | - local id = math.randWeight(tmpCfg, "weight") | |
321 | - local reward, change = role:award(tmpCfg[id].award, {log = {desc = "actGachakon", int1 = actid, int2 = id}}) | |
350 | + if count > remain then return 5 end | |
351 | + | |
352 | + role:costItems(cost, {log = {desc = "actGachakon", int1 = actid, int2 = count}}) | |
322 | 353 | |
323 | - gachakonInfo[id] = (gachakonInfo[id] or 0) + 1 | |
354 | + local reward, change = role:award(award, {log = {desc = "actGachakon", int1 = actid, int2 = count}}) | |
355 | + if reset then | |
356 | + gachakonInfo = {} | |
357 | + end | |
324 | 358 | role.activity:updateActData("Gachakon", gachakonInfo) |
325 | 359 | |
326 | 360 | SendPacket(actionCodes.Activity_gachakonRpc, MsgPack.pack(role:packReward(reward, change))) |
327 | 361 | return true |
328 | 362 | end |
329 | 363 | |
364 | +function _M.hangDropRpc(agent, data) | |
365 | + local role = agent.role | |
366 | + local msg = MsgPack.unpack(data) | |
367 | + local actid = msg.actid | |
368 | + if not role.activity:isOpenById(actid) then return 1 end | |
369 | + | |
370 | + local actCfg = csvdb["activity_putCsv"][actid] | |
371 | + if not actCfg then return 2 end | |
372 | + | |
373 | + local award, period = "", 0 | |
374 | + for i = 1, #actCfg do | |
375 | + local cfg = actCfg[i] | |
376 | + if not cfg then | |
377 | + break | |
378 | + end | |
379 | + if cfg.condition ~= "" then | |
380 | + local arr = cfg.condition:toArray(true, "=") | |
381 | + local type = arr[1] | |
382 | + if type == 1 then | |
383 | + local actId = arr[2] | |
384 | + local carbonId = arr[3] | |
385 | + if not role.activity:isOpenById(actid) then return 3 end | |
386 | + local clInfo = role.activity:getActData("ChallengeLevel") or {} | |
387 | + if not clInfo[carbonId] then | |
388 | + break | |
389 | + end | |
390 | + end | |
391 | + end | |
392 | + award = cfg.reward | |
393 | + period = cfg.period * 60 | |
394 | + end | |
395 | + local actData = role.activity:getActData("HangDrop") or 0 | |
396 | + local timeNow = skynet.timex() | |
397 | + if period == 0 or award == "" then | |
398 | + return 4 | |
399 | + end | |
400 | + local num = math.floor((timeNow - actData)/ period) | |
401 | + num = num > 8 and 8 or num | |
402 | + if num == 0 then | |
403 | + return 5 | |
404 | + end | |
405 | + local reward, change = {}, nil | |
406 | + for id, value in pairs(award:toNumMap()) do | |
407 | + reward[id] = value * num | |
408 | + end | |
409 | + | |
410 | + reward, change = role:award(reward, {log = {desc = "actHangDrop", int1 = actid, int2 = num}}) | |
411 | + | |
412 | + role.activity:updateActData("HangDrop", timeNow) | |
413 | + | |
414 | + SendPacket(actionCodes.Activity_hangDropRpc, MsgPack.pack(role:packReward(reward, change))) | |
415 | + | |
416 | + return true | |
417 | +end | |
418 | + | |
330 | 419 | return _M |
331 | 420 | \ No newline at end of file | ... | ... |
src/actions/StoreAction.lua
... | ... | @@ -405,15 +405,20 @@ function _M.getTotalRechargeAwardRpc(agent, data) |
405 | 405 | local totalRechargeRecord = role.storeData:getProperty("totalRR") |
406 | 406 | local flag = string.char(string.getbit(totalRechargeRecord, index)) |
407 | 407 | if flag == "1" then return 1 end |
408 | - local cfg = csvdb["Csv"][index] | |
408 | + local cfg = csvdb["activity_payRebateCsv"][index] | |
409 | 409 | if not cfg then return 2 end |
410 | - if cfg.condition > totalTwd then return 3 end | |
410 | + if cfg.twd > totalTwd then return 3 end | |
411 | 411 | |
412 | 412 | totalRechargeRecord = string.setbit(totalRechargeRecord, index) |
413 | 413 | role.storeData:updateProperty({field = "totalRR", value = totalRechargeRecord}) |
414 | + local main = cfg.main_reward:toNumMap() | |
415 | + local sub = cfg.sub_reward:toNumMap() | |
416 | + for k, v in pairs(sub) do | |
417 | + main[k] = (main[k] or 0) + v | |
418 | + end | |
414 | 419 | |
415 | - local reward, _ = role:award(cfg.reward, {log = {desc = "totalRecharge", int1 = index}}) | |
416 | - SendPacket(actionCodes.Store_getTotalRechargeAwardRpc, MsgPack.pack({reward = reward})) | |
420 | + local reward, change = role:award(main, {log = {desc = "totalRecharge", int1 = index}}) | |
421 | + SendPacket(actionCodes.Store_getTotalRechargeAwardRpc, MsgPack.pack(role:packReward(reward, change))) | |
417 | 422 | return true |
418 | 423 | end |
419 | 424 | ... | ... |
src/models/Activity.lua
... | ... | @@ -56,7 +56,7 @@ Activity.schema = { |
56 | 56 | |
57 | 57 | act17 = {"table", {}}, -- {id=关卡星数, totalDmg=Boss总伤害} |
58 | 58 | act18 = {"table", {}, true}, -- {id=兑换数量} |
59 | - act19 = {"table", {}}, -- {挂机信息} | |
59 | + act19 = {"number", 0}, -- {挂机信息} | |
60 | 60 | act20 = {"table", {}}, -- {id=扭蛋抽出数量} |
61 | 61 | } |
62 | 62 | |
... | ... | @@ -148,7 +148,7 @@ function Activity:isOpen(activityType) |
148 | 148 | return false |
149 | 149 | end |
150 | 150 | |
151 | -function Activity:isOpneById(id) | |
151 | +function Activity:isOpenById(id) | |
152 | 152 | return self._isOpen[id] |
153 | 153 | end |
154 | 154 | |
... | ... | @@ -426,13 +426,34 @@ activityFunc[Activity.ActivityType.CalendaTask] = { |
426 | 426 | -- 兑换 |
427 | 427 | activityFunc[Activity.ActivityType.Exchange] = { |
428 | 428 | ["init"] = function(self, actType, isCrossDay, notify, actId) |
429 | - local role = self.owner | |
430 | 429 | local actData = self:getActData(actType) or {} |
431 | 430 | actData[actId] = {} |
432 | 431 | self:updateActData(actType, actData, not notify) |
433 | 432 | end, |
434 | - --["close"] = function(self, actType, notify, actId) | |
435 | - --end, | |
433 | + ["crossDay"] = function(self, actType, notify, actId) | |
434 | + local actData = self:getActData(actType) or {} | |
435 | + local lastTs = actData["ts"] or 0 | |
436 | + local timeNow = skynet.timex() | |
437 | + local cfg = csvdb["activity_ctrlCsv"][actId] | |
438 | + if not cfg then return end | |
439 | + local refreshTimes = cfg.condition2:toArray(false, "=") | |
440 | + for i = 1, #refreshTimes do | |
441 | + local rt = toUnixtime(refreshTimes[1]..string_format("%02x", RESET_TIME)) | |
442 | + if timeNow >= rt and rt > lastTs then | |
443 | + lastTs = rt | |
444 | + actData = {} | |
445 | + end | |
446 | + end | |
447 | + if next(actData) then | |
448 | + actData["ts"] = lastTs | |
449 | + self:updateActData(actType, actData, not notify) | |
450 | + end | |
451 | + end, | |
452 | + ["close"] = function(self, actType, notify, actId) | |
453 | + local actData = self:getActData(actType) or {} | |
454 | + actData[actId] = nil | |
455 | + self:updateActData(actType, actData, not notify) | |
456 | + end, | |
436 | 457 | } |
437 | 458 | |
438 | 459 | -- 扭蛋机 |
... | ... | @@ -445,6 +466,19 @@ activityFunc[Activity.ActivityType.Gachakon] = { |
445 | 466 | end, |
446 | 467 | } |
447 | 468 | |
469 | +-- 挂机掉落 | |
470 | +activityFunc[Activity.ActivityType.HangDrop] = { | |
471 | + ["init"] = function(self, actType, isCrossDay, notify, actId) | |
472 | + local actime = self:getProperty("actime") | |
473 | + local startTime = actime[actId] | |
474 | + local actData = self:getActData(actType) or 0 | |
475 | + local cfg = csvdb["activity_putCsv"][actId] | |
476 | + if not cfg then return end | |
477 | + actData = startTime | |
478 | + self:updateActData(actType, actData, not notify) | |
479 | + end | |
480 | +} | |
481 | + | |
448 | 482 | function Activity:initActivity(actId, isCrossDay, notify) |
449 | 483 | local actData = csvdb["activity_ctrlCsv"][actId] |
450 | 484 | if not actData then return end |
... | ... | @@ -473,7 +507,7 @@ function Activity:refreshDailyData(notify) |
473 | 507 | if status and actData then |
474 | 508 | local actType = actData.showType |
475 | 509 | if activityFunc[actType] and activityFunc[actType]['crossDay'] then |
476 | - activityFunc[actType]["crossDay"](self, actType, notify) | |
510 | + activityFunc[actType]["crossDay"](self, actType, notify, actId) | |
477 | 511 | end |
478 | 512 | end |
479 | 513 | end |
... | ... | @@ -490,8 +524,8 @@ end |
490 | 524 | -- 获取此次挂机掉落翻倍时长 |
491 | 525 | function Activity:getActHangDoubleTime(lastTs, nowTs) |
492 | 526 | local type = "DoubleDrop" |
493 | - local actId = checkActivityType(type) | |
494 | - local isOpen = self:isOpen(type) | |
527 | + --local actId = checkActivityType(type) | |
528 | + local isOpen, actId = self:isOpen(type) | |
495 | 529 | local openTs = self:getProperty("actime")[actId] or 0 |
496 | 530 | local timeNow = skynet.timex() |
497 | 531 | lastTs = math.max(lastTs, openTs) | ... | ... |