DrillLogic.lua 61 KB

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