Commit 25a376ded1d6b525c25f9e51b8dcd30db574eb4b

Authored by zhouhaihai
1 parent 222a7d5f

冒险使用道具

Showing 2 changed files with 28 additions and 48 deletions   Show diff stats
src/actions/AdvAction.lua
@@ -270,9 +270,36 @@ function _M.useItemRpc(agent, data) @@ -270,9 +270,36 @@ function _M.useItemRpc(agent, data)
270 local role = agent.role 270 local role = agent.role
271 local msg = MsgPack.unpack(data) 271 local msg = MsgPack.unpack(data)
272 272
  273 + local itemId = msg.itemId -- 道具Id
  274 + local count = msg.count or 1 --数量
  275 + local target = msg.target -- {roomId = 1, blockId = 1} 选择的目标
  276 +
  277 + local itemData = csvdb["adv_itemCsv"][itemId]
  278 + if not itemData then return end
  279 +
273 local adv = role:getAdvData() 280 local adv = role:getAdvData()
274 - local status = adv:useItem(msg.itemId, msg.count, msg.target) -- target {roomId = 1, blockId = 1} 选择的目标 281 + --重置数量
  282 + if itemData["function"] == 0 or itemData["function"] == 2 then count = 1 end
  283 + if not adv:cost({[itemId] = count}, {}, true) then return true end
  284 +
  285 + local status = true
  286 + for i = 1, count do
  287 + status = status and adv:doActive(itemData.effect, target) -- target
  288 + if not status then
  289 + break
  290 + end
  291 + end
275 if not status then return end 292 if not status then return end
  293 +
  294 + --消耗
  295 + if itemData["function"] == 0 or itemData["function"] == 1 then
  296 + adv:cost({[itemId] = count}, {})
  297 + end
  298 +
  299 + adv:checkAchievement(Adv.AchievType.UseItem, count, itemId)
  300 + adv:afterRound()
  301 + adv:saveDB()
  302 +
276 SendPacket(actionCodes.Adv_useItemRpc, MsgPack.pack({events = adv:popBackEvents()})) 303 SendPacket(actionCodes.Adv_useItemRpc, MsgPack.pack({events = adv:popBackEvents()}))
277 return true 304 return true
278 end 305 end
@@ -747,34 +747,6 @@ function Adv:clickBlock(roomId, blockId, params) @@ -747,34 +747,6 @@ function Adv:clickBlock(roomId, blockId, params)
747 return status 747 return status
748 end 748 end
749 749
750 ---使用道具产生效果  
751 -function Adv:useItem(itemId, count, target)  
752 - count = count or 1  
753 - local itemData = csvdb["adv_itemCsv"][itemId]  
754 - if not itemData then return end  
755 - --重置数量  
756 - if itemData["function"] == 0 or itemData["function"] == 2 then count = 1 end  
757 - if not self:cost({[itemId] = count}, {}, true) then return true end  
758 - --消耗  
759 - if itemData["function"] == 0 or itemData["function"] == 1 then  
760 - self:cost({[itemId] = count}, {})  
761 - end  
762 - --生效  
763 - if itemData.type == 1 or itemData.type == 0 then --技能  
764 - self.battle.player:releaseSkill(itemData.effect, target)  
765 - elseif itemData.type == 2 then --掉落  
766 - local item = csvdb["event_dropCsv"][itemData.effect]["range"]:randWeight(true)  
767 - self:backReward(self:award({[item[1]] = item[2]}, {}))  
768 - else  
769 - return  
770 - end  
771 -  
772 - self:checkAchievement(Adv.AchievType.UseItem, count, itemId)  
773 -  
774 - self:afterRound()  
775 - self:saveDB()  
776 - return true  
777 -end  
778 750
779 function Adv:doActive(activeId, target) 751 function Adv:doActive(activeId, target)
780 local activeData = csvdb["adv_activeCsv"][activeId] 752 local activeData = csvdb["adv_activeCsv"][activeId]
@@ -948,25 +920,6 @@ function Adv:doActive(activeId, target) @@ -948,25 +920,6 @@ function Adv:doActive(activeId, target)
948 return true 920 return true
949 end 921 end
950 922
951 ---使用技能  
952 -function Adv:usePotion(potionId, potionLevel, target)  
953 - -- cost  
954 - local potionData = csvdb["adv_potionCsv"][potionId][potionLevel]  
955 -  
956 - local enemy = self.battle:getEnemy(target.roomId, target.blockId)  
957 - if not enemy then return end  
958 - --生效  
959 - if potionData.type == 1 or potionData.type == 0 then --技能  
960 - self.battle.player:releaseSkill(potionData.effect, enemy)  
961 - elseif potionData.type == 2 then --掉落  
962 - local item = csvdb["event_dropCsv"][potionData.effect]["range"]:randWeight(true)  
963 - self:backReward(self:award({[item[1]] = item[2]}, {}))  
964 - else  
965 - return  
966 - end  
967 -  
968 - return true  
969 -end  
970 923
971 -- 地图上物品变化 924 -- 地图上物品变化
972 function Adv:mapItemChange(ctype) 925 function Adv:mapItemChange(ctype)