lostTempleCombatLogic.lua 12 KB

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