lostTempleCombatLogic.lua 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382
  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. -- 精灵
  188. local elfList = {}
  189. local combatElfList = combatHeroDB.elfList
  190. if combatElfList then
  191. for i=1, CombatDefine.COMBAT_ELF_CNT do
  192. local elfId = combatElfList[i]
  193. local elfObj = CombatLogic.createElfObj(human, elfId, i)
  194. if elfObj then
  195. elfList[i] = elfObj
  196. end
  197. end
  198. end
  199. return objList, helpList, rolebase, formation, jiban, elfList
  200. end
  201. -- 获取怪物组id
  202. function getCombatMonsterOutID(human, side, args, combatType)
  203. if side == CombatDefine.ATTACK_SIDE then return end
  204. if not human.lostTemple then return end
  205. local putY = tonumber(args[1])
  206. if not putY then return end
  207. local grid = LostTempleLogic.checkPutByY(human, putY)
  208. if not grid then return end
  209. return grid.monsterOutID
  210. end
  211. -- 战斗
  212. function fight(human, args)
  213. if not human.lostTemple then return end
  214. local putY = tonumber(args[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 power = CombatPosLogic.getCombatHeroZDL(human, CombatDefine.COMBAT_TYPE24)
  220. if power <= 0 then
  221. Broadcast.sendErr(human, Lang.COMBAT_ERR_NO_SET_FIGHT)
  222. return
  223. end
  224. CombatLogic.combatBegin(human, 1001, args, CombatDefine.COMBAT_TYPE24)
  225. end
  226. -- 战斗结束
  227. function onFightEnd(human, result, combatType, cbParam, combatInfo, param)
  228. if not human.lostTemple then return end
  229. local putY = tonumber(param[1])
  230. if not putY then return end
  231. local grid = LostTempleLogic.checkPutByY(human, putY)
  232. if not grid then return end
  233. if not grid.monsterOutID then return end
  234. local elementConfig = ElementExcel[grid.id]
  235. if not elementConfig then return end
  236. local rewardConfig = LostTempleExcel.Drop[elementConfig.arg[1]]
  237. if not rewardConfig then return end
  238. local msgRet = Msg.gc.GC_LOST_TEMPLE_FIGHT_END
  239. msgRet.gdReward[0] = 0
  240. msgRet.randomReward[0] = 0
  241. if result == CombatDefine.RESULT_WIN then
  242. for _, item in ipairs(rewardConfig.drop) do
  243. msgRet.gdReward[0] = msgRet.gdReward[0] + 1
  244. Grid.makeItem(msgRet.gdReward[msgRet.gdReward[0]], item[1], item[2])
  245. BagLogic.addItem(human, item[1], item[2], "lostTemple")
  246. end
  247. local mathRandom = math.random(1, 10000)
  248. if mathRandom <= rewardConfig.randomdrop[1] then
  249. msgRet.randomReward[0] = 1
  250. local randomIndex = math.random(2, #rewardConfig.randomdrop)
  251. local randomItem = rewardConfig.randomdrop[randomIndex]
  252. human.lostTemple.randomReward = human.lostTemple.randomReward or { }
  253. human.lostTemple.randomReward[randomItem[1]] = human.lostTemple.randomReward[randomItem[1]] or 0
  254. human.lostTemple.randomReward[randomItem[1]] = human.lostTemple.randomReward[randomItem[1]] + randomItem[2]
  255. Grid.makeItem(msgRet.randomReward[1], randomItem[1], randomItem[2])
  256. end
  257. -- BOOS
  258. if not LostTempleLogic.putSet(human, putY, elementConfig.cmd) then
  259. LostTempleLogic.nextGrid(human, putY)
  260. else
  261. --通关判断
  262. if LostTempleLogic.IsPass(human) then
  263. YunYingLogic.onCallBack(human, "lostTempleCombat", 1)
  264. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1208)
  265. end
  266. end
  267. else
  268. grid.objStatus = grid.objStatus or { }
  269. -- 更新防守方血量
  270. for index = 1, CombatDefine.COMBAT_HERO_CNT do
  271. local defPos = CombatLogic.getPos(CombatDefine.DEFEND_SIDE, index)
  272. local defObj = combatInfo.objList[defPos]
  273. if defObj ~= nil then
  274. local hp = defObj.hp
  275. local hpMax = CombatObj.getHpMax(defObj)
  276. local hpRate = hp / hpMax
  277. grid.objStatus[defPos] = grid.objStatus[defPos] or { }
  278. grid.objStatus[defPos].hpRate = hpRate
  279. end
  280. end
  281. end
  282. -- 更新攻击方血量
  283. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE24)
  284. human.lostTemple.heroStatus = human.lostTemple.heroStatus or { }
  285. for index = 1, CombatDefine.COMBAT_HERO_CNT do
  286. local atkPos = CombatLogic.getPos(CombatDefine.ATTACK_SIDE, index)
  287. local atkObj = combatInfo.objList[atkPos]
  288. if atkObj ~= nil then
  289. local hp = atkObj.hp
  290. local hpMax = CombatObj.getHpMax(atkObj)
  291. local hpRate = hp / hpMax
  292. if hpRate < 1.0 then
  293. human.lostTemple.heroStatus[atkObj.uuid] = hpRate
  294. end
  295. -- 阵上英雄下阵
  296. if combatHero and hp <= 0 then
  297. for pos, uuid in pairs(combatHero) do
  298. if uuid == atkObj.uuid then
  299. combatHero[pos] = nil
  300. end
  301. end
  302. end
  303. end
  304. end
  305. LostTempleLogic.dbSave(human)
  306. CombatLogic.fontCombatFinish(msgRet.data, combatInfo)
  307. Msg.send(msgRet, human.fd)
  308. end
  309. function isDot(human)
  310. --print("[LostTempleCombatLogic_isDot] 进入红点判断")
  311. if not RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1208) then
  312. print("[LostTempleCombatLogic_isDot] 未开启该系统")
  313. return false
  314. end
  315. local bRet = LostTempleLogic.IsPass(human)
  316. if nil == bRet then
  317. print("[LostTempleCombatLogic_isDot] 没有获取到对应数据")
  318. return false
  319. end
  320. --print("[LostTempleCombatLogic_isDot] 没有获取到对应数据 bRet = "..(true == bRet and 1 or 0))
  321. return (bRet == false) and true or false
  322. end