BattleLogic.lua 65 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929
  1. local Lang = require("common.Lang")
  2. local BattleExcel = require("excel.battle")
  3. local MonsterExcel = require("excel.monster")
  4. local DropExcel = require("excel.drop")
  5. local Msg = require("core.Msg")
  6. local ObjHuman = require("core.ObjHuman")
  7. local Grid = require("bag.Grid")
  8. local BagLogic = require("bag.BagLogic")
  9. local ItemDefine = require("bag.ItemDefine")
  10. local Broadcast = require("broadcast.Broadcast")
  11. local CombatDefine = require("combat.CombatDefine")
  12. local CombatPosLogic = require("combat.CombatPosLogic")
  13. local CombatLogic = require("combat.CombatLogic")
  14. local DailyTaskLogic = require("dailyTask.DailyTaskLogic")
  15. local RoleDefine = require("role.RoleDefine")
  16. local ChengjiuLogic = require("chengjiu.ChengjiuLogic")
  17. local ChengjiuDefine = require("chengjiu.ChengjiuDefine")
  18. local HeroExcel = require("excel.hero")
  19. local SkillExcel = require("excel.skill")
  20. local MonthactExcel = require("excel.monthAct")
  21. local Util = require("common.Util")
  22. local KingWorldLogic = require("present.KingWorldLogic")
  23. local ChatPaoMaLogic = require("chat.ChatPaoMaLogic")
  24. local BRoleLogic = require("billboard.BRoleLogic")
  25. local BillboardDefine = require("billboard.BillboardDefine")
  26. local SkinLogic = require("skin.SkinLogic")
  27. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  28. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  29. local GuideLogic = require("guide.GuideLogic")
  30. local PanelDefine = require("broadcast.PanelDefine")
  31. local HeroGrid = require("hero.HeroGrid")
  32. local TuiSongLiBao = require("present.TuiSongLiBao")
  33. local CombatVideo = require("combat.CombatVideo")
  34. local RoleLogic = require("role.RoleLogic")
  35. local BattleDBLogic = require("battle.BattleDBLogic")
  36. local ProjectLogic = require("platform.ProjectLogic")
  37. local LuaMongo = _G.lua_mongo
  38. local DB = require("common.DB")
  39. local VipLogic = require("vip.VipLogic")
  40. local MoshouLogic = require("moshou.MoshouLogic")
  41. local RoleExcel = require("excel.role")
  42. local TequanShopLogic = require("present.TequanShopLogic")
  43. local HeroDefine = require("hero.HeroDefine")
  44. local BarTaskLogic = require("bar.BarTaskLogic")
  45. local ItemExcel = require("excel.item").item
  46. local EquipExcel = require("excel.equip").equip
  47. local HeroLogic = require("hero.HeroLogic")
  48. local SuipianLogic = require("bag.SuipianLogic")
  49. local JibanLogic = require("combat.JibanLogic")
  50. local YunYingLogic = require("yunying.YunYingLogic")
  51. local PanelDefine = require("broadcast.PanelDefine")
  52. local YyHandler = require("yunying.Handler")
  53. local EquipLogic = require("equip.EquipLogic")
  54. local SysParameter = require("common.SysParameter")
  55. local XingYaoGongMing = require("xingYaoMen.XingYaoGongMing")
  56. local AbsActLogic = require("absAct.AbsActLogic")
  57. local HeroLogLogic = require("absAct.HeroLogLogic")
  58. local DropExchangeLogic = require("absAct.DropExchangeLogic")
  59. local MengxinLogic = require("present.MengxinLogic")
  60. local Log = require("common.Log")
  61. BATTLE_HANG_EXP_OUT_PERIOD = 60 -- 经验产出时间间隔
  62. BATTLE_HANG_ITEM_OUT_PERIOD = 300 -- 战利品道具产出时间间隔
  63. BATTLE_HANG_ITEM_OUT_PERIOD_2 = 7200 -- 战利品道具产出时间间隔2小时掉落一次
  64. BATTLE_LOGIN_LEV_TIPS = 50 -- 登录检测挂机时间过久提示 最高等级
  65. BATTLE_LOGIN_TIME_TIPS = 10 * 60 -- 登录检测挂机超过多久提示
  66. BATTLE_MOPUP_CNT = 4
  67. BATTLE_MOPUP_CNT_VIP = 11
  68. BATTLE_MOPUP_FREE_CNT = 1
  69. BATTLE_MOPUP_FREE_CNT_VIP = 3
  70. BATTLE_LEVEL_PLAYER_LIST = { }
  71. local STATUS_NONE = 1 -- 不可领
  72. local STATUS_CANGET = 2 -- 可领
  73. -- 挂机收益最多累计x秒
  74. function getHangMaxTime(human)
  75. local hour = VipLogic.getPowerArgs(human, VipLogic.VIP_POWER10)
  76. return(hour or 0) * 3600
  77. end
  78. local function wrapHangFightNet(net, heroConfig, skillConfig)
  79. net.body = heroConfig.body
  80. net.height = heroConfig.height
  81. net.weight = heroConfig.width
  82. net.fireType = skillConfig and skillConfig.fireType or 0
  83. net.attackEffect = skillConfig and skillConfig.attackEffect or ""
  84. net.flyEffect = skillConfig and skillConfig.flyEffect or ""
  85. net.flyCoords = skillConfig and skillConfig.flyCoords or ""
  86. net.hitEffect = skillConfig and skillConfig.hitEffect or ""
  87. net.hitSound = skillConfig and skillConfig.hitSound or ""
  88. end
  89. local function fontBattleSkillNet(skillNet, skillID)
  90. local skillConfig = SkillExcel.skill[skillID]
  91. if not skillConfig then
  92. return
  93. end
  94. skillNet.skillID = skillID
  95. skillNet.fireType = skillConfig.fireType
  96. skillNet.readyAction = skillConfig.readyAction
  97. skillNet.attackPart = skillConfig.attackPart
  98. skillNet.attackAction = skillConfig.attackAction
  99. skillNet.readyEffect = skillConfig.readyEffect
  100. skillNet.attackEffect = skillConfig.attackEffect
  101. skillNet.hitEffect = skillConfig.hitEffect
  102. skillNet.flyEffect = skillConfig.flyEffect
  103. skillNet.flyCoords = skillConfig.flyCoords
  104. skillNet.hitBack = skillConfig.hitBack
  105. skillNet.effectTime = skillConfig.effectTime
  106. skillNet.contentType = skillConfig.contentType
  107. skillNet.content = skillConfig.content
  108. skillNet.movieEffect = skillConfig.movieEffect
  109. skillNet.quake = skillConfig.quake
  110. skillNet.flySound = skillConfig.flySound
  111. skillNet.fireSound = skillConfig.fireSound
  112. skillNet.hitSound = skillConfig.hitSound
  113. skillNet.cvSound = skillConfig.cvSound
  114. skillNet.screenMask = skillConfig.screenMask
  115. skillNet.screenCam = skillConfig.screenCam
  116. skillNet.largeEffect = skillConfig.largeEffect
  117. skillNet.lie = skillConfig.lie
  118. skillNet.cuoZhen = skillConfig.cuoZhen
  119. skillNet.skillDelay = skillConfig.skillDelay
  120. skillNet.isFraming = skillConfig.isFraming
  121. return true
  122. end
  123. function getBattleRoleList(worldMapId)
  124. BATTLE_LEVEL_PLAYER_LIST[worldMapId] = BATTLE_LEVEL_PLAYER_LIST[worldMapId] or { }
  125. local config = BattleExcel.map[worldMapId]
  126. QueryRoleByNodeID = { guajiID = { ["$gte"] = config.minLevel, ["$lte"] = config.maxLevel } }
  127. local fields = { }
  128. RoleLogic.makeRoleBaseFields(fields)
  129. LuaMongo.find(DB.db_char, QueryRoleByNodeID, fields, 50)
  130. local len = 0
  131. while true do
  132. local charDb = { }
  133. if not LuaMongo.next(charDb) then
  134. break
  135. end
  136. len = len + 1
  137. BATTLE_LEVEL_PLAYER_LIST[worldMapId][charDb._id] = { }
  138. RoleLogic.makeRoleBase(charDb, BATTLE_LEVEL_PLAYER_LIST[worldMapId][charDb._id])
  139. if len >= 50 then
  140. return
  141. end
  142. end
  143. end
  144. function initAfterStart()
  145. local len = #BattleExcel.map
  146. for i = 1, len do
  147. getBattleRoleList(i)
  148. end
  149. end
  150. function onLogin(human)
  151. if human.db.lv >= BATTLE_LOGIN_LEV_TIPS then
  152. return
  153. end
  154. calcBattleOut(human)
  155. local now = os.time()
  156. local expTime = now - human.db.battleOut.expTs1
  157. if expTime >= BATTLE_LOGIN_TIME_TIPS then
  158. local msgRet = Msg.gc.GC_BATTLE_HANG_TIME_SPILL
  159. msgRet.time = expTime
  160. Msg.send(msgRet, human.fd)
  161. end
  162. end
  163. -- 是否领取
  164. local WeiLen = 30
  165. function isGetReward(human, id)
  166. if not human.db.battleRewards then
  167. return
  168. end
  169. local flags = human.db.battleRewards
  170. local intIndex = math.ceil(id / WeiLen)
  171. if not flags[intIndex] then
  172. return
  173. end
  174. local byteIndex = id % WeiLen
  175. if Util.getBit(flags[intIndex], byteIndex) > 0 then
  176. return true
  177. end
  178. end
  179. function getTongguanIndex(human)
  180. if not human.db.battleRewards then
  181. return 1
  182. end
  183. local flags = human.db.battleRewards
  184. for id, v in ipairs(BattleExcel.node) do
  185. if #v.tongguan ~= 0 then
  186. local intIndex = math.ceil(id / WeiLen)
  187. if not flags[intIndex] then
  188. return id
  189. end
  190. local byteIndex = id % WeiLen
  191. if Util.getBit(flags[intIndex], byteIndex) == 0 then
  192. return id
  193. end
  194. end
  195. end
  196. return
  197. end
  198. -- 设置领取
  199. function setGetReward(human, id)
  200. if not human.db.battleRewards then
  201. human.db.battleRewards = { }
  202. end
  203. local flags = human.db.battleRewards
  204. local intIndex = math.ceil(id / WeiLen)
  205. local byteIndex = id % WeiLen
  206. flags[intIndex] = flags[intIndex] or 0
  207. flags[intIndex] = Util.setBit(flags[intIndex], byteIndex)
  208. end
  209. -- 是否有可领取的
  210. function hasCanGetReward(human)
  211. for id, cf in ipairs(BattleExcel.node) do
  212. if id > human.db.guajiID then
  213. break
  214. end
  215. if #cf.tongguan > 0 and not isGetReward(human, id) then
  216. return true
  217. end
  218. end
  219. end
  220. local BATTLEID_2_NAME = nil
  221. function getBattleName(battleID)
  222. if not BATTLEID_2_NAME then
  223. BATTLEID_2_NAME = { }
  224. for id, cf in ipairs(BattleExcel.node) do
  225. BATTLEID_2_NAME[id] = cf.name
  226. end
  227. end
  228. local nodeConfig = BattleExcel.node[battleID]
  229. local mapConfig = nodeConfig and BattleExcel.map[nodeConfig.mapID]
  230. local mapName = mapConfig and mapConfig.name or ""
  231. return BATTLEID_2_NAME[battleID] or "", mapName
  232. end
  233. function hangFightQuery(human)
  234. local battleID = human.db.battleID > #BattleExcel.node and #BattleExcel.node or human.db.battleID
  235. local nowNodeConfig = BattleExcel.node[battleID]
  236. local monsterOutID = nowNodeConfig.monsterOutID
  237. local monsterOutConfig = MonsterExcel.monsterOut[monsterOutID]
  238. local msgRet = Msg.gc.GC_BATTLE_HANG_FIGHT
  239. local len = 0
  240. for _, monster in ipairs(monsterOutConfig.member) do
  241. local monsterID = monster[1]
  242. len = len + 1
  243. local monsterConfig = MonsterExcel.monster[monsterID]
  244. local skillConfig = SkillExcel.skill[monsterConfig.normalAtkID]
  245. wrapHangFightNet(msgRet.monsterList[len], monsterConfig, skillConfig)
  246. end
  247. msgRet.monsterList[0] = len
  248. len = 0
  249. if human.db.combatHero[CombatDefine.COMBAT_TYPE1] then
  250. local tb = { }
  251. for i = 1, #human.db.combatHero[CombatDefine.COMBAT_TYPE1] do
  252. tb[#tb + 1] = human.db.combatHero[CombatDefine.COMBAT_TYPE1][i]
  253. end
  254. local tb2 = { }
  255. for i = 1, 3 do
  256. local r = math.ceil(math.random(0, #tb))
  257. r = r == 0 and 1 or r
  258. tb2[#tb2 + 1] = tb[r]
  259. tb[r] = tb[#tb]
  260. tb[#tb] = nil
  261. if not tb[1] then
  262. break
  263. end
  264. end
  265. for i = 1, #tb2 do
  266. len = len + 1
  267. local heroGrid = HeroLogic.getHeroGridByUuid(human, tb2[i])
  268. if heroGrid then
  269. local heroConfig = HeroExcel.hero[heroGrid.id]
  270. local _, skinSkillConf = SkinLogic.getHeroSkin(human, tb2[i])
  271. local skillConfig = SkillExcel.skill[heroConfig.normalAtkID]
  272. if skinSkillConf then
  273. skillConfig = SkillExcel.skill[skinSkillConf.normalAtkID]
  274. end
  275. wrapHangFightNet(msgRet.attackerList[i], heroConfig, skillConfig)
  276. local body, head = SkinLogic.getBody(human, tb2[i])
  277. if body then
  278. msgRet.attackerList[i].body = body
  279. end
  280. end
  281. end
  282. end
  283. msgRet.attackerList[0] = len
  284. -- Msg.trace(msgRet)
  285. Msg.send(msgRet, human.fd)
  286. end
  287. local function getExtraRewardID(human)
  288. local config = BattleExcel.extraReward
  289. local battleExtraReward = human.db.battleExtraReward
  290. for id, data in ipairs(config) do
  291. if not battleExtraReward or not battleExtraReward[id] then
  292. return id, data
  293. end
  294. end
  295. end
  296. local function getExtraRewardState(human, extraRewardID)
  297. local config = BattleExcel.extraReward[extraRewardID]
  298. if not config then
  299. return 0
  300. end
  301. if human.db.battleExtraReward and human.db.battleExtraReward[extraRewardID] then
  302. return 0
  303. end
  304. local guajiID = human.db.guajiID
  305. if guajiID >= config.needBattleID then
  306. return 1
  307. end
  308. return 0
  309. end
  310. local function makeExtraRewardShow(human, net)
  311. local config = BattleExcel.extraReward
  312. local extraID, data = getExtraRewardID(human)
  313. if not extraID then
  314. return
  315. end
  316. net[0] = 1
  317. net[1].needBattleID = data.needBattleID
  318. net[1].descID = data.descID
  319. net[1].desc = data.desc or ""
  320. net[1].extraHero[0] = 0
  321. net[1].extraItem[0] = 0
  322. if data.extraHeroID > 0 then
  323. net[1].extraHero[0] = 1
  324. HeroGrid.makeHeroSimpleByID(net[1].extraHero[1], data.extraHeroID, nil, nil, human)
  325. HeroGrid.makeHeroSimpleByGeneral(net[1].extraHero[1], data.extraHeroID)
  326. else
  327. net[1].extraItem[0] = 1
  328. Grid.makeItem(net[1].extraItem[1], data.extraReward[1], data.extraReward[2])
  329. end
  330. net[1].state = getExtraRewardState(human, extraID)
  331. end
  332. -- 随机道具
  333. local function randItemOut(dropRule, weightSum)
  334. if weightSum < 1 then
  335. return
  336. end
  337. local r = math.random(1, weightSum)
  338. for i = 1, #dropRule do
  339. local itemID = dropRule[i][1]
  340. local itemCnt1 = dropRule[i][2]
  341. local itemCnt2 = dropRule[i][3]
  342. local weight = dropRule[i][4]
  343. if r <= weight then
  344. local itemCnt = math.random(itemCnt1, itemCnt2)
  345. return itemID, itemCnt
  346. end
  347. r = r - weight
  348. end
  349. end
  350. function fontExtraDataSSZH(net, mapID, nowBattleID)
  351. local nodeCnt = 0
  352. if ProjectLogic.isSszh() then
  353. for i = 1, #BattleExcel.node do
  354. local nodeTempConfig = BattleExcel.node[i]
  355. if nodeTempConfig.mapID == mapID then
  356. nodeCnt = nodeCnt + 1
  357. local posNet = net.posList[nodeCnt]
  358. local pos = nodeTempConfig.pos
  359. posNet.battleID = i
  360. posNet.posX = pos and pos[1] or 0
  361. posNet.posY = pos and pos[2] or 0
  362. posNet.nodeName = getBattleName(i)
  363. posNet.roleBase[0] = 0
  364. if i == nowBattleID then
  365. local videoTb = BattleDBLogic.queryBattleDbByNodeID(i)
  366. local sharkData = videoTb and videoTb.shark[2]
  367. if sharkData then
  368. posNet.roleBase[0] = 1
  369. RoleLogic.makeRoleBase(videoTb.roleBase, posNet.roleBase[1])
  370. end
  371. end
  372. posNet.isBig = nodeTempConfig.isBig or 0
  373. end
  374. end
  375. end
  376. net.posList[0] = nodeCnt
  377. end
  378. function fontVideoInfo(human, net, monsterConfig)
  379. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE1)
  380. local len = #combatHero
  381. -- 自己没队伍时,不显示
  382. if len == 0 then
  383. net.ownBody[0] = 0
  384. net.enemyBody[0] = 0
  385. else
  386. -- 设置真实数据
  387. local cnt = 0
  388. for k, v in pairs(combatHero) do
  389. -- body数据
  390. if v ~= "0" then
  391. local heroGird, bagIndex = HeroLogic.getHeroGridByUuid(human, v)
  392. if heroGird ~= nil then
  393. cnt = cnt + 1
  394. local config = HeroExcel.hero[heroGird.id]
  395. if config then
  396. local attrConfig = HeroDefine.getAttrConfig(heroGird.id, config.star)
  397. local normalAtkID = attrConfig.normalAtkID
  398. local skill = attrConfig.battleSkill
  399. local body, head = SkinLogic.getBody(human, bagIndex)
  400. net.ownBody[cnt].body = body or config.body
  401. fontBattleSkillNet(net.ownBody[cnt].atkId, normalAtkID)
  402. fontBattleSkillNet(net.ownBody[cnt].skill, skill)
  403. net.ownBody[cnt].pos = k
  404. net.ownBody[cnt].atkType = SkillExcel.skill[normalAtkID].areaPara
  405. local attrs = ObjHuman.getHeroAttrs(human, heroGird.bagIndex)
  406. net.ownBody[cnt].hp = attrs[RoleDefine.HP]
  407. end
  408. end
  409. end
  410. end
  411. net.ownBody[0] = cnt
  412. cnt = 0
  413. local memberConfig = monsterConfig.member
  414. for k, v in pairs(memberConfig) do
  415. -- body数据
  416. cnt = cnt + 1
  417. local config = MonsterExcel.monster[v[1]]
  418. if config then
  419. local normalAtkID = config.normalAtkID
  420. net.enemyBody[cnt].body = config.body
  421. fontBattleSkillNet(net.enemyBody[cnt].atkId, normalAtkID)
  422. fontBattleSkillNet(net.enemyBody[cnt].skill, normalAtkID)
  423. net.enemyBody[cnt].pos = k
  424. net.enemyBody[cnt].atkType = SkillExcel.skill[normalAtkID].areaPara
  425. local attrID = monsterConfig.attrID[k]
  426. local attrConfig = MonsterExcel.monsterAttr[attrID].attrs
  427. for _, value in pairs(attrConfig) do
  428. if value[1] == RoleDefine.HP then
  429. net.enemyBody[cnt].hp = value[2]
  430. break
  431. end
  432. end
  433. end
  434. end
  435. net.enemyBody[0] = cnt
  436. end
  437. end
  438. -- 战役主界面查询
  439. function query(human)
  440. local msgRet = Msg.gc.GC_BATTLE_QUERY
  441. msgRet.nowBattleID = human.db.battleID
  442. local configNode = #BattleExcel.node
  443. local nowBattleID = human.db.battleID > configNode and configNode or human.db.battleID
  444. local nowNodeConfig = BattleExcel.node[nowBattleID]
  445. msgRet.maxBattleID = configNode
  446. msgRet.mapID = nowNodeConfig.mapID
  447. msgRet.nodeID = nowNodeConfig.curLevel
  448. msgRet.sceneID = nowNodeConfig.sceneID
  449. local nowMapConfig = BattleExcel.map[nowNodeConfig.mapID]
  450. msgRet.mapName = nowMapConfig.name
  451. msgRet.nodeName = nowNodeConfig.name
  452. msgRet.needLv = nowNodeConfig.needLv
  453. msgRet.bg = nowMapConfig.bg
  454. msgRet.canBattle = 0
  455. msgRet.doubleCnt = 0
  456. if nowNodeConfig.needLv > human.db.lv then
  457. msgRet.canBattle = nowNodeConfig.needLv
  458. end
  459. local double = RoleSystemLogic.isDouble(human, RoleSystemDefine.ROLE_SYS_ID_1104)
  460. if
  461. double and human.db.bar and human.db.bar.doubleCnt and
  462. human.db.bar.doubleCnt <= BarTaskLogic.DEFAULT_MAX_DOUBLE_CNT
  463. then
  464. msgRet.doubleCnt = BarTaskLogic.DEFAULT_MAX_DOUBLE_CNT - human.db.bar.doubleCnt
  465. elseif double and not human.db.bar then
  466. msgRet.doubleCnt = BarTaskLogic.DEFAULT_MAX_DOUBLE_CNT
  467. end
  468. msgRet.tongguan[0] = 0
  469. local id = getTongguanIndex(human)
  470. if id == nil then
  471. msgRet.tongguan[0] = 0
  472. else
  473. msgRet.tongguan[0] = 1
  474. local state = isGetReward(human, id)
  475. local cf = BattleExcel.node[id].tongguan
  476. local net = msgRet.tongguan[1]
  477. if state == true then
  478. net.status = STATUS_NONE
  479. else
  480. net.status =(id > human.db.guajiID) and STATUS_CANGET or STATUS_NONE
  481. end
  482. net.levelName = getBattleName(id)
  483. net.index = id
  484. net.nowBattle = getBattleName(human.db.guajiID)
  485. net.reward[0] = 0
  486. net.heroReward[0] = 0
  487. -- 是英雄
  488. if cf[1][3] then
  489. net.heroReward[0] = 1
  490. local other = { }
  491. other.star = cf[1][3]
  492. HeroGrid.makeHeroSimpleByID(net.heroReward[1], cf[1][1], nil, other, human)
  493. HeroGrid.makeHeroSimpleByGeneral(net.heroReward[1], cf[1][1])
  494. else
  495. net.reward[0] = 1
  496. for i = 1, net.reward[0] do
  497. local itemID = cf[i][1]
  498. local itemCnt = cf[i][2]
  499. Grid.makeItem(net.reward[i], itemID, itemCnt)
  500. end
  501. end
  502. end
  503. local outSec = 0
  504. if human.db.battleOut ~= nil then
  505. local now = os.time()
  506. outSec = now - human.db.battleOut.expTs1
  507. end
  508. local maxHangTime = getHangMaxTime(human)
  509. msgRet.maxTime = maxHangTime
  510. if maxHangTime >= outSec then
  511. msgRet.time = outSec
  512. else
  513. msgRet.time = maxHangTime
  514. end
  515. -- 悬赏情报数量
  516. msgRet.xushang = human.db.bar and human.db.bar.qingbao or 0
  517. msgRet.xushangMax = RoleExcel.exp[human.db.lv].qingBaoMax
  518. -- 悬赏红点
  519. msgRet.xsDot = 0
  520. if BarTaskLogic.isDot(human) then
  521. msgRet.xsDot = 1
  522. end
  523. msgRet.canMopup = 0
  524. if TequanShopLogic.isActiveMopup(human) then
  525. msgRet.canMopup = human.db.mopupDoCnt < BATTLE_MOPUP_CNT_VIP and 1 or 0
  526. else
  527. msgRet.canMopup = human.db.mopupDoCnt < BATTLE_MOPUP_CNT and 1 or 0
  528. end
  529. local monsterOutId = nowNodeConfig.monsterOutID
  530. local monsterConfig = MonsterExcel.monsterOut[monsterOutId]
  531. fontVideoInfo(human, msgRet.videoInfo, monsterConfig)
  532. fontExtraDataSSZH(msgRet.extraDataSSZH, nowNodeConfig.mapID, nowBattleID)
  533. -- Msg.trace(msgRet)
  534. Msg.send(msgRet, human.fd)
  535. hangFightQuery(human)
  536. end
  537. -- 获取当前地图ID
  538. function getMapID(human, args)
  539. local battleID = human.db.battleID
  540. local config = BattleExcel.node[battleID]
  541. if not config then
  542. return
  543. end
  544. local mapConfig = BattleExcel.map[config.mapID]
  545. if not config then
  546. return
  547. end
  548. local mapID = config.sceneID
  549. return mapID
  550. end
  551. -- 战役挂机界面查询
  552. function onHookQuery(human)
  553. local msgRet = Msg.gc.GC_BATTLE_HANG_QUERY
  554. calcBattleOut(human)
  555. local expAdd = human.db.battleOut.exp
  556. local jinbiAdd = human.db.battleOut.jinbi
  557. local greenExpAdd = human.db.battleOut.greenExp
  558. local qingbaoAdd = human.db.battleOut.qingbao
  559. local skip = GuideLogic.getGuideSkip(human, GuideLogic.SKIPTYPE_JUMP_BATTLE_EXP)
  560. if not skip then
  561. expAdd = 1510
  562. end
  563. local items = { }
  564. local len = #items
  565. local tempTable = { }
  566. if human.db.battleOut.items then
  567. tempTable = Util.copyTable(human.db.battleOut.items)
  568. end
  569. tempTable[ItemDefine.ITEM_EXP_ID] = tempTable[ItemDefine.ITEM_EXP_ID] or 0
  570. tempTable[ItemDefine.ITEM_EXP_ID] = expAdd
  571. tempTable[ItemDefine.ITEM_JINBI_ID] = tempTable[ItemDefine.ITEM_JINBI_ID] or 0
  572. tempTable[ItemDefine.ITEM_JINBI_ID] = jinbiAdd
  573. tempTable[ItemDefine.ITEM_GREEN_EXP_ID] = tempTable[ItemDefine.ITEM_GREEN_EXP_ID] or 0
  574. tempTable[ItemDefine.ITEM_GREEN_EXP_ID] = greenExpAdd
  575. tempTable[ItemDefine.ITEM_QINGBAO_ID] = tempTable[ItemDefine.ITEM_QINGBAO_ID] or 0
  576. tempTable[ItemDefine.ITEM_QINGBAO_ID] = qingbaoAdd
  577. local list = DropExchangeLogic.getAbsCanDrop(human)
  578. if list then
  579. for k, v in pairs(list) do
  580. if tempTable[k] and tempTable[k] > 0 then
  581. len = len + 1
  582. items[len] = { }
  583. items[len].id = k
  584. items[len].cnt = tempTable[k]
  585. end
  586. end
  587. end
  588. for k, v in pairs(tempTable) do
  589. if not list or not list[k] then
  590. len = len + 1
  591. items[len] = { }
  592. items[len].id = k
  593. items[len].cnt = v
  594. end
  595. end
  596. -- 发消息
  597. local guajiID = human.db.guajiID > #BattleExcel.node and #BattleExcel.node or human.db.guajiID
  598. if guajiID == 0 then
  599. return Broadcast.sendErr(human, Lang.BATTLE_GUAJI_ERR)
  600. end
  601. local nodeConfig = BattleExcel.node[guajiID]
  602. local now = os.time()
  603. local outSec = now - human.db.battleOut.expTs1
  604. local maxHangTime = getHangMaxTime(human)
  605. msgRet.maxTime = maxHangTime
  606. if maxHangTime >= outSec then
  607. msgRet.time = outSec
  608. else
  609. msgRet.time = maxHangTime
  610. end
  611. for i = 1, #items do
  612. Grid.makeItem(msgRet.items[i], items[i].id, items[i].cnt)
  613. end
  614. local len = #items
  615. if human.db.battleOut.equip then
  616. for k, equipGrid in ipairs(human.db.battleOut.equip) do
  617. len = len + 1
  618. Grid.makeItem(msgRet.items[len], equipGrid.id, 1, nil, equipGrid)
  619. end
  620. end
  621. msgRet.items[0] = len
  622. msgRet.exp = nodeConfig.hangExp
  623. msgRet.jinbi = nodeConfig.hangJinbi
  624. msgRet.greenExp = nodeConfig.hangGreenExp
  625. msgRet.qingbao = nodeConfig.hangQingbao or 0
  626. Msg.send(msgRet, human.fd)
  627. end
  628. local function isChapterDot(human, mapID)
  629. local chapterReward = human.db.chapterReward or { }
  630. if chapterReward[mapID] then
  631. return false
  632. end
  633. local battleID = human.db.battleID
  634. local battleNodeConfig = BattleExcel.node[battleID]
  635. if not battleNodeConfig then
  636. if battleID == #BattleExcel.node + 1 then
  637. return true
  638. else
  639. return false
  640. end
  641. else
  642. local roleMapId = battleNodeConfig.mapID
  643. if roleMapId <= mapID then
  644. return false
  645. end
  646. end
  647. return true
  648. end
  649. function battleWorldMapQuery(human)
  650. local msgRet = Msg.gc.GC_BATTLE_WORLD_MAP_QUERY
  651. local worldMapConfig = BattleExcel.map
  652. local battleID = human.db.battleID > #BattleExcel.node and #BattleExcel.node or human.db.battleID
  653. local battleNodeConfig = BattleExcel.node[battleID]
  654. local len = #worldMapConfig
  655. for i = 1, len do
  656. local v = worldMapConfig[i]
  657. msgRet.worldMap[i].mapID = i
  658. msgRet.worldMap[i].mapName = v.name or ""
  659. msgRet.worldMap[i].mapBuild = v.build or 0
  660. msgRet.worldMap[i].mapBg = v.bg or 0
  661. msgRet.worldMap[i].mapPos[0] = 2
  662. msgRet.worldMap[i].mapPos[1] = v.pos[1]
  663. msgRet.worldMap[i].mapPos[2] = v.pos[2]
  664. msgRet.worldMap[i].status =(battleNodeConfig.mapID >= i) and 1 or 0
  665. msgRet.worldMap[i].story = v.des or ""
  666. if battleNodeConfig.mapID == i then
  667. msgRet.worldMap[i].maxLevel = battleNodeConfig.maxLevel
  668. msgRet.worldMap[i].curLevel = battleNodeConfig.curLevel
  669. else
  670. msgRet.worldMap[i].maxLevel = 0
  671. msgRet.worldMap[i].curLevel = 0
  672. end
  673. local reward = v.reward
  674. local l = 0
  675. msgRet.worldMap[i].chapterReward[0] = #reward
  676. for _, rewardData in pairs(reward) do
  677. l = l + 1
  678. Grid.makeItem(msgRet.worldMap[i].chapterReward[l], rewardData[1], rewardData[2])
  679. end
  680. msgRet.worldMap[i].chapterDot = 0
  681. if isChapterDot(human, i) then
  682. msgRet.worldMap[i].chapterDot = 1
  683. end
  684. local cnt = 0
  685. BATTLE_LEVEL_PLAYER_LIST[i] = BATTLE_LEVEL_PLAYER_LIST[i] or { }
  686. for s, t in pairs(BATTLE_LEVEL_PLAYER_LIST[i]) do
  687. cnt = cnt + 1
  688. RoleLogic.makeRoleBase(t, msgRet.worldMap[i].roleList[cnt])
  689. if cnt >= 3 then
  690. break
  691. end
  692. end
  693. msgRet.worldMap[i].roleList[0] = cnt
  694. end
  695. msgRet.worldMap[0] = len
  696. Msg.send(msgRet, human.fd)
  697. end
  698. function battleNodeQuery(human, mapID)
  699. local msgRet = Msg.gc.GC_BATTLE_NODE_QUERY
  700. local nodeConfig = BattleExcel.node
  701. local lenConfig = #nodeConfig
  702. local len = 0
  703. msgRet.battleID = human.db.battleID or 0
  704. for i = 1, lenConfig do
  705. local v = nodeConfig[i]
  706. if v.mapID == mapID then
  707. len = len + 1
  708. msgRet.nodeInfo[len].nodeName = v.name
  709. msgRet.nodeInfo[len].battleID = i
  710. msgRet.nodeInfo[len].needLv = v.needLv
  711. msgRet.nodeInfo[len].needZDL = v.needZDL
  712. msgRet.nodeInfo[len].hasSuipian = v.hasSuipian
  713. end
  714. end
  715. msgRet.nodeInfo[0] = len
  716. Msg.send(msgRet, human.fd)
  717. end
  718. function initBattleOut(human, now)
  719. if human.db.battleOut then
  720. return
  721. end
  722. human.db.battleOut = { }
  723. human.db.battleOut.expTs1 = now
  724. -- 经验开始产出时间戳
  725. human.db.battleOut.expTs2 = now
  726. -- 经验产出结算时间戳
  727. human.db.battleOut.itemTs1 = now
  728. -- 道具产出时间戳
  729. human.db.battleOut.itemTs2 = now
  730. -- 道具产出结算时间戳
  731. human.db.battleOut.exp = 0
  732. human.db.battleOut.jinbi = 0
  733. human.db.battleOut.greenExp = 0
  734. human.db.battleOut.qingbao = 0
  735. human.db.battleOut.items = nil
  736. -- 产出的待收获的战利品
  737. human.db.battleOut.equip = nil
  738. -- 产出的待收获的装备
  739. end
  740. function calcBattleOut(human)
  741. local now = os.time()
  742. initBattleOut(human, now)
  743. calcBattleExpOut(human, now)
  744. calcBattleItemOut(human, now)
  745. end
  746. -- 获取正确的剩余可收益的结算时间
  747. function getSurMaxHangTime(maxHangTime, ts1, now)
  748. if ts1 + maxHangTime > now then
  749. return now
  750. else
  751. return ts1 + maxHangTime
  752. end
  753. end
  754. function calcBattleExpOut(human, now)
  755. local maxHangTime = getHangMaxTime(human)
  756. if human.db.battleOut.expTs2 - human.db.battleOut.expTs1 >= maxHangTime then
  757. return
  758. end
  759. local outTime = getSurMaxHangTime(maxHangTime, human.db.battleOut.expTs1, now)
  760. local outSec = outTime - human.db.battleOut.expTs2
  761. local outCnt = math.floor(outSec / BATTLE_HANG_EXP_OUT_PERIOD)
  762. if outCnt < 1 then
  763. return
  764. end
  765. local guajiID = human.db.guajiID > #BattleExcel.node and #BattleExcel.node or human.db.guajiID
  766. if guajiID == 0 then
  767. return
  768. end
  769. local nowNodeConfig = BattleExcel.node[guajiID]
  770. human.db.battleOut.expTs2 = human.db.battleOut.expTs2 + outCnt * BATTLE_HANG_EXP_OUT_PERIOD
  771. if now - human.db.battleOut.expTs1 >= maxHangTime then
  772. human.db.battleOut.expTs2 = now
  773. end
  774. local vipExpAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER7) or 0) / 100
  775. local vipJinAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER8) or 0) / 100
  776. local vipGreenExpAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER9) or 0) / 100
  777. local vipQingbaoAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER19) or 0) / 100
  778. local exp = nowNodeConfig.hangExp
  779. local jinbi = nowNodeConfig.hangJinbi
  780. local greenExp = nowNodeConfig.hangGreenExp
  781. local qingbao = nowNodeConfig.hangQingbao
  782. human.db.battleOut.exp = human.db.battleOut.exp + math.floor(outCnt * exp *(1 + vipExpAdd))
  783. human.db.battleOut.jinbi = human.db.battleOut.jinbi + math.floor(outCnt * jinbi *(1 + vipJinAdd))
  784. human.db.battleOut.greenExp = human.db.battleOut.greenExp + math.floor(outCnt * greenExp *(1 + vipGreenExpAdd))
  785. human.db.battleOut.qingbao = human.db.battleOut.qingbao + math.floor(outCnt * qingbao *(1 + vipQingbaoAdd))
  786. end
  787. -- 根据时间计算道具产出
  788. local ITEM_OUT_LIST = { }
  789. function getItemOutsByTime(config, sec)
  790. Util.cleanTable(ITEM_OUT_LIST)
  791. local outCnt = math.floor(sec / BATTLE_HANG_ITEM_OUT_PERIOD)
  792. if outCnt < 1 then
  793. return ITEM_OUT_LIST
  794. end
  795. -- 普通掉落
  796. local dropID = config.dropID
  797. local dropConfig = DropExcel.dropBattle[dropID]
  798. local weightSum = 0
  799. for i = 1, #dropConfig.dropRule do
  800. local tempConfig = dropConfig.dropRule[i]
  801. weightSum = weightSum + tempConfig[4]
  802. end
  803. for i = 1, outCnt do
  804. local itemID, itemCnt = randItemOut(dropConfig.dropRule, weightSum)
  805. if itemCnt and itemCnt > 0 then
  806. ITEM_OUT_LIST[itemID] =(ITEM_OUT_LIST[itemID] or 0) + itemCnt
  807. end
  808. end
  809. for i = 1, #dropConfig.dropRule2 do
  810. local tempConfig = dropConfig.dropRule2[i]
  811. local itemID = tempConfig[1]
  812. local itemMin = tempConfig[2]
  813. local itemMax = tempConfig[3]
  814. local itemCnt = math.random(itemMin, itemMax) * outCnt
  815. if itemCnt > 0 then
  816. ITEM_OUT_LIST[itemID] =(ITEM_OUT_LIST[itemID] or 0) + itemCnt
  817. end
  818. end
  819. -- 三小时掉落
  820. outCnt = math.floor(sec / BATTLE_HANG_ITEM_OUT_PERIOD_2)
  821. if outCnt < 1 then
  822. return ITEM_OUT_LIST
  823. end
  824. weightSum = 0
  825. for i = 1, #dropConfig.dropRule3 do
  826. local tempConfig = dropConfig.dropRule3[i]
  827. weightSum = weightSum + tempConfig[4]
  828. end
  829. for i = 1, outCnt do
  830. local itemID, itemCnt = randItemOut(dropConfig.dropRule3, weightSum)
  831. if itemCnt and itemCnt > 0 then
  832. ITEM_OUT_LIST[itemID] =(ITEM_OUT_LIST[itemID] or 0) + itemCnt
  833. end
  834. end
  835. return ITEM_OUT_LIST
  836. end
  837. function calcBattleItemOut(human, now)
  838. local maxHangTime = getHangMaxTime(human)
  839. if human.db.battleOut.itemTs2 - human.db.battleOut.itemTs1 >= maxHangTime then
  840. return
  841. end
  842. local outTime = getSurMaxHangTime(maxHangTime, human.db.battleOut.itemTs1, now)
  843. local outSec = outTime - human.db.battleOut.itemTs2
  844. local outCnt = math.floor(outSec / BATTLE_HANG_ITEM_OUT_PERIOD)
  845. if outCnt < 1 then
  846. return
  847. end
  848. local guajiID = human.db.guajiID > #BattleExcel.node and #BattleExcel.node or human.db.guajiID
  849. if guajiID == 0 then
  850. return
  851. end
  852. local sec = outCnt * BATTLE_HANG_ITEM_OUT_PERIOD
  853. human.db.battleOut.itemTs2 = human.db.battleOut.itemTs2 + sec
  854. if now - human.db.battleOut.itemTs1 >= maxHangTime then
  855. human.db.battleOut.itemTs2 = now
  856. end
  857. local nodeConfig = BattleExcel.node[guajiID]
  858. local items = getItemOutsByTime(nodeConfig, sec)
  859. for itemID, itemCnt in pairs(items) do
  860. -- 判定是否是装备
  861. if ItemDefine.isEquip(itemID) then
  862. -- 生成装备
  863. local equipGrid = EquipLogic.makeEquip(itemID)
  864. if equipGrid then
  865. human.db.battleOut.equip = human.db.battleOut.equip or { }
  866. human.db.battleOut.equip[#human.db.battleOut.equip + 1] = equipGrid
  867. end
  868. else
  869. human.db.battleOut.items = human.db.battleOut.items or { }
  870. human.db.battleOut.items[itemID] = human.db.battleOut.items[itemID] or 0
  871. human.db.battleOut.items[itemID] = human.db.battleOut.items[itemID] + itemCnt
  872. end
  873. end
  874. DropExchangeLogic.getDropItem(human, outSec, BATTLE_HANG_ITEM_OUT_PERIOD, human.db.battleOut)
  875. end
  876. -- 获取挂机收益
  877. function hangGet(human)
  878. local ret, items = hangExpGet(human)
  879. if ret == 1 then
  880. return Broadcast.sendErr(human, Lang.BATTLE_HANG_GET_EXP_ERR_NONE)
  881. elseif ret == 2 then
  882. return Broadcast.sendErr(human, Lang.COMMON_ADD_JINBI_LIMIT)
  883. elseif ret == 0 then
  884. query(human)
  885. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1101)
  886. end
  887. end
  888. function hangExpGet(human)
  889. calcBattleOut(human)
  890. if human.db.battleOut.exp == 0 then
  891. return 1
  892. end
  893. local jinbiAdd = human.db.battleOut.jinbi
  894. if not ObjHuman.canAddJinbi(human, jinbiAdd) then
  895. return 2
  896. end
  897. -- 检测装备数量
  898. if human.db.battleOut.equip then
  899. local equipCnt = #human.db.battleOut.equip
  900. if not EquipLogic.checkEmptyCnt(human, equipCnt) then
  901. return
  902. end
  903. end
  904. local items = { }
  905. local len = #items
  906. local maxHangTime = getHangMaxTime(human)
  907. if human.db.battleOut.expTs2 - human.db.battleOut.expTs1 >= maxHangTime then
  908. local now = os.time()
  909. human.db.battleOut.expTs2 = now
  910. end
  911. if human.db.battleOut.itemTs2 - human.db.battleOut.itemTs1 >= maxHangTime then
  912. local now = os.time()
  913. human.db.battleOut.itemTs2 = now
  914. end
  915. human.db.battleOut.itemTs1 = human.db.battleOut.itemTs2
  916. -- 改db
  917. local tempTable = human.db.battleOut.items or { }
  918. human.db.battleOut.items = nil
  919. for k, v in pairs(tempTable) do
  920. len = len + 1
  921. items[len] = { }
  922. items[len].id = k
  923. items[len].cnt = v
  924. end
  925. human.db.battleOut.expTs1 = human.db.battleOut.expTs2
  926. local expAdd = human.db.battleOut.exp
  927. local greenExpAdd = human.db.battleOut.greenExp
  928. local qingbaoAdd = human.db.battleOut.qingbao
  929. -- 新手指引 强制经验
  930. local flag = GuideLogic.getGuideSkip(human, GuideLogic.SKIPTYPE_JUMP_BATTLE_EXP)
  931. if not flag then
  932. expAdd = 1510
  933. end
  934. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_BATTLE_EXP)
  935. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_BATTLE_GUAJI)
  936. human.db.battleOut.exp = 0
  937. human.db.battleOut.jinbi = 0
  938. human.db.battleOut.greenExp = 0
  939. human.db.battleOut.qingbao = 0
  940. len = len + 1
  941. items[len] = { }
  942. items[len].id = ItemDefine.ITEM_EXP_ID
  943. items[len].cnt = expAdd
  944. len = len + 1
  945. items[len] = { }
  946. items[len].id = ItemDefine.ITEM_JINBI_ID
  947. items[len].cnt = jinbiAdd
  948. len = len + 1
  949. items[len] = { }
  950. items[len].id = ItemDefine.ITEM_GREEN_EXP_ID
  951. items[len].cnt = greenExpAdd
  952. len = len + 1
  953. items[len] = { }
  954. items[len].id = ItemDefine.ITEM_QINGBAO_ID
  955. items[len].cnt = qingbaoAdd
  956. -- 给道具
  957. for i = 1, #items do
  958. local tempID = items[i].id
  959. local tempCnt = items[i].cnt
  960. BagLogic.addItem(human, tempID, tempCnt, "battle")
  961. end
  962. -- 给装备
  963. if human.db.battleOut.equip then
  964. for k, equipGrid in ipairs(human.db.battleOut.equip) do
  965. EquipLogic.addByEquipGrid(human, equipGrid, "battle", true)
  966. end
  967. human.db.battleOut.equip = nil
  968. end
  969. return 0, items
  970. end
  971. -- 挂机节点设置
  972. function nodeSet(human, battleID)
  973. local nodeConfig = BattleExcel.node[battleID]
  974. if nodeConfig == nil then
  975. return
  976. end
  977. -- 前置条件判断
  978. if battleID > human.db.battleID then
  979. return Broadcast.sendErr(human, Lang.BATTLE_ID_OVER)
  980. end
  981. -- 等级判断
  982. if human.db.lv < nodeConfig.needLv then
  983. return Broadcast.sendErr(human, Util.format(Lang.ROLE_LEV_ERROR, nodeConfig.needLv))
  984. end
  985. calcBattleOut(human)
  986. human.db.guajiID = battleID
  987. setBattleID(human, battleID)
  988. Msg.send(Msg.gc.GC_BATTLE_NODE_SET, human.fd)
  989. query(human)
  990. end
  991. -- 挂机节点详细信息查询
  992. function nodeDetailQuery(human, battleID)
  993. local nodeConfig = BattleExcel.node[battleID]
  994. if nodeConfig == nil then
  995. return
  996. end
  997. local msgRet = Msg.gc.GC_BATTLE_NODE_DETAIL_QUERY
  998. msgRet.battleID = battleID
  999. msgRet.exp = nodeConfig.hangExp
  1000. msgRet.jinbi = nodeConfig.hangJinbi
  1001. msgRet.greenExp = nodeConfig.hangGreenExp
  1002. msgRet.qingbao = nodeConfig.hangQingbao or 0
  1003. msgRet.nodeName = getBattleName(battleID)
  1004. local dropID = nodeConfig.dropID
  1005. local dropConfig = DropExcel.dropBattle[dropID]
  1006. local dropCnt = 0
  1007. local list = DropExchangeLogic.getAbsCanDrop(human)
  1008. if list then
  1009. for k, v in pairs(list) do
  1010. dropCnt = dropCnt + 1
  1011. Grid.makeItem(msgRet.items[dropCnt], k, v)
  1012. end
  1013. end
  1014. for i = 1, #dropConfig.dropRule do
  1015. local tempConfig = dropConfig.dropRule[i]
  1016. local itemID = tempConfig[1]
  1017. local itemCnt = tempConfig[3]
  1018. local itemRate = tempConfig[4]
  1019. if itemCnt > 0 and itemRate > 0 then
  1020. dropCnt = dropCnt + 1
  1021. Grid.makeItem(msgRet.items[dropCnt], itemID, 1)
  1022. end
  1023. end
  1024. for i = 1, #dropConfig.dropRule3 do
  1025. local tempConfig = dropConfig.dropRule3[i]
  1026. local itemID = tempConfig[1]
  1027. local itemCnt = tempConfig[3]
  1028. local itemRate = tempConfig[4]
  1029. if itemCnt > 0 and itemRate > 0 then
  1030. dropCnt = dropCnt + 1
  1031. Grid.makeItem(msgRet.items[dropCnt], itemID, 1)
  1032. end
  1033. end
  1034. msgRet.items[0] = dropCnt
  1035. Msg.send(msgRet, human.fd)
  1036. end
  1037. -- 挑战当前挂机节点
  1038. function fight(human)
  1039. local battleID = human.db.battleID
  1040. if BattleExcel.node[human.db.battleID] == nil then
  1041. local msgRet = Msg.gc.GC_BATTLE_GOBACK_MAIN
  1042. msgRet.panelIDs[0] = 1
  1043. msgRet.panelIDs[1] = PanelDefine.PANEL_ID_1008
  1044. Msg.send(msgRet, human.fd)
  1045. return Broadcast.sendErr(human, Lang.BATTLE_MAX_LEVEL)
  1046. end
  1047. if human.db.lv < BattleExcel.node[human.db.battleID].needLv then
  1048. local msgRet = Msg.gc.GC_BATTLE_GOBACK_MAIN
  1049. msgRet.panelIDs[0] = 1
  1050. msgRet.panelIDs[1] = PanelDefine.PANEL_ID_1008
  1051. Msg.send(msgRet, human.fd)
  1052. return Broadcast.sendErr(human, Util.format(Lang.ROLE_LEV_ERROR, BattleExcel.node[human.db.battleID].needLv))
  1053. end
  1054. local config = BattleExcel.node[battleID]
  1055. local mapConfig = BattleExcel.map[config.mapID]
  1056. local monsterOutID = config.monsterOutID
  1057. local mapID = mapConfig.bg
  1058. CombatLogic.combatBegin(human, config.sceneID, monsterOutID, CombatDefine.COMBAT_TYPE1, battleID)
  1059. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_BATTLE)
  1060. end
  1061. function onFightEnd(human, result, fightTypeID, param1, combatInfo)
  1062. -- 设置一些战斗结算信息
  1063. combatInfo.defender.name = Util.format(Lang.COMBAT_BATTLE_DEFEND_NAME, param1)
  1064. if CombatDefine.RESULT_WIN ~= result then
  1065. return
  1066. end
  1067. local guajiID = human.db.guajiID
  1068. local battleID = human.db.battleID
  1069. if battleID ~= param1 then
  1070. return
  1071. end
  1072. local oldGuajiID = guajiID
  1073. local nextGuajiID = guajiID + 1
  1074. local nextBattleID = battleID + 1
  1075. local nextBattleConfig = BattleExcel.node[nextBattleID]
  1076. local config = BattleExcel.node[battleID]
  1077. -- 如果过大关卡
  1078. if nextBattleConfig and nextBattleConfig.mapID ~= config.mapID then
  1079. -- 清除记录
  1080. BATTLE_LEVEL_PLAYER_LIST[config.mapID] = BATTLE_LEVEL_PLAYER_LIST[config.mapID] or { }
  1081. BATTLE_LEVEL_PLAYER_LIST[config.mapID][human.db._id] = nil
  1082. -- 增加新纪录
  1083. BATTLE_LEVEL_PLAYER_LIST[nextBattleConfig.mapID] = BATTLE_LEVEL_PLAYER_LIST[nextBattleConfig.mapID] or { }
  1084. BATTLE_LEVEL_PLAYER_LIST[nextBattleConfig.mapID][human.db._id] = { }
  1085. RoleLogic.getRoleBase(human, BATTLE_LEVEL_PLAYER_LIST[nextBattleConfig.mapID][human.db._id])
  1086. else
  1087. if config.mapID == 1 then
  1088. BATTLE_LEVEL_PLAYER_LIST[config.mapID] = BATTLE_LEVEL_PLAYER_LIST[config.mapID] or { }
  1089. if BATTLE_LEVEL_PLAYER_LIST[config.mapID][human.db._id] == nil then
  1090. -- 增加新纪录
  1091. BATTLE_LEVEL_PLAYER_LIST[config.mapID][human.db._id] = { }
  1092. RoleLogic.getRoleBase(human, BATTLE_LEVEL_PLAYER_LIST[config.mapID][human.db._id])
  1093. end
  1094. else
  1095. if not BATTLE_LEVEL_PLAYER_LIST[config.mapID] or not BATTLE_LEVEL_PLAYER_LIST[config.mapID][human.db._id] then
  1096. BATTLE_LEVEL_PLAYER_LIST[config.mapID] = BATTLE_LEVEL_PLAYER_LIST[config.mapID] or { }
  1097. BATTLE_LEVEL_PLAYER_LIST[config.mapID][human.db._id] = { }
  1098. RoleLogic.getRoleBase(human, BATTLE_LEVEL_PLAYER_LIST[config.mapID][human.db._id])
  1099. end
  1100. end
  1101. end
  1102. human.db.battleID = battleID + 1
  1103. -- 通过第10关,默认开启二倍速
  1104. if human.db.battleID == 10 then
  1105. human.db.combatSpeed = 2
  1106. end
  1107. combatInfo.attacker.oldLv = human.db.lv
  1108. -- 给奖励
  1109. combatInfo.rewardItem = { }
  1110. for i = 1, #config.winReward do
  1111. local itemID = config.winReward[i][1]
  1112. local itemCnt = config.winReward[i][2]
  1113. -- 装备不在这显示
  1114. combatInfo.rewardItem[i] = combatInfo.rewardItem[i] or { }
  1115. combatInfo.rewardItem[i] = { itemID, itemCnt }
  1116. BagLogic.addItem(human, itemID, itemCnt, "battle_win")
  1117. end
  1118. combatInfo.attacker.lv = human.db.lv
  1119. combatInfo.getEquip = human.getEquip
  1120. human.getEquip = nil
  1121. -- TODO:记录主线关卡
  1122. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, human.db._id, human.db.account, human.db.name, human.db.battleID)
  1123. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1101)
  1124. GuideLogic.onCallback(human)
  1125. JibanLogic.onCallback(human, 1, battleID)
  1126. TuiSongLiBao.tuiSongLiBaoOnTask(
  1127. human,
  1128. TuiSongLiBao.TUISONGLIBAOTASK_ZHENGZHAN,
  1129. human.db.guajiID - 1,
  1130. human.db.guajiID - 2
  1131. )
  1132. ChengjiuLogic.onCallback(human, ChengjiuDefine.CJ_TASK_TYPE_1, nextGuajiID)
  1133. MengxinLogic.onCallBack(human, MengxinLogic.MX_TASK_TYPE_1, nextGuajiID)
  1134. for k, v in pairs(KingWorldLogic.funcID) do
  1135. YunYingLogic.updateIcon(KingWorldLogic.YYInfo[k], human)
  1136. break
  1137. end
  1138. -- 存储战斗记录
  1139. local videoUuid = CombatVideo.saveBattleVideo(human.db._id, combatInfo)
  1140. human.db.battleVideoUuid = videoUuid
  1141. BattleDBLogic.updateBattleDB(combatInfo.attacker, battleID, combatInfo, videoUuid)
  1142. if nextBattleConfig and nextBattleConfig.mapID ~= config.mapID then
  1143. -- 新的地图
  1144. -- 通知客户端
  1145. Msg.send(Msg.gc.GC_BATTLE_NODE_SET, human.fd)
  1146. end
  1147. human.db.guajiID = nextGuajiID
  1148. if nextBattleConfig then
  1149. setBattleID(human, nextGuajiID)
  1150. end
  1151. local showNext = 1
  1152. if BattleExcel.node[human.db.battleID] and human.db.lv < BattleExcel.node[human.db.battleID].needLv then
  1153. showNext = 2
  1154. end
  1155. if human.db.lv < 5 then
  1156. showNext = 0
  1157. end
  1158. nextBattleConfig = BattleExcel.node[human.db.battleID]
  1159. if not nextBattleConfig then
  1160. showNext = 0
  1161. end
  1162. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1105)
  1163. -- 额外奖励
  1164. local needLevel, itemName = getNextRewardName(human)
  1165. if needLevel ~= nil then
  1166. local tb = { needLevel, Lang.BATTLE_FIGHT_GUAN, "|", itemName, "|", showNext }
  1167. local str = table.concat(tb)
  1168. combatInfo.endParam = str
  1169. else
  1170. local tb = { showNext }
  1171. local str = table.concat(tb)
  1172. combatInfo.endParam = str
  1173. end
  1174. end
  1175. function setBattleID(human, guajiID)
  1176. if guajiID > human.db.guajiID and human.db.guajiID ~= 0 then
  1177. -- 下发挂机收益升级提示
  1178. local msgRet = Msg.gc.GC_BATTLE_REWARD_UP
  1179. Grid.makeItem(msgRet.itemExp, ItemDefine.ITEM_EXP_ID, 1)
  1180. Grid.makeItem(msgRet.itemJinbi, ItemDefine.ITEM_JINBI_ID, 1)
  1181. Grid.makeItem(msgRet.itemGreenExp, ItemDefine.ITEM_GREEN_EXP_ID, 1)
  1182. Grid.makeItem(msgRet.itemQingbao, ItemDefine.ITEM_QINGBAO_ID, 1)
  1183. local oldConfig = BattleExcel.node[human.db.guajiID]
  1184. local newConfig = BattleExcel.node[guajiID]
  1185. msgRet.expOld = oldConfig.hangExp
  1186. msgRet.expNew = newConfig.hangExp
  1187. msgRet.jinbiOld = oldConfig.hangJinbi
  1188. msgRet.jinbiNew = newConfig.hangJinbi
  1189. msgRet.greenExpOld = oldConfig.hangGreenExp
  1190. msgRet.greenExpNew = newConfig.hangGreenExp
  1191. msgRet.qingbaoOld = oldConfig.hangQingbao
  1192. msgRet.qingbaoNew = newConfig.hangQingbao
  1193. Msg.send(msgRet, human.fd)
  1194. end
  1195. -- 刷新排行榜
  1196. BRoleLogic.updateData(BillboardDefine.TYPE_BATTLE, human.db)
  1197. end
  1198. -- GM
  1199. function setBattleByGm(human, val, maxBattleID)
  1200. val = tonumber(val)
  1201. if not val or val <= 1 then
  1202. return
  1203. end
  1204. local nodeConfig = BattleExcel.node[val]
  1205. if not nodeConfig then
  1206. return
  1207. end
  1208. if maxBattleID then
  1209. maxBattleID = tonumber(maxBattleID)
  1210. else
  1211. maxBattleID = val
  1212. end
  1213. setBattleID(human, val)
  1214. human.db.battleID = val
  1215. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1105)
  1216. end
  1217. function mopupQuery(human)
  1218. ObjHuman.updateDaily(human)
  1219. local msgRet = Msg.gc.GC_BATTLE_MOPUP_QUERY
  1220. local guajiID = human.db.guajiID > #BattleExcel.node and #BattleExcel.node or human.db.guajiID
  1221. if guajiID == 0 then
  1222. return Broadcast.sendErr(human, Lang.BATTLE_MOPUP_ERR)
  1223. end
  1224. human.db.mopupDoCnt = human.db.mopupDoCnt or 0
  1225. local nextDoCnt = human.db.mopupDoCnt + 1
  1226. local nodeConfig = BattleExcel.node[guajiID]
  1227. local dropID = nodeConfig.dropID
  1228. local dropConfig = DropExcel.dropBattle[dropID]
  1229. local dropCnt = 0
  1230. -- ABS掉落活动显示到第一个
  1231. dropCnt = DropExchangeLogic.getDropItemSaoQuery(human, msgRet, dropCnt)
  1232. for i = 1, #dropConfig.dropRule do
  1233. if dropCnt >= #msgRet.item then
  1234. break
  1235. end
  1236. dropCnt = dropCnt + 1
  1237. local tempConfig = dropConfig.dropRule[i]
  1238. local itemID = tempConfig[1]
  1239. Grid.makeItem(msgRet.item[dropCnt], itemID, 1)
  1240. end
  1241. for i = 1, #dropConfig.dropRule3 do
  1242. if dropCnt >= #msgRet.item then
  1243. break
  1244. end
  1245. dropCnt = dropCnt + 1
  1246. local tempConfig = dropConfig.dropRule3[i]
  1247. local itemID = tempConfig[1]
  1248. Grid.makeItem(msgRet.item[dropCnt], itemID, 1)
  1249. end
  1250. local mapConfig = BattleExcel.map[nodeConfig.mapID]
  1251. msgRet.name = mapConfig.name
  1252. msgRet.item[0] = dropCnt
  1253. if TequanShopLogic.isActiveMopup(human) then
  1254. msgRet.leftCnt = BATTLE_MOPUP_CNT_VIP - human.db.mopupDoCnt
  1255. else
  1256. msgRet.leftCnt = BATTLE_MOPUP_CNT - human.db.mopupDoCnt
  1257. end
  1258. local mupopExcel = BattleExcel.mupop[nextDoCnt]
  1259. if mupopExcel then
  1260. if not TequanShopLogic.isActiveMopup(human) then
  1261. msgRet.need = mupopExcel.cost
  1262. if human.db.mopupFreeCnt < BATTLE_MOPUP_FREE_CNT then
  1263. msgRet.need = 0
  1264. end
  1265. else
  1266. msgRet.need = mupopExcel.vipCost
  1267. if human.db.mopupFreeCnt < BATTLE_MOPUP_FREE_CNT_VIP then
  1268. msgRet.need = 0
  1269. end
  1270. end
  1271. else
  1272. msgRet.need = 0
  1273. end
  1274. msgRet.vip = TequanShopLogic.isActiveMopup(human) and 1 or 0
  1275. msgRet.nowCnt = human.db.mopupDoCnt
  1276. msgRet.exp = nodeConfig.hangExp
  1277. msgRet.jinbi = nodeConfig.hangJinbi
  1278. msgRet.greenExp = nodeConfig.hangGreenExp
  1279. msgRet.qingbao = nodeConfig.hangQingbao
  1280. Msg.send(msgRet, human.fd)
  1281. end
  1282. function mopupFight(human)
  1283. -- 等级判断
  1284. ObjHuman.updateDaily(human)
  1285. local need = 0
  1286. human.db.mopupDoCnt = human.db.mopupDoCnt or 0
  1287. human.db.mopupFreeCnt = human.db.mopupFreeCnt or 0
  1288. local nextDoCnt = human.db.mopupDoCnt + 1
  1289. local mupopExcel = BattleExcel.mupop[nextDoCnt]
  1290. if not mupopExcel then
  1291. return Broadcast.sendErr(human, Lang.BATTLE_MOPUP_CNT_OVER)
  1292. end
  1293. if not TequanShopLogic.isActiveMopup(human) then
  1294. if human.db.mopupDoCnt >= BATTLE_MOPUP_CNT then
  1295. return Broadcast.sendErr(human, Lang.BATTLE_MOPUP_CNT_OVER)
  1296. end
  1297. need = mupopExcel.cost
  1298. -- 如果免费次数小于1次,则按免费算
  1299. if human.db.mopupFreeCnt < BATTLE_MOPUP_FREE_CNT then
  1300. need = 0
  1301. end
  1302. else
  1303. if human.db.mopupDoCnt >= BATTLE_MOPUP_CNT_VIP then
  1304. return Broadcast.sendErr(human, Lang.BATTLE_MOPUP_CNT_OVER)
  1305. end
  1306. need = mupopExcel.vipCost
  1307. -- 如果免费次数小于3次,则按免费算
  1308. if human.db.mopupFreeCnt < BATTLE_MOPUP_FREE_CNT_VIP then
  1309. need = 0
  1310. end
  1311. end
  1312. if not ObjHuman.checkRMB(human, need) then
  1313. return
  1314. end
  1315. if need <= 0 then
  1316. human.db.mopupFreeCnt = human.db.mopupFreeCnt + 1
  1317. end
  1318. ObjHuman.decZuanshi(human, - need, "battleMopup")
  1319. local len = #BattleExcel.node
  1320. human.db.mopupDoCnt = human.db.mopupDoCnt + 1
  1321. local guajiID = human.db.guajiID > #BattleExcel.node and #BattleExcel.node or human.db.guajiID
  1322. if guajiID == 0 then
  1323. return Broadcast.sendErr(human, Lang.BATTLE_MOPUP_ERR)
  1324. end
  1325. local config = BattleExcel.node[guajiID]
  1326. local msgRet = Msg.gc.GC_BATTLE_MOPUP_FIGHT
  1327. local vipExpAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER7) or 0) / 100
  1328. local vipJinAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER8) or 0) / 100
  1329. local vipGreenExpAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER9) or 0) / 100
  1330. local vipQingbaoAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER19) or 0) / 100
  1331. local exp = config.hangExp * 120
  1332. local jinbi = config.hangJinbi * 120
  1333. local greenExp = config.hangGreenExp * 120
  1334. local qingbao = config.hangQingbao * 120
  1335. local addExp = math.floor(exp *(1 + vipExpAdd))
  1336. local addJinbi = math.floor(jinbi *(1 + vipJinAdd))
  1337. local addGreenExp = math.floor(greenExp *(1 + vipGreenExpAdd))
  1338. local addQingbao = math.floor(qingbao *(1 + vipQingbaoAdd))
  1339. local time = 7200
  1340. local itemTable = getItemOutsByTime(config, time)
  1341. -- 掉落活动
  1342. DropExchangeLogic.getDropItemSao(human, time, itemTable)
  1343. local flag = GuideLogic.getGuideSkip(human, GuideLogic.SKIPTYPE_JUMP_BATTLE_SD)
  1344. if not flag then
  1345. local equipID = SysParameter.getSysParameter(SysParameter.PARAMETER_10)
  1346. itemTable[equipID] = 1
  1347. end
  1348. itemTable[ItemDefine.ITEM_JINBI_ID] = itemTable[ItemDefine.ITEM_JINBI_ID] or 0
  1349. itemTable[ItemDefine.ITEM_EXP_ID] = itemTable[ItemDefine.ITEM_EXP_ID] or 0
  1350. itemTable[ItemDefine.ITEM_GREEN_EXP_ID] = itemTable[ItemDefine.ITEM_GREEN_EXP_ID] or 0
  1351. itemTable[ItemDefine.ITEM_QINGBAO_ID] = itemTable[ItemDefine.ITEM_QINGBAO_ID] or 0
  1352. itemTable[ItemDefine.ITEM_JINBI_ID] = itemTable[ItemDefine.ITEM_JINBI_ID] + addJinbi
  1353. itemTable[ItemDefine.ITEM_EXP_ID] = itemTable[ItemDefine.ITEM_EXP_ID] + addExp
  1354. itemTable[ItemDefine.ITEM_GREEN_EXP_ID] = itemTable[ItemDefine.ITEM_GREEN_EXP_ID] + addGreenExp
  1355. itemTable[ItemDefine.ITEM_QINGBAO_ID] = itemTable[ItemDefine.ITEM_QINGBAO_ID] + addQingbao
  1356. msgRet.item[0] = 0
  1357. -- 双倍日
  1358. local double = RoleSystemLogic.isDouble(human, RoleSystemDefine.ROLE_SYS_ID_1101)
  1359. local rewardCnt = double and 2 or 1
  1360. for itemID, itemCnt in pairs(itemTable) do
  1361. itemCnt = itemCnt * rewardCnt
  1362. if not ItemDefine.isEquip(itemID) then
  1363. msgRet.item[0] = msgRet.item[0] + 1
  1364. Grid.makeItem(msgRet.item[msgRet.item[0]], itemID, itemCnt)
  1365. end
  1366. BagLogic.addItem(human, itemID, itemCnt, "battle")
  1367. end
  1368. msgRet.item[0] = EquipLogic.makeEquipItem(human, msgRet.item, msgRet.item[0])
  1369. msgRet.double = double and 1 or 0
  1370. msgRet.exp = itemTable[ItemDefine.ITEM_EXP_ID] * rewardCnt
  1371. msgRet.jinbi = itemTable[ItemDefine.ITEM_JINBI_ID] * rewardCnt
  1372. msgRet.greenExp = itemTable[ItemDefine.ITEM_GREEN_EXP_ID] * rewardCnt
  1373. msgRet.qingbao = itemTable[ItemDefine.ITEM_QINGBAO_ID] * rewardCnt
  1374. Msg.send(msgRet, human.fd)
  1375. mopupQuery(human)
  1376. query(human)
  1377. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1101)
  1378. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_BATTLE_SD)
  1379. DailyTaskLogic.recordDailyTaskFinishCnt(human, DailyTaskLogic.DAILY_TASK_ID_12, 1)
  1380. ChengjiuLogic.onCallback(human, ChengjiuDefine.CJ_TASK_TYPE_3, 1)
  1381. HeroLogLogic.finishTaskCB(human, HeroLogLogic.HERO_LOG_TYPE_3, 1)
  1382. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_2001)
  1383. YunYingLogic.onCallBack(human, "onMopup", 1)
  1384. end
  1385. function updateDaily(human)
  1386. human.db.mopupFreeCnt = 0
  1387. human.db.mopupDoCnt = 0
  1388. end
  1389. function getTongGuanReward(human, id)
  1390. local cf = BattleExcel.node[id]
  1391. if not cf then
  1392. return
  1393. end
  1394. if #cf.tongguan < 1 then
  1395. return
  1396. end
  1397. print("human.db.guajiID,id", human.db.guajiID, id)
  1398. if human.db.guajiID < id then
  1399. return
  1400. end
  1401. if isGetReward(human, id) then
  1402. return
  1403. end
  1404. if #cf.tongguan == 1 and cf.tongguan[1][3] then
  1405. -- 英雄
  1406. if HeroLogic.getEmptyCnt(human) < 1 then
  1407. return Broadcast.sendErr(human, Lang.HERO_BAG_FULL)
  1408. end
  1409. local heroID = cf.tongguan[1][1]
  1410. local cnt = cf.tongguan[1][2]
  1411. local star = cf.tongguan[1][3]
  1412. if cnt <= 0 then
  1413. return
  1414. end
  1415. setGetReward(human, id)
  1416. local msg = Msg.gc.GC_SUIPIAN_SUMMON
  1417. for i = 1, cnt do
  1418. local heroGrid = HeroGrid.createHeroGrid(heroID, star)
  1419. HeroLogic.addHeroByGrid(human, heroGrid, "battle_extra_reward")
  1420. SuipianLogic.makeResultItemData(msg.heroList[i], heroID, 1, 1)
  1421. end
  1422. msg.isHero = 1
  1423. msg.list[0] = 0
  1424. msg.heroList[0] = cnt
  1425. msg.fenJieList[0] = 0
  1426. Msg.send(msg, human.fd)
  1427. else
  1428. setGetReward(human, id)
  1429. BagLogic.addItemList(human, cf.tongguan, "tongguan")
  1430. end
  1431. -- 触发国王君临奖励
  1432. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE5, id)
  1433. query(human)
  1434. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1101)
  1435. if id == 80 then
  1436. KingWorldLogic.setState(human, 1)
  1437. end
  1438. end
  1439. function isDot(human)
  1440. -- 通过大关卡奖励
  1441. local chapterReward = human.db.chapterReward or { }
  1442. local battleID = human.db.battleID
  1443. local battleNodeConfig = BattleExcel.node[battleID]
  1444. if not battleNodeConfig then
  1445. local nodeCnt = #BattleExcel.node
  1446. local mapCnt = #BattleExcel.map
  1447. if battleID == nodeCnt + 1 and not chapterReward[mapCnt] then
  1448. return true
  1449. else
  1450. return false
  1451. end
  1452. else
  1453. local mapID = battleNodeConfig.mapID
  1454. for i = mapID - 1, 1, -1 do
  1455. if not chapterReward[i] then
  1456. return true
  1457. end
  1458. end
  1459. end
  1460. return false
  1461. -- if human.db.lv < 9 then
  1462. -- return false
  1463. -- end
  1464. -- -- 有免费扫荡次数的时候有红点
  1465. -- human.db.mopupFreeCnt = human.db.mopupFreeCnt or 0
  1466. -- if TequanShopLogic.isActiveMopup(human) then
  1467. -- if human.db.mopupFreeCnt < 3 then
  1468. -- return true
  1469. -- end
  1470. -- else
  1471. -- if human.db.mopupFreeCnt < 1 then
  1472. -- return true
  1473. -- end
  1474. -- end
  1475. -- -- 有通关奖励可领取的时候有红点
  1476. -- if hasCanGetReward(human) then
  1477. -- return true
  1478. -- end
  1479. -- -- 战役挂机时间超过1小时的时候有红点
  1480. -- if human.db.battleOut ~= nil then
  1481. -- local now = os.time()
  1482. -- local outSec = now - human.db.battleOut.expTs1
  1483. -- if outSec >= 3600 then
  1484. -- return true
  1485. -- end
  1486. -- end
  1487. -- return false
  1488. end
  1489. function clacItemTwoHours(human)
  1490. local items = { }
  1491. local outCnt = math.floor(7200 / BATTLE_HANG_ITEM_OUT_PERIOD)
  1492. local guajiID = human.db.guajiID > #BattleExcel.node and #BattleExcel.node or human.db.guajiID
  1493. if guajiID == 0 then
  1494. return items
  1495. end
  1496. local nodeConfig = BattleExcel.node[guajiID]
  1497. local dropID = nodeConfig.dropID
  1498. local dropConfig = DropExcel.dropBattle[dropID]
  1499. local totalWeight = 0
  1500. for i = 1, #dropConfig.dropRule do
  1501. local tempConfig = dropConfig.dropRule[i]
  1502. totalWeight = totalWeight + tempConfig[4]
  1503. end
  1504. for j = 1, outCnt do
  1505. local randomNum = math.random(1, totalWeight)
  1506. for i = 1, #dropConfig.dropRule do
  1507. local tempConfig = dropConfig.dropRule[i]
  1508. local itemID = tempConfig[1]
  1509. local itemCnt1 = tempConfig[2]
  1510. local itemCnt2 = tempConfig[3]
  1511. local itemRate = tempConfig[4]
  1512. if randomNum <= itemRate then
  1513. local realAdd = math.random(itemCnt1, itemCnt2)
  1514. items[itemID] = realAdd
  1515. break
  1516. end
  1517. randomNum = randomNum - itemRate
  1518. end
  1519. end
  1520. return items
  1521. end
  1522. local MailManager = require("mail.MailManager")
  1523. function clacItemCntGM(human, cnt, guajiID)
  1524. local items = { }
  1525. local outCnt = cnt
  1526. local nodeConfig = BattleExcel.node[guajiID]
  1527. local dropID = nodeConfig.dropID
  1528. local dropConfig = DropExcel.dropBattle[dropID]
  1529. local totalWeight = 0
  1530. for i = 1, #dropConfig.dropRule do
  1531. local tempConfig = dropConfig.dropRule[i]
  1532. totalWeight = totalWeight + tempConfig[4]
  1533. end
  1534. for j = 1, outCnt do
  1535. local randomNum = math.random(1, totalWeight)
  1536. for i = 1, #dropConfig.dropRule do
  1537. local tempConfig = dropConfig.dropRule[i]
  1538. local itemID = tempConfig[1]
  1539. local itemCnt1 = tempConfig[2]
  1540. local itemCnt2 = tempConfig[3]
  1541. local itemRate = tempConfig[4]
  1542. if randomNum <= itemRate then
  1543. local realAdd = math.random(itemCnt1, itemCnt2)
  1544. items[itemID] = items[itemID] or 0
  1545. items[itemID] = items[itemID] + realAdd
  1546. break
  1547. end
  1548. randomNum = randomNum - itemRate
  1549. end
  1550. end
  1551. local item = { }
  1552. local index = 0
  1553. for k, v in pairs(items) do
  1554. index = index + 1
  1555. item[index] = { k, v }
  1556. end
  1557. MailManager.add(MailManager.SYSTEM, human.db._id, "", "", item, "")
  1558. end
  1559. function getBattleID(human)
  1560. local num = 0
  1561. if human.db.guajiID then
  1562. num = human.db.guajiID or 0
  1563. end
  1564. return num
  1565. end
  1566. --------------------------------------------- combat ----------------------------------------------
  1567. function getCombatMonsterOutID(human, side)
  1568. if side ~= CombatDefine.DEFEND_SIDE then
  1569. return
  1570. end
  1571. local config = BattleExcel.node[human.db.battleID]
  1572. if not config then
  1573. return
  1574. end
  1575. return config.monsterOutID
  1576. end
  1577. function getCombatName(human)
  1578. local name = getBattleName(human.db.battleID)
  1579. return Util.format(Lang.COMBAT_BATTLE_EXNAME, name)
  1580. end
  1581. -------------------------------------------combat end--------------------
  1582. function battleSharkQuery(human, nodeID)
  1583. local msgRet = Msg.gc.GC_BATTLE_SHARK_QUERY
  1584. local videoTb = BattleDBLogic.queryBattleDbByNodeID(nodeID)
  1585. if videoTb == nil then
  1586. msgRet.battleShark[0] = 0
  1587. else
  1588. local len = #videoTb.shark
  1589. for i = 1, len do
  1590. local v = videoTb.shark[i]
  1591. RoleLogic.makeRoleBase(v.roleBase, msgRet.battleShark[i].roleBase)
  1592. msgRet.battleShark[i].type = i
  1593. msgRet.battleShark[i].videoUuid = v.videoUuid
  1594. msgRet.battleShark[i].param = v.param or 0
  1595. end
  1596. msgRet.battleShark[0] = len
  1597. end
  1598. -- Msg.trace(msgRet)
  1599. Msg.send(msgRet, human.fd)
  1600. end
  1601. local QueryRoleByNodeID = { }
  1602. function worldMapRoleListQuery(human, worldMapId)
  1603. -- if worldMapId == 1 then return end
  1604. local msgRet = Msg.gc.GC_BATTLE_WORLD_MAP_ROLELIST_QUERY
  1605. local len = 0
  1606. for k, v in pairs(BATTLE_LEVEL_PLAYER_LIST[worldMapId]) do
  1607. len = len + 1
  1608. RoleLogic.makeRoleBase(v, msgRet.roleList[len])
  1609. if len >= 50 then
  1610. break
  1611. end
  1612. end
  1613. msgRet.roleList[0] = len
  1614. Msg.send(msgRet, human.fd)
  1615. end
  1616. -- 章节(地图)掉落列表
  1617. function sendMapDroItemsList(human)
  1618. local battleID = human.db.battleID or 1
  1619. local maxBattleConfig = BattleExcel.node[battleID]
  1620. local maxMapID = maxBattleConfig and maxBattleConfig.mapID or(#BattleExcel.node + 1)
  1621. local msgRet = Msg.gc.GC_BATTLE_MAP_DROPITEMS_LIST
  1622. msgRet.list[0] = 0
  1623. for mapID, mapConfig in ipairs(BattleExcel.map) do
  1624. msgRet.list[0] = msgRet.list[0] + 1
  1625. local net = msgRet.list[msgRet.list[0]]
  1626. net.mapID = mapID
  1627. net.mapName = mapConfig.name
  1628. net.isOpen =(mapID <= maxMapID) and 1 or 0
  1629. end
  1630. -- Msg.trace(msgRet)
  1631. Msg.send(msgRet, human.fd)
  1632. end
  1633. -- 章节(地图)掉落详情
  1634. function sendMapDroItemsDetail(human, mapID)
  1635. local mapConfig = BattleExcel.map[mapID]
  1636. if not mapConfig then
  1637. return
  1638. end
  1639. local msgRet = Msg.gc.GC_BATTLE_MAP_DROPITEMS_DETAIL
  1640. msgRet.mapID = mapID
  1641. msgRet.items[0] = math.min(#mapConfig.dropItemsShow, #msgRet.items)
  1642. for i = 1, msgRet.items[0] do
  1643. local itemID = mapConfig.dropItemsShow[i][1]
  1644. local itemCnt = mapConfig.dropItemsShow[i][2]
  1645. Grid.makeItem(msgRet.items[i], itemID, itemCnt)
  1646. end
  1647. -- Msg.trace(msgRet)
  1648. Msg.send(msgRet, human.fd)
  1649. end
  1650. -- 获取当前战役的 怪物ID
  1651. function getBattleMonsterOutID(human)
  1652. local battleID = human.db.battleID
  1653. local config = BattleExcel.node[battleID]
  1654. return config.monsterOutID
  1655. end
  1656. function onUpdatePos(human)
  1657. BRoleLogic.updateData(BillboardDefine.TYPE_ZHANDOULI, human.db)
  1658. end
  1659. function getNextRewardName(human)
  1660. for i = human.db.guajiID + 1, #BattleExcel.node do
  1661. if #BattleExcel.node[i].tongguan > 0 then
  1662. local itemID = BattleExcel.node[i].tongguan[1][1]
  1663. local itemConfig = ItemDefine.getConfig(itemID)
  1664. if itemConfig == nil then
  1665. return
  1666. else
  1667. return i - human.db.guajiID, itemConfig.name
  1668. end
  1669. end
  1670. end
  1671. end
  1672. --[[
  1673. 通关章节后领取奖励
  1674. ]]
  1675. function battleChapterReward(human, mapID)
  1676. local mapConf = BattleExcel.map[mapID]
  1677. if not mapConf then
  1678. return
  1679. end
  1680. -- 没有通过当前大关卡
  1681. local battleID = human.db.battleID
  1682. local battleNodeConfig = BattleExcel.node[battleID]
  1683. local roleMapId
  1684. if not battleNodeConfig then
  1685. if battleID ~= #BattleExcel.node + 1 then
  1686. return
  1687. else
  1688. roleMapId = #BattleExcel.map
  1689. end
  1690. else
  1691. roleMapId = battleNodeConfig.mapID
  1692. end
  1693. if mapID > roleMapId then
  1694. return
  1695. end
  1696. if not human.db.chapterReward then
  1697. human.db.chapterReward = { }
  1698. end
  1699. -- 判断是否已经领取了当前大关卡的奖励
  1700. local chapterReward = human.db.chapterReward
  1701. if chapterReward[mapID] then
  1702. return Broadcast.sendErr(human, Lang.FRIEND_HEART_GET_HAD)
  1703. end
  1704. human.db.chapterReward[mapID] = true
  1705. ObjHuman.save(human)
  1706. local reward = mapConf.reward
  1707. BagLogic.addItemList(human, reward, "chapterReward")
  1708. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1105)
  1709. local msgRet = Msg.gc.GC_BATTLE_CHAPTER_REWARD
  1710. msgRet.mapID = mapID
  1711. Msg.send(msgRet, human.fd)
  1712. end