DrillLogic.lua 54 KB

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