lostTempleCombatLogic.lua 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334
  1. --[[
  2. 失落神庙 战斗模块
  3. ]]
  4. local Msg = require("core.Msg")
  5. local LuaMongo = _G.lua_mongo
  6. local DB = require("common.DB")
  7. local LostTempleExcel = require("excel.lostTemple")
  8. local ElementExcel = require("excel.lostTemple").Element
  9. local LostTempleLogic = require("lostTemple.lostTempleLogic")
  10. local CombatLogic = require("combat.CombatLogic")
  11. local CombatDefine = require("combat.CombatDefine")
  12. local BagLogic = require("bag.BagLogic")
  13. local Grid = require("bag.Grid")
  14. local CombatObj = require("combat.CombatObj")
  15. local CombatImpl = require("combat.CombatImpl")
  16. local HeroGrid = require("hero.HeroGrid")
  17. local HeroExcel = require("excel.hero")
  18. local CombatPosLogic = require("combat.CombatPosLogic")
  19. local MoshouLogic = require("moshou.MoshouLogic")
  20. local JibanLogic = require("combat.JibanLogic")
  21. local RoleDefine = require("role.RoleDefine")
  22. local Util = require("common.Util")
  23. local SkinLogic = require("skin.SkinLogic")
  24. local XingYaoGongMing = require("xingYaoMen.XingYaoGongMing")
  25. local BeSkill = require("combat.BeSkill")
  26. local Skill = require("combat.Skill")
  27. local RoleAttr = require("role.RoleAttr")
  28. local ItemDefine = require("bag.ItemDefine")
  29. -------------------------------------- combat -----------------------------------------
  30. -- 获取属性
  31. function getHeroAttrs(human, index)
  32. human.lostTempleAttr = human.lostTempleAttr or { }
  33. if not human.lostTempleAttr[index] then
  34. human.lostTempleAttr[index] = RoleAttr.calcHeroGrid(human.lostTemple.summonHero[index], index, human)
  35. end
  36. return human.lostTempleAttr[index]
  37. end
  38. -- 根据uuid 获取heroGrid
  39. function getHeroGridByUuid(human, uuid)
  40. if not uuid or uuid == "" or uuid == "0" then return end
  41. for index = 1, human.db.heroBag[0] do
  42. local heroGrid = human.db.heroBag[index]
  43. if heroGrid and type(heroGrid) == "table" then
  44. if heroGrid.uuid == uuid then
  45. return heroGrid
  46. end
  47. end
  48. end
  49. -- 获取临时背包的
  50. if human.lostTemple and human.lostTemple.summonHero then
  51. for i = 1, human.lostTemple.summonHero[0] do
  52. local heroGrid = human.lostTemple.summonHero[i]
  53. if heroGrid and type(heroGrid) == "table" then
  54. if heroGrid.uuid == uuid then
  55. return heroGrid
  56. end
  57. end
  58. end
  59. end
  60. return nil
  61. end
  62. -- 阵容设定
  63. function checkUpdatePos(human, msg)
  64. if not human.lostTemple then return end
  65. local posList = CombatPosLogic.getPosList(msg.formation)
  66. local heroList = Util.split(msg.heroList, ",")
  67. local helpList = Util.split(msg.helpList, ",", true)
  68. local cnt = 0
  69. local useList = { }
  70. local fatherList = { }
  71. -- 确定英雄存不存在
  72. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  73. local uuid = heroList[i] or ""
  74. if uuid ~= "0" and uuid ~= "" then
  75. if i == CombatDefine.COMBAT_HERO_CNT and CombatPosLogic.canBackup(human) == 0 then
  76. -- 援军未激活
  77. return
  78. end
  79. if posList[i] == nil and i ~= CombatDefine.COMBAT_HERO_CNT then
  80. -- 站位不可用
  81. return
  82. end
  83. local heroGrid = getHeroGridByUuid(human, uuid)
  84. if not heroGrid then return end
  85. local heroConfig = HeroExcel.hero[heroGrid.id]
  86. if useList[uuid] or fatherList[heroGrid.id] then
  87. -- 同父类英雄重复
  88. return
  89. else
  90. cnt = cnt + 1
  91. useList[uuid] = true
  92. fatherList[heroGrid.id] = true
  93. end
  94. end
  95. end
  96. if cnt == 0 then
  97. -- 上阵英雄空
  98. return
  99. end
  100. -- 检查辅助对象是否激活 todo
  101. return true, heroList, helpList
  102. end
  103. -- 战斗前加属性
  104. function onFightBegin(human, cbParam, combatType, param)
  105. local putY = tonumber(param[1])
  106. if not putY then return end
  107. local grid = LostTempleLogic.checkPutByY(human, putY)
  108. if not grid then return end
  109. if not grid.monsterOutID then return end
  110. for index = 1, CombatDefine.COMBAT_HERO_CNT do
  111. -- 攻方血量
  112. local atkPos = CombatLogic.getPos(CombatDefine.ATTACK_SIDE, index)
  113. local atkObj = CombatImpl.objList[atkPos]
  114. if atkObj ~= nil then
  115. -- 英雄状态
  116. if human.lostTemple.heroStatus then
  117. local hpRate = human.lostTemple.heroStatus[atkObj.uuid] or 1.0
  118. local hpMax = CombatObj.getHpMax(atkObj)
  119. atkObj.hp = math.ceil(hpMax * hpRate)
  120. if atkObj.hp <= 0 then
  121. atkObj.hp = 1
  122. end
  123. if atkObj.hp >= hpMax then
  124. atkObj.hp = hpMax
  125. end
  126. end
  127. -- 属性
  128. if human.lostTemple.summonTree then
  129. atkObj.isSysAttrChange = true
  130. for key, value in pairs(human.lostTemple.summonTree) do
  131. atkObj.sysAttr[key] = atkObj.sysAttr[key] + value
  132. end
  133. end
  134. end
  135. -- 守方血量
  136. local defPos = CombatLogic.getPos(CombatDefine.DEFEND_SIDE, index)
  137. local defObj = CombatImpl.objList[defPos]
  138. local objStatus = grid.objStatus and grid.objStatus[defPos] or nil
  139. if defObj ~= nil and objStatus then
  140. local hpMax = CombatObj.getHpMax(defObj)
  141. defObj.hp = math.ceil(objStatus.hpRate * hpMax)
  142. end
  143. end
  144. end
  145. -- 根据英雄背包创建临时对象
  146. function createHumanObj(human, uuid)
  147. if not uuid then return end
  148. local heroGrid = getHeroGridByUuid(human, uuid)
  149. if not heroGrid or type(heroGrid) ~= "table" then return end
  150. return CombatLogic.createHeroObjByHeroGrid(human, heroGrid)
  151. end
  152. -- 获取英雄阵容
  153. function getHumanObjList(human, combatType)
  154. local teamType = CombatPosLogic.getTeamType(combatType)
  155. if not teamType then return end
  156. local combatHero, _, formation, combatHeroDB = CombatPosLogic.getCombatHeros(human, combatType)
  157. if not combatHero then return end
  158. if formation == 0 then
  159. formation = 1
  160. end
  161. local heroStatus = human.lostTemple.heroStatus
  162. local jiban = JibanLogic.getJibanHero(human, combatHeroDB)
  163. local objList = { }
  164. local zhandouli = 0
  165. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  166. local uuid = combatHero[i]
  167. local obj = createHumanObj(human, uuid)
  168. if obj then
  169. local hpRate = heroStatus and heroStatus[uuid] or 1.0
  170. if hpRate > 0 then
  171. zhandouli = zhandouli + obj.attrs[RoleDefine.ZHANDOULI]
  172. objList[i] = obj
  173. else
  174. combatHero[i] = nil
  175. end
  176. end
  177. end
  178. local helpList = { }
  179. local pet = MoshouLogic.createCombatMoshow(human, combatType)
  180. helpList[CombatDefine.HELP_TYPE1] = pet
  181. local rolebase = CombatLogic.createRoleBaseByDB(human.db, zhandouli)
  182. return objList, helpList, rolebase, formation, jiban
  183. end
  184. -- 获取怪物组id
  185. function getCombatMonsterOutID(human, side, args, combatType)
  186. if side == CombatDefine.ATTACK_SIDE then return end
  187. if not human.lostTemple then return end
  188. local putY = tonumber(args[1])
  189. if not putY then return end
  190. local grid = LostTempleLogic.checkPutByY(human, putY)
  191. if not grid then return end
  192. return grid.monsterOutID
  193. end
  194. -- 战斗
  195. function fight(human, args)
  196. if not human.lostTemple then return end
  197. local putY = tonumber(args[1])
  198. if not putY then return end
  199. local grid = LostTempleLogic.checkPutByY(human, putY)
  200. if not grid then return end
  201. if not grid.monsterOutID then return end
  202. CombatLogic.combatBegin(human, 1001, args, CombatDefine.COMBAT_TYPE24)
  203. end
  204. -- 战斗结束
  205. function onFightEnd(human, result, combatType, cbParam, combatInfo, param)
  206. if not human.lostTemple then return end
  207. local putY = tonumber(param[1])
  208. if not putY then return end
  209. local grid = LostTempleLogic.checkPutByY(human, putY)
  210. if not grid then return end
  211. if not grid.monsterOutID then return end
  212. local elementConfig = ElementExcel[grid.id]
  213. if not elementConfig then return end
  214. local rewardConfig = LostTempleExcel.Drop[elementConfig.arg[1]]
  215. if not rewardConfig then return end
  216. local msgRet = Msg.gc.GC_LOST_TEMPLE_FIGHT_END
  217. msgRet.gdReward[0] = 0
  218. msgRet.randomReward[0] = 0
  219. if result == CombatDefine.RESULT_WIN then
  220. for _, item in ipairs(rewardConfig.drop) do
  221. msgRet.gdReward[0] = msgRet.gdReward[0] + 1
  222. Grid.makeItem(msgRet.gdReward[msgRet.gdReward[0]], item[1], item[2])
  223. BagLogic.addItem(human, item[1], item[2], "lostTemple")
  224. end
  225. local mathRandom = math.random(1, 10000)
  226. if mathRandom <= rewardConfig.randomdrop[1] then
  227. msgRet.randomReward[0] = 1
  228. local randomIndex = math.random(2, #rewardConfig.randomdrop)
  229. local randomItem = rewardConfig.randomdrop[randomIndex]
  230. human.lostTemple.randomReward = human.lostTemple.randomReward or { }
  231. human.lostTemple.randomReward[randomItem[1]] = human.lostTemple.randomReward[randomItem[1]] or 0
  232. human.lostTemple.randomReward[randomItem[1]] = human.lostTemple.randomReward[randomItem[1]] + randomItem[2]
  233. Grid.makeItem(msgRet.randomReward[1], randomItem[1], randomItem[2])
  234. end
  235. -- BOOS
  236. if not LostTempleLogic.putSet(human, putY, elementConfig.cmd) then
  237. LostTempleLogic.nextGrid(human, putY)
  238. end
  239. else
  240. grid.objStatus = grid.objStatus or { }
  241. -- 更新防守方血量
  242. for index = 1, CombatDefine.COMBAT_HERO_CNT do
  243. local defPos = CombatLogic.getPos(CombatDefine.DEFEND_SIDE, index)
  244. local defObj = combatInfo.objList[defPos]
  245. if defObj ~= nil then
  246. local hp = defObj.hp
  247. local hpMax = CombatObj.getHpMax(defObj)
  248. local hpRate = hp / hpMax
  249. grid.objStatus[defPos] = grid.objStatus[defPos] or { }
  250. grid.objStatus[defPos].hpRate = hpRate
  251. end
  252. end
  253. end
  254. -- 更新攻击方血量
  255. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE24)
  256. human.lostTemple.heroStatus = human.lostTemple.heroStatus or { }
  257. for index = 1, CombatDefine.COMBAT_HERO_CNT do
  258. local atkPos = CombatLogic.getPos(CombatDefine.ATTACK_SIDE, index)
  259. local atkObj = combatInfo.objList[atkPos]
  260. if atkObj ~= nil then
  261. local hp = atkObj.hp
  262. local hpMax = CombatObj.getHpMax(atkObj)
  263. local hpRate = hp / hpMax
  264. if hpRate < 1.0 then
  265. human.lostTemple.heroStatus[atkObj.uuid] = hpRate
  266. end
  267. -- 阵上英雄下阵
  268. if combatHero and hp <= 0 then
  269. for pos, uuid in pairs(combatHero) do
  270. if uuid == atkObj.uuid then
  271. combatHero[pos] = nil
  272. end
  273. end
  274. end
  275. end
  276. end
  277. LostTempleLogic.dbSave(human)
  278. CombatLogic.fontCombatFinish(msgRet.data, combatInfo)
  279. Msg.send(msgRet, human.fd)
  280. end