DrillLogic.lua 48 KB

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