From 8955225bcf74ac31cb4dfa6ca0436d8d9cdae11f Mon Sep 17 00:00:00 2001 From: zhouhaihai Date: Tue, 17 Nov 2020 11:50:42 +0800 Subject: [PATCH] 快速拾取。快速使用 --- src/actions/AdvAction.lua | 21 ++------------------- src/adv/Adv.lua | 134 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------- src/adv/AdvBlock.lua | 12 ++++++++++++ src/adv/AdvPassive.lua | 4 ++-- 4 files changed, 107 insertions(+), 64 deletions(-) diff --git a/src/actions/AdvAction.lua b/src/actions/AdvAction.lua index 71d7baa..16964bc 100644 --- a/src/actions/AdvAction.lua +++ b/src/actions/AdvAction.lua @@ -527,25 +527,8 @@ function _M.useItemRpc(agent, data) adv:cost({[itemId] = count}, {log = {desc = "useItem", int1 = itemId, int2 = count}}) adv:backUse({[itemId] = count}) end - - if itemId == 5020 then - role:finishGuide(53) - end - adv:checkAchievement(adv.AchievType.UseItem, count, itemId) - adv:mylog({desc = "useItem", int1 = itemId, int2 = count}) - - role:log("mission_pick_use", { - mission_threadid = adv.chapterId, -- 大地图ID - mission_threadname = (csvdb["adv_chapterCsv"][adv.chapterId] or {})["chapter"] or "auto", -- 大地图名称 - mission_id = adv.level, -- 关卡ID - item_id = itemId, -- 道具ID - mission_pick_use_num = count, -- 道具使用量 - mission_sequenceid = adv.logid, -- 本次拾荒ID,用于关联一次拾荒产生多条不同类型的日志 - }) - - for i = 1, count do - adv:doActive(itemData.effect, target) -- target - end + + adv:useItem(itemId, count, target) adv:afterRound() adv:saveDB() diff --git a/src/adv/Adv.lua b/src/adv/Adv.lua index eef71ca..084f68a 100644 --- a/src/adv/Adv.lua +++ b/src/adv/Adv.lua @@ -936,7 +936,7 @@ end -- log long1 字段被征用!!! -- 在冒险中获得的物品都发放在冒险背包内 -function Adv:award(gift, params) +function Adv:award(gift, params, backRewardParams) params = params or {} local tgift = {} if type(gift) == "string" then @@ -948,6 +948,8 @@ function Adv:award(gift, params) end local items = self.owner:getProperty("advItems") local oldItems = items + + local autoUse = {} for itemId, count in pairs(tgift) do if count > 0 then local buffAdd = self.battle.player:getRewardChange(itemId) @@ -956,41 +958,45 @@ function Adv:award(gift, params) self:checkAchievement(Adv.AchievType.GetItem, count, itemId) end tgift[itemId] = count - local origin = items:getv(itemId, 0) - local nums = origin + count - - if csvdb["adv_artifactCsv"][itemId] then -- 获得神器 - self:awardArtifact(itemId, params) - if not self.owner:checkOverGuide(55) then - self.owner:saveGuide(55,1,true) - end + if globalCsv.adv_auto_useItem[itemId] and count > 0 then + autoUse[itemId] = count else - if nums <= 0 then - items = items:delk(itemId) - nums = 0 + local origin = items:getv(itemId, 0) + local nums = origin + count + + if csvdb["adv_artifactCsv"][itemId] then -- 获得神器 + self:awardArtifact(itemId, params) + if not self.owner:checkOverGuide(55) then + self.owner:saveGuide(55,1,true) + end else - items = items:setv(itemId, nums) - end + if nums <= 0 then + items = items:delk(itemId) + nums = 0 + else + items = items:setv(itemId, nums) + end - if itemId == 16 and not self.owner:checkOverGuide(51,4) then - self.owner:saveGuide(51,4) - end - if params.log then - local log = clone(params.log) - if log["cint1"] or log["cint2"] or log["cint3"] or log["long1"] then - print("addAdvItem error log have cint1 or cint2 or cint3 ", debug.traceback()) + if itemId == 16 and not self.owner:checkOverGuide(51,4) then + self.owner:saveGuide(51,4) end - log["cint1"] = itemId - log["cint2"] = math.abs(count) - log["cint3"] = self.chapterId - log["long1"] = self.level - if count >= 0 then - self.owner:mylog("in_adv", log) + if params.log then + local log = clone(params.log) + if log["cint1"] or log["cint2"] or log["cint3"] or log["long1"] then + print("addAdvItem error log have cint1 or cint2 or cint3 ", debug.traceback()) + end + log["cint1"] = itemId + log["cint2"] = math.abs(count) + log["cint3"] = self.chapterId + log["long1"] = self.level + if count >= 0 then + self.owner:mylog("in_adv", log) + else + self.owner:mylog("out_adv", log) + end else - self.owner:mylog("out_adv", log) + print("addAdvItem no log ", debug.traceback()) end - else - print("addAdvItem no log ", debug.traceback()) end end end @@ -1001,10 +1007,48 @@ function Adv:award(gift, params) if tgift[ItemId.OldCoin] then self.battle.player:attrChangeCondBuffCheck(0) end + + if backRewardParams then + self:backReward(tgift, backRewardParams) + end + + if next(autoUse) then + for itemId, count in pairs(autoUse) do + self:useItem(itemId, count) + end + self:backUse(autoUse, 1) + end return tgift end +function Adv:useItem(itemId, count, target) + local itemData = csvdb["adv_itemCsv"][itemId] + if not itemData then return end + + if itemData["function"] == 0 or itemData["function"] == 2 then count = 1 end + + if itemId == 5020 then + role:finishGuide(53) + end + + self:checkAchievement(self.AchievType.UseItem, count, itemId) + self:mylog({desc = "useItem", int1 = itemId, int2 = count}) + + self.owner:log("mission_pick_use", { + mission_threadid = self.chapterId, -- 大地图ID + mission_threadname = (csvdb["adv_chapterCsv"][self.chapterId] or {})["chapter"] or "auto", -- 大地图名称 + mission_id = self.level, -- 关卡ID + item_id = itemId, -- 道具ID + mission_pick_use_num = count, -- 道具使用量 + mission_sequenceid = self.logid, -- 本次拾荒ID,用于关联一次拾荒产生多条不同类型的日志 + }) + + for i = 1, count do + self:doActive(itemData.effect, target) -- target + end +end + -- 消耗物品 优先冒险背包 --check 只是检查够不够 function Adv:cost(item, params, check) local items = self.owner:getProperty("advItems") @@ -1071,7 +1115,7 @@ local function clickOut(self, room, block, params, isExit) self.battle.player:triggerPassive(Passive.DOWN_LAYER) if curFloorData then - self:backReward(self:award({[ItemId.AdvPoint] = curFloorData.exp}, {log = {desc = "passReward", int1 = self.chapterId, int2 = self.level}})) + self:award({[ItemId.AdvPoint] = curFloorData.exp}, {log = {desc = "passReward", int1 = self.chapterId, int2 = self.level}}, {}) end local isHaveRelay = self:isHaveRelay(self.level) @@ -1255,7 +1299,7 @@ local function chooseCommon(self, room, block, chooseData, choose, tag) skynet.error(string.format("[ERROR]: event_dropCsv no id %s in %s id: %s", effect[2], tag, chooseData.id)) end end - self:backReward(self:award(reward, {log = {desc = "chooseEvent", key1 = tag, int1 = chooseData.id}}), {roomId = room.roomId, blockId = block.blockId}) + self:award(reward, {log = {desc = "chooseEvent", key1 = tag, int1 = chooseData.id}}, {roomId = room.roomId, blockId = block.blockId}) end, [2] = function() --获得冒险buff local layer = effect[3] or 1 @@ -1419,14 +1463,12 @@ local function clickDrop(self, room, block, params) if not self.battle or not self.battle.player then return end self.battle.player:triggerPassive(Passive.CLICK_DROP) - local reward = self:award({[block.event.item[1]] = block.event.item[2]}, {log = {desc = "clickDrop"}}) - -- local reward = self:award({[5801] = 1}) - -- 获取绷带的引导 + local reward = self:award({[block.event.item[1]] = block.event.item[2]}, {log = {desc = "clickDrop"}}, {roomId = room.roomId, blockId = block.blockId}) + if block.event.item[1] == 5020 and not self.owner:checkOverGuide(53,2) then self.owner:saveGuide(53,2) end block:clear() - self:backReward(reward, {roomId = room.roomId, blockId = block.blockId}) return true end @@ -1447,7 +1489,7 @@ local function clickTrader(self, room, block, params) local costCount = math.ceil(goodsData.price * (block.event.shop[buyId][2] or 100) / 100) if not self:cost({[goodsData.currency] = costCount}, {log = {desc = "clickTrader", int1 = block.event.id}}) then return false, 6 end --不够 self:backCost({[goodsData.currency] = costCount}) - local reward = self:award({[goodsData.item] = goodsData.num}, {log = {desc = "clickTrader", int1 = block.event.id}}) + self:award({[goodsData.item] = goodsData.num}, {log = {desc = "clickTrader", int1 = block.event.id}}, {}) if goodsData.restrict == 1 then self.shopStatus[goodsData.goods] = (self.shopStatus[goodsData.goods] or 0) + 1 elseif goodsData.restrict == 2 then @@ -1459,7 +1501,6 @@ local function clickTrader(self, room, block, params) buyCount = buyCount + 1 self:checkTask(Adv.TaskType.Shop, 1, block.event.id) self:checkAchievement(Adv.AchievType.Shop, 1, block.event.id) - self:backReward(reward) if (traderData.purchasetime ~= 0 and traderData.purchasetime <= buyCount) or #block.event.shop <= buyCount then block:clear() @@ -1501,7 +1542,7 @@ local function clickClick(self, room, block, params) local item = csvdb["event_dropCsv"][dropId]["range"]:randWeight(true) reward[item[1]] = (reward[item[1]] or 0) + item[2] end - self:backReward(self:award(reward, {log = {desc = "clickClick", int1 = block.event.id}}), {roomId = room.roomId, blockId = block.blockId}) + self:award(reward, {log = {desc = "clickClick", int1 = block.event.id}}, {roomId = room.roomId, blockId = block.blockId}) end, [3] = function() for _, buffId in ipairs(clickData.effect:toArray(true, "=")) do @@ -1989,10 +2030,13 @@ end function Adv:pushBackEvent(btype, params) table.insert(self.backEvents, {btype = btype, params = params}) end - +--[=[ +tag +1 自动拾取 +--]=] function Adv:backReward(items, params) params = params or {} - self:pushBackEvent(AdvBackEventType.Reward, {items = items, roomId = params.roomId, blockId = params.blockId}) + self:pushBackEvent(AdvBackEventType.Reward, {items = items, roomId = params.roomId, blockId = params.blockId, tag = params.tag}) end -- if is player enemyId is nil @@ -2033,8 +2077,12 @@ function Adv:backCost(items) self:pushBackEvent(AdvBackEventType.Cost, {items = items}) end -function Adv:backUse(items) - self:pushBackEvent(AdvBackEventType.Use, {items = items}) +--[=[ +tag +1 自动使用 +--]=] +function Adv:backUse(items, tag) + self:pushBackEvent(AdvBackEventType.Use, {items = items, tag = tag}) end diff --git a/src/adv/AdvBlock.lua b/src/adv/AdvBlock.lua index 63606a0..a213081 100644 --- a/src/adv/AdvBlock.lua +++ b/src/adv/AdvBlock.lua @@ -58,6 +58,7 @@ function Block:updateEvent(event, isInit) end self:randomEvent() end + self:quickDrop() end function Block:clear() @@ -263,9 +264,20 @@ function Block:open() local adv = map.adv self.isOpen = true self:randomEvent() + self:quickDrop() return true end +function Block:quickDrop() + if self:getEventType() == AdvEventType.Drop and self.event.item then + local itemId, count = table.unpack(self.event.item) + if globalCsv.adv_auto_collect[itemId] then + self.room.map.adv:award({[itemId] = count}, {log = {desc = "clickDrop"}}, {roomId = self.room.roomId, blockId = self.blockId, tag = 1}) + self:clear() + end + end +end + function Block:getObstacle() local data = self:getEventData() if not data then return 0 end diff --git a/src/adv/AdvPassive.lua b/src/adv/AdvPassive.lua index 6529fee..d9d536c 100644 --- a/src/adv/AdvPassive.lua +++ b/src/adv/AdvPassive.lua @@ -494,7 +494,7 @@ function Passive:effect8(dropId) skynet.error(string.format("CSVDATA Error adv_map_passive %s effect 8 not id %s in event_drop", self.id, dropId)) end local item = dropData["range"]:randWeight(true) - self.owner.battle.adv:backReward(self.owner.battle.adv:award({[item[1]] = item[2]}, {log = {desc = "passive", int1 = self.id}}), {roomId = self.owner.roomId, blockId = self.owner.blockId}) + self.owner.battle.adv:award({[item[1]] = item[2]}, {log = {desc = "passive", int1 = self.id}}, {roomId = self.owner.roomId, blockId = self.owner.blockId}) end @@ -509,7 +509,7 @@ function Passive:effect9(itemId, triggerPms, ratio, max) return end if not cond then return end - self.owner.battle.adv:backReward(self.owner.battle.adv:award({[itemId] = math.floor(math.max(0, math.min(max, cond / ratio)))}, {log = {desc = "passive", int1 = self.id}}), {roomId = self.owner.roomId, blockId = self.owner.blockId}) + self.owner.battle.adv:award({[itemId] = math.floor(math.max(0, math.min(max, cond / ratio)))}, {log = {desc = "passive", int1 = self.id}}, {roomId = self.owner.roomId, blockId = self.owner.blockId}) end --10=战斗额外掉落次数 -- libgit2 0.21.2