From 0027e33bf25e2172a48fa33ae3d7deccdc77d844 Mon Sep 17 00:00:00 2001 From: chenyueqi Date: Wed, 30 Dec 2020 15:55:49 +0800 Subject: [PATCH] 调理剂生产和使用逻辑优化 --- src/GlobalVar.lua | 2 +- src/actions/AdvAction.lua | 14 +++++--------- src/actions/CarAction.lua | 11 +++-------- src/actions/DinerAction.lua | 21 +++++++++++---------- src/adv/Adv.lua | 54 +++++++++++++++++++++++++++++++++++++++++++++++++----- src/models/RolePlugin.lua | 34 ++++++++++++++++++++++++++++++++++ 6 files changed, 103 insertions(+), 33 deletions(-) diff --git a/src/GlobalVar.lua b/src/GlobalVar.lua index f34c4d7..a9cbf55 100644 --- a/src/GlobalVar.lua +++ b/src/GlobalVar.lua @@ -72,7 +72,7 @@ ItemType = { EquipBase = 9, -- 基础装备 Rune = 10, -- 符文 Cuisine = 11, -- 料理(用于增加好感度、贩卖获得金币) - LunchBox = 12, -- 便当盒(料理合成,冒险系统消耗道具) + Potion = 12, -- 拾荒药剂 TimeBox = 13, -- 时间箱(开启需要时间,随机产出道具) AdvItem = 14, -- 冒险道具 FuncOpen = 15, -- 管理功能开放 diff --git a/src/actions/AdvAction.lua b/src/actions/AdvAction.lua index 009b34c..794da80 100644 --- a/src/actions/AdvAction.lua +++ b/src/actions/AdvAction.lua @@ -543,8 +543,8 @@ function _M.usePotionRpc(agent, data) local msg = MsgPack.unpack(data) local potionId = msg.potionId -- 营养剂Id local target = msg.target -- {roomId = 1, blockId = 1} 选择的目标 - local potionLv = role.dinerData:getProperty("dishTree"):getv(potionId, 0) - if potionLv == 0 then return 1 end + local potionLv = role.dinerData:getProperty("dishTree"):getv(potionId, 1) + if potionLv < 1 then return 1 end local potionSet = csvdb["adv_potionCsv"][potionId] if not potionSet then return 2 end @@ -552,12 +552,9 @@ function _M.usePotionRpc(agent, data) local potionData = potionSet[potionLv] if not potionData then return 3 end - local potionBag = role:getProperty("potionBag") - local own = potionBag[potionId] or 0 - if own <= 0 then return 4 end - if not isCanContinue(role) then return end local adv = role:getAdvData() + if not adv:cost({[potionId] = 1}, {}, true) then return 4 end if adv:isWaitChooseArtifact() then return end adv:mylog({desc = "usePotion", int1 = potionId}) @@ -565,8 +562,7 @@ function _M.usePotionRpc(agent, data) local status = adv:doActive(potionData.effect, target) -- target if not status then return end - potionBag[potionId] = own - 1 - role:updateProperty({field = "potionBag", value = potionBag}) + adv:cost({[potionId] = 1}, {log = {desc = "usePotion", int1 = potionId}}) adv:pushBackEvent(AdvBackEventType.Potion, {id = potionId}) adv:afterRound() adv:saveDB() @@ -737,7 +733,7 @@ function _M.endBattleRpc(agent, data) role:finishGuide(52) -- 调理剂使用引导(生命药剂) if not role:checkOverGuide(61) then - local potionBag = role:getProperty("potionBag") + local potionBag = role:getProperty("advItems"):toNumMap() local own = potionBag[10] or 0 if own > 0 then -- 造假 diff --git a/src/actions/CarAction.lua b/src/actions/CarAction.lua index 105002a..87c9c6f 100644 --- a/src/actions/CarAction.lua +++ b/src/actions/CarAction.lua @@ -13,7 +13,7 @@ function _M.makePotionRpc( agent, data ) local count = msg.count if count < 1 then return 0 end local potionBag = role:getProperty("potionBag") - local potionLv = role.dinerData:getProperty("dishTree"):getv(potionId, 0) + local potionLv = role.dinerData:getProperty("dishTree"):getv(potionId, 1) if potionLv < 1 then return 1 end local potionSet = csvdb["adv_potionCsv"][potionId] @@ -22,20 +22,15 @@ function _M.makePotionRpc( agent, data ) local potionData = potionSet[potionLv] if not potionData then return 3 end - local own = potionBag[potionId] or 0 - if own+count > potionData.limit then - return 4 - end - local cost = potionData.material:toNumMap() for k, n in pairs(cost) do cost[k] = n * count end if not role:checkItemEnough(cost) then - return 5 + return 4 end - role:costItems(cost, {log = {desc = "makePotion", int1 = potionId, int2 = count}}) + local own = potionBag[potionId] or 0 potionBag[potionId] = own + count role:updateProperty({field = "potionBag", value = potionBag}) role:checkTaskEnter("PotionMake", {count = count, id = potionId}) diff --git a/src/actions/DinerAction.lua b/src/actions/DinerAction.lua index d386a88..c3c6786 100644 --- a/src/actions/DinerAction.lua +++ b/src/actions/DinerAction.lua @@ -385,22 +385,12 @@ function _M.talentUpRpc( agent, data ) local msg = MsgPack.unpack(data) local dish = msg.dish local dishTree = role.dinerData:getProperty("dishTree") - local dishLevel = dishTree:getv(dish, 0) local talentSet = csvdb["diner_talentCsv"][dish] if not talentSet then return 1 end - local talentData = talentSet[dishLevel] - if not talentData then - return 2 - end - - if not talentSet[dishLevel+1] then - return 21 - end - local typ = math.floor(dish/100 + 1) local treeSet = csvdb["diner_treeCsv"][typ] if not treeSet then @@ -412,6 +402,17 @@ function _M.talentUpRpc( agent, data ) return 4 end + -- 调理剂的默认等级是1级 + local dishLevel = dishTree:getv(dish, treeData.rarity == 2 and 1 or 0) + local talentData = talentSet[dishLevel] + if not talentData then + return 2 + end + + if not talentSet[dishLevel+1] then + return 21 + end + local limit = talentData.pointFront:toNumMap() for k,v in pairs(limit) do local lv = dishTree:getv(k, 0) diff --git a/src/adv/Adv.lua b/src/adv/Adv.lua index c3bb80e..91009e4 100644 --- a/src/adv/Adv.lua +++ b/src/adv/Adv.lua @@ -146,6 +146,10 @@ function Adv:initByChapter(params) end end + if self.level == 1 or self.isRelay then + self:supplyPotion() + end + self.maps = {} self.maps[1] = AdvMap.new(self, 1, mapId, isEnter, isNewRelay) @@ -396,9 +400,16 @@ function Adv:forceOver(notNotify) local advTeam = self.owner:getProperty("advTeam") advTeam.player = nil + local advPotionCsv = csvdb["adv_potionCsv"] + local potionBag = self.owner:getProperty("potionBag") + local reward = self.owner:getProperty("advItems"):toNumMap() for itemId, count in pairs(reward) do - reward[itemId] = math.ceil(count * globalCsv.adv_fail_reward_ratio / 100) -- 奖励相当于失败 + if advPotionCsv[itemId] then + potionBag[itemId] = (potionBag[itemId] or 0) + count + else + reward[itemId] = math.ceil(count * globalCsv.adv_fail_reward_ratio / 100) -- 奖励相当于失败 + end end self.owner:award(reward, {log = {desc = "advOver", int1 = self.chapterId}}) @@ -409,6 +420,7 @@ function Adv:forceOver(notNotify) advItems = "", advAFGet = {}, advAFWear = {}, + potionBag = potionBag, }, notNotify) end end @@ -789,12 +801,18 @@ function Adv:over(success, rewardRatio, overType) self.battle.player:triggerPassive(Passive.ADV_OVER, {score = score, level = self.level}) local reward = {} + local advPotionCsv = csvdb["adv_potionCsv"] + local potionBag = self.owner:getProperty("potionBag") for itemId, count in pairs(self.owner:getProperty("advItems"):toNumMap()) do local itemCsv = csvdb["itemCsv"][itemId] if not itemCsv then print("ERROR: no itemId in ItemCsv : ", itemId) elseif itemCsv.type ~= ItemType.AdvItem then - reward[itemId] = math.ceil(count * rewardRatio / 100) + if advPotionCsv[itemId] then + potionBag[itemId] = (potionBag[itemId] or 0) + count + else + reward[itemId] = math.ceil(count * rewardRatio / 100) + end end end reward = self.owner:award(reward, {log = {desc = "advOver", int1 = self.chapterId}}) @@ -889,6 +907,7 @@ function Adv:over(success, rewardRatio, overType) advItems = "", advAFGet = {}, advAFWear = {}, + potionBag = potionBag, }) self:pushBackEvent(AdvBackEventType.End, { success = success, @@ -973,7 +992,8 @@ function Adv:award(gift, params, backRewardParams) if globalCsv.adv_auto_useItem[itemId] and count > 0 then autoUse[itemId] = count else - local origin = items:getv(itemId, 0) + local transId = globalCsv.adv_item_potion[itemId] or itemId + local origin = items:getv(transId, 0) local nums = origin + count if csvdb["adv_artifactCsv"][itemId] then -- 获得神器 @@ -983,10 +1003,10 @@ function Adv:award(gift, params, backRewardParams) end else if nums <= 0 then - items = items:delk(itemId) + items = items:delk(transId) nums = 0 else - items = items:setv(itemId, nums) + items = items:setv(transId, nums) end if itemId == 16 and not self.owner:checkOverGuide(51,4) then @@ -1064,6 +1084,7 @@ end -- 消耗物品 优先冒险背包 --check 只是检查够不够 function Adv:cost(item, params, check) local items = self.owner:getProperty("advItems") + local potionCsv = csvdb["adv_potionCsv"] local less = {} local advCost = {} for itemId, count in pairs(item) do @@ -1077,9 +1098,13 @@ function Adv:cost(item, params, check) less[itemId] = -last end + if potionCsv[itemId] and last < 0 then -- 只能使用冒险背包里的药水 + return + end end if next(less) and not self.owner:checkItemEnough(less) then return end --不够 if check then return true end + self:award(advCost, params) if next(less) then self.owner:costItems(less, params) @@ -1087,6 +1112,25 @@ function Adv:cost(item, params, check) return true end +-- 补满冒险背包药剂,从药剂背包扣除药水放到冒险背包 +function Adv:supplyPotion() + local potionCsv = csvdb["adv_potionCsv"] + local potionBag = self.owner:getProperty("potionBag") + local advItems = self.owner:getProperty("advItems") + for potionId, set in pairs(potionCsv) do + local count = potionBag[potionId] or 0 + if count > 0 then + local num = math.min(set[1].limit,count) + advItems = advItems:setv(potionId,num) + potionBag[potionId] = num ~= count and (count - num) or nil + end + end + self.owner:updateProperties({ + advItems = advItems, + potionBag = potionBag, + }) +end + --事件点击处理 local function clickOut(self, room, block, params, isExit) if self:getCurMap():checkOver() then --检查是否可以出去了 diff --git a/src/models/RolePlugin.lua b/src/models/RolePlugin.lua index 1f27d19..f8cbbf1 100644 --- a/src/models/RolePlugin.lua +++ b/src/models/RolePlugin.lua @@ -131,6 +131,9 @@ function RolePlugin.bind(Role) self:addItem(pms) end end, + [ItemType.Potion] = function () + self:addPotion({id = itemId, count = count, notNotify = pms.notNotify, log = pms.log}) + end, } -- 对数量筛查 count = checkItemCount(self, itemId, count) @@ -290,6 +293,37 @@ function RolePlugin.bind(Role) self:changeCrossServerPvpSelfInfo("level") end + function Role:addPotion(params) + dump(params) + local pId = globalCsv.adv_item_potion[params.id] + local potionBag = self:getProperty("potionBag") + local origin = potionBag[pId] or 0 + local nums = origin + params.count + potionBag[pId] = nums + + self:logItems(params.id, origin, nums, params.log) + if params.log then + local log = clone(params.log) + if log["cint1"] or log["cint2"] then + print("addItem error log have cint1 or cint2 ", debug.traceback()) + end + log["cint1"] = params.id + log["cint2"] = math.abs(params.count) + if params.count <= 0 then + self:mylog("out_item", log) + else + self:mylog("in_item", log) + end + else + print("addItem no log ", debug.traceback()) + end + + self:updateProperty({field = "potionBag", value = potionBag}) + if not params.notNotify then + SendPacket(actionCodes.Role_updateItems, MsgPack.pack({[params.id] = params.count})) + end + end + function Role:addItem(params) params = params or {} params.count = math.floor(params.count or 0) -- libgit2 0.21.2