DrillLogic.lua 48 KB

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