Commit 0027e33bf25e2172a48fa33ae3d7deccdc77d844
1 parent
fbd1b98c
调理剂生产和使用逻辑优化
Showing
6 changed files
with
103 additions
and
33 deletions
Show diff stats
src/GlobalVar.lua
| @@ -72,7 +72,7 @@ ItemType = { | @@ -72,7 +72,7 @@ ItemType = { | ||
| 72 | EquipBase = 9, -- 基础装备 | 72 | EquipBase = 9, -- 基础装备 |
| 73 | Rune = 10, -- 符文 | 73 | Rune = 10, -- 符文 |
| 74 | Cuisine = 11, -- 料理(用于增加好感度、贩卖获得金币) | 74 | Cuisine = 11, -- 料理(用于增加好感度、贩卖获得金币) |
| 75 | - LunchBox = 12, -- 便当盒(料理合成,冒险系统消耗道具) | 75 | + Potion = 12, -- 拾荒药剂 |
| 76 | TimeBox = 13, -- 时间箱(开启需要时间,随机产出道具) | 76 | TimeBox = 13, -- 时间箱(开启需要时间,随机产出道具) |
| 77 | AdvItem = 14, -- 冒险道具 | 77 | AdvItem = 14, -- 冒险道具 |
| 78 | FuncOpen = 15, -- 管理功能开放 | 78 | FuncOpen = 15, -- 管理功能开放 |
src/actions/AdvAction.lua
| @@ -543,8 +543,8 @@ function _M.usePotionRpc(agent, data) | @@ -543,8 +543,8 @@ function _M.usePotionRpc(agent, data) | ||
| 543 | local msg = MsgPack.unpack(data) | 543 | local msg = MsgPack.unpack(data) |
| 544 | local potionId = msg.potionId -- 营养剂Id | 544 | local potionId = msg.potionId -- 营养剂Id |
| 545 | local target = msg.target -- {roomId = 1, blockId = 1} 选择的目标 | 545 | local target = msg.target -- {roomId = 1, blockId = 1} 选择的目标 |
| 546 | - local potionLv = role.dinerData:getProperty("dishTree"):getv(potionId, 0) | ||
| 547 | - if potionLv == 0 then return 1 end | 546 | + local potionLv = role.dinerData:getProperty("dishTree"):getv(potionId, 1) |
| 547 | + if potionLv < 1 then return 1 end | ||
| 548 | 548 | ||
| 549 | local potionSet = csvdb["adv_potionCsv"][potionId] | 549 | local potionSet = csvdb["adv_potionCsv"][potionId] |
| 550 | if not potionSet then return 2 end | 550 | if not potionSet then return 2 end |
| @@ -552,12 +552,9 @@ function _M.usePotionRpc(agent, data) | @@ -552,12 +552,9 @@ function _M.usePotionRpc(agent, data) | ||
| 552 | local potionData = potionSet[potionLv] | 552 | local potionData = potionSet[potionLv] |
| 553 | if not potionData then return 3 end | 553 | if not potionData then return 3 end |
| 554 | 554 | ||
| 555 | - local potionBag = role:getProperty("potionBag") | ||
| 556 | - local own = potionBag[potionId] or 0 | ||
| 557 | - if own <= 0 then return 4 end | ||
| 558 | - | ||
| 559 | if not isCanContinue(role) then return end | 555 | if not isCanContinue(role) then return end |
| 560 | local adv = role:getAdvData() | 556 | local adv = role:getAdvData() |
| 557 | + if not adv:cost({[potionId] = 1}, {}, true) then return 4 end | ||
| 561 | if adv:isWaitChooseArtifact() then return end | 558 | if adv:isWaitChooseArtifact() then return end |
| 562 | 559 | ||
| 563 | adv:mylog({desc = "usePotion", int1 = potionId}) | 560 | adv:mylog({desc = "usePotion", int1 = potionId}) |
| @@ -565,8 +562,7 @@ function _M.usePotionRpc(agent, data) | @@ -565,8 +562,7 @@ function _M.usePotionRpc(agent, data) | ||
| 565 | local status = adv:doActive(potionData.effect, target) -- target | 562 | local status = adv:doActive(potionData.effect, target) -- target |
| 566 | if not status then return end | 563 | if not status then return end |
| 567 | 564 | ||
| 568 | - potionBag[potionId] = own - 1 | ||
| 569 | - role:updateProperty({field = "potionBag", value = potionBag}) | 565 | + adv:cost({[potionId] = 1}, {log = {desc = "usePotion", int1 = potionId}}) |
| 570 | adv:pushBackEvent(AdvBackEventType.Potion, {id = potionId}) | 566 | adv:pushBackEvent(AdvBackEventType.Potion, {id = potionId}) |
| 571 | adv:afterRound() | 567 | adv:afterRound() |
| 572 | adv:saveDB() | 568 | adv:saveDB() |
| @@ -737,7 +733,7 @@ function _M.endBattleRpc(agent, data) | @@ -737,7 +733,7 @@ function _M.endBattleRpc(agent, data) | ||
| 737 | role:finishGuide(52) | 733 | role:finishGuide(52) |
| 738 | -- 调理剂使用引导(生命药剂) | 734 | -- 调理剂使用引导(生命药剂) |
| 739 | if not role:checkOverGuide(61) then | 735 | if not role:checkOverGuide(61) then |
| 740 | - local potionBag = role:getProperty("potionBag") | 736 | + local potionBag = role:getProperty("advItems"):toNumMap() |
| 741 | local own = potionBag[10] or 0 | 737 | local own = potionBag[10] or 0 |
| 742 | if own > 0 then | 738 | if own > 0 then |
| 743 | -- 造假 | 739 | -- 造假 |
src/actions/CarAction.lua
| @@ -13,7 +13,7 @@ function _M.makePotionRpc( agent, data ) | @@ -13,7 +13,7 @@ function _M.makePotionRpc( agent, data ) | ||
| 13 | local count = msg.count | 13 | local count = msg.count |
| 14 | if count < 1 then return 0 end | 14 | if count < 1 then return 0 end |
| 15 | local potionBag = role:getProperty("potionBag") | 15 | local potionBag = role:getProperty("potionBag") |
| 16 | - local potionLv = role.dinerData:getProperty("dishTree"):getv(potionId, 0) | 16 | + local potionLv = role.dinerData:getProperty("dishTree"):getv(potionId, 1) |
| 17 | if potionLv < 1 then return 1 end | 17 | if potionLv < 1 then return 1 end |
| 18 | 18 | ||
| 19 | local potionSet = csvdb["adv_potionCsv"][potionId] | 19 | local potionSet = csvdb["adv_potionCsv"][potionId] |
| @@ -22,20 +22,15 @@ function _M.makePotionRpc( agent, data ) | @@ -22,20 +22,15 @@ function _M.makePotionRpc( agent, data ) | ||
| 22 | local potionData = potionSet[potionLv] | 22 | local potionData = potionSet[potionLv] |
| 23 | if not potionData then return 3 end | 23 | if not potionData then return 3 end |
| 24 | 24 | ||
| 25 | - local own = potionBag[potionId] or 0 | ||
| 26 | - if own+count > potionData.limit then | ||
| 27 | - return 4 | ||
| 28 | - end | ||
| 29 | - | ||
| 30 | local cost = potionData.material:toNumMap() | 25 | local cost = potionData.material:toNumMap() |
| 31 | for k, n in pairs(cost) do | 26 | for k, n in pairs(cost) do |
| 32 | cost[k] = n * count | 27 | cost[k] = n * count |
| 33 | end | 28 | end |
| 34 | if not role:checkItemEnough(cost) then | 29 | if not role:checkItemEnough(cost) then |
| 35 | - return 5 | 30 | + return 4 |
| 36 | end | 31 | end |
| 37 | - | ||
| 38 | role:costItems(cost, {log = {desc = "makePotion", int1 = potionId, int2 = count}}) | 32 | role:costItems(cost, {log = {desc = "makePotion", int1 = potionId, int2 = count}}) |
| 33 | + local own = potionBag[potionId] or 0 | ||
| 39 | potionBag[potionId] = own + count | 34 | potionBag[potionId] = own + count |
| 40 | role:updateProperty({field = "potionBag", value = potionBag}) | 35 | role:updateProperty({field = "potionBag", value = potionBag}) |
| 41 | role:checkTaskEnter("PotionMake", {count = count, id = potionId}) | 36 | role:checkTaskEnter("PotionMake", {count = count, id = potionId}) |
src/actions/DinerAction.lua
| @@ -385,22 +385,12 @@ function _M.talentUpRpc( agent, data ) | @@ -385,22 +385,12 @@ function _M.talentUpRpc( agent, data ) | ||
| 385 | local msg = MsgPack.unpack(data) | 385 | local msg = MsgPack.unpack(data) |
| 386 | local dish = msg.dish | 386 | local dish = msg.dish |
| 387 | local dishTree = role.dinerData:getProperty("dishTree") | 387 | local dishTree = role.dinerData:getProperty("dishTree") |
| 388 | - local dishLevel = dishTree:getv(dish, 0) | ||
| 389 | 388 | ||
| 390 | local talentSet = csvdb["diner_talentCsv"][dish] | 389 | local talentSet = csvdb["diner_talentCsv"][dish] |
| 391 | if not talentSet then | 390 | if not talentSet then |
| 392 | return 1 | 391 | return 1 |
| 393 | end | 392 | end |
| 394 | 393 | ||
| 395 | - local talentData = talentSet[dishLevel] | ||
| 396 | - if not talentData then | ||
| 397 | - return 2 | ||
| 398 | - end | ||
| 399 | - | ||
| 400 | - if not talentSet[dishLevel+1] then | ||
| 401 | - return 21 | ||
| 402 | - end | ||
| 403 | - | ||
| 404 | local typ = math.floor(dish/100 + 1) | 394 | local typ = math.floor(dish/100 + 1) |
| 405 | local treeSet = csvdb["diner_treeCsv"][typ] | 395 | local treeSet = csvdb["diner_treeCsv"][typ] |
| 406 | if not treeSet then | 396 | if not treeSet then |
| @@ -412,6 +402,17 @@ function _M.talentUpRpc( agent, data ) | @@ -412,6 +402,17 @@ function _M.talentUpRpc( agent, data ) | ||
| 412 | return 4 | 402 | return 4 |
| 413 | end | 403 | end |
| 414 | 404 | ||
| 405 | + -- 调理剂的默认等级是1级 | ||
| 406 | + local dishLevel = dishTree:getv(dish, treeData.rarity == 2 and 1 or 0) | ||
| 407 | + local talentData = talentSet[dishLevel] | ||
| 408 | + if not talentData then | ||
| 409 | + return 2 | ||
| 410 | + end | ||
| 411 | + | ||
| 412 | + if not talentSet[dishLevel+1] then | ||
| 413 | + return 21 | ||
| 414 | + end | ||
| 415 | + | ||
| 415 | local limit = talentData.pointFront:toNumMap() | 416 | local limit = talentData.pointFront:toNumMap() |
| 416 | for k,v in pairs(limit) do | 417 | for k,v in pairs(limit) do |
| 417 | local lv = dishTree:getv(k, 0) | 418 | local lv = dishTree:getv(k, 0) |
src/adv/Adv.lua
| @@ -146,6 +146,10 @@ function Adv:initByChapter(params) | @@ -146,6 +146,10 @@ function Adv:initByChapter(params) | ||
| 146 | end | 146 | end |
| 147 | end | 147 | end |
| 148 | 148 | ||
| 149 | + if self.level == 1 or self.isRelay then | ||
| 150 | + self:supplyPotion() | ||
| 151 | + end | ||
| 152 | + | ||
| 149 | self.maps = {} | 153 | self.maps = {} |
| 150 | self.maps[1] = AdvMap.new(self, 1, mapId, isEnter, isNewRelay) | 154 | self.maps[1] = AdvMap.new(self, 1, mapId, isEnter, isNewRelay) |
| 151 | 155 | ||
| @@ -396,9 +400,16 @@ function Adv:forceOver(notNotify) | @@ -396,9 +400,16 @@ function Adv:forceOver(notNotify) | ||
| 396 | local advTeam = self.owner:getProperty("advTeam") | 400 | local advTeam = self.owner:getProperty("advTeam") |
| 397 | advTeam.player = nil | 401 | advTeam.player = nil |
| 398 | 402 | ||
| 403 | + local advPotionCsv = csvdb["adv_potionCsv"] | ||
| 404 | + local potionBag = self.owner:getProperty("potionBag") | ||
| 405 | + | ||
| 399 | local reward = self.owner:getProperty("advItems"):toNumMap() | 406 | local reward = self.owner:getProperty("advItems"):toNumMap() |
| 400 | for itemId, count in pairs(reward) do | 407 | for itemId, count in pairs(reward) do |
| 401 | - reward[itemId] = math.ceil(count * globalCsv.adv_fail_reward_ratio / 100) -- 奖励相当于失败 | 408 | + if advPotionCsv[itemId] then |
| 409 | + potionBag[itemId] = (potionBag[itemId] or 0) + count | ||
| 410 | + else | ||
| 411 | + reward[itemId] = math.ceil(count * globalCsv.adv_fail_reward_ratio / 100) -- 奖励相当于失败 | ||
| 412 | + end | ||
| 402 | end | 413 | end |
| 403 | self.owner:award(reward, {log = {desc = "advOver", int1 = self.chapterId}}) | 414 | self.owner:award(reward, {log = {desc = "advOver", int1 = self.chapterId}}) |
| 404 | 415 | ||
| @@ -409,6 +420,7 @@ function Adv:forceOver(notNotify) | @@ -409,6 +420,7 @@ function Adv:forceOver(notNotify) | ||
| 409 | advItems = "", | 420 | advItems = "", |
| 410 | advAFGet = {}, | 421 | advAFGet = {}, |
| 411 | advAFWear = {}, | 422 | advAFWear = {}, |
| 423 | + potionBag = potionBag, | ||
| 412 | }, notNotify) | 424 | }, notNotify) |
| 413 | end | 425 | end |
| 414 | end | 426 | end |
| @@ -789,12 +801,18 @@ function Adv:over(success, rewardRatio, overType) | @@ -789,12 +801,18 @@ function Adv:over(success, rewardRatio, overType) | ||
| 789 | self.battle.player:triggerPassive(Passive.ADV_OVER, {score = score, level = self.level}) | 801 | self.battle.player:triggerPassive(Passive.ADV_OVER, {score = score, level = self.level}) |
| 790 | 802 | ||
| 791 | local reward = {} | 803 | local reward = {} |
| 804 | + local advPotionCsv = csvdb["adv_potionCsv"] | ||
| 805 | + local potionBag = self.owner:getProperty("potionBag") | ||
| 792 | for itemId, count in pairs(self.owner:getProperty("advItems"):toNumMap()) do | 806 | for itemId, count in pairs(self.owner:getProperty("advItems"):toNumMap()) do |
| 793 | local itemCsv = csvdb["itemCsv"][itemId] | 807 | local itemCsv = csvdb["itemCsv"][itemId] |
| 794 | if not itemCsv then | 808 | if not itemCsv then |
| 795 | print("ERROR: no itemId in ItemCsv : ", itemId) | 809 | print("ERROR: no itemId in ItemCsv : ", itemId) |
| 796 | elseif itemCsv.type ~= ItemType.AdvItem then | 810 | elseif itemCsv.type ~= ItemType.AdvItem then |
| 797 | - reward[itemId] = math.ceil(count * rewardRatio / 100) | 811 | + if advPotionCsv[itemId] then |
| 812 | + potionBag[itemId] = (potionBag[itemId] or 0) + count | ||
| 813 | + else | ||
| 814 | + reward[itemId] = math.ceil(count * rewardRatio / 100) | ||
| 815 | + end | ||
| 798 | end | 816 | end |
| 799 | end | 817 | end |
| 800 | reward = self.owner:award(reward, {log = {desc = "advOver", int1 = self.chapterId}}) | 818 | reward = self.owner:award(reward, {log = {desc = "advOver", int1 = self.chapterId}}) |
| @@ -889,6 +907,7 @@ function Adv:over(success, rewardRatio, overType) | @@ -889,6 +907,7 @@ function Adv:over(success, rewardRatio, overType) | ||
| 889 | advItems = "", | 907 | advItems = "", |
| 890 | advAFGet = {}, | 908 | advAFGet = {}, |
| 891 | advAFWear = {}, | 909 | advAFWear = {}, |
| 910 | + potionBag = potionBag, | ||
| 892 | }) | 911 | }) |
| 893 | self:pushBackEvent(AdvBackEventType.End, { | 912 | self:pushBackEvent(AdvBackEventType.End, { |
| 894 | success = success, | 913 | success = success, |
| @@ -973,7 +992,8 @@ function Adv:award(gift, params, backRewardParams) | @@ -973,7 +992,8 @@ function Adv:award(gift, params, backRewardParams) | ||
| 973 | if globalCsv.adv_auto_useItem[itemId] and count > 0 then | 992 | if globalCsv.adv_auto_useItem[itemId] and count > 0 then |
| 974 | autoUse[itemId] = count | 993 | autoUse[itemId] = count |
| 975 | else | 994 | else |
| 976 | - local origin = items:getv(itemId, 0) | 995 | + local transId = globalCsv.adv_item_potion[itemId] or itemId |
| 996 | + local origin = items:getv(transId, 0) | ||
| 977 | local nums = origin + count | 997 | local nums = origin + count |
| 978 | 998 | ||
| 979 | if csvdb["adv_artifactCsv"][itemId] then -- 获得神器 | 999 | if csvdb["adv_artifactCsv"][itemId] then -- 获得神器 |
| @@ -983,10 +1003,10 @@ function Adv:award(gift, params, backRewardParams) | @@ -983,10 +1003,10 @@ function Adv:award(gift, params, backRewardParams) | ||
| 983 | end | 1003 | end |
| 984 | else | 1004 | else |
| 985 | if nums <= 0 then | 1005 | if nums <= 0 then |
| 986 | - items = items:delk(itemId) | 1006 | + items = items:delk(transId) |
| 987 | nums = 0 | 1007 | nums = 0 |
| 988 | else | 1008 | else |
| 989 | - items = items:setv(itemId, nums) | 1009 | + items = items:setv(transId, nums) |
| 990 | end | 1010 | end |
| 991 | 1011 | ||
| 992 | if itemId == 16 and not self.owner:checkOverGuide(51,4) then | 1012 | if itemId == 16 and not self.owner:checkOverGuide(51,4) then |
| @@ -1064,6 +1084,7 @@ end | @@ -1064,6 +1084,7 @@ end | ||
| 1064 | -- 消耗物品 优先冒险背包 --check 只是检查够不够 | 1084 | -- 消耗物品 优先冒险背包 --check 只是检查够不够 |
| 1065 | function Adv:cost(item, params, check) | 1085 | function Adv:cost(item, params, check) |
| 1066 | local items = self.owner:getProperty("advItems") | 1086 | local items = self.owner:getProperty("advItems") |
| 1087 | + local potionCsv = csvdb["adv_potionCsv"] | ||
| 1067 | local less = {} | 1088 | local less = {} |
| 1068 | local advCost = {} | 1089 | local advCost = {} |
| 1069 | for itemId, count in pairs(item) do | 1090 | for itemId, count in pairs(item) do |
| @@ -1077,9 +1098,13 @@ function Adv:cost(item, params, check) | @@ -1077,9 +1098,13 @@ function Adv:cost(item, params, check) | ||
| 1077 | less[itemId] = -last | 1098 | less[itemId] = -last |
| 1078 | end | 1099 | end |
| 1079 | 1100 | ||
| 1101 | + if potionCsv[itemId] and last < 0 then -- 只能使用冒险背包里的药水 | ||
| 1102 | + return | ||
| 1103 | + end | ||
| 1080 | end | 1104 | end |
| 1081 | if next(less) and not self.owner:checkItemEnough(less) then return end --不够 | 1105 | if next(less) and not self.owner:checkItemEnough(less) then return end --不够 |
| 1082 | if check then return true end | 1106 | if check then return true end |
| 1107 | + | ||
| 1083 | self:award(advCost, params) | 1108 | self:award(advCost, params) |
| 1084 | if next(less) then | 1109 | if next(less) then |
| 1085 | self.owner:costItems(less, params) | 1110 | self.owner:costItems(less, params) |
| @@ -1087,6 +1112,25 @@ function Adv:cost(item, params, check) | @@ -1087,6 +1112,25 @@ function Adv:cost(item, params, check) | ||
| 1087 | return true | 1112 | return true |
| 1088 | end | 1113 | end |
| 1089 | 1114 | ||
| 1115 | +-- 补满冒险背包药剂,从药剂背包扣除药水放到冒险背包 | ||
| 1116 | +function Adv:supplyPotion() | ||
| 1117 | + local potionCsv = csvdb["adv_potionCsv"] | ||
| 1118 | + local potionBag = self.owner:getProperty("potionBag") | ||
| 1119 | + local advItems = self.owner:getProperty("advItems") | ||
| 1120 | + for potionId, set in pairs(potionCsv) do | ||
| 1121 | + local count = potionBag[potionId] or 0 | ||
| 1122 | + if count > 0 then | ||
| 1123 | + local num = math.min(set[1].limit,count) | ||
| 1124 | + advItems = advItems:setv(potionId,num) | ||
| 1125 | + potionBag[potionId] = num ~= count and (count - num) or nil | ||
| 1126 | + end | ||
| 1127 | + end | ||
| 1128 | + self.owner:updateProperties({ | ||
| 1129 | + advItems = advItems, | ||
| 1130 | + potionBag = potionBag, | ||
| 1131 | + }) | ||
| 1132 | +end | ||
| 1133 | + | ||
| 1090 | --事件点击处理 | 1134 | --事件点击处理 |
| 1091 | local function clickOut(self, room, block, params, isExit) | 1135 | local function clickOut(self, room, block, params, isExit) |
| 1092 | if self:getCurMap():checkOver() then --检查是否可以出去了 | 1136 | if self:getCurMap():checkOver() then --检查是否可以出去了 |
src/models/RolePlugin.lua
| @@ -131,6 +131,9 @@ function RolePlugin.bind(Role) | @@ -131,6 +131,9 @@ function RolePlugin.bind(Role) | ||
| 131 | self:addItem(pms) | 131 | self:addItem(pms) |
| 132 | end | 132 | end |
| 133 | end, | 133 | end, |
| 134 | + [ItemType.Potion] = function () | ||
| 135 | + self:addPotion({id = itemId, count = count, notNotify = pms.notNotify, log = pms.log}) | ||
| 136 | + end, | ||
| 134 | } | 137 | } |
| 135 | -- 对数量筛查 | 138 | -- 对数量筛查 |
| 136 | count = checkItemCount(self, itemId, count) | 139 | count = checkItemCount(self, itemId, count) |
| @@ -290,6 +293,37 @@ function RolePlugin.bind(Role) | @@ -290,6 +293,37 @@ function RolePlugin.bind(Role) | ||
| 290 | self:changeCrossServerPvpSelfInfo("level") | 293 | self:changeCrossServerPvpSelfInfo("level") |
| 291 | end | 294 | end |
| 292 | 295 | ||
| 296 | + function Role:addPotion(params) | ||
| 297 | + dump(params) | ||
| 298 | + local pId = globalCsv.adv_item_potion[params.id] | ||
| 299 | + local potionBag = self:getProperty("potionBag") | ||
| 300 | + local origin = potionBag[pId] or 0 | ||
| 301 | + local nums = origin + params.count | ||
| 302 | + potionBag[pId] = nums | ||
| 303 | + | ||
| 304 | + self:logItems(params.id, origin, nums, params.log) | ||
| 305 | + if params.log then | ||
| 306 | + local log = clone(params.log) | ||
| 307 | + if log["cint1"] or log["cint2"] then | ||
| 308 | + print("addItem error log have cint1 or cint2 ", debug.traceback()) | ||
| 309 | + end | ||
| 310 | + log["cint1"] = params.id | ||
| 311 | + log["cint2"] = math.abs(params.count) | ||
| 312 | + if params.count <= 0 then | ||
| 313 | + self:mylog("out_item", log) | ||
| 314 | + else | ||
| 315 | + self:mylog("in_item", log) | ||
| 316 | + end | ||
| 317 | + else | ||
| 318 | + print("addItem no log ", debug.traceback()) | ||
| 319 | + end | ||
| 320 | + | ||
| 321 | + self:updateProperty({field = "potionBag", value = potionBag}) | ||
| 322 | + if not params.notNotify then | ||
| 323 | + SendPacket(actionCodes.Role_updateItems, MsgPack.pack({[params.id] = params.count})) | ||
| 324 | + end | ||
| 325 | + end | ||
| 326 | + | ||
| 293 | function Role:addItem(params) | 327 | function Role:addItem(params) |
| 294 | params = params or {} | 328 | params = params or {} |
| 295 | params.count = math.floor(params.count or 0) | 329 | params.count = math.floor(params.count or 0) |