lostTempleCombatLogic.lua 13 KB

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