From 7bb30dca2407dc585f93d933ce0456bb041cb4a0 Mon Sep 17 00:00:00 2001 From: zhouhaihai Date: Tue, 4 Aug 2020 19:12:22 +0800 Subject: [PATCH] 修改发奖 --- src/actions/ActivityAction.lua | 22 +++++++++++----------- src/actions/AdvAction.lua | 26 +++++++++++++------------- src/actions/CarAction.lua | 12 ++++++------ src/actions/DinerAction.lua | 39 ++++++++++++++++++++------------------- src/actions/EmailAction.lua | 13 ++++++------- src/actions/GmAction.lua | 6 ++++++ src/actions/HangAction.lua | 33 +++++++++++++++++++-------------- src/actions/HeroAction.lua | 18 ++++++++---------- src/actions/PvpAction.lua | 14 ++++++++------ src/actions/RoleAction.lua | 43 +++++++++++++++++++++++-------------------- src/actions/TowerAction.lua | 6 +++--- src/adv/AdvTask.lua | 16 ++++++++-------- src/models/RolePlugin.lua | 8 +++++++- 13 files changed, 138 insertions(+), 118 deletions(-) diff --git a/src/actions/ActivityAction.lua b/src/actions/ActivityAction.lua index e5e8a07..fff5b85 100644 --- a/src/actions/ActivityAction.lua +++ b/src/actions/ActivityAction.lua @@ -32,9 +32,9 @@ function _M.sudokuRpc(agent, data) if (sudoku.task[phase][id] or 0) < curData.con1 then return 2 end sudoku.task[phase][id] = -1 - local task = role:award(curData.reward, {log = {desc = "sudoku", int1 = id, int2 = phase}}) -- 任务奖励 + local task, tchange = role:award(curData.reward, {log = {desc = "sudoku", int1 = id, int2 = phase}}) -- 任务奖励 - local reward = {} + local reward, rchange = {} local rId = {} for pid, pdata in pairs(csvdb["guide_sudoku_rewardCsv"][phase] or {}) do local pos = pdata.pos:toArray(true, "=") @@ -60,14 +60,14 @@ function _M.sudokuRpc(agent, data) if not next(reward) then reward = nil else - reward = role:award(reward, {log = {desc = "sudokuR", int1 = id, int2 = phase}}) + reward, rchange = role:award(reward, {log = {desc = "sudokuR", int1 = id, int2 = phase}}) end role:updateProperty({field = "sudoku", value = sudoku}) role:log("act_action", {desc = "sudoku", int1 = id, int2 = phase}) - SendPacket(actionCodes.Activity_sudokuRpc, MsgPack.pack({task = task, reward = reward, rId = rId})) + SendPacket(actionCodes.Activity_sudokuRpc, MsgPack.pack({task = role:packReward(task, tchange), reward = role:packReward(reward, rchange), rId = rId})) return true end @@ -90,7 +90,7 @@ function _M.sudokuRewardRpc(agent, data) end end - local reward = role:award(globalCsv.guide_sudoku_reward[phase], {log = {desc = "sudokuRP", int1 = phase}}) + local reward, change = role:award(globalCsv.guide_sudoku_reward[phase], {log = {desc = "sudokuRP", int1 = phase}}) sudoku[-1] = phase + 1 sudoku.task[phase] = nil @@ -100,7 +100,7 @@ function _M.sudokuRewardRpc(agent, data) end role:updateProperty({field = "sudoku", value = sudoku}) - SendPacket(actionCodes.Activity_sudokuRewardRpc, MsgPack.pack(reward)) + SendPacket(actionCodes.Activity_sudokuRewardRpc, MsgPack.pack(role:packReward(reward, change))) return true end @@ -125,10 +125,10 @@ function _M.signRpc(agent, data) end signs[curDay] = yearMonth - local reward = role:award(monthData[curDay].item, {log = {desc = "sign", int1 = yearMonth, int2 = curDay}}) + local reward, change = role:award(monthData[curDay].item, {log = {desc = "sign", int1 = yearMonth, int2 = curDay}}) role:changeUpdates({{type = "sign", field = curDay, value = yearMonth}}) - SendPacket(actionCodes.Activity_signRpc, MsgPack.pack(reward)) + SendPacket(actionCodes.Activity_signRpc, MsgPack.pack(role:packReward(reward, change))) return true end @@ -138,7 +138,7 @@ function _M.actSignRpc(agent, data) if not role.activity:isOpen("Sign") then return 1 end local curData = role.activity:getActData("Sign") - local reward = {} + local reward, change = {} for day, csvData in ipairs(csvdb["new_signInCsv"]) do if day <= (curData[0] or 0) then if not curData[day] then @@ -154,9 +154,9 @@ function _M.actSignRpc(agent, data) end if next(reward) then role.activity:updateActData("Sign", curData) - reward = role:award(reward, {log = {desc = "actSign"}}) + reward, change = role:award(reward, {log = {desc = "actSign"}}) end - SendPacket(actionCodes.Activity_actSignRpc, MsgPack.pack(reward)) + SendPacket(actionCodes.Activity_actSignRpc, MsgPack.pack(role:packReward(reward, change))) return true end diff --git a/src/actions/AdvAction.lua b/src/actions/AdvAction.lua index 2aa6450..4279a6b 100644 --- a/src/actions/AdvAction.lua +++ b/src/actions/AdvAction.lua @@ -290,7 +290,7 @@ function _M.endHangRpc(agent, data) local chapterData = csvdb["adv_chapterCsv"][chapterId] if not chapterData then return end - local reward, isFull + local reward, isFull, change if skynet.timex() >= info.time then -- 英雄加成 local idleUnit = chapterData.idleUnit:toNumMap() @@ -321,7 +321,7 @@ function _M.endHangRpc(agent, data) for itemId, count in pairs(idleReward) do idleReward[itemId] = math.floor(count * (maxCampsite.idleValue + upUnit) / 100) end - reward = role:award(idleReward, {log = {desc = "advHang", int1 = chapterId}}) + reward, change = role:award(idleReward, {log = {desc = "advHang", int1 = chapterId}}) else if cancel then role:changeAdvCount(-chapterData.limitlevel) @@ -339,7 +339,7 @@ function _M.endHangRpc(agent, data) role:log("adv_action", {desc = "endHang", int1 = chapterId, short1 = cancel and 1 or 0}) - SendPacket(actionCodes.Adv_endHangRpc, MsgPack.pack({reward = reward, isFull = isFull})) + SendPacket(actionCodes.Adv_endHangRpc, MsgPack.pack({reward = reward, change = change, isFull = isFull})) return true end @@ -381,9 +381,9 @@ function _M.finishTaskRpc(agent, data) if not isCanContinue(role) then return end local adv = role:getAdvData() local taskId = msg.taskId -- -1 则是主线任务 - local status, reward + local status, reward, change if taskId == -1 then - status, reward = adv:finishMTask() + status, reward, change = adv:finishMTask() else status, reward = adv:finishTask(taskId) adv:checkAchievement(adv.AchievType.TaskLayer, 1, taskId) @@ -395,7 +395,7 @@ function _M.finishTaskRpc(agent, data) adv:log({desc = "finishTask", int1 = taskId}) - SendPacket(actionCodes.Adv_finishTaskRpc, MsgPack.pack({reward = reward})) + SendPacket(actionCodes.Adv_finishTaskRpc, MsgPack.pack(role:packReward(reward, change))) return true end @@ -749,11 +749,11 @@ function _M.repayWheelSurfRpc(agent, data) advDrawB[ptype] = advDrawB[ptype] - globalCsv.adv_draw_back_cond role:updateProperty({field = "advDrawB", value = advDrawB}) local gift = drawData["pool3"]:randWeight(true) - local reward = {[gift[1]] = gift[2]} - reward = role:award(reward, {log = {desc = "advRepayWheelSurf", int1 = ptype}}) + local reward, change = {[gift[1]] = gift[2]} + reward, change = role:award(reward, {log = {desc = "advRepayWheelSurf", int1 = ptype}}) role:log("adv_action", {desc = "advRepayWheelSurf", int1 = ptype}) - SendPacket(actionCodes.Adv_repayWheelSurfRpc, MsgPack.pack({reward = reward})) + SendPacket(actionCodes.Adv_repayWheelSurfRpc, MsgPack.pack(role:packReward(reward, change))) return true end @@ -766,17 +766,17 @@ function _M.finishAchievRpc(agent, data) local adv = role:getAdvData() - local status, reward + local status, reward, change if ctype == 1 then - status, reward = adv:finishAchievement(chapterId, taskId) + status, reward, change = adv:finishAchievement(chapterId, taskId) elseif ctype == 2 then - status, reward = adv:getAchievementReward(chapterId, taskId) + status, reward, change = adv:getAchievementReward(chapterId, taskId) end if not status then return end adv:updateAchievement() role:log("adv_action", {desc = "finishAchiev", short1 = ctype, int1 = chapterId, int2 = taskId}) - SendPacket(actionCodes.Adv_finishAchievRpc, MsgPack.pack({reward = reward})) + SendPacket(actionCodes.Adv_finishAchievRpc, MsgPack.pack(role:packReward(reward, change))) return true end diff --git a/src/actions/CarAction.lua b/src/actions/CarAction.lua index 2a43a01..4712c81 100644 --- a/src/actions/CarAction.lua +++ b/src/actions/CarAction.lua @@ -150,7 +150,7 @@ function _M.saleEquipRpc(agent, data ) local own = role:getEquipCount(typ,lv) if math.illegalNum(count, 1, own) then return end end - local reward = {} + local reward, change = {} local allCount = 0 for id, count in pairs(backs) do allCount = allCount + count @@ -165,11 +165,11 @@ function _M.saleEquipRpc(agent, data ) end end role:checkTaskEnter("SaleEquip", {count = allCount}) - reward = role:award(reward, {log = {desc = "saleEquip"}}) + reward, change = role:award(reward, {log = {desc = "saleEquip"}}) role:log("role_action", {desc = "saleEquip", int1 = allCount}) - SendPacket(actionCodes.Car_saleEquipRpc, MsgPack.pack({reward = reward})) + SendPacket(actionCodes.Car_saleEquipRpc, MsgPack.pack(role:packReward(reward, change))) return true end @@ -179,7 +179,7 @@ function _M.saleRuneRpc(agent, data ) local backs = msg.backs if not backs then return end - local reward = {} + local reward, change = {} local count = 0 for _, uid in pairs(backs) do count = count + 1 @@ -196,9 +196,9 @@ function _M.saleRuneRpc(agent, data ) role:delRunes(backs, {log = {desc = "saleRune"}}) role:checkTaskEnter("DecoRune", {count = count}) - reward = role:award(reward, {log = {desc = "saleRune"}}) + reward, change = role:award(reward, {log = {desc = "saleRune"}}) - SendPacket(actionCodes.Car_saleRuneRpc, MsgPack.pack({reward = reward})) + SendPacket(actionCodes.Car_saleRuneRpc, MsgPack.pack(role:packReward(reward, change))) return true end diff --git a/src/actions/DinerAction.lua b/src/actions/DinerAction.lua index ee41e17..a5b3f56 100644 --- a/src/actions/DinerAction.lua +++ b/src/actions/DinerAction.lua @@ -141,19 +141,19 @@ function _M.removeSellRpc( agent, data ) end role.dinerData:updateSell(slot) - local reward = {} + local reward, change = {} local cost = dishData.material:toNumMap() for k, n in pairs(cost) do local sum = n*sell.count reward[k] = sum end - reward = role:award(reward, {log = {desc = "removeSell"}}) + reward, change = role:award(reward, {log = {desc = "removeSell"}}) sells[slot].count = 0 role:log("diner_action", {desc = "removeSell", int1 = dish}) role.dinerData:updateProperty({field = "sells", value = json.encode(sells)}) - SendPacket(actionCodes.Diner_removeSellRpc, MsgPack.pack({reward = reward})) + SendPacket(actionCodes.Diner_removeSellRpc, MsgPack.pack({reward = reward, change = change})) return true end @@ -195,7 +195,7 @@ function _M.getSellRewardRpc( agent, data ) role:checkTaskEnter("FoodSellGold", {count = v}) end end - role:award(gift, {log = {desc = "dinerSell"}}) + local reward, change = role:award(gift, {log = {desc = "dinerSell"}}) role.dinerData:popularAdd(popular) @@ -206,7 +206,7 @@ function _M.getSellRewardRpc( agent, data ) role:log("diner_action", {desc = "sell"}) - SendPacket(actionCodes.Diner_getSellRewardRpc, MsgPack.pack({reward = reward})) + SendPacket(actionCodes.Diner_getSellRewardRpc, MsgPack.pack({reward = reward, change = change})) return true end @@ -266,7 +266,8 @@ function _M.expediteSellRpc( agent, data ) role:checkTaskEnter("FoodSellGold", {count = v}) end end - role:award(gift, {log = {desc = "dinerSell"}}) + local change + reward, change = role:award(gift, {log = {desc = "dinerSell"}}) role.dinerData:popularAdd(popular) @@ -278,7 +279,7 @@ function _M.expediteSellRpc( agent, data ) role:log("diner_action", {desc = "sellQ"}) - SendPacket(actionCodes.Diner_expediteSellRpc, MsgPack.pack({reward = reward,popular = popular})) + SendPacket(actionCodes.Diner_expediteSellRpc, MsgPack.pack({reward = reward, change = change, popular = popular})) return true end @@ -493,7 +494,7 @@ function _M.updateTaskRpc( agent, data ) return 5 end - + local reward, change if cmd == 0 then if order.status ~= 0 then return 30 @@ -522,7 +523,7 @@ function _M.updateTaskRpc( agent, data ) end role:log("diner_action", {desc = "finishTask", int1 = order.id}) - role:award(taskData.reward, {log = {desc = "dinerFinishTask", int1 = order.id}}) + reward, change = role:award(taskData.reward, {log = {desc = "dinerFinishTask", int1 = order.id}}) table.remove(orders,index) role:checkTaskEnter("OverOderTask", {rarity = taskSet.rarity}) else @@ -530,7 +531,7 @@ function _M.updateTaskRpc( agent, data ) end role.dinerData:updateProperty({field = "order", value = json.encode(orders)}) - SendPacket(actionCodes.Diner_updateTaskRpc, '') + SendPacket(actionCodes.Diner_updateTaskRpc, MsgPack.pack({reward = reward, change = change})) return true end @@ -681,12 +682,12 @@ function _M.getGreenhouseRpc( agent, data ) end end role.dinerData:updateProperty({field = "gfood", value = gfood}) - local reward = role:award(reward, {log = {desc = "greenHourse", int1 = level}}) + local reward, change = role:award(reward, {log = {desc = "greenHourse", int1 = level}}) role:checkTaskEnter("FoodMGet") role:log("diner_action", {desc = "greenHourse"}) - SendPacket(actionCodes.Diner_getGreenhouseRpc, MsgPack.pack({reward = reward})) + SendPacket(actionCodes.Diner_getGreenhouseRpc, MsgPack.pack({reward = reward, change = change})) return true end @@ -798,7 +799,7 @@ function _M.entrustRpc(agent , data) local entrustId = entrust[1] if not entrustId then return end - local reward + local reward, change if ctype == 1 then -- 完成 local curData = csvdb["diner_missionCsv"][entrustId] if not curData then return end @@ -813,7 +814,7 @@ function _M.entrustRpc(agent , data) return end - reward = role:award(curData.reward, {log = {desc = "dinerEntrus", int1 = entrustId}}) + reward, change = role:award(curData.reward, {log = {desc = "dinerEntrus", int1 = entrustId}}) table.remove(entrust, 1) elseif ctype == 2 then -- 放弃 table.remove(entrust, 1) @@ -824,7 +825,7 @@ function _M.entrustRpc(agent , data) role:log("diner_action", {desc = "entrus", short1 = ctype, int1 = entrustId}) - SendPacket(actionCodes.Diner_entrustRpc, MsgPack.pack({reward = reward})) + SendPacket(actionCodes.Diner_entrustRpc, MsgPack.pack({reward = reward, change = change})) return true end @@ -845,12 +846,12 @@ function _M.collectRpc(agent , data) for slot, _ in pairs(sells) do role.dinerData:updateSell(slot) end - local reward = role:award(customerData.reward, {log = {desc = "dinerCollect", int1 = id}}) + local reward, change = role:award(customerData.reward, {log = {desc = "dinerCollect", int1 = id}}) customer[id] = 1 role.dinerData:updateProperty({field = "customer", value = customer}) -- 解锁了 role:log("diner_action", {desc = "collect", int1 = id}) - SendPacket(actionCodes.Diner_collectRpc, MsgPack.pack({reward = reward})) + SendPacket(actionCodes.Diner_collectRpc, MsgPack.pack({reward = reward, change = change})) return true end @@ -874,13 +875,13 @@ function _M.comboRewardRpc(agent , data) end comboStatus[id] = 1 - local reward = role:award(comboData.reward, {log = {desc = "dinerCombo", int1 = id}}) + local reward, change = role:award(comboData.reward, {log = {desc = "dinerCombo", int1 = id}}) role.dinerData:updateProperty({field = "comboStatus", value = comboStatus}) -- 解锁了 role:log("diner_action", {desc = "combo", int1 = id}) - SendPacket(actionCodes.Diner_comboRewardRpc, MsgPack.pack({reward = reward})) + SendPacket(actionCodes.Diner_comboRewardRpc, MsgPack.pack({reward = reward, change = change})) return true end diff --git a/src/actions/EmailAction.lua b/src/actions/EmailAction.lua index e5d504b..b26515f 100644 --- a/src/actions/EmailAction.lua +++ b/src/actions/EmailAction.lua @@ -86,7 +86,7 @@ function _M.drawAllAttachRpc(agent, data) local role = agent.role local roleId = role:getProperty("id") - local reward = {} + local reward, change = {} local ids = {} local emails = loadEmails(roleId) @@ -95,19 +95,18 @@ function _M.drawAllAttachRpc(agent, data) local attachments = getEmailAttachments(email) if attachments ~= "" then local emailId = email:getProperty("id") - local items = role:award(attachments, {log = {desc = "draw_attach", int1 = emailId, key1 = email:getProperty("title")}}) ids[emailId] = 1 red:hset(string.format(R_EMAIL_ITEM, roleId, emailId), "status", 2) role:log("mail_action", {desc = "draw_attach", int1 = emailId, key1 = email:getProperty("title"), key2 = attachments}) - for key, v in pairs(items) do + for key, v in pairs(attachments:toNumMap()) do reward[key] = (reward[key] or 0) + v end end end end) - - SendPacket(actionCodes.Email_drawAllAttachRpc, MsgPack.pack({ids = ids, reward = reward})) + reward, change = role:award(reward, {log = {desc = "draw_attach"}}) + SendPacket(actionCodes.Email_drawAllAttachRpc, MsgPack.pack({ids = ids, reward = reward, change = change})) return true end @@ -125,9 +124,9 @@ function _M.drawAttachRpc(agent, data) local attachments = getEmailAttachments(email) if attachments == "" then return end - local reward = role:award(attachments, {log = {desc = "draw_attach", int1 = emailId, key1 = email:getProperty("title")}}) + local reward, change = role:award(attachments, {log = {desc = "draw_attach", int1 = emailId, key1 = email:getProperty("title")}}) redisproxy:hset(rds, "status", 2) -- 领取标记 - SendPacket(actionCodes.Email_drawAttachRpc, MsgPack.pack({reward = reward})) + SendPacket(actionCodes.Email_drawAttachRpc, MsgPack.pack({reward = reward, change = change})) role:log("mail_action", {desc = "draw_attach", int1 = id, key1 = email:getProperty("title"), key2 = attachments}) return true diff --git a/src/actions/GmAction.lua b/src/actions/GmAction.lua index ec349a1..5750d21 100644 --- a/src/actions/GmAction.lua +++ b/src/actions/GmAction.lua @@ -517,6 +517,12 @@ function _M.ayncPurchase(role, params) return role:handlePurchase(params) or "" end +function _M.test(role, params) + local id = tonum(params.pm1, 0) + local store = require ("actions.StoreAction") + store.shopBuyRpc({role = role}, MsgPack.pack({id = id})) + return "成功" +end return _M \ No newline at end of file diff --git a/src/actions/HangAction.lua b/src/actions/HangAction.lua index 17c1c15..3e1cfd1 100644 --- a/src/actions/HangAction.lua +++ b/src/actions/HangAction.lua @@ -203,7 +203,7 @@ function _M.endBattleRpc(agent, data) if role:checkHangPass(carbonId) then return 4 end - local reward + local reward, change if msg.starNum and msg.starNum > 0 then --win role:hangFinish(carbonId) if carbonData.main ~= 1 then @@ -217,7 +217,7 @@ function _M.endBattleRpc(agent, data) for itemId, count in pairs(carbonData.item_clear:toNumMap()) do reward[itemId] = count end - reward = role:award(reward, {log = {desc = "hangBattle", int1 = carbonId}}) + reward, change = role:award(reward, {log = {desc = "hangBattle", int1 = carbonId}}) role:checkTaskEnter("HangPass", {id = carbonId}) end @@ -229,6 +229,7 @@ function _M.endBattleRpc(agent, data) SendPacket(actionCodes.Hang_endBattleRpc, MsgPack.pack({ starNum = msg.starNum, reward = reward, + change = change, })) return true end @@ -276,7 +277,7 @@ function _M.getRewardRpc(agent , data) checkReward(role) local items = role:getProperty("hangBag") if not next(items) then return end - local reward = role:award(items, {log = {desc = "hangReward"}}) + local reward, change = role:award(items, {log = {desc = "hangReward"}}) table.clear(items) local hangInfo = role:getProperty("hangInfo") local nowTime = skynet.timex() @@ -291,7 +292,8 @@ function _M.getRewardRpc(agent , data) role:checkTaskEnter("HangGetGold", {count = reward[ItemId.Gold]}) end SendPacket(actionCodes.Hang_getRewardRpc, MsgPack.pack({ - reward = reward + reward = reward, + change = change })) return true end @@ -388,14 +390,15 @@ function _M.quickRpc(agent , data) local cur = pool[math.randWeight(pool, 3)] reward[cur[1]] = (reward[cur[1]] or 0) + cur[2] end - - reward = role:award(reward, {log = {desc = "quickHang", int1 = hangInfo.carbonId}}) + local change + reward, change = role:award(reward, {log = {desc = "quickHang", int1 = hangInfo.carbonId}}) if reward[ItemId.Gold] then role:checkTaskEnter("HangGetGold", {count = reward[ItemId.Gold]}) end role:checkTaskEnter("HangQuick") SendPacket(actionCodes.Hang_quickRpc, MsgPack.pack({ - reward = reward + reward = reward, + change = change })) return true end @@ -497,7 +500,7 @@ function _M.endBonusBattleRpc(agent, data) if role.__bonusBattleCache.id ~= id or role.__bonusBattleCache.key ~= key then return 2 end local bonusData = csvdb["bonus_battleCsv"][id] - local reward + local reward, change if starNum and starNum > 0 then -- 胜利扣除次数 local bonusC = role.dailyData:getProperty("bonusC") @@ -511,7 +514,7 @@ function _M.endBonusBattleRpc(agent, data) if chance[1] ~= 0 then reward[chance[1]] = (reward[chance[1]] or 0) + chance[2] end - reward = role:award(reward, {log = {desc = "bonusBattle", int1 = id}}) + reward, change = role:award(reward, {log = {desc = "bonusBattle", int1 = id}}) role:checkTaskEnter("BonusPass", {id = id}) end @@ -519,7 +522,9 @@ function _M.endBonusBattleRpc(agent, data) SendPacket(actionCodes.Hang_endBonusBattleRpc, MsgPack.pack({ starNum = starNum, - reward = reward})) + reward = reward, + change = change + })) return true end @@ -534,12 +539,12 @@ function _M.hangGiftRpc(agent, data) local hangGift = role:getProperty("hangGift") if hangGift[id] then return 2 end - local reward = role:award(carbonData.item_clear_special, {log = {desc = "hangGift", int1 = id}}) + local reward, change = role:award(carbonData.item_clear_special, {log = {desc = "hangGift", int1 = id}}) role:log("hang_action", {desc = "hangGift", int1 = id}) role:changeUpdates({{type = "hangGift", field = id, value = 1}}) - SendPacket(actionCodes.Hang_hangGiftRpc, MsgPack.pack(reward)) + SendPacket(actionCodes.Hang_hangGiftRpc, MsgPack.pack({reward = reward, change = change})) return true end @@ -577,9 +582,9 @@ function _M.chatLineRpc(agent, data) chatline[id] = skynet.timex() role:updateProperty({field = "chatline", value = chatline}) - local reward = role:award(idleData.chatline_reward, {log = {desc = "chatline", int1 = id}}) + local reward, change = role:award(idleData.chatline_reward, {log = {desc = "chatline", int1 = id}}) - SendPacket(actionCodes.Hang_chatLineRpc, MsgPack.pack(reward)) + SendPacket(actionCodes.Hang_chatLineRpc, MsgPack.pack({reward = reward, change = change})) return true end diff --git a/src/actions/HeroAction.lua b/src/actions/HeroAction.lua index f5631eb..4f0cd38 100644 --- a/src/actions/HeroAction.lua +++ b/src/actions/HeroAction.lua @@ -600,15 +600,12 @@ function _M.createHeroRandomRpc(agent, data) local temp = randomData.gift1:randWeight(true) if not temp or not next(temp) then return end - local reward = {} - if role:isHaveHero(temp[1]) then - reward = {[temp[1]] = cost} - else - reward = {[temp[1] + ItemStartId.Hero] = 1} - end + role:costItems({[itemId] = cost}, {log = {desc = "createHeroRandom"}}) - reward = role:award(reward, {log = {desc = "createHeroRandom"}}) - SendPacket(actionCodes.Hero_createHeroRandomRpc, MsgPack.pack({reward = reward})) + local reward, change = role:award({[temp[1] + ItemStartId.Hero] = 1}, {log = {desc = "createHeroRandom"}}) + + + SendPacket(actionCodes.Hero_createHeroRandomRpc, MsgPack.pack(role:packReward(reward, change))) return true end @@ -677,9 +674,10 @@ function _M.getResetRewardRpc(agent, data) for itemId, count in pairs(reward) do reward[itemId] = math.floor(count * globalCsv.unit_back_discount) end - reward = role:award(reward, {log = {desc = "resetHero", int1 = msg.id, int2 = hero:getProperty("type")}}) + local change + reward, change = role:award(reward, {log = {desc = "resetHero", int1 = msg.id, int2 = hero:getProperty("type")}}) - SendPacket(actionCodes.Hero_getResetRewardRpc, MsgPack.pack({reward = reward})) + SendPacket(actionCodes.Hero_getResetRewardRpc, MsgPack.pack(role:packReward(reward, change))) return true end diff --git a/src/actions/PvpAction.lua b/src/actions/PvpAction.lua index dd7bbaa..a4785c2 100644 --- a/src/actions/PvpAction.lua +++ b/src/actions/PvpAction.lua @@ -334,7 +334,7 @@ function _M.endBattleRpc(agent, data) if not match then return end local temp = string.randWeight(csvdb["player_expCsv"][role:getProperty("level")].pvpBonus, true) - local reward = role:award({[temp[1]] = temp[2]}, {log = {desc = "pvpBattleC"}}) + local reward, change = role:award({[temp[1]] = temp[2]}, {log = {desc = "pvpBattleC"}}) local myScore, matchScore, oldmyScore, oldMatchScore, myRank, oldMyRank = role:changePvpScoreCommon(match.t == 1 and match.id or -1, isWin) _pvpBattleInfoCacheC = {} --重新发阵容了 没毛病 @@ -395,6 +395,7 @@ function _M.endBattleRpc(agent, data) SendPacket(actionCodes.Pvp_endBattleRpc, MsgPack.pack({ reward = reward, + change = change, myScore = myScore, matchScore = matchScore, oldmyScore = oldmyScore, @@ -621,7 +622,7 @@ function _M.endBattleHRpc(agent, data) -- 战斗结束了发奖 local temp = string.randWeight(csvdb["player_expCsv"][role:getProperty("level")].pvpgroupBonus, true) - local reward = role:award({[temp[1]] = temp[2]}, {log = {desc = "pvpBattleH"}}) + local reward, change = role:award({[temp[1]] = temp[2]}, {log = {desc = "pvpBattleH"}}) local myScore, matchScore, oldmyScore, oldMatchScore, myRank, oldMyRank = 0, 0, 0, 0, 0, 0 if role:isTimeResetOpen(TimeReset.PvpHight) then myScore, matchScore, oldmyScore, oldMatchScore, myRank, oldMyRank = role:changePvpScoreHigh(match.t == 1 and match.id or -1, isWin) @@ -694,6 +695,7 @@ function _M.endBattleHRpc(agent, data) SendPacket(actionCodes.Pvp_endBattleHRpc, MsgPack.pack({ reward = reward, + change = change, myScore = myScore, matchScore = matchScore, oldmyScore = oldmyScore, @@ -837,10 +839,10 @@ function _M.highDivisionGiftRpc(agent, data) pvpHGift = {}, }) - local reward = role:award(newReward, {log = {desc = "pvpDivisionH"}}) + local reward, change = role:award(newReward, {log = {desc = "pvpDivisionH"}}) role:log("pvp_action", {desc = "pvpDivisionH"}) - SendPacket(actionCodes.Pvp_highDivisionGiftRpc, MsgPack.pack({reward = reward})) + SendPacket(actionCodes.Pvp_highDivisionGiftRpc, MsgPack.pack(role:packReward(reward, change))) return true end @@ -871,11 +873,11 @@ function _M.shopBuyRpc(agent, data) for id, c in pairs(gift) do gift[id] = c * count end - local reward = role:award(gift, {log = {desc = "pvpShop", int1 = id, int2 = count}}) + local reward, change = role:award(gift, {log = {desc = "pvpShop", int1 = id, int2 = count}}) role:log("pvp_action", {desc = "pvpShop", int1 = id, int2 = count}) - SendPacket(actionCodes.Pvp_shopBuyRpc, MsgPack.pack({reward = reward})) + SendPacket(actionCodes.Pvp_shopBuyRpc, MsgPack.pack(role:packReward(reward, change))) return true end diff --git a/src/actions/RoleAction.lua b/src/actions/RoleAction.lua index 3aa965e..83bed42 100644 --- a/src/actions/RoleAction.lua +++ b/src/actions/RoleAction.lua @@ -408,9 +408,9 @@ function _M.saleItemRpc(agent, data) end role:costItems(backs, {log = {desc = "saleItem"}}) - local reward = role:award(reward, {log = {desc = "saleItem"}}) + local reward, change = role:award(reward, {log = {desc = "saleItem"}}) role:checkTaskEnter("DecoFrag", {count = fragCount}) - SendPacket(actionCodes.Role_saleItemRpc, MsgPack.pack({reward = reward})) + SendPacket(actionCodes.Role_saleItemRpc, MsgPack.pack(role:packReward(reward, change))) return true end @@ -447,9 +447,10 @@ function _M.openItemRpc(agent, data) reward[0] = nil role:costItems({[itemId] = count}, {log = {desc = "openItem"}}) - reward = role:award(reward, {log = {desc = "openItem", int1 = itemId, int2 = count}}) + local change + reward, change = role:award(reward, {log = {desc = "openItem", int1 = itemId, int2 = count}}) - SendPacket(actionCodes.Role_openItemRpc, MsgPack.pack({reward = reward})) + SendPacket(actionCodes.Role_openItemRpc, MsgPack.pack(role:packReward(reward, change))) return true end @@ -461,7 +462,7 @@ function _M.openTimeBoxRpc(agent, data) if math.illegalNum(slot, 1, role:getFuncLv(FuncOpenType.TimeBoxSlot)) then return end local boxL = role:getProperty("boxL") - local reward = {} + local reward, change = {} if oper == 1 then -- 打开 local itemId = msg.itemId if role:getItemCount(itemId) < 1 then return end @@ -509,7 +510,7 @@ function _M.openTimeBoxRpc(agent, data) reward[0] = nil boxL[slot] = nil - reward = role:award(reward, {log = {desc = "openTimeBox", int1 = boxId}}) + reward, change = role:award(reward, {log = {desc = "openTimeBox", int1 = boxId}}) role:checkTaskEnter("OpenBox", {id = boxId}) else return @@ -517,7 +518,7 @@ function _M.openTimeBoxRpc(agent, data) role:setProperty("boxL") --刷新 role:changeUpdates({{type = "boxL", field = slot, value = boxL[slot], isOnlyToC = true}}) -- 通知客户端 - SendPacket(actionCodes.Role_openTimeBoxRpc, MsgPack.pack({reward = reward})) + SendPacket(actionCodes.Role_openTimeBoxRpc, MsgPack.pack(role:packReward(reward, change))) return true end @@ -568,9 +569,10 @@ function _M.openSpeedUpBoxRpc(agent, data) end role:costItems({[id] = count}, {log = {desc = "speedUpBox"}}) - reward = role:award(reward, {log = {desc = "speedUpBox"}, int1 = id, int2 = count}) + local change + reward, change = role:award(reward, {log = {desc = "speedUpBox"}, int1 = id, int2 = count}) - SendPacket(actionCodes.Role_openSpeedUpBoxRpc, MsgPack.pack({reward = reward})) + SendPacket(actionCodes.Role_openSpeedUpBoxRpc, MsgPack.pack(role:packReward(reward, change))) return true end @@ -596,8 +598,8 @@ function _M.storyBookRewardRpc(agent, data) storyStatus[storyId] = storyStatus[storyId] or {} storyStatus[storyId].s = -1 role:changeUpdates({{ type = "storyB", field = storyId, value = storyStatus[storyId] }}) - local reward = role:award(storyBookData.gift, {log = {desc = "storybookReward", int1 = storyId}}) - SendPacket(actionCodes.Role_storyBookRewardRpc, MsgPack.pack({reward = reward})) + local reward, change = role:award(storyBookData.gift, {log = {desc = "storybookReward", int1 = storyId}}) + SendPacket(actionCodes.Role_storyBookRewardRpc, MsgPack.pack(role:packReward(reward, change))) return true end @@ -648,7 +650,7 @@ function _M.taskRpc(agent, data) return 3 end - local reward = role:award(taskData.reward, {log = {desc = "finishTask", int1 = taskType, int2 = taskId}}) + local reward, change = role:award(taskData.reward, {log = {desc = "finishTask", int1 = taskType, int2 = taskId}}) local active = (taskStatus["a"] or 0) + taskData.active role:changeUpdates({ @@ -656,7 +658,7 @@ function _M.taskRpc(agent, data) { type = roleField[taskType], field = "a", value = active} }) - SendPacket(actionCodes.Role_taskRpc, MsgPack.pack({reward = reward})) + SendPacket(actionCodes.Role_taskRpc, MsgPack.pack(role:packReward(reward, change))) return true end @@ -681,12 +683,12 @@ function _M.taskActiveRpc(agent, data) return end - local reward = role:award(taskData.reward, {log = {desc = "taskActive", int1 = taskType, int2 = taskId}}) + local reward, change = role:award(taskData.reward, {log = {desc = "taskActive", int1 = taskType, int2 = taskId}}) role:changeUpdates({ { type = roleField[taskType], field = {"at", taskId}, value = -1 } }) - SendPacket(actionCodes.Role_taskActiveRpc, MsgPack.pack({reward = reward})) + SendPacket(actionCodes.Role_taskActiveRpc, MsgPack.pack(role:packReward(reward, change))) return true end @@ -712,7 +714,7 @@ function _M.achiveRpc(agent, data) return 3 end - local reward = role:award(achiveTask.reward, {log = {desc = "finishAchive", int1 = taskId}}) + local reward, change = role:award(achiveTask.reward, {log = {desc = "finishAchive", int1 = taskId}}) role:changeUpdates({ { type = "achiveV", field = taskId, value = skynet.timex() } }) @@ -745,7 +747,7 @@ function _M.achiveRpc(agent, data) end end - SendPacket(actionCodes.Role_achiveRpc, MsgPack.pack({reward = reward})) + SendPacket(actionCodes.Role_achiveRpc, MsgPack.pack(role:packReward(reward, change))) return true end @@ -921,11 +923,12 @@ function _M.drawCodeRpc(agent, data) if ret == 0 then local giftId = tonumber(result.giftId) role:setProperty("codeStr", codestr:setv(giftId, 1)) - local reward = role:award(result.gift, {log = {desc = "drawCode", key1 = code, int1 = giftId}}) + local reward, change = role:award(result.gift, {log = {desc = "drawCode", key1 = code, int1 = giftId}}) SendPacket(actionCodes.Role_drawCodeRpc, MsgPack.pack({ result = ret, reward = reward, + change = change, })) return true end @@ -1046,8 +1049,8 @@ function _M.goldBuyRpc(agent, data) end role.dailyData:updateProperty({field = "goldBuyT", value = curT + 1}) role:costItems({[ItemId.Diamond] = costD}, {log = {desc = "goldBuy"}}) - local reward = role:award({[ItemId.Gold] = goldC}, {log = {desc = "goldBuy"}}) - SendPacket(actionCodes.Role_goldBuyRpc, MsgPack.pack({reward = reward})) + local reward, change = role:award({[ItemId.Gold] = goldC}, {log = {desc = "goldBuy"}}) + SendPacket(actionCodes.Role_goldBuyRpc, MsgPack.pack(role:packReward(reward, change))) return true end diff --git a/src/actions/TowerAction.lua b/src/actions/TowerAction.lua index 05eaeb1..a39f602 100644 --- a/src/actions/TowerAction.lua +++ b/src/actions/TowerAction.lua @@ -97,14 +97,14 @@ function _M.endBattleRpc(agent, data) local curCount, nextTime = getUpdateTime(towerInfo.c, towerInfo.t) - local reward + local reward, change if msg.starNum and msg.starNum > 0 then --win curCount = math.min(curCount + 1, globalCsv.tower_count_limit) -- 返还次数 --排行榜 role:setTowerRank(towerInfo.l) towerInfo.l = towerInfo.l + 1 - reward = role:award(curTower.reward, {log = {desc = "towerBattle", int1 = id}}) + reward, change = role:award(curTower.reward, {log = {desc = "towerBattle", int1 = id}}) role:checkTaskEnter("TowerPass", {level = towerInfo.l - 1}) end @@ -115,7 +115,7 @@ function _M.endBattleRpc(agent, data) role:log("tower_action", {desc = "endBattle", short1 = msg.starNum > 0 and 1 or 0, int1 = id}) - SendPacket(actionCodes.Tower_endBattleRpc, MsgPack.pack({reward = reward})) + SendPacket(actionCodes.Tower_endBattleRpc, MsgPack.pack({reward = reward, change = change})) return true end diff --git a/src/adv/AdvTask.lua b/src/adv/AdvTask.lua index ddca25b..02cc6ed 100644 --- a/src/adv/AdvTask.lua +++ b/src/adv/AdvTask.lua @@ -183,12 +183,12 @@ function AdvTask.bind(Adv) -- 完成主线任务 function Adv:finishMTask() - local ok, reward + local ok, reward, change if self.advMTask.status == -1 then --已完成带领取 local mainTaskData = csvdb["adv_questCsv"][self.advMTask.id] if not mainTaskData then return end if mainTaskData.reward == 1 then - reward = self.owner:award(mainTaskData.rewardValue, {log = {desc = "advMainTask", int1 = self.advMTask.id}}) + reward, change = self.owner:award(mainTaskData.rewardValue, {log = {desc = "advMainTask", int1 = self.advMTask.id}}) end self.advMTask.id = self.advMTask.id + 1 self.advMTask.status = 0 @@ -204,7 +204,7 @@ function AdvTask.bind(Adv) ok = true advTaskChange.m = true end - return ok, reward + return ok, reward, change end function Adv:updateTask(notNotify) @@ -388,7 +388,7 @@ function AdvTask.bind(Adv) local achievData = (csvdb["adv_achievementCsv"][chapterId] or {})[taskId] local status = (self.owner:getProperty(achievField)[chapterId] or {})[taskId] or -1 - local reward = {} + local reward, change = {} if status >= achievData.value1 then insertChange(self, chapterId, taskId, -1) local count = (self.owner:getProperty(achievField)[chapterId] or {})[-1] or 0 @@ -396,8 +396,8 @@ function AdvTask.bind(Adv) insertChange(self, chapterId, -1, count) -- 发放奖励 - reward = self.owner:award(achievData.reward, {log = {desc = "advAchiev", int1 = chapterId, int2 = taskId}}) - return true, reward + reward, change = self.owner:award(achievData.reward, {log = {desc = "advAchiev", int1 = chapterId, int2 = taskId}}) + return true, reward, change end end @@ -408,9 +408,9 @@ function AdvTask.bind(Adv) local status = ((self.owner:getProperty(achievField)[chapterId] or {})["pts"] or {})[taskId] or 0 if status == -1 or count < achievData.pt then return end - local reward = self.owner:award(achievData.reward, {log = {desc = "advAchievReward", int1 = chapterId, int2 = taskId}}) + local reward, change = self.owner:award(achievData.reward, {log = {desc = "advAchievReward", int1 = chapterId, int2 = taskId}}) insertChange(self, chapterId, taskId, -1, true) - return true, reward + return true, reward, change end function Adv:updateAchievement(notNotify) diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index 048b5d0..5374505 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -145,10 +145,16 @@ function RolePlugin.bind(Role) end end end - + if not next(allChange) then allChange = nil end return reward, allChange --实际获得的奖励 和 最高级奖励转化过程 end + + function Role:packReward(reward, change) + if not reward then return nil end + return {reward = reward, change = change} + end + function Role:awardExpireItem(expireTime, gift, params) if expireTime <= skynet.timex() then return -- libgit2 0.21.2