DrillLogic.lua 52 KB

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