DrillLogic.lua 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527
  1. ---------------------------------------------------
  2. -- 过关斩将/圣树试炼
  3. ---------------------------------------------------
  4. --[[
  5. db.drill = {
  6. time = 1, -- 这次数据的时间
  7. diff = 1, -- 选择的难度
  8. drillId = 1, -- 今日最大 通关关卡
  9. maxDiff = 1, -- 最大通关难度
  10. lastDiff = 1, -- 昨日选择的难度
  11. lastDrillId = 1, -- 昨日最大关卡
  12. myHelpIndex = 1, -- 我选择的援助出去英雄
  13. helpoutList = {}, -- 我选择的援助英雄
  14. dayGet = {}, -- 今日已获得奖励
  15. boxGet = {}, -- 今日宝箱 已领取
  16. }
  17. ]]--
  18. local Config = require("Config")
  19. local DrillExcel = require("excel.drill")
  20. local MailExcel = require("excel.mail")
  21. local MonsterExcel = require("excel.monster")
  22. local Util = require("common.Util")
  23. local Lang = require("common.Lang")
  24. local CommonDB = require("common.CommonDB")
  25. local Msg = require("core.Msg")
  26. local InnerMsg = require("core.InnerMsg")
  27. local ObjHuman = require("core.ObjHuman")
  28. local Timer = require("core.Timer")
  29. local Broadcast = require("broadcast.Broadcast")
  30. local Grid = require("bag.Grid")
  31. local BagLogic = require("bag.BagLogic")
  32. local CombatImpl = require("combat.CombatImpl")
  33. local CombatObj = require("combat.CombatObj")
  34. local CombatLogic = require("combat.CombatLogic")
  35. local CombatDefine = require("combat.CombatDefine")
  36. local CombatPosLogic = require("combat.CombatPosLogic")
  37. local CopyManage = require("copy.CopyManage")
  38. local ChatPaoMaLogic = require("chat.ChatPaoMaLogic")
  39. local DrillDB = require("drill.DrillDB")
  40. local DrillMiddleLogic = require("drill.DrillMiddleLogic")
  41. local DrillLogicAttribute = require("drill.DrillLogicAttribute")
  42. local HeroGrid = require("hero.HeroGrid")
  43. local HeroDefine = require("hero.HeroDefine")
  44. local RoleDefine = require("role.RoleDefine")
  45. local RoleLogic = require("role.RoleLogic")
  46. local RoleDBLogic = require("role.RoleDBLogic")
  47. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  48. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  49. local MailManager = require("mail.MailManager")
  50. local MiddleConnect = require("middle.MiddleConnect")
  51. local HeroExcel = require("excel.hero")
  52. local FriendDBLogic = require("friend.FriendDBLogic")
  53. local ChengjiuLogic = require("chengjiu.ChengjiuLogic")
  54. local ChengjiuDefine = require("chengjiu.ChengjiuDefine")
  55. local LiLianLogic = require("dailyTask.LiLianLogic")
  56. local BeSkill = require("combat.BeSkill")
  57. local SkinLogic = require("skin.SkinLogic")
  58. local DailyTaskLogic = require("dailyTask.DailyTaskLogic")
  59. local ItemDefine = require("bag.ItemDefine")
  60. local VipLogic = require("vip.VipLogic")
  61. local HeroLogic = require("hero.HeroLogic")
  62. local MailDefine = require("mail.MailIdDefine")
  63. local JibanLogic = require("combat.JibanLogic")
  64. local HeroLogLogic = require("absAct.HeroLogLogic")
  65. local HeroGrowUp = require("absAct.HeroGrowUp")
  66. local MengxinLogic = require("present.MengxinLogic")
  67. local YunYingLogic = require("yunying.YunYingLogic")
  68. local queryFields = {["uuid"] = 1}
  69. local queryFieldsList = {}
  70. local queryUuidFields = {["uuid"] = 1}
  71. local queryRawardFields = {["drillId"] = 1, ["rawardStatus"] = 1}
  72. local sortTable = {}
  73. SEASON_KEEP_DAY = 1 -- 1天一个流程
  74. STATE_NOOPEN = 0 -- 未开始
  75. STATE_OPEN = 1 -- 开始
  76. STATE_READY = 2 -- 准备期间
  77. -- 难度说明
  78. DIFF_NORMAL = 1 -- 普通难度
  79. DIFF_ELITE = 2 -- 精英难度
  80. DIFF_INCUBI = 3 -- 噩梦难度
  81. DRILL_BOX_STATE_0 = 0 -- 未领取
  82. DRILL_BOX_STATE_1 = 1 -- 可领取
  83. DRILL_BOX_STATE_2 = 2 -- 已领取
  84. DRILL_BOX_GOD_MAX = 3 -- 诸神怜悯 最大获奖次数
  85. local FRIEND_ITEM_CNT = 10 -- 每次助战获得x点友情点
  86. local MAX_HEROCOMBAT_MUL = 150 -- 助战英雄最大倍数百分比
  87. local INIT_HP_MAX = 100
  88. -- 获取剩余时间
  89. function getState()
  90. -- if MiddleConnect.IS_MIDDLE_CONNECT ~= true then
  91. -- return STATE_NOOPEN, Lang.MIDDLE_SVR_ERR_CONNECT
  92. -- end
  93. return STATE_OPEN
  94. end
  95. -- 判断
  96. function isOpen(human, sendTip)
  97. --[[
  98. local isok, tip = CopyManage.isOpen(CopyInfo, human)
  99. if not isok then
  100. if sendTip and tip then
  101. Broadcast.sendErr(human, tip)
  102. end
  103. return
  104. end
  105. local state, _, tip = getState()
  106. if state ~= STATE_OPEN then
  107. if sendTip and tip then
  108. Broadcast.sendErr(human, tip)
  109. end
  110. return
  111. end
  112. ]]
  113. return true
  114. end
  115. -- 活动开始倒计时
  116. function getStartLeftTime(human)
  117. local state, leftSec = getState()
  118. if state ~= STATE_NOOPEN then
  119. return leftSec
  120. end
  121. return 0
  122. end
  123. function getCopyState(human)
  124. local state = getState()
  125. return state
  126. end
  127. -- 最大通关难度
  128. function getMaxDiff(human)
  129. if not human.db.drill then
  130. return 0
  131. end
  132. return human.db.drill.maxDiff or 0
  133. end
  134. function setMaxDiff(human, diff)
  135. if not human.db.drill then return end
  136. human.db.drill = human.db.drill or {}
  137. human.db.drill.maxDiff = diff
  138. end
  139. -- 获取关卡奖励配置
  140. function getDrillItems(drillId, diff)
  141. local config = DrillExcel.drill[drillId]
  142. if not config then return end
  143. if diff == DIFF_NORMAL then
  144. return config.items
  145. end
  146. return config["items" .. diff]
  147. end
  148. -- 数据重置
  149. -- 重置关卡数据
  150. -- 重置关卡阵容
  151. -- 每天0点检测是否开启了试炼 进行清除
  152. function onHour()
  153. DrillDB.checkDrillReset()
  154. end
  155. function dayCheck()
  156. if _G.is_middle then return end
  157. DrillDB.reset()
  158. end
  159. -- 查询时间
  160. function querySec(human)
  161. if not isOpen(human, true) then return end
  162. local state, leftSec = getState()
  163. local msgRet = Msg.gc.GC_DRILL_SEC
  164. msgRet.leftSec = leftSec
  165. msgRet.isStart = (state == STATE_OPEN) and 1 or 0
  166. Msg.send(msgRet, human.fd)
  167. queryDrillId(human)
  168. end
  169. function inintDrill(human)
  170. if not human.db.drill then
  171. human.db.drill = {}
  172. local drill = human.db.drill
  173. drill.time = 0
  174. drill.diff = 0
  175. drill.drillId = nil
  176. drill.maxDiff = 0
  177. drill.lastDiff = 0
  178. drill.lastDrillId = 0
  179. drill.myHelpIndex = 0
  180. drill.dayGet = nil
  181. drill.boxGet = nil
  182. drill.myHelpHero = nil
  183. drill.helpoutList = nil
  184. end
  185. end
  186. function updateDaily(human)
  187. -- CombatPosLogic.cleanCombatHeros(human, CombatDefine.COMBAT_TYPE9)
  188. local drillDB = human.db.drill
  189. if not drillDB then return end
  190. if Util.isSameDay(drillDB.time) then
  191. return
  192. end
  193. local surDay = Util.diffDay(drillDB.time)
  194. if surDay == 1 then
  195. drillDB.lastDrillId = drillDB.drillId
  196. drillDB.lastDiff = drillDB.diff
  197. else
  198. drillDB.lastDrillId = 0
  199. drillDB.lastDiff = 0
  200. end
  201. drillDB.time = os.time()
  202. drillDB.drillId = nil
  203. drillDB.diff = 0
  204. drillDB.dayGet = nil
  205. drillDB.boxGet = nil
  206. drillDB.myHelpIndex = 0
  207. drillDB.myHelpHero = nil
  208. drillDB.helpoutList = nil
  209. end
  210. -- 修正 玩家DB 玩家卡0点 选择难度挑战 DrilDB 后清 导致 玩家DB 和 DrillDB 对不上 后续修改为 以DrillDB 为准
  211. function fixDrillDB(human)
  212. if human.db.drill then
  213. human.db.drill.diff = 0
  214. end
  215. end
  216. -- 难度选择查询
  217. function diffChoseQuery(human)
  218. if not human.db.drill then
  219. inintDrill(human)
  220. end
  221. local drill = human.db.drill
  222. if not drill.diff or drill.diff == 0 then
  223. local msgRet = Msg.gc.GC_DRILL_DIFF
  224. msgRet.isGuide = drill.isGuide or 1
  225. drill.isGuide = 0
  226. for i = DIFF_NORMAL , DIFF_INCUBI do
  227. local config = DrillExcel.define[i]
  228. local net = msgRet.list[i]
  229. net.diff = i
  230. net.canChose = i == DIFF_NORMAL and 1 or 0
  231. net.reward[0] = 0
  232. net.needZhanli = config.needZhanli
  233. if drill.maxDiff >= i - 1 and human.db.zhandouli >= config.needZhanli then
  234. net.canChose = 1
  235. end
  236. end
  237. msgRet.list[0] = DIFF_INCUBI
  238. Msg.send(msgRet, human.fd)
  239. end
  240. end
  241. function checkSaoDang(human, diff, lastDiff, lastId)
  242. local diff = diff
  243. local id = 1
  244. local drillDB = human.db.drill
  245. if not drillDB then return diff, id end
  246. lastId = lastId and lastId or 0
  247. lastId = lastId <= #DrillExcel.drill and lastId or #DrillExcel.drill
  248. local double = RoleSystemLogic.isDouble(human, RoleSystemDefine.ROLE_SYS_ID_1204)
  249. local rewardCnt = double and 2 or 1
  250. if lastDiff and lastDiff == diff and lastId > 10 then
  251. id = lastId - 10
  252. for i = 1 , id do
  253. local drillItems = getDrillItems( i, lastDiff)
  254. -- 关卡奖励
  255. for _, item in ipairs(drillItems) do
  256. local itemID = item[1]
  257. local itemCnt = item[2] * rewardCnt
  258. drillDB.dayGet = drillDB.dayGet or {}
  259. drillDB.dayGet[itemID] = (drillDB.dayGet[itemID] or 0) + itemCnt
  260. BagLogic.addItem(human, itemID, itemCnt, "drill")
  261. end
  262. end
  263. -- BagLogic.sendItemGetList(human, itemList, "drill")
  264. local msgRet = Msg.gc.GC_DRILL_SAODANG_ITEM
  265. msgRet.drillId = id
  266. local len = 0
  267. for k , v in pairs(drillDB.dayGet) do
  268. len = len + 1
  269. Grid.makeItem(msgRet.itemList[len], k, v)
  270. end
  271. msgRet.itemList[0] = len
  272. msgRet.double = double and 1 or 0
  273. Msg.send(msgRet, human.fd)
  274. id = id + 1
  275. end
  276. return diff, id
  277. end
  278. function saodangQuest(human, drillId)
  279. if drillId <= 1 then return end
  280. local drill = human.db.drill
  281. if not drill then return end
  282. local diff = drill.diff
  283. local dirllDefConfig = DrillExcel.define[drill.diff]
  284. if not dirllDefConfig then return end
  285. local drillData = DrillDB.getDrillDataByUuid(human.db._id)
  286. if not drillData then
  287. fristQust(human, drillId)
  288. return
  289. end
  290. local zhandouli = CombatPosLogic.getCombatHeroZDL(human, CombatDefine.COMBAT_TYPE1)
  291. if zhandouli <= 0 then return Broadcast.sendErr(human, Lang.COMBAT_ERR_NO_SET_FIGHT) end
  292. if human.maxZDL and human.maxZDL.zhandouli and human.maxZDL.zhandouli > zhandouli then
  293. -- 获取玩家真正的最高战力 防止玩家 战役上阵 战力低 去匹配 低战力对手
  294. zhandouli = human.maxZDL.zhandouli
  295. end
  296. local notTab = {}
  297. for i = 1 , drillId do
  298. local drillObj = pipei(human, i, diff, zhandouli, notTab)
  299. drillData.drillObjs[i] = Util.copyTable(drillObj)
  300. end
  301. DrillDB.updateDrillData(drillData)
  302. end
  303. -- 选择难度
  304. function choseDiff(human, diff)
  305. if not human.db.drill then
  306. inintDrill(human)
  307. end
  308. local drill = human.db.drill
  309. local now = os.time()
  310. if not drill.diff or drill.diff == 0 then
  311. drill.dayGet = {}
  312. drill.boxGet = {}
  313. drill.myHelpIndex = 0
  314. drill.myHelpHero = nil
  315. drill.helpoutList = nil
  316. drill.time = now
  317. drill.diff, drill.drillId = checkSaoDang(human, diff, drill.lastDiff, drill.lastDrillId)
  318. local drillData = DrillDB.getDrillDataByUuid(human.db._id)
  319. -- 临时处理
  320. if not drillData then
  321. quest(human, drill.drillId)
  322. else
  323. quest(human, drillData.drillId + 1)
  324. end
  325. saodangQuest(human, drill.drillId )
  326. queryDrillId(human)
  327. end
  328. end
  329. -- 获取宝箱状态
  330. function getBoxState(drill, index)
  331. local state = DRILL_BOX_STATE_0
  332. if not drill.drillId or drill.drillId <= 0 then
  333. return state
  334. end
  335. local config = DrillExcel.box[index]
  336. if drill.drillId > config.needDrill then
  337. state = DRILL_BOX_STATE_1
  338. end
  339. if drill.boxGet and drill.boxGet[index] and drill.boxGet[index].state then
  340. state = DRILL_BOX_STATE_2
  341. end
  342. return state
  343. end
  344. -- 查询关卡Id
  345. function queryDrillId(human, drillData)
  346. drillData = drillData or DrillDB.getDrillDataByUuid(human.db._id)
  347. if not drillData then -- 没有记录 请求第一关
  348. fixDrillDB(human)
  349. return diffChoseQuery(human) -- quest(human)
  350. end
  351. local drill = human.db.drill
  352. local diff = drill.diff
  353. if not drill.diff or drill.diff == 0 then
  354. diff = drillData.diff
  355. end
  356. if diff == 0 then
  357. return diffChoseQuery(human)
  358. end
  359. local msgRet = Msg.gc.GC_DRILL_ID
  360. msgRet.drillId = drillData.drillId
  361. msgRet.diff = diff
  362. msgRet.maxDiff = drill.maxDiff
  363. msgRet.dayGet[0] = 2
  364. local dayJinbi = drill.dayGet and drill.dayGet[ItemDefine.ITEM_JINBI_ID] or 0
  365. local dayCoin = drill.dayGet and drill.dayGet[ItemDefine.ITEM_DRILL_COIN_ID] or 0
  366. Grid.makeItem(msgRet.dayGet[1], ItemDefine.ITEM_JINBI_ID, dayJinbi )
  367. Grid.makeItem(msgRet.dayGet[2], ItemDefine.ITEM_DRILL_COIN_ID, dayCoin )
  368. msgRet.box[0] = #DrillExcel.box
  369. for k, config in ipairs(DrillExcel.box) do
  370. local net = msgRet.box[k]
  371. net.index = k
  372. net.needId= config.needDrill
  373. net.state = getBoxState(drill, k)
  374. local itemID1 = config["items"..diff][1][1]
  375. local itemCnt1 = config["items"..diff][1][2]
  376. local itemID2 = config["items"..diff][2][1]
  377. local itemCnt2 = config["items"..diff][2][2]
  378. Grid.makeItem(net.reward[1], itemID1, itemCnt1 )
  379. Grid.makeItem(net.reward[2], itemID2, itemCnt2 )
  380. net.reward[0] = 2
  381. if config["items"..diff][3] then
  382. local itemID3 = config["items"..diff][3][1]
  383. local itemCnt3 = config["items"..diff][3][2]
  384. Grid.makeItem(net.reward[3], itemID3, itemCnt3 )
  385. net.reward[0] = 3
  386. end
  387. end
  388. -- Msg.trace(msgRet)
  389. Msg.send(msgRet, human.fd)
  390. end
  391. -- 是否被击杀
  392. function isObjKill(drillObj)
  393. if drillObj == nil then return end
  394. if drillObj.objStatus == nil then
  395. return
  396. end
  397. for _, hpRate in pairs(drillObj.objStatus) do
  398. if hpRate > 0 then
  399. return
  400. end
  401. end
  402. return true
  403. end
  404. -- 查询关卡状态
  405. function query(human, drillId)
  406. --if not isOpen(human, true) then return end
  407. local drill = human.db.drill
  408. if not drill then return end
  409. local drillCfg = DrillExcel.drill[drillId]
  410. if not drillCfg then return end
  411. local drillData = DrillDB.getDrillDataByUuid(human.db._id)
  412. if not drillData then return end
  413. local drillObj = drillData.drillObjs[drillId]
  414. if not drillObj then
  415. if drillId < 15 and drillData.drillId == drillId then
  416. quest(human, drillId)
  417. end
  418. return
  419. end
  420. local double = RoleSystemLogic.isDouble(human, RoleSystemDefine.ROLE_SYS_ID_1204)
  421. local rewardCnt = double and 2 or 1
  422. --require("common.Util").printTable(drillObj)
  423. local nowId = drillData.drillId
  424. local msgRet = Msg.gc.GC_DRILL_INFO
  425. msgRet.drillId = drillId
  426. msgRet.svrName = drillObj.svrName or Config.DB_NAME
  427. RoleLogic.makeRoleBase(drillObj, msgRet.roleBase)
  428. msgRet.reward[0] = 0
  429. msgRet.double = double and 1 or 0
  430. local itemConfig = drillCfg.items
  431. if drill.diff == DIFF_ELITE then
  432. itemConfig = drillCfg.items2
  433. elseif drill.diff == DIFF_INCUBI then
  434. itemConfig = drillCfg.items3
  435. end
  436. for _, item in pairs(itemConfig) do
  437. msgRet.reward[0] = msgRet.reward[0] + 1
  438. Grid.makeItem(msgRet.reward[msgRet.reward[0]], item[1], item[2] * rewardCnt)
  439. end
  440. msgRet.defence[0] = 0
  441. for i = 1, CombatDefine.COMBAT_HERO_CNT do
  442. local obj = drillObj.heroList[i]
  443. if obj then
  444. local hpRate = DrillLogicAttribute.getObjHpRate(drillObj, obj.bagIndex)
  445. local hp = math.ceil(INIT_HP_MAX * hpRate)
  446. local hpMax = INIT_HP_MAX
  447. hp = nowId > drillId and 0 or hp
  448. local others = HeroGrid.createOthers(obj.lv, hp, hpMax, obj.star)
  449. msgRet.defence[0] = msgRet.defence[0] + 1
  450. if drillObj.monsterOutID and drillObj.monsterOutID > 0 then
  451. HeroGrid.makeHeroSimpleByMonsterID(msgRet.defence[msgRet.defence[0]], obj.id, others)
  452. else
  453. HeroGrid.makeHeroSimpleByID(msgRet.defence[msgRet.defence[0]], obj.id, i, others)
  454. end
  455. end
  456. end
  457. local quick = CombatLogic.getQuick(human, CombatDefine.COMBAT_TYPE9)
  458. local showNext = 0
  459. if getMaxDiff(human) >= drill.diff and human.db.lv >= 120 then
  460. showNext = 1
  461. end
  462. msgRet.quick = quick or 0
  463. msgRet.showNext = showNext
  464. --Msg.trace(msgRet)
  465. Msg.send(msgRet, human.fd)
  466. -- 推送英雄的状态信息
  467. sendHeroList(human, drillData.heroStatus)
  468. end
  469. local FIX_LIST = {}
  470. function sendHeroList(human, heroStatus)
  471. local drillData = DrillDB.getDrillDataByUuid(human.db._id)
  472. if not drillData then return end
  473. local drill = human.db.drill
  474. if not drill then return end
  475. heroStatus = heroStatus and heroStatus or drillData.heroStatus
  476. local config = DrillExcel.define[drillData.diff]
  477. local msgRet = Msg.gc.GC_DRILL_HERO
  478. msgRet.isFirst = 1
  479. msgRet.isLast = 0
  480. msgRet.heroList[0] = 0
  481. msgRet.helpList[0] = 0
  482. local limit = human.drill or {}
  483. -- 雇佣英雄
  484. if drillData.helpUuids then
  485. for targetUuid, v in pairs(drillData.helpUuids) do
  486. msgRet.helpList[0] = msgRet.helpList[0] + 1
  487. local net = msgRet.helpList[msgRet.helpList[0]]
  488. if fontHelpNet(net, targetUuid, true) then
  489. -- 其它数据
  490. local hpRate = DrillLogicAttribute.getHelpHpRate(drillData, targetUuid)
  491. net.heroSimple.hp = math.ceil(INIT_HP_MAX * hpRate)
  492. net.heroSimple.hpMax = INIT_HP_MAX
  493. if limit.combatHelpUuid and limit.combatHelpUuid == targetUuid then
  494. net.pos = human.drill.combatHelpPos
  495. end
  496. if v.win or net.heroSimple.hp <= 0 then
  497. net.state = 1
  498. net.pos = 0
  499. end
  500. end
  501. end
  502. end
  503. local heroMinLevel = config and config.heroMinLevel or 0
  504. -- 背包的英雄
  505. for index,heroGrid in pairs(human.db.heroBag) do
  506. if index ~= 0 and heroGrid.lv >= heroMinLevel then
  507. if msgRet.heroList[0] >= #msgRet.heroList then
  508. Msg.send(msgRet, human.fd)
  509. msgRet.heroList[0] = 0
  510. msgRet.helpList[0] = 0
  511. msgRet.isFirst = 0
  512. end
  513. msgRet.heroList[0] = msgRet.heroList[0] + 1
  514. local heroNet = msgRet.heroList[msgRet.heroList[0]]
  515. HeroGrid.makeHeroSimple(heroNet, heroGrid, index)
  516. -- 其它数据
  517. local hpRate = DrillLogicAttribute.getHeroHpRate(drillData, heroGrid.uuid)
  518. heroNet.hp = math.ceil(INIT_HP_MAX * hpRate)
  519. heroNet.hpMax = INIT_HP_MAX
  520. end
  521. end
  522. if msgRet.heroList[0] > 0 or msgRet.isFirst == 1 then
  523. msgRet.isLast = 1
  524. -- Msg.trace(msgRet)
  525. Msg.send(msgRet, human.fd)
  526. end
  527. end
  528. function drillBoxGet(human, index)
  529. local drill = human.db.drill
  530. if not drill or not drill.diff or drill.diff == 0 then
  531. return
  532. end
  533. local config = DrillExcel.box[index]
  534. if not config then return end
  535. local state = getBoxState(drill, index)
  536. if state ~= 1 then
  537. return
  538. end
  539. drill.boxGet = drill.boxGet or {}
  540. drill.boxGet[index] = drill.boxGet[index] or {}
  541. drill.boxGet[index].cnt = drill.boxGet[index].cnt or 0
  542. drill.boxGet[index].cnt = drill.boxGet[index].cnt + 1
  543. local msgRet = Msg.gc.GC_DRILL_BOX_GET
  544. msgRet.type = 0
  545. msgRet.index = index
  546. local random = math.random(1, 100)
  547. if random <= 10 and drill.boxGet[index].cnt < DRILL_BOX_GOD_MAX then
  548. -- 诸神的怜悯
  549. msgRet.type = drill.boxGet[index].cnt >= DRILL_BOX_GOD_MAX - 1 and 2 or 1
  550. else
  551. drill.boxGet[index].state = 1
  552. end
  553. Msg.send(msgRet, human.fd)
  554. local itemConfig = config.items1
  555. if drill.diff == DIFF_ELITE then
  556. itemConfig = config.items2
  557. elseif drill.diff == DIFF_INCUBI then
  558. itemConfig = config.items3
  559. end
  560. BagLogic.addItemList(human, itemConfig, "drill")
  561. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1204)
  562. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1201)
  563. -- queryDrillId(human)
  564. end
  565. --奖励预览
  566. function rewardPreview(human)
  567. if not isOpen(human, true) then return end
  568. local msgRet = Msg.gc.GC_DRILL_REWARD_PREVIEW
  569. msgRet.list[0] = 0
  570. for drillId, cf in pairs(DrillExcel.drill) do
  571. msgRet.list[0] = msgRet.list[0] + 1
  572. local net = msgRet.list[msgRet.list[0]]
  573. net.drillId = drillId
  574. net.items[0] = #cf.items
  575. for i, item in ipairs(cf.items) do
  576. local itemID = item[1]
  577. local itemCnt = item[2]
  578. Grid.makeItem(net.items[i], itemID, itemCnt)
  579. end
  580. end
  581. Msg.send(msgRet, human.fd)
  582. end
  583. -- 邮件提醒
  584. function sendDrillTip(human)
  585. if human.db.mailtips[RoleSystemLogic.ROLE_MAILTIPS_ID1] == nil then
  586. human.db.mailtips[RoleSystemLogic.ROLE_MAILTIPS_ID1] = os.time()
  587. end
  588. local curTime = os.time()
  589. local daySec = 3600 * 24;
  590. if curTime - human.db.mailtips[RoleSystemLogic.ROLE_MAILTIPS_ID1] < daySec then
  591. return
  592. end
  593. human.db.mailtips[RoleSystemLogic.ROLE_MAILTIPS_ID1] = curTime
  594. if not isOpen(human) then return end
  595. end
  596. --------------------------------------------------------------------------------------
  597. --加入跨服试炼队列
  598. --检测是否有竞技场阵容
  599. --加入数据推送至中心服 [g->m]
  600. function onJjcPos(human)
  601. local heroList, helpList, rolebase , formation = CombatLogic.getHumanObjList(human, CombatDefine.COMBAT_TYPE3)
  602. if not heroList or not next(heroList) then return end -- 没有上阵
  603. local drillObj = DrillDB.createDrillObj(human)
  604. if not drillObj then return end
  605. DrillDB.updateDrillObj(drillObj)
  606. end
  607. --请求关卡记录
  608. ------------ 匹配规则 -----------------------
  609. function getDifficulty(quJian, diff,config)
  610. local str1 = ""
  611. local str2 = ""
  612. local stradd = ""
  613. if quJian == 2 then
  614. stradd = "1"
  615. end
  616. if diff == DIFF_NORMAL then
  617. str1 = "zdlMin"
  618. str2 = "zdlMax"
  619. elseif diff == DIFF_ELITE then
  620. str1 = "zdlMinElite"
  621. str2 = "zdlMaxElite"
  622. elseif diff == DIFF_INCUBI then
  623. str1 = "zdlMinIncubi"
  624. str2 = "zdlMaxIncubi"
  625. end
  626. if stradd == "" then
  627. return config[str1], config[str2]
  628. else
  629. return config[str1..stradd], config[str2..stradd]
  630. end
  631. end
  632. function getZhanLiByNpc(zhandouli)
  633. local DrillNpcExcel = DrillExcel.npc
  634. local maxCnt = #DrillNpcExcel
  635. if DrillNpcExcel[maxCnt].zhandouli[2] < zhandouli then
  636. return DrillNpcExcel[maxCnt].zhandouli[1], DrillNpcExcel[maxCnt].zhandouli[2]
  637. end
  638. for k, config in ipairs(DrillExcel.npc) do
  639. if config.zhandouli[1] <= zhandouli and config.zhandouli[2] >= zhandouli then
  640. return config.zhandouli[1], config.zhandouli[2]
  641. end
  642. end
  643. return DrillExcel.npc[1].zhandouli[1], DrillExcel.npc[1].zhandouli[2]
  644. end
  645. function findRandomObj(zdlMin, zdlMax, notTab, isRobot)
  646. local drillObj = DrillDB.randomDrillObj(zdlMin, zdlMax, notTab, isRobot)
  647. return drillObj
  648. end
  649. -- 请求关卡
  650. function pipei(human, drillId, diff, zhandouli, notTab)
  651. local drillCfg = DrillExcel.drill[drillId]
  652. if not drillCfg then return end
  653. local minPer, maxPer = getDifficulty(1, diff, drillCfg)
  654. local zdlMin = math.ceil(minPer / 10000 * zhandouli)
  655. local zdlMax = math.ceil(maxPer / 10000 * zhandouli)
  656. local drillObj
  657. if (diff == DIFF_NORMAL and drillId <= 10) or
  658. (diff == DIFF_ELITE and drillId <= 8) or
  659. (diff == DIFF_INCUBI and drillId <= 6) then
  660. drillObj = findRandomObj(zdlMin, zdlMax, notTab, true)
  661. if not drillObj then
  662. minPer, maxPer = getDifficulty(2, diff, drillCfg)
  663. zdlMin = math.ceil(minPer / 10000 * zhandouli)
  664. zdlMax = math.ceil(maxPer / 10000 * zhandouli)
  665. if zdlMin <= DrillExcel.npc[1].zhandouli[2] then
  666. zdlMin = DrillExcel.npc[1].zhandouli[1]
  667. zdlMax = DrillExcel.npc[1].zhandouli[2]
  668. end
  669. drillObj = findRandomObj(zdlMin, zdlMax, notTab, true)
  670. if not drillObj then
  671. zdlMin,zdlMax = getZhanLiByNpc(zhandouli)
  672. drillObj = findRandomObj(zdlMin, zdlMax, notTab, true)
  673. end
  674. end
  675. else
  676. drillObj = findRandomObj(zdlMin, zdlMax, notTab)
  677. if not drillObj then
  678. minPer, maxPer = getDifficulty(2, diff, drillCfg)
  679. zdlMin = math.ceil(minPer / 10000 * zhandouli)
  680. zdlMax = math.ceil(maxPer / 10000 * zhandouli)
  681. drillObj = findRandomObj(zdlMin, zdlMax, notTab)
  682. if not drillObj then
  683. minPer = minPer - 500
  684. maxPer = maxPer + 500
  685. zdlMin = math.ceil(minPer / 10000 * zhandouli)
  686. zdlMax = math.ceil(maxPer / 10000 * zhandouli)
  687. drillObj = findRandomObj(zdlMin, zdlMax, notTab)
  688. if not drillObj then
  689. if zdlMin <= DrillExcel.npc[1].zhandouli[2] then
  690. zdlMin = DrillExcel.npc[1].zhandouli[1]
  691. zdlMax = DrillExcel.npc[1].zhandouli[2]
  692. end
  693. drillObj = findRandomObj(zdlMin, zdlMax, notTab, true)
  694. if not drillObj then
  695. zdlMin = zhandouli - 50001
  696. zdlMax = zhandouli + 50001
  697. zdlMin = zdlMin > DrillExcel.npc[1].zhandouli[1] and zdlMin or DrillExcel.npc[1].zhandouli[1]
  698. zdlMax = zdlMax > DrillExcel.npc[1].zhandouli[2] and zdlMax or DrillExcel.npc[1].zhandouli[2]
  699. local maxID = #DrillExcel.npc
  700. zdlMin = zdlMin < DrillExcel.npc[maxID].zhandouli[1] and zdlMin or DrillExcel.npc[maxID].zhandouli[1]
  701. zdlMax = zdlMax < DrillExcel.npc[maxID].zhandouli[2] and zdlMax or DrillExcel.npc[maxID].zhandouli[2]
  702. drillObj = findRandomObj(zdlMin, zdlMax, notTab, true)
  703. end
  704. end
  705. end
  706. end
  707. end
  708. if not drillObj then
  709. return Broadcast.sendErr(human, Lang.DRILL_NOT_FING_DRILL)
  710. end
  711. return drillObj
  712. end
  713. -----------------------------------------------------------
  714. --计算战力区间
  715. function fristQust(human, drillId)
  716. local drill = human.db.drill
  717. if not drill then return end
  718. local diff = drill.diff
  719. local dirllDefConfig = DrillExcel.define[drill.diff]
  720. if not dirllDefConfig then return end
  721. local drillData = DrillDB.getDrillDataByUuid(human.db._id)
  722. if drillData then return end
  723. drillId = drillId and drillId or 1
  724. if drillId > dirllDefConfig.maxDrillID then return end
  725. local zhandouli = CombatPosLogic.getCombatHeroZDL(human, CombatDefine.COMBAT_TYPE1)
  726. if zhandouli <= 0 then
  727. drill.diff = 0
  728. return Broadcast.sendErr(human, Lang.COMBAT_ERR_NO_SET_FIGHT)
  729. end
  730. local notTab = {}
  731. if human.maxZDL and human.maxZDL.zhandouli and human.maxZDL.zhandouli > zhandouli then
  732. -- 获取玩家真正的最高战力 防止玩家 战役上阵 战力低 去匹配 低战力对手
  733. zhandouli = human.maxZDL.zhandouli
  734. end
  735. local drillObj = pipei(human, drillId, diff, zhandouli, notTab)
  736. if not drillObj then return end
  737. local drillData = DrillDB.createDrillData(human, drillId)
  738. drillData.diff = diff
  739. drillData.drillObjs[drillId] = Util.copyTable(drillObj)
  740. DrillDB.updateDrillData(drillData)
  741. queryDrillId(human, drillData)
  742. end
  743. function quest(human, drillId)
  744. local drill = human.db.drill
  745. if not drill then return end
  746. local diff = drill.diff
  747. local dirllDefConfig = DrillExcel.define[drill.diff]
  748. if not dirllDefConfig then return end
  749. local drillData = DrillDB.getDrillDataByUuid(human.db._id)
  750. if not drillData then
  751. fristQust(human, drillId)
  752. return
  753. end
  754. if drillId > dirllDefConfig.maxDrillID then return end
  755. local notTab = {}
  756. notTab[#notTab + 1] = human.db._id
  757. if drillData then
  758. for i = 1, dirllDefConfig.maxDrillID do
  759. local drillObj = drillData.drillObjs[i]
  760. if drillObj then
  761. notTab[#notTab + 1] = drillObj._id or drillObj.uuid
  762. end
  763. end
  764. end
  765. local zhandouli = CombatPosLogic.getCombatHeroZDL(human, CombatDefine.COMBAT_TYPE1)
  766. if zhandouli <= 0 then return Broadcast.sendErr(human, Lang.COMBAT_ERR_NO_SET_FIGHT) end
  767. if human.maxZDL and human.maxZDL.zhandouli and human.maxZDL.zhandouli > zhandouli then
  768. -- 获取玩家真正的最高战力 防止玩家 战役上阵 战力低 去匹配 低战力对手
  769. zhandouli = human.maxZDL.zhandouli
  770. end
  771. local drillObj = pipei(human, drillId, diff, zhandouli, notTab)
  772. drillData.drillObjs[drillId] = Util.copyTable(drillObj)
  773. DrillDB.updateDrillData(drillData)
  774. -- queryDrillId(human, drillData)
  775. end
  776. -- myHelpIndex = 1, -- 我选择的援助出去英雄
  777. -- helpoutList = {}, -- 我选择的援助英雄
  778. -- 选择自己的 出战 英雄
  779. function dispatchMyHelpHero(human, index)
  780. local drill = human.db.drill
  781. if not drill then return end
  782. local drillData = DrillDB.getDrillDataByUuid(human.db._id)
  783. if not drillData then return end
  784. -- if drillData.helpInfo then
  785. -- return Broadcast.sendErr(human, Lang.DRILL_CHOOSE_MY_ERR_HAD)
  786. -- end
  787. -- 当日已经派遣过
  788. if drill.myHelpIndex and drill.myHelpIndex > 0 then
  789. return Broadcast.sendErr(human, Lang.DRILL_CHOOSE_MY_ERR_HAD)
  790. end
  791. local heroGrid = human.db.heroBag[index]
  792. if type(heroGrid) ~= "table" then
  793. return Broadcast.sendErr(human, Lang.DRILL_CHOOSE_MY_ERR_INDEX)
  794. end
  795. local combatObj = CombatLogic.createHumanObj(human, heroGrid.uuid)
  796. local rolebase = CombatLogic.createRoleBaseByDB(human.db)
  797. if not combatObj or not rolebase then
  798. return Broadcast.sendErr(human, Lang.DRILL_CHOOSE_MY_ERR_INDEX)
  799. end
  800. combatObj.bagIndex = nil
  801. combatObj.friendUuid = human.db._id
  802. local helpInfo = {}
  803. helpInfo.heroGrid = heroGrid
  804. helpInfo.combatObj = combatObj
  805. helpInfo.rolebase = rolebase
  806. drillData.helpInfo = helpInfo
  807. drill.myHelpIndex = index
  808. DrillDB.updateDrillData(drillData)
  809. local heroID = heroGrid.id
  810. local heroConfig = HeroExcel.hero[heroID]
  811. if heroConfig == nil then return end
  812. drill.myHelpIndex = index
  813. drill.myHelpHero = helpInfo
  814. helpHeroFriendQuery(human)
  815. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1204)
  816. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1201)
  817. end
  818. -- 获取最大血量
  819. function getCombatObjHpMax(obj)
  820. if obj.hpMax then return obj.hpMax end
  821. local hpMax = obj.attrs[RoleDefine.HP]
  822. hpMax = math.ceil(hpMax * (1 + obj.attrs[RoleDefine.HP_RATE]/10000))
  823. return hpMax
  824. end
  825. -- 封装助战结构体
  826. function fontHelpNet(net, targetUuid)
  827. local tDrillData = DrillDB.getDrillDataByUuid(targetUuid)
  828. if not tDrillData then return end
  829. local tHelpInfo = tDrillData.helpInfo
  830. if not tHelpInfo then return end
  831. net.uuid = targetUuid
  832. net.name = tHelpInfo.rolebase.name
  833. net.state = 0
  834. net.pos = 0
  835. HeroGrid.makeHeroSimple(net.heroSimple, tHelpInfo.heroGrid)
  836. return true
  837. end
  838. local helpHeroFields = {lv = 1, name = 1, head = 1, technology=1, heroBag = 1, combatHero = 1, drill = 1}
  839. function helpHeroFriendQuery(human)
  840. local drill = human.db.drill
  841. if not drill then return end
  842. local drillData = DrillDB.getDrillDataByUuid(human.db._id)
  843. if not drillData then return end
  844. local now = os.time()
  845. local msgRet = Msg.gc.GC_DRILL_FRIEND_HELP_QUERY
  846. msgRet.myHelpIndex = drill.myHelpIndex and drill.myHelpIndex or 0
  847. msgRet.ownChose[0] = 0
  848. msgRet.herolist[0] = 0
  849. local len = 0
  850. -- 我已经选择了 部分 援助英雄
  851. if drill.helpoutList then
  852. for uuid, v in pairs(drill.helpoutList) do
  853. local net = msgRet.ownChose[msgRet.ownChose[0] + 1]
  854. if fontHelpNet(net, uuid, true) then
  855. msgRet.ownChose[0] = msgRet.ownChose[0] + 1
  856. end
  857. end
  858. end
  859. -- 玩家最多选择 三位好友援助英雄
  860. if len < 3 then
  861. len = 0
  862. local cnt, list = FriendDBLogic.getFriendUuids(human.db._id)
  863. for i = 1, cnt do
  864. local targetUuid = list[i].uuid
  865. if not drill.helpoutList or not drill.helpoutList[targetUuid] then
  866. if msgRet.herolist[0] >= #msgRet.herolist then
  867. break
  868. end
  869. local net = msgRet.herolist[msgRet.herolist[0] + 1]
  870. if fontHelpNet(net, targetUuid) then
  871. msgRet.herolist[0] = msgRet.herolist[0] + 1
  872. end
  873. end
  874. end
  875. end
  876. -- Msg.trace(msgRet)
  877. Msg.send(msgRet, human.fd)
  878. end
  879. -- 选择支援我的好友助战
  880. local HELP_MAIL_ITEMS = {{}}
  881. function choseHelpFriendHero(human, uuid)
  882. if not uuid or uuid == "" then
  883. return
  884. end
  885. local drill = human.db.drill
  886. if not drill then return end
  887. local drillData = DrillDB.getDrillDataByUuid(human.db._id)
  888. if not drillData then return end
  889. -- 今天 已经选择该玩家英雄援助了
  890. if drill.helpoutList and drill.helpoutList[uuid] then
  891. return
  892. end
  893. if not FriendDBLogic.isFriend(human.db._id, uuid) then
  894. return
  895. end
  896. if drill.helpoutList then
  897. local len = 0
  898. for k, _ in pairs(drill.helpoutList) do
  899. len = len + 1
  900. end
  901. if len >= 3 then
  902. return
  903. end
  904. end
  905. local friendHuman
  906. friendHuman = ObjHuman.onlineUuid[uuid]
  907. if not friendHuman then
  908. local db = RoleDBLogic.getDb(uuid, helpHeroFields)
  909. if db then
  910. friendHuman = {db = db}
  911. end
  912. end
  913. local drillFriend = friendHuman.db.drill
  914. if not drillFriend or not drillFriend.myHelpHero then
  915. return
  916. end
  917. -- 检查这个数据是否是当天设置的
  918. if not Util.isSameDay(drillFriend.time) then
  919. return
  920. end
  921. local tDrillData = DrillDB.getDrillDataByUuid(uuid)
  922. local helpInfo = tDrillData and tDrillData.helpInfo
  923. if not helpInfo then
  924. return Broadcast.sendErr(human, Lang.DRILL_CHOOSE_FRIEND_ERR_INFO)
  925. end
  926. local maxZhandouli = HeroLogic.getHeroMaxZDL(human)
  927. if helpInfo.heroGrid.zhandouli > maxZhandouli * MAX_HEROCOMBAT_MUL / 100 then
  928. return Broadcast.sendErr(human, Util.format(Lang.LIANYU_MY_SELECT_ERR_ZDL, MAX_HEROCOMBAT_MUL))
  929. end
  930. drill.helpoutList = drill.helpoutList or {}
  931. drill.helpoutList[uuid] = {}
  932. drill.helpoutList[uuid].time = os.time()
  933. DrillLogicAttribute.setHelp(drillData ,uuid)
  934. DrillDB.updateDrillData(drillData)
  935. -- 给好友发送雇佣奖励
  936. HELP_MAIL_ITEMS[1][1] = ItemDefine.ITEM_FRIEND_ID
  937. HELP_MAIL_ITEMS[1][2] = FRIEND_ITEM_CNT
  938. local mailConfig = MailExcel.mail[MailDefine.MAIL_ID_DRILL_HELP]
  939. local title = mailConfig.title
  940. local senderName = mailConfig.senderName
  941. local content = Util.format(mailConfig.content, human.db.name)
  942. MailManager.add(MailManager.SYSTEM, uuid, title, content, HELP_MAIL_ITEMS, senderName)
  943. helpHeroFriendQuery(human)
  944. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1204)
  945. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1201)
  946. end
  947. function curFuhuoCnt(human, drillData)
  948. local maxCnt = VipLogic.getPowerArgs(human, VipLogic.VIP_POWER5)
  949. local oldCnt = DrillLogicAttribute.getOperCnt(drillData, DrillLogicAttribute.DRILL_OPER_1)
  950. local curCnt = maxCnt - oldCnt
  951. curCnt = curCnt > 0 and curCnt or 0
  952. return maxCnt, curCnt
  953. end
  954. function getResetNeedZuanshi(drillData, maxCnt)
  955. local oldCnt = DrillLogicAttribute.getOperCnt(drillData, DrillLogicAttribute.DRILL_OPER_1)
  956. if oldCnt >= maxCnt then
  957. return 0
  958. end
  959. local operConfig = DrillExcel.oper[oldCnt + 1]
  960. return operConfig.zuanshi
  961. end
  962. function fuhuoQuery(human)
  963. local drillData = DrillDB.getDrillDataByUuid(human.db._id)
  964. if not drillData then return end
  965. local msgRet = Msg.gc.GC_DRILL_FUHUO_QUERY
  966. msgRet.maxCnt, msgRet.canCnt = curFuhuoCnt(human, drillData)
  967. msgRet.needZuanshi = getResetNeedZuanshi(drillData, msgRet.maxCnt)
  968. Msg.send(msgRet, human.fd)
  969. end
  970. function getHelpHeroState(human, args)
  971. local choseUuid = args[1]
  972. local drill = human.db.drill
  973. if not drill then return false end
  974. if drill.helpoutList and drill.helpoutList[choseUuid] then
  975. local hero = drill.helpoutList[choseUuid]
  976. -- 挑战胜利过的 不能作为出战英雄
  977. if hero.winCnt and hero.winCnt > 0 then return false end
  978. local hp = hero.helpObj.attrs[RoleDefine.HP]
  979. if hp <= 0 then return false end
  980. return true, hero.heroObj
  981. end
  982. return false
  983. end
  984. -- 助战英雄上阵
  985. function setHelpCombatPos(human, uuid, pos)
  986. if not isOpen(human, true) then return end
  987. local drill = human.db.drill
  988. if not drill then return false end
  989. local drillData = DrillDB.getDrillDataByUuid(human.db._id)
  990. if not drillData then return end
  991. if drill.helpoutList and drill.helpoutList[uuid] then
  992. human.drill = human.drill or {}
  993. human.drill.combatHelpUuid = uuid
  994. human.drill.combatHelpPos = pos
  995. end
  996. end
  997. -- 防御方数据
  998. function getDefender(drillObj)
  999. local objList = {}
  1000. for index, obj in pairs(drillObj.heroList) do
  1001. if DrillLogicAttribute.getObjHpRate(drillObj, obj.bagIndex) > 0 then -- 剔除死亡的
  1002. objList[index] = obj
  1003. end
  1004. end
  1005. local roleBase = {}
  1006. RoleLogic.makeRoleBase(drillObj, roleBase)
  1007. return objList, drillObj.helpList, roleBase, drillObj.formation, drillObj.jiban
  1008. end
  1009. -- 攻击方数据
  1010. function getAttacker(human, drillData, pos2uuidAtk)
  1011. local drill = human.db.drill
  1012. if not drill then return end
  1013. local objList, helpList, rolebase, formation, jiban = CombatLogic.getHumanObjList(human, CombatDefine.COMBAT_TYPE9)
  1014. for pos, obj in pairs(objList) do
  1015. local heroGrid = human.db.heroBag[obj.bagIndex]
  1016. if heroGrid then
  1017. pos2uuidAtk[pos] = heroGrid.uuid
  1018. end
  1019. end
  1020. -- 助战英雄
  1021. local combatHelpUuid = human.drill and human.drill.combatHelpUuid
  1022. local combatHelpPos = human.drill and human.drill.combatHelpPos
  1023. if combatHelpUuid and combatHelpPos then
  1024. if drill.helpoutList and drill.helpoutList[combatHelpUuid] then
  1025. local tDrillData = DrillDB.getDrillDataByUuid(combatHelpUuid)
  1026. local combatHelp = tDrillData and tDrillData.helpInfo
  1027. if combatHelp and DrillLogicAttribute.getHelpHpRate(drillData, combatHelpUuid) > 0 and
  1028. CombatPosLogic.checkPos(formation, combatHelpPos) then
  1029. objList[combatHelpPos] = combatHelp.combatObj
  1030. pos2uuidAtk[combatHelpPos] = combatHelpUuid
  1031. end
  1032. end
  1033. end
  1034. return objList, helpList, rolebase, formation, jiban
  1035. end
  1036. -------------------------------------- combat -----------------------------------------
  1037. -- 判断是否合适上阵
  1038. local function isFixCombatPos(heroGrid, drillData, config)
  1039. if type(heroGrid) ~= "table" then return end
  1040. if not drillData then return end
  1041. if config and config.heroMinLevel and heroGrid.lv < config.heroMinLevel then return end -- 等级不满足
  1042. local hpRate = DrillLogicAttribute.getHeroHpRate(drillData, heroGrid.uuid)
  1043. if hpRate <= 0 then return end -- 死掉了
  1044. return true
  1045. end
  1046. -- 不合适的下阵
  1047. function updateCombatPosCheck(human, drillData)
  1048. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE9)
  1049. if not combatHero then return end
  1050. local drillDB = human.db.drill
  1051. local config = DrillExcel.define[drillData.diff]
  1052. for pos, uuid in pairs(combatHero) do
  1053. local heroGrid = HeroLogic.getHeroGridByUuid(human, uuid)
  1054. if heroGrid and not isFixCombatPos(heroGrid, drillData, config) then
  1055. combatHero[pos] = nil
  1056. end
  1057. end
  1058. end
  1059. -- 战斗前加属性
  1060. function onFightBegin(human, cbParam)
  1061. for index = 1, CombatDefine.COMBAT_HERO_ALL_CNT do
  1062. local obj = CombatImpl.objList[index]
  1063. if obj then
  1064. if index <= CombatDefine.COMBAT_HERO_CNT then
  1065. calcAttrAtk(human, index, obj,cbParam )
  1066. else
  1067. calcAttrDef(human, index, obj, cbParam)
  1068. end
  1069. end
  1070. end
  1071. end
  1072. function getHelpGrid(human, uuid)
  1073. local drill = human.db.drill
  1074. if drill.helpoutList and drill.helpoutList[uuid] then
  1075. return drill.helpoutList[uuid].heroGrid
  1076. end
  1077. end
  1078. -- 所有属性计算完毕,重新设置血量(攻击)
  1079. function calcAttrAtk(human, pos, obj, cbParam)
  1080. local uuid = cbParam.pos2uuidAtk[pos]
  1081. if not uuid then return end
  1082. local hpRate = nil
  1083. if (obj.bagIndex or 0) > 0 then
  1084. hpRate = DrillLogicAttribute.getHeroHpRate(cbParam.drillData, uuid)
  1085. else
  1086. hpRate = DrillLogicAttribute.getHelpHpRate(cbParam.drillData, uuid)
  1087. end
  1088. local hpMax = CombatObj.getHpMax(obj)
  1089. obj.hp = math.ceil(hpRate * hpMax)
  1090. end
  1091. -- 所有属性计算完毕,重新设置血量(防守)
  1092. function calcAttrDef(human, pos, obj, cbParam)
  1093. local hpRate = DrillLogicAttribute.getObjHpRate(cbParam.drillObj, obj.bagIndex)
  1094. local hpMax = CombatObj.getHpMax(obj)
  1095. obj.hp = math.ceil(hpRate * hpMax)
  1096. end
  1097. -- 战斗
  1098. function fight(human, args)
  1099. if not isOpen(human, true) then return end
  1100. if human.db.combatQuick and human.db.combatQuick[CombatDefine.COMBAT_TYPE9] and human.db.combatQuick[CombatDefine.COMBAT_TYPE9] == 1 then
  1101. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE9 )
  1102. if CombatLogic.isCombatHeroEmpty(combatHero) then
  1103. queryDrillId(human)
  1104. return Broadcast.sendErr(human, Lang.DRILL_NOT_FIGHT_NOT_HERO)
  1105. end
  1106. end
  1107. local drill = human.db.drill
  1108. if not drill then return false end
  1109. local drillDB = human.db.drill
  1110. local drillData = DrillDB.getDrillDataByUuid(human.db._id)
  1111. if not drillData then
  1112. return Broadcast.sendErr(human, Lang.DRILL_IS_FINSH)
  1113. end
  1114. local drillId = tonumber(args[1] or 0)
  1115. if drillId ~= drillData.drillId then
  1116. return
  1117. end
  1118. local config = DrillExcel.drill[drillId]
  1119. if not config then return end
  1120. local drillObj = drillData.drillObjs[drillId]
  1121. if not drillObj then return end -- 不存在。。
  1122. updateCombatPosCheck(human, drillData)
  1123. local args = {}
  1124. local pos2uuidAtk = {}
  1125. args.defender, args.defHelp, args.defRBase, args.defFormation, args.defJiban = getDefender(drillObj)
  1126. args.attacker, args.atkHelp, args.atkRBase, args.atkFormation, args.atkJiban = getAttacker(human, drillData, pos2uuidAtk)
  1127. args.drillId = drillData.drillId
  1128. local cbParam = {}
  1129. cbParam.pos2uuidAtk = pos2uuidAtk
  1130. cbParam.diff = drillData.diff
  1131. cbParam.drillId = drillData.drillId
  1132. cbParam.drillData = drillData
  1133. cbParam.drillObj = drillObj
  1134. cbParam.combatHelpPos = human.drill and human.drill.combatHelpPos
  1135. cbParam.combatHelpUuid = human.drill and human.drill.combatHelpUuid
  1136. CombatLogic.combatBegin(human, config.mapID, args, CombatDefine.COMBAT_TYPE9, cbParam)
  1137. end
  1138. -- 获取当前地图ID
  1139. function getMapID(human, args)
  1140. local drillDB = human.db.drill
  1141. local drillData = DrillDB.getDrillDataByUuid(human.db._id)
  1142. local drillId = tonumber(args[1] or args.drillId or 0)
  1143. if drillId ~= drillData.drillId then
  1144. return
  1145. end
  1146. local config = DrillExcel.drill[drillId]
  1147. if not config then return end
  1148. return config.mapID
  1149. end
  1150. -- 刷新drillData记录的血量
  1151. function combatOnUpdate(human, cbParam, combatInfo)
  1152. for index = 1, CombatDefine.COMBAT_HERO_CNT do
  1153. -- 更新攻击方血量
  1154. local atkPos = CombatLogic.getPos(CombatDefine.ATTACK_SIDE, index)
  1155. local atkObj = combatInfo.objList[atkPos]
  1156. if atkObj ~= nil then
  1157. local hp = atkObj.hp
  1158. local hpMax = CombatObj.getHpMax(atkObj)
  1159. local hpRate = hp / hpMax
  1160. local uuid = cbParam.pos2uuidAtk[index]
  1161. if (atkObj.bagIndex or 0) > 0 then
  1162. DrillLogicAttribute.setHeroHpRate(cbParam.drillData, uuid, hpRate)
  1163. else
  1164. DrillLogicAttribute.setHelpHpRate(cbParam.drillData, uuid, hpRate)
  1165. end
  1166. end
  1167. -- 更新防守方血量
  1168. local defPos = CombatLogic.getPos(CombatDefine.DEFEND_SIDE, index)
  1169. local defObj = combatInfo.objList[defPos]
  1170. if defObj ~= nil then
  1171. local hp = defObj.hp
  1172. local hpMax = CombatObj.getHpMax(defObj)
  1173. local hpRate = hp / hpMax
  1174. DrillLogicAttribute.setObjHpRate(cbParam.drillObj, defObj.bagIndex, hpRate)
  1175. end
  1176. end
  1177. updateCombatPosCheck(human, cbParam.drillData)
  1178. end
  1179. -- 战胜回调
  1180. function onFightWinCallback(human, result , diff,drillID)
  1181. LiLianLogic.onCallback(human,LiLianLogic.LILIAN_OUTID11,1,diff)
  1182. DailyTaskLogic.recordDailyTaskFinishCnt(human, DailyTaskLogic.DAILY_TASK_ID_11, 1)
  1183. HeroGrowUp.onCallback(human, HeroGrowUp.TASKTYPE16, 1)
  1184. MengxinLogic.onCallBack(human,MengxinLogic.MX_TASK_TYPE_8,drillID)
  1185. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1204)
  1186. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1201)
  1187. end
  1188. -- 援助英雄 添加胜利
  1189. function addHelpWin(human, drillData)
  1190. if human.drill and human.drill.combatHelpUuid then
  1191. DrillLogicAttribute.setHelpWin(drillData, human.drill.combatHelpUuid)
  1192. end
  1193. end
  1194. -- 通关回调
  1195. function tongGuan(human, diff)
  1196. if getMaxDiff(human) < diff then
  1197. setMaxDiff(human, diff)
  1198. end
  1199. end
  1200. -- 战斗结束
  1201. function onFightEnd(human, result, combatType, cbParam, combatInfo)
  1202. local isOtherDay = false
  1203. if not Util.isSameDay(combatInfo.time) then
  1204. isOtherDay = true
  1205. end
  1206. local drillDB = human.db.drill
  1207. if not drillDB then return end
  1208. combatOnUpdate(human, cbParam, combatInfo)
  1209. local drillData = cbParam.drillData
  1210. local isKill = true
  1211. if not isObjKill(cbParam.drillObj) then -- 未击杀对面
  1212. isKill = false
  1213. end
  1214. local diff = cbParam.diff or drillData.diff
  1215. if not isOtherDay then
  1216. if not isKill then
  1217. return DrillDB.updateDrillData(drillData)
  1218. end
  1219. -- 刷新最大通关难度
  1220. local dirllDefConfig = DrillExcel.define[diff]
  1221. if cbParam.drillId >= dirllDefConfig.maxDrillID then
  1222. tongGuan(human, diff)
  1223. ChengjiuLogic.onCallback(human,ChengjiuDefine.CJ_TASK_TYPE_17,1)
  1224. HeroLogLogic.finishTaskCB(human,HeroLogLogic.HERO_LOG_TYPE_5,1)
  1225. end
  1226. drillData.drillId = drillData.drillId + 1
  1227. drillDB.drillId = drillData.drillId
  1228. addHelpWin(human, drillData)
  1229. DrillDB.updateDrillData(drillData)
  1230. quest(human, cbParam.drillId + 1)
  1231. --[[if drillDB.drillId == cbParam.drillId and drillDB.diff == diff then
  1232. if cbParam.drillId <= dirllDefConfig.maxDrillID then
  1233. drillDB.drillId = drillDB.drillId + 1
  1234. drillData.drillId = drillData.drillId + 1
  1235. end
  1236. addHelpWin(human, drillData)
  1237. DrillDB.updateDrillData(drillData)
  1238. quest(human, cbParam.drillId + 1)
  1239. end]]
  1240. else
  1241. if not isKill then
  1242. updateDaily(human)
  1243. return
  1244. end
  1245. end
  1246. local drillItems = getDrillItems(cbParam.drillId, diff)
  1247. local double = RoleSystemLogic.isDouble(human, RoleSystemDefine.ROLE_SYS_ID_1204)
  1248. local rewardCnt = double and 2 or 1
  1249. combatInfo.double = double and 2 or 0
  1250. -- 关卡奖励
  1251. local itemList = {}
  1252. for k, item in ipairs(drillItems) do
  1253. local itemID = item[1]
  1254. local itemCnt = item[2] * rewardCnt
  1255. itemList[k] = {}
  1256. itemList[k][1] = itemID
  1257. itemList[k][2] = itemCnt
  1258. BagLogic.addItem(human, itemID, itemCnt, "drill")
  1259. if not isOtherDay then
  1260. drillDB.dayGet = drillDB.dayGet or {}
  1261. drillDB.dayGet[itemID] = (drillDB.dayGet[itemID] or 0) + itemCnt
  1262. end
  1263. end
  1264. combatInfo.rewardItem = itemList
  1265. human.drill = nil
  1266. if isOtherDay then
  1267. updateDaily(human)
  1268. end
  1269. -- 回调
  1270. onFightWinCallback(human,result, diff,cbParam.drillId)
  1271. YunYingLogic.onCallBack(human, "onDrill",1)
  1272. end
  1273. --[[
  1274. -- 增加关卡
  1275. function questMid(fd, msg)
  1276. local uuid = msg.uuid
  1277. local drillId = msg.drillId
  1278. local drillObj = msg.drillObj
  1279. if not RoleDBLogic.isUuidExistInDB(uuid) then
  1280. return
  1281. end
  1282. local drillData = DrillDB.getDrillDataByUuid(uuid)
  1283. if not drillData then
  1284. -- if drillId ~= 1 then return end -- 注意哦
  1285. drillData = DrillDB.createDrillData(uuid)
  1286. else
  1287. if drillData.drillId ~= drillId then return end
  1288. end
  1289. print("drillObj",drillObj._id, drillId)
  1290. drillData.drillObjs[drillId] = Util.copyTable(drillObj)
  1291. DrillDB.updateDrillData(drillData)
  1292. local human = ObjHuman.onlineUuid[uuid]
  1293. if human == nil then return end
  1294. queryDrillId(human, drillData)
  1295. end
  1296. ]]
  1297. function isDot(human)
  1298. local isOpen = RoleSystemLogic.isOpen(human, RoleSystemDefine.ROLE_SYS_ID_1204)
  1299. if not isOpen then return false end
  1300. if not human.db.drill then
  1301. return true
  1302. end
  1303. for k, _ in ipairs(DrillExcel.box) do
  1304. if getBoxState(human.db.drill, k) == DRILL_BOX_STATE_1 then
  1305. return true
  1306. end
  1307. end
  1308. if human.db.drill.myHelpIndex and human.db.drill.myHelpIndex > 0 then
  1309. return false
  1310. end
  1311. return true
  1312. end
  1313. function getQuick(human)
  1314. if getMaxDiff(human) > 0 then
  1315. return 1
  1316. end
  1317. return 0
  1318. end