BattleLogic.lua 67 KB

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