DrillLogicAttribute.lua 7.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. ---------------------------------------------------
  2. -- 过关斩将/圣树试炼
  3. ---------------------------------------------------
  4. local DrillExcel = require("excel.drill")
  5. local Util = require("common.Util")
  6. local Lang = require("common.Lang")
  7. local Msg = require("core.Msg")
  8. local ObjHuman = require("core.ObjHuman")
  9. local Broadcast = require("broadcast.Broadcast")
  10. local Grid = require("bag.Grid")
  11. local BagLogic = require("bag.BagLogic")
  12. local ItemDefine = require("bag.ItemDefine")
  13. local CombatLogic = require("combat.CombatLogic")
  14. local CombatDefine = require("combat.CombatDefine")
  15. local CombatObj = require("combat.CombatObj")
  16. local CombatPosLogic = require("combat.CombatPosLogic")
  17. local DrillDB = require("drill.DrillDB")
  18. local DrillLogic = require("drill.DrillLogic")
  19. -- 操作类型
  20. DRILL_OPER_1 = 1 -- 复活
  21. DRILL_OPER_2 = 2 -- 回血
  22. DRILL_OPER_3 = 3 -- 加buff
  23. DRILL_BUFF_1 = 1 -- 攻击
  24. DRILL_BUFF_2 = 2 -- 血量
  25. DRILL_BUFF_3 = 3 -- 速度
  26. DRILL_BUFF_4 = 4 -- 降低对方治疗量
  27. -- 获取buff等级
  28. function getBuffLv(drillData, id)
  29. if not drillData.buff then return 0 end
  30. return drillData.buff[id] or 0
  31. end
  32. -- 获取buff值
  33. function getBuffValue(drillData, id)
  34. local buffConfig = DrillExcel.buff[id]
  35. if not buffConfig then return 0 end
  36. return buffConfig.per * getBuffLv(drillData, id)
  37. end
  38. -- 提升buff等级
  39. function addBuffLv(drillData, id)
  40. drillData.buff = drillData.buff or {}
  41. drillData.buff[id] = (drillData.buff[id] or 0) + 1
  42. end
  43. -- 获取操作次数
  44. function getOperCnt(drillData, optype)
  45. if not drillData.oper then return 0 end
  46. return drillData.oper[optype] or 0
  47. end
  48. -- 操作次数+1
  49. function addOperCnt(drillData, optype)
  50. drillData.oper = drillData.oper or {}
  51. drillData.oper[optype] = (drillData.oper[optype] or 0) + 1
  52. end
  53. -- 获取血量百分比 1表示满
  54. function getHeroHpRate(drillData, uuid)
  55. if not drillData.heroStatus then return 1 end
  56. return drillData.heroStatus[uuid] or 1
  57. end
  58. -- 设置血量百分比
  59. function setHeroHpRate(drillData, uuid, hpRate)
  60. hpRate = math.max(hpRate, 0)
  61. hpRate = math.min(hpRate, 1)
  62. drillData.heroStatus = drillData.heroStatus or {}
  63. drillData.heroStatus[uuid] = hpRate
  64. end
  65. -- 获取敌人血量百分比
  66. function getObjHpRate(drillObj, index)
  67. if not drillObj.objStatus then return 1 end
  68. return drillObj.objStatus[index] or 1
  69. end
  70. -- 设置敌人血量百分比
  71. function setObjHpRate(drillObj, index, hpRate)
  72. hpRate = math.max(hpRate, 0)
  73. hpRate = math.min(hpRate, 1)
  74. drillObj.objStatus = drillObj.objStatus or {}
  75. drillObj.objStatus[index] = hpRate
  76. end
  77. -- 重置buff等信息 (每关打完重置)
  78. function clearBuff(drillData)
  79. drillData.buff = nil
  80. drillData.oper = nil
  81. end
  82. function setHelp(drillData, uuid)
  83. drillData.helpUuids = drillData.helpUuids or {}
  84. drillData.helpUuids[uuid] = {}
  85. drillData.helpUuids[uuid].time = os.time()
  86. end
  87. function setHelpWin(drillData, uuid)
  88. drillData.helpUuids = drillData.helpUuids or {}
  89. if drillData.helpUuids[uuid] then
  90. drillData.helpUuids[uuid].win = 1
  91. end
  92. end
  93. -- 获取血量百分比 1表示满
  94. function getHelpHpRate(drillData, uuid)
  95. if not drillData.helpHeroStatus then return 1 end
  96. return drillData.helpHeroStatus[uuid] or 1
  97. end
  98. -- 设置血量百分比
  99. function setHelpHpRate(drillData, uuid, hpRate)
  100. hpRate = math.max(hpRate, 0)
  101. hpRate = math.min(hpRate, 1)
  102. drillData.helpHeroStatus = drillData.helpHeroStatus or {}
  103. drillData.helpHeroStatus[uuid] = hpRate
  104. end
  105. -------------------------------------------------------------------------------------------
  106. -- 查询buff列表
  107. function queryAttrInfo(human, drillData)
  108. --[[
  109. drillData = drillData or DrillDB.getDrillDataByUuid(human.db._id)
  110. if not drillData then return end
  111. local msgRet = Msg.gc.GC_DRILL_ATTR_INFO
  112. msgRet.buff[0] = #DrillExcel.buff
  113. for i = 1, msgRet.buff[0] do
  114. local buffConfig = DrillExcel.buff[i]
  115. local buffNet = msgRet.buff[i]
  116. local buffLv = getBuffLv(drillData, i)
  117. local pp = (buffConfig.mode == 0) and 100 or 1
  118. local value = buffConfig.per * buffLv / pp
  119. buffNet.type = i
  120. buffNet.lv = buffLv
  121. buffNet.name = buffConfig.name
  122. buffNet.desc2 = Util.format(buffConfig.desc2, value)
  123. end
  124. msgRet.oper[0] = #DrillExcel.oper
  125. for i = 1, msgRet.oper[0] do
  126. local operConfig = DrillExcel.oper[i]
  127. local operNet = msgRet.oper[i]
  128. local operCnt = getOperCnt(drillData, i)
  129. operNet.type = i
  130. operNet.consume = operConfig.consume + operCnt * operConfig.add
  131. end
  132. Grid.makeItem(msgRet.useItem, DrillDefine.itemID, 1)
  133. msgRet.price = DrillDefine.price
  134. Msg.send(msgRet, human.fd)
  135. ]]
  136. end
  137. -- 回血 复活
  138. function operHp(human, operType, heroIndex)
  139. if operType ~= DRILL_OPER_1 then -- 复活
  140. return
  141. end
  142. local heroIndexList = Util.split(heroIndex, "|")
  143. if #heroIndexList > 6 then
  144. return
  145. end
  146. if #heroIndexList > 0 then
  147. for i = 1, #heroIndexList do
  148. local drillData = DrillDB.getDrillDataByUuid(human.db._id)
  149. if not drillData then return end
  150. if drillData.drillId > #DrillExcel.drill then
  151. return --已通关
  152. end
  153. local index = tonumber(heroIndexList[i])
  154. local heroGrid = (index > 0) and human.db.heroBag[index]
  155. if type(heroGrid) ~= "table" then return end
  156. -- 道具判断
  157. local operCnt = getOperCnt(drillData, operType)
  158. local operConfig = DrillExcel.oper[operCnt + 1]
  159. if not operConfig then
  160. -- 复活次数已经满了
  161. return
  162. end
  163. local consume = operConfig.zuanshi
  164. if BagLogic.getItemCnt(human, ItemDefine.ITEM_ZUANSHI_ID) < consume then
  165. return Broadcast.sendErr(human, Util.format(Lang.COMMON_NO_ITEM, ItemDefine.getValue(ItemDefine.ITEM_ZUANSHI_ID, "name")))
  166. end
  167. local hpRate = getHeroHpRate(drillData, heroGrid.uuid)
  168. if hpRate == 1 then return end -- 满血
  169. if operType == DRILL_OPER_1 then -- 复活
  170. --死亡英雄不能回血 只能复活
  171. if hpRate > 0 then return end
  172. elseif operType == DRILL_OPER_2 then -- 回血
  173. --没死亡的英雄不能复活 只能回血
  174. if hpRate == 0 then return end
  175. else
  176. return
  177. end
  178. -- 先扣道具
  179. BagLogic.delItem(human, ItemDefine.ITEM_ZUANSHI_ID, consume, "drill_oper")
  180. -- 再设置血量
  181. setHeroHpRate(drillData, heroGrid.uuid, 1)
  182. DrillDB.updateDrillData(drillData)
  183. end
  184. local drillData = DrillDB.getDrillDataByUuid(human.db._id)
  185. if not drillData then return end
  186. addOperCnt(drillData, operType)
  187. DrillDB.updateDrillData(drillData)
  188. Broadcast.sendErr(human, Lang.DRILL_FUHUO_SUCCESS)
  189. DrillLogic.fuhuoQuery(human)
  190. queryAttrInfo(human, drillData)
  191. DrillLogic.sendHeroList(human, drillData.heroStatus)
  192. end
  193. end
  194. -- 加buff 针对关卡 没有BUF 了
  195. function operBuff(human)
  196. --[[
  197. local drillData = DrillDB.getDrillDataByUuid(human.db._id)
  198. if not drillData then return end
  199. if drillData.drillId > #DrillExcel.drill then
  200. return --已通关
  201. end
  202. -- 道具判断
  203. local operType = DRILL_OPER_3
  204. local operCnt = getOperCnt(drillData, operType)
  205. local operConfig = DrillExcel.oper[operType]
  206. local consume = operConfig.consume + operCnt * operConfig.add
  207. if BagLogic.getItemCnt(human, DrillDefine.itemID) < consume then
  208. return Broadcast.sendErr(human, Util.format(Lang.COMMON_NO_ITEM, ItemDefine.getValue(DrillDefine.itemID, "name")))
  209. end
  210. -- 先扣道具
  211. BagLogic.delItem(human, DrillDefine.itemID, consume, "drill_oper")
  212. addOperCnt(drillData, operType)
  213. -- 再给buff
  214. local buffType = math.random(1, #DrillExcel.buff)
  215. addBuffLv(drillData, buffType)
  216. DrillDB.updateDrillData(drillData)
  217. queryAttrInfo(human, drillData)
  218. local msgRet = Msg.gc.GC_DRILL_OPER_BUFF
  219. msgRet.buffType = buffType
  220. Msg.send(msgRet, human.fd)
  221. ]]
  222. end