DrillLogic.lua 48 KB

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