DrillLogic.lua 58 KB

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