lostTempleCombatLogic.lua 12 KB

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