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 | 72 | EquipBase = 9, -- 基础装备 |
73 | 73 | Rune = 10, -- 符文 |
74 | 74 | Cuisine = 11, -- 料理(用于增加好感度、贩卖获得金币) |
75 | - LunchBox = 12, -- 便当盒(料理合成,冒险系统消耗道具) | |
75 | + Potion = 12, -- 拾荒药剂 | |
76 | 76 | TimeBox = 13, -- 时间箱(开启需要时间,随机产出道具) |
77 | 77 | AdvItem = 14, -- 冒险道具 |
78 | 78 | FuncOpen = 15, -- 管理功能开放 | ... | ... |
src/actions/AdvAction.lua
... | ... | @@ -543,8 +543,8 @@ function _M.usePotionRpc(agent, data) |
543 | 543 | local msg = MsgPack.unpack(data) |
544 | 544 | local potionId = msg.potionId -- 营养剂Id |
545 | 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 | 549 | local potionSet = csvdb["adv_potionCsv"][potionId] |
550 | 550 | if not potionSet then return 2 end |
... | ... | @@ -552,12 +552,9 @@ function _M.usePotionRpc(agent, data) |
552 | 552 | local potionData = potionSet[potionLv] |
553 | 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 | 555 | if not isCanContinue(role) then return end |
560 | 556 | local adv = role:getAdvData() |
557 | + if not adv:cost({[potionId] = 1}, {}, true) then return 4 end | |
561 | 558 | if adv:isWaitChooseArtifact() then return end |
562 | 559 | |
563 | 560 | adv:mylog({desc = "usePotion", int1 = potionId}) |
... | ... | @@ -565,8 +562,7 @@ function _M.usePotionRpc(agent, data) |
565 | 562 | local status = adv:doActive(potionData.effect, target) -- target |
566 | 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 | 566 | adv:pushBackEvent(AdvBackEventType.Potion, {id = potionId}) |
571 | 567 | adv:afterRound() |
572 | 568 | adv:saveDB() |
... | ... | @@ -737,7 +733,7 @@ function _M.endBattleRpc(agent, data) |
737 | 733 | role:finishGuide(52) |
738 | 734 | -- 调理剂使用引导(生命药剂) |
739 | 735 | if not role:checkOverGuide(61) then |
740 | - local potionBag = role:getProperty("potionBag") | |
736 | + local potionBag = role:getProperty("advItems"):toNumMap() | |
741 | 737 | local own = potionBag[10] or 0 |
742 | 738 | if own > 0 then |
743 | 739 | -- 造假 | ... | ... |
src/actions/CarAction.lua
... | ... | @@ -13,7 +13,7 @@ function _M.makePotionRpc( agent, data ) |
13 | 13 | local count = msg.count |
14 | 14 | if count < 1 then return 0 end |
15 | 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 | 17 | if potionLv < 1 then return 1 end |
18 | 18 | |
19 | 19 | local potionSet = csvdb["adv_potionCsv"][potionId] |
... | ... | @@ -22,20 +22,15 @@ function _M.makePotionRpc( agent, data ) |
22 | 22 | local potionData = potionSet[potionLv] |
23 | 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 | 25 | local cost = potionData.material:toNumMap() |
31 | 26 | for k, n in pairs(cost) do |
32 | 27 | cost[k] = n * count |
33 | 28 | end |
34 | 29 | if not role:checkItemEnough(cost) then |
35 | - return 5 | |
30 | + return 4 | |
36 | 31 | end |
37 | - | |
38 | 32 | role:costItems(cost, {log = {desc = "makePotion", int1 = potionId, int2 = count}}) |
33 | + local own = potionBag[potionId] or 0 | |
39 | 34 | potionBag[potionId] = own + count |
40 | 35 | role:updateProperty({field = "potionBag", value = potionBag}) |
41 | 36 | role:checkTaskEnter("PotionMake", {count = count, id = potionId}) | ... | ... |
src/actions/DinerAction.lua
... | ... | @@ -385,22 +385,12 @@ function _M.talentUpRpc( agent, data ) |
385 | 385 | local msg = MsgPack.unpack(data) |
386 | 386 | local dish = msg.dish |
387 | 387 | local dishTree = role.dinerData:getProperty("dishTree") |
388 | - local dishLevel = dishTree:getv(dish, 0) | |
389 | 388 | |
390 | 389 | local talentSet = csvdb["diner_talentCsv"][dish] |
391 | 390 | if not talentSet then |
392 | 391 | return 1 |
393 | 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 | 394 | local typ = math.floor(dish/100 + 1) |
405 | 395 | local treeSet = csvdb["diner_treeCsv"][typ] |
406 | 396 | if not treeSet then |
... | ... | @@ -412,6 +402,17 @@ function _M.talentUpRpc( agent, data ) |
412 | 402 | return 4 |
413 | 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 | 416 | local limit = talentData.pointFront:toNumMap() |
416 | 417 | for k,v in pairs(limit) do |
417 | 418 | local lv = dishTree:getv(k, 0) | ... | ... |
src/adv/Adv.lua
... | ... | @@ -146,6 +146,10 @@ function Adv:initByChapter(params) |
146 | 146 | end |
147 | 147 | end |
148 | 148 | |
149 | + if self.level == 1 or self.isRelay then | |
150 | + self:supplyPotion() | |
151 | + end | |
152 | + | |
149 | 153 | self.maps = {} |
150 | 154 | self.maps[1] = AdvMap.new(self, 1, mapId, isEnter, isNewRelay) |
151 | 155 | |
... | ... | @@ -396,9 +400,16 @@ function Adv:forceOver(notNotify) |
396 | 400 | local advTeam = self.owner:getProperty("advTeam") |
397 | 401 | advTeam.player = nil |
398 | 402 | |
403 | + local advPotionCsv = csvdb["adv_potionCsv"] | |
404 | + local potionBag = self.owner:getProperty("potionBag") | |
405 | + | |
399 | 406 | local reward = self.owner:getProperty("advItems"):toNumMap() |
400 | 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 | 413 | end |
403 | 414 | self.owner:award(reward, {log = {desc = "advOver", int1 = self.chapterId}}) |
404 | 415 | |
... | ... | @@ -409,6 +420,7 @@ function Adv:forceOver(notNotify) |
409 | 420 | advItems = "", |
410 | 421 | advAFGet = {}, |
411 | 422 | advAFWear = {}, |
423 | + potionBag = potionBag, | |
412 | 424 | }, notNotify) |
413 | 425 | end |
414 | 426 | end |
... | ... | @@ -789,12 +801,18 @@ function Adv:over(success, rewardRatio, overType) |
789 | 801 | self.battle.player:triggerPassive(Passive.ADV_OVER, {score = score, level = self.level}) |
790 | 802 | |
791 | 803 | local reward = {} |
804 | + local advPotionCsv = csvdb["adv_potionCsv"] | |
805 | + local potionBag = self.owner:getProperty("potionBag") | |
792 | 806 | for itemId, count in pairs(self.owner:getProperty("advItems"):toNumMap()) do |
793 | 807 | local itemCsv = csvdb["itemCsv"][itemId] |
794 | 808 | if not itemCsv then |
795 | 809 | print("ERROR: no itemId in ItemCsv : ", itemId) |
796 | 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 | 816 | end |
799 | 817 | end |
800 | 818 | reward = self.owner:award(reward, {log = {desc = "advOver", int1 = self.chapterId}}) |
... | ... | @@ -889,6 +907,7 @@ function Adv:over(success, rewardRatio, overType) |
889 | 907 | advItems = "", |
890 | 908 | advAFGet = {}, |
891 | 909 | advAFWear = {}, |
910 | + potionBag = potionBag, | |
892 | 911 | }) |
893 | 912 | self:pushBackEvent(AdvBackEventType.End, { |
894 | 913 | success = success, |
... | ... | @@ -973,7 +992,8 @@ function Adv:award(gift, params, backRewardParams) |
973 | 992 | if globalCsv.adv_auto_useItem[itemId] and count > 0 then |
974 | 993 | autoUse[itemId] = count |
975 | 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 | 997 | local nums = origin + count |
978 | 998 | |
979 | 999 | if csvdb["adv_artifactCsv"][itemId] then -- 获得神器 |
... | ... | @@ -983,10 +1003,10 @@ function Adv:award(gift, params, backRewardParams) |
983 | 1003 | end |
984 | 1004 | else |
985 | 1005 | if nums <= 0 then |
986 | - items = items:delk(itemId) | |
1006 | + items = items:delk(transId) | |
987 | 1007 | nums = 0 |
988 | 1008 | else |
989 | - items = items:setv(itemId, nums) | |
1009 | + items = items:setv(transId, nums) | |
990 | 1010 | end |
991 | 1011 | |
992 | 1012 | if itemId == 16 and not self.owner:checkOverGuide(51,4) then |
... | ... | @@ -1064,6 +1084,7 @@ end |
1064 | 1084 | -- 消耗物品 优先冒险背包 --check 只是检查够不够 |
1065 | 1085 | function Adv:cost(item, params, check) |
1066 | 1086 | local items = self.owner:getProperty("advItems") |
1087 | + local potionCsv = csvdb["adv_potionCsv"] | |
1067 | 1088 | local less = {} |
1068 | 1089 | local advCost = {} |
1069 | 1090 | for itemId, count in pairs(item) do |
... | ... | @@ -1077,9 +1098,13 @@ function Adv:cost(item, params, check) |
1077 | 1098 | less[itemId] = -last |
1078 | 1099 | end |
1079 | 1100 | |
1101 | + if potionCsv[itemId] and last < 0 then -- 只能使用冒险背包里的药水 | |
1102 | + return | |
1103 | + end | |
1080 | 1104 | end |
1081 | 1105 | if next(less) and not self.owner:checkItemEnough(less) then return end --不够 |
1082 | 1106 | if check then return true end |
1107 | + | |
1083 | 1108 | self:award(advCost, params) |
1084 | 1109 | if next(less) then |
1085 | 1110 | self.owner:costItems(less, params) |
... | ... | @@ -1087,6 +1112,25 @@ function Adv:cost(item, params, check) |
1087 | 1112 | return true |
1088 | 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 | 1135 | local function clickOut(self, room, block, params, isExit) |
1092 | 1136 | if self:getCurMap():checkOver() then --检查是否可以出去了 | ... | ... |
src/models/RolePlugin.lua
... | ... | @@ -131,6 +131,9 @@ function RolePlugin.bind(Role) |
131 | 131 | self:addItem(pms) |
132 | 132 | end |
133 | 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 | 139 | count = checkItemCount(self, itemId, count) |
... | ... | @@ -290,6 +293,37 @@ function RolePlugin.bind(Role) |
290 | 293 | self:changeCrossServerPvpSelfInfo("level") |
291 | 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 | 327 | function Role:addItem(params) |
294 | 328 | params = params or {} |
295 | 329 | params.count = math.floor(params.count or 0) | ... | ... |