DrillLogic.lua 51 KB

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