diff --git a/src/actions/AdvAction.lua b/src/actions/AdvAction.lua index b55d2ef..f12b36a 100644 --- a/src/actions/AdvAction.lua +++ b/src/actions/AdvAction.lua @@ -270,9 +270,36 @@ function _M.useItemRpc(agent, data) local role = agent.role local msg = MsgPack.unpack(data) + local itemId = msg.itemId -- 道具Id + local count = msg.count or 1 --数量 + local target = msg.target -- {roomId = 1, blockId = 1} 选择的目标 + + local itemData = csvdb["adv_itemCsv"][itemId] + if not itemData then return end + local adv = role:getAdvData() - local status = adv:useItem(msg.itemId, msg.count, msg.target) -- target {roomId = 1, blockId = 1} 选择的目标 + --重置数量 + if itemData["function"] == 0 or itemData["function"] == 2 then count = 1 end + if not adv:cost({[itemId] = count}, {}, true) then return true end + + local status = true + for i = 1, count do + status = status and adv:doActive(itemData.effect, target) -- target + if not status then + break + end + end if not status then return end + + --消耗 + if itemData["function"] == 0 or itemData["function"] == 1 then + adv:cost({[itemId] = count}, {}) + end + + adv:checkAchievement(Adv.AchievType.UseItem, count, itemId) + adv:afterRound() + adv:saveDB() + SendPacket(actionCodes.Adv_useItemRpc, MsgPack.pack({events = adv:popBackEvents()})) return true end diff --git a/src/adv/Adv.lua b/src/adv/Adv.lua index 1389c92..794692a 100644 --- a/src/adv/Adv.lua +++ b/src/adv/Adv.lua @@ -747,34 +747,6 @@ function Adv:clickBlock(roomId, blockId, params) return status end ---使用道具产生效果 -function Adv:useItem(itemId, count, target) - count = count or 1 - 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 not self:cost({[itemId] = count}, {}, true) then return true end - --消耗 - if itemData["function"] == 0 or itemData["function"] == 1 then - self:cost({[itemId] = count}, {}) - end - --生效 - if itemData.type == 1 or itemData.type == 0 then --技能 - self.battle.player:releaseSkill(itemData.effect, target) - elseif itemData.type == 2 then --掉落 - local item = csvdb["event_dropCsv"][itemData.effect]["range"]:randWeight(true) - self:backReward(self:award({[item[1]] = item[2]}, {})) - else - return - end - - self:checkAchievement(Adv.AchievType.UseItem, count, itemId) - - self:afterRound() - self:saveDB() - return true -end function Adv:doActive(activeId, target) local activeData = csvdb["adv_activeCsv"][activeId] @@ -948,25 +920,6 @@ function Adv:doActive(activeId, target) return true end ---使用技能 -function Adv:usePotion(potionId, potionLevel, target) - -- cost - local potionData = csvdb["adv_potionCsv"][potionId][potionLevel] - - local enemy = self.battle:getEnemy(target.roomId, target.blockId) - if not enemy then return end - --生效 - if potionData.type == 1 or potionData.type == 0 then --技能 - self.battle.player:releaseSkill(potionData.effect, enemy) - elseif potionData.type == 2 then --掉落 - local item = csvdb["event_dropCsv"][potionData.effect]["range"]:randWeight(true) - self:backReward(self:award({[item[1]] = item[2]}, {})) - else - return - end - - return true -end -- 地图上物品变化 function Adv:mapItemChange(ctype) -- libgit2 0.21.2