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,6 +221,8 @@ actionCodes = { | ||
| 221 | Activity_actCalendaTaskRpc = 655, | 221 | Activity_actCalendaTaskRpc = 655, |
| 222 | Activity_actPaySignRpc = 656, | 222 | Activity_actPaySignRpc = 656, |
| 223 | Activity_exchangeRpc = 657, | 223 | Activity_exchangeRpc = 657, |
| 224 | + Activity_gachakonRpc = 658, | ||
| 225 | + Activity_hangDropRpc = 659, | ||
| 224 | 226 | ||
| 225 | Radio_startQuestRpc = 700, | 227 | Radio_startQuestRpc = 700, |
| 226 | Radio_finishQuestRpc = 701, | 228 | Radio_finishQuestRpc = 701, |
src/actions/ActivityAction.lua
| @@ -277,7 +277,8 @@ function _M.exchangeRpc(agent, data) | @@ -277,7 +277,8 @@ function _M.exchangeRpc(agent, data) | ||
| 277 | local exchangeData = curData[actid] or {} | 277 | local exchangeData = curData[actid] or {} |
| 278 | local curCount = exchangeData[id] or 0 | 278 | local curCount = exchangeData[id] or 0 |
| 279 | local actCfg = exchangeCfg[id] | 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 | local costs = actCfg.goods:toNumMap() | 283 | local costs = actCfg.goods:toNumMap() |
| 283 | if not role:checkItemEnough(costs) then return 5 end | 284 | if not role:checkItemEnough(costs) then return 5 end |
| @@ -299,32 +300,120 @@ function _M.gachakonRpc(agent, data) | @@ -299,32 +300,120 @@ function _M.gachakonRpc(agent, data) | ||
| 299 | local role = agent.role | 300 | local role = agent.role |
| 300 | local msg = MsgPack.unpack(data) | 301 | local msg = MsgPack.unpack(data) |
| 301 | local actid = msg.actid | 302 | local actid = msg.actid |
| 303 | + local count = msg.count | ||
| 304 | + | ||
| 305 | + if count > 10 then return end | ||
| 306 | + | ||
| 302 | if not role.activity:isOpenById(actid) then return 1 end | 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 | local actCfg = csvdb["activity_capsuleToysCsv"][actid] | 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 | local gachakonInfo = role.activity:getActData("Gachakon") or {} | 322 | local gachakonInfo = role.activity:getActData("Gachakon") or {} |
| 308 | local tmpCfg = clone(actCfg) | 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 | end | 346 | end |
| 347 | + remain = remain + 1 | ||
| 317 | end | 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 | role.activity:updateActData("Gachakon", gachakonInfo) | 358 | role.activity:updateActData("Gachakon", gachakonInfo) |
| 325 | 359 | ||
| 326 | SendPacket(actionCodes.Activity_gachakonRpc, MsgPack.pack(role:packReward(reward, change))) | 360 | SendPacket(actionCodes.Activity_gachakonRpc, MsgPack.pack(role:packReward(reward, change))) |
| 327 | return true | 361 | return true |
| 328 | end | 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 | return _M | 419 | return _M |
| 331 | \ No newline at end of file | 420 | \ No newline at end of file |
src/actions/StoreAction.lua
| @@ -405,15 +405,20 @@ function _M.getTotalRechargeAwardRpc(agent, data) | @@ -405,15 +405,20 @@ function _M.getTotalRechargeAwardRpc(agent, data) | ||
| 405 | local totalRechargeRecord = role.storeData:getProperty("totalRR") | 405 | local totalRechargeRecord = role.storeData:getProperty("totalRR") |
| 406 | local flag = string.char(string.getbit(totalRechargeRecord, index)) | 406 | local flag = string.char(string.getbit(totalRechargeRecord, index)) |
| 407 | if flag == "1" then return 1 end | 407 | if flag == "1" then return 1 end |
| 408 | - local cfg = csvdb["Csv"][index] | 408 | + local cfg = csvdb["activity_payRebateCsv"][index] |
| 409 | if not cfg then return 2 end | 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 | totalRechargeRecord = string.setbit(totalRechargeRecord, index) | 412 | totalRechargeRecord = string.setbit(totalRechargeRecord, index) |
| 413 | role.storeData:updateProperty({field = "totalRR", value = totalRechargeRecord}) | 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 | return true | 422 | return true |
| 418 | end | 423 | end |
| 419 | 424 |
src/models/Activity.lua
| @@ -56,7 +56,7 @@ Activity.schema = { | @@ -56,7 +56,7 @@ Activity.schema = { | ||
| 56 | 56 | ||
| 57 | act17 = {"table", {}}, -- {id=关卡星数, totalDmg=Boss总伤害} | 57 | act17 = {"table", {}}, -- {id=关卡星数, totalDmg=Boss总伤害} |
| 58 | act18 = {"table", {}, true}, -- {id=兑换数量} | 58 | act18 = {"table", {}, true}, -- {id=兑换数量} |
| 59 | - act19 = {"table", {}}, -- {挂机信息} | 59 | + act19 = {"number", 0}, -- {挂机信息} |
| 60 | act20 = {"table", {}}, -- {id=扭蛋抽出数量} | 60 | act20 = {"table", {}}, -- {id=扭蛋抽出数量} |
| 61 | } | 61 | } |
| 62 | 62 | ||
| @@ -148,7 +148,7 @@ function Activity:isOpen(activityType) | @@ -148,7 +148,7 @@ function Activity:isOpen(activityType) | ||
| 148 | return false | 148 | return false |
| 149 | end | 149 | end |
| 150 | 150 | ||
| 151 | -function Activity:isOpneById(id) | 151 | +function Activity:isOpenById(id) |
| 152 | return self._isOpen[id] | 152 | return self._isOpen[id] |
| 153 | end | 153 | end |
| 154 | 154 | ||
| @@ -426,13 +426,34 @@ activityFunc[Activity.ActivityType.CalendaTask] = { | @@ -426,13 +426,34 @@ activityFunc[Activity.ActivityType.CalendaTask] = { | ||
| 426 | -- 兑换 | 426 | -- 兑换 |
| 427 | activityFunc[Activity.ActivityType.Exchange] = { | 427 | activityFunc[Activity.ActivityType.Exchange] = { |
| 428 | ["init"] = function(self, actType, isCrossDay, notify, actId) | 428 | ["init"] = function(self, actType, isCrossDay, notify, actId) |
| 429 | - local role = self.owner | ||
| 430 | local actData = self:getActData(actType) or {} | 429 | local actData = self:getActData(actType) or {} |
| 431 | actData[actId] = {} | 430 | actData[actId] = {} |
| 432 | self:updateActData(actType, actData, not notify) | 431 | self:updateActData(actType, actData, not notify) |
| 433 | end, | 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,6 +466,19 @@ activityFunc[Activity.ActivityType.Gachakon] = { | ||
| 445 | end, | 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 | function Activity:initActivity(actId, isCrossDay, notify) | 482 | function Activity:initActivity(actId, isCrossDay, notify) |
| 449 | local actData = csvdb["activity_ctrlCsv"][actId] | 483 | local actData = csvdb["activity_ctrlCsv"][actId] |
| 450 | if not actData then return end | 484 | if not actData then return end |
| @@ -473,7 +507,7 @@ function Activity:refreshDailyData(notify) | @@ -473,7 +507,7 @@ function Activity:refreshDailyData(notify) | ||
| 473 | if status and actData then | 507 | if status and actData then |
| 474 | local actType = actData.showType | 508 | local actType = actData.showType |
| 475 | if activityFunc[actType] and activityFunc[actType]['crossDay'] then | 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 | end | 511 | end |
| 478 | end | 512 | end |
| 479 | end | 513 | end |
| @@ -490,8 +524,8 @@ end | @@ -490,8 +524,8 @@ end | ||
| 490 | -- 获取此次挂机掉落翻倍时长 | 524 | -- 获取此次挂机掉落翻倍时长 |
| 491 | function Activity:getActHangDoubleTime(lastTs, nowTs) | 525 | function Activity:getActHangDoubleTime(lastTs, nowTs) |
| 492 | local type = "DoubleDrop" | 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 | local openTs = self:getProperty("actime")[actId] or 0 | 529 | local openTs = self:getProperty("actime")[actId] or 0 |
| 496 | local timeNow = skynet.timex() | 530 | local timeNow = skynet.timex() |
| 497 | lastTs = math.max(lastTs, openTs) | 531 | lastTs = math.max(lastTs, openTs) |
src/models/RoleLog.lua
| @@ -46,6 +46,7 @@ local ItemReason = { | @@ -46,6 +46,7 @@ local ItemReason = { | ||
| 46 | actExchange = 131, -- 兑换活动 | 46 | actExchange = 131, -- 兑换活动 |
| 47 | actGachakon = 132, -- 扭蛋活动 | 47 | actGachakon = 132, -- 扭蛋活动 |
| 48 | totalRecharge = 133, -- 累计充值奖励 | 48 | totalRecharge = 133, -- 累计充值奖励 |
| 49 | + actHangDrop = 134, -- 掉落活动奖励 | ||
| 49 | 50 | ||
| 50 | 51 | ||
| 51 | advHang = 301, -- 拾荒挂机 | 52 | advHang = 301, -- 拾荒挂机 |