DrillLogic.lua 48 KB

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