BattleLogic.lua 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014
  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. local idx = 1
  614. for i = 1, #items do
  615. Grid.makeItem(msgRet.items[i], items[i].id, items[i].cnt)
  616. end
  617. local len = #items
  618. if human.db.battleOut.equip then
  619. for k, equipGrid in ipairs(human.db.battleOut.equip) do
  620. if len >= 10 then
  621. msgRet.items[0] = len
  622. msgRet.isEnd = 0
  623. msgRet.index = idx
  624. msgRet.maxTime = maxHangTime
  625. if maxHangTime >= outSec then
  626. msgRet.time = outSec
  627. else
  628. msgRet.time = maxHangTime
  629. end
  630. local minHour = math.floor(msgRet.time / HOUR_SEC)
  631. minHour = (minHour ~= 0) and minHour or 1
  632. msgRet.diamond = minHour * DIAMOND_COST_PER_HOUR
  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. len = 0
  639. idx = idx + 1
  640. msgRet = Msg.gc.GC_BATTLE_HANG_QUERY
  641. end
  642. len = len + 1
  643. Grid.makeItem(msgRet.items[len], equipGrid.id, 1, nil, equipGrid)
  644. end
  645. end
  646. msgRet.isEnd = 1
  647. msgRet.index = idx
  648. msgRet.items[0] = len
  649. msgRet.maxTime = maxHangTime
  650. if maxHangTime >= outSec then
  651. msgRet.time = outSec
  652. else
  653. msgRet.time = maxHangTime
  654. end
  655. local minHour = math.floor(msgRet.time / HOUR_SEC)
  656. minHour = (minHour ~= 0) and minHour or 1
  657. msgRet.diamond = minHour * DIAMOND_COST_PER_HOUR
  658. msgRet.exp = nodeConfig.hangExp
  659. msgRet.jinbi = nodeConfig.hangJinbi
  660. msgRet.greenExp = nodeConfig.hangGreenExp
  661. msgRet.qingbao = nodeConfig.hangQingbao or 0
  662. Msg.send(msgRet, human.fd)
  663. end
  664. local function isChapterDot(human, mapID)
  665. local chapterReward = human.db.chapterReward or { }
  666. if chapterReward[mapID] then
  667. return false
  668. end
  669. local battleID = human.db.battleID
  670. local battleNodeConfig = BattleExcel.node[battleID]
  671. if not battleNodeConfig then
  672. if battleID == #BattleExcel.node + 1 then
  673. return true
  674. else
  675. return false
  676. end
  677. else
  678. local roleMapId = battleNodeConfig.mapID
  679. if roleMapId <= mapID then
  680. return false
  681. end
  682. end
  683. return true
  684. end
  685. function battleWorldMapQuery(human)
  686. local msgRet = Msg.gc.GC_BATTLE_WORLD_MAP_QUERY
  687. local worldMapConfig = BattleExcel.map
  688. local battleID = human.db.battleID > #BattleExcel.node and #BattleExcel.node or human.db.battleID
  689. local battleNodeConfig = BattleExcel.node[battleID]
  690. local len = #worldMapConfig
  691. for i = 1, len do
  692. local v = worldMapConfig[i]
  693. msgRet.worldMap[i].mapID = i
  694. msgRet.worldMap[i].mapName = v.name or ""
  695. msgRet.worldMap[i].mapBuild = v.build or 0
  696. msgRet.worldMap[i].mapBg = v.bg or 0
  697. msgRet.worldMap[i].mapPos[0] = 2
  698. msgRet.worldMap[i].mapPos[1] = v.pos[1]
  699. msgRet.worldMap[i].mapPos[2] = v.pos[2]
  700. msgRet.worldMap[i].status =(battleNodeConfig.mapID >= i) and 1 or 0
  701. msgRet.worldMap[i].story = v.des or ""
  702. if battleNodeConfig.mapID == i then
  703. msgRet.worldMap[i].maxLevel = battleNodeConfig.maxLevel
  704. msgRet.worldMap[i].curLevel = battleNodeConfig.curLevel
  705. else
  706. msgRet.worldMap[i].maxLevel = 0
  707. msgRet.worldMap[i].curLevel = 0
  708. end
  709. local reward = v.reward
  710. local l = 0
  711. msgRet.worldMap[i].chapterReward[0] = #reward
  712. for _, rewardData in pairs(reward) do
  713. l = l + 1
  714. Grid.makeItem(msgRet.worldMap[i].chapterReward[l], rewardData[1], rewardData[2])
  715. end
  716. msgRet.worldMap[i].chapterDot = 0
  717. if isChapterDot(human, i) then
  718. msgRet.worldMap[i].chapterDot = 1
  719. end
  720. local cnt = 0
  721. BATTLE_LEVEL_PLAYER_LIST[i] = BATTLE_LEVEL_PLAYER_LIST[i] or { }
  722. for s, t in pairs(BATTLE_LEVEL_PLAYER_LIST[i]) do
  723. cnt = cnt + 1
  724. RoleLogic.makeRoleBase(t, msgRet.worldMap[i].roleList[cnt])
  725. if cnt >= 3 then
  726. break
  727. end
  728. end
  729. msgRet.worldMap[i].roleList[0] = cnt
  730. end
  731. msgRet.worldMap[0] = len
  732. Msg.send(msgRet, human.fd)
  733. end
  734. function battleNodeQuery(human, mapID)
  735. local msgRet = Msg.gc.GC_BATTLE_NODE_QUERY
  736. local nodeConfig = BattleExcel.node
  737. local lenConfig = #nodeConfig
  738. local len = 0
  739. msgRet.battleID = human.db.battleID or 0
  740. for i = 1, lenConfig do
  741. local v = nodeConfig[i]
  742. if v.mapID == mapID then
  743. len = len + 1
  744. msgRet.nodeInfo[len].nodeName = v.name
  745. msgRet.nodeInfo[len].battleID = i
  746. msgRet.nodeInfo[len].needLv = v.needLv
  747. msgRet.nodeInfo[len].needZDL = v.needZDL
  748. msgRet.nodeInfo[len].hasSuipian = v.hasSuipian
  749. end
  750. end
  751. msgRet.nodeInfo[0] = len
  752. Msg.send(msgRet, human.fd)
  753. end
  754. function initBattleOut(human, now)
  755. if human.db.battleOut then
  756. return
  757. end
  758. human.db.battleOut = { }
  759. human.db.battleOut.expTs1 = now
  760. -- 经验开始产出时间戳
  761. human.db.battleOut.expTs2 = now
  762. -- 经验产出结算时间戳
  763. human.db.battleOut.itemTs1 = now
  764. -- 道具产出时间戳
  765. human.db.battleOut.itemTs2 = now
  766. -- 道具产出结算时间戳
  767. human.db.battleOut.exp = 0
  768. human.db.battleOut.jinbi = 0
  769. human.db.battleOut.greenExp = 0
  770. human.db.battleOut.qingbao = 0
  771. human.db.battleOut.items = nil
  772. -- 产出的待收获的战利品
  773. human.db.battleOut.equip = nil
  774. -- 产出的待收获的装备
  775. end
  776. function calcBattleOut(human,isDiamond)
  777. local now = os.time()
  778. initBattleOut(human, now)
  779. calcBattleExpOut(human, now)
  780. calcBattleItemOut(human, now)
  781. if isDiamond then -- 钻石消耗 所有产出翻1.5倍
  782. human.db.battleOut.exp = math.floor(human.db.battleOut.exp * DIAMOND_ADDITION)
  783. human.db.battleOut.jinbi = math.floor(human.db.battleOut.jinbi * DIAMOND_ADDITION)
  784. human.db.battleOut.greenExp = math.floor(human.db.battleOut.greenExp * DIAMOND_ADDITION)
  785. human.db.battleOut.qingbao = math.floor(human.db.battleOut.qingbao * DIAMOND_ADDITION)
  786. local items = human.db.battleOut.items or {}
  787. for id,cnt in pairs(items) do
  788. items[id] = math.floor(cnt * DIAMOND_ADDITION)
  789. end
  790. local equipList = human.db.battleOut.equip or {}
  791. local equipMap = {}
  792. for _,equip in ipairs(equipList) do
  793. equipMap[equip.id] = equipMap[equip.id] or 0
  794. equipMap[equip.id] = equipMap[equip.id] + 1
  795. end
  796. for id,cnt in pairs(equipMap) do
  797. local count = math.floor(cnt * DIAMOND_ADDITION)
  798. for i = cnt,count do
  799. local equipGrid = EquipLogic.makeEquip(id)
  800. equipList[#equipList + 1] = equipGrid
  801. end
  802. end
  803. end
  804. end
  805. -- 获取正确的剩余可收益的结算时间
  806. function getSurMaxHangTime(maxHangTime, ts1, now)
  807. if ts1 + maxHangTime > now then
  808. return now
  809. else
  810. return ts1 + maxHangTime
  811. end
  812. end
  813. function calcBattleExpOut(human, now)
  814. local maxHangTime = getHangMaxTime(human)
  815. if human.db.battleOut.expTs2 - human.db.battleOut.expTs1 >= maxHangTime then
  816. return
  817. end
  818. local outTime = getSurMaxHangTime(maxHangTime, human.db.battleOut.expTs1, now)
  819. local outSec = outTime - human.db.battleOut.expTs2
  820. local outCnt = math.floor(outSec / BATTLE_HANG_EXP_OUT_PERIOD)
  821. if outCnt < 1 then
  822. return
  823. end
  824. local guajiID = human.db.guajiID > #BattleExcel.node and #BattleExcel.node or human.db.guajiID
  825. if guajiID == 0 then
  826. return
  827. end
  828. local nowNodeConfig = BattleExcel.node[guajiID]
  829. human.db.battleOut.expTs2 = human.db.battleOut.expTs2 + outCnt * BATTLE_HANG_EXP_OUT_PERIOD
  830. if now - human.db.battleOut.expTs1 >= maxHangTime then
  831. human.db.battleOut.expTs2 = now
  832. end
  833. local vipExpAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER7) or 0) / 100
  834. local vipJinAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER8) or 0) / 100
  835. local vipGreenExpAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER9) or 0) / 100
  836. local vipQingbaoAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER19) or 0) / 100
  837. local exp = nowNodeConfig.hangExp
  838. local jinbi = nowNodeConfig.hangJinbi
  839. local greenExp = nowNodeConfig.hangGreenExp
  840. local qingbao = nowNodeConfig.hangQingbao
  841. human.db.battleOut.exp = human.db.battleOut.exp + math.floor(outCnt * exp *(1 + vipExpAdd))
  842. human.db.battleOut.jinbi = human.db.battleOut.jinbi + math.floor(outCnt * jinbi *(1 + vipJinAdd))
  843. human.db.battleOut.greenExp = human.db.battleOut.greenExp + math.floor(outCnt * greenExp *(1 + vipGreenExpAdd))
  844. human.db.battleOut.qingbao = human.db.battleOut.qingbao + math.floor(outCnt * qingbao *(1 + vipQingbaoAdd))
  845. end
  846. -- 根据时间计算道具产出
  847. local ITEM_OUT_LIST = { }
  848. function getItemOutsByTime(config, sec)
  849. Util.cleanTable(ITEM_OUT_LIST)
  850. local outCnt = math.floor(sec / BATTLE_HANG_ITEM_OUT_PERIOD)
  851. if outCnt < 1 then
  852. return ITEM_OUT_LIST
  853. end
  854. -- 普通掉落
  855. local dropID = config.dropID
  856. local dropConfig = DropExcel.dropBattle[dropID]
  857. local weightSum = 0
  858. for i = 1, #dropConfig.dropRule do
  859. local tempConfig = dropConfig.dropRule[i]
  860. weightSum = weightSum + tempConfig[4]
  861. end
  862. for i = 1, outCnt do
  863. local itemID, itemCnt = randItemOut(dropConfig.dropRule, weightSum)
  864. if itemCnt and itemCnt > 0 then
  865. ITEM_OUT_LIST[itemID] =(ITEM_OUT_LIST[itemID] or 0) + itemCnt
  866. end
  867. end
  868. for i = 1, #dropConfig.dropRule2 do
  869. local tempConfig = dropConfig.dropRule2[i]
  870. local itemID = tempConfig[1]
  871. local itemMin = tempConfig[2]
  872. local itemMax = tempConfig[3]
  873. local itemCnt = math.random(itemMin, itemMax) * outCnt
  874. if itemCnt > 0 then
  875. ITEM_OUT_LIST[itemID] =(ITEM_OUT_LIST[itemID] or 0) + itemCnt
  876. end
  877. end
  878. -- 三小时掉落
  879. outCnt = math.floor(sec / BATTLE_HANG_ITEM_OUT_PERIOD_2)
  880. if outCnt < 1 then
  881. return ITEM_OUT_LIST
  882. end
  883. weightSum = 0
  884. for i = 1, #dropConfig.dropRule3 do
  885. local tempConfig = dropConfig.dropRule3[i]
  886. weightSum = weightSum + tempConfig[4]
  887. end
  888. for i = 1, outCnt do
  889. local itemID, itemCnt = randItemOut(dropConfig.dropRule3, weightSum)
  890. if itemCnt and itemCnt > 0 then
  891. ITEM_OUT_LIST[itemID] =(ITEM_OUT_LIST[itemID] or 0) + itemCnt
  892. end
  893. end
  894. return ITEM_OUT_LIST
  895. end
  896. function calcBattleItemOut(human, now,isDiamond)
  897. local maxHangTime = getHangMaxTime(human)
  898. if human.db.battleOut.itemTs2 - human.db.battleOut.itemTs1 >= maxHangTime then
  899. return
  900. end
  901. local outTime = getSurMaxHangTime(maxHangTime, human.db.battleOut.itemTs1, now)
  902. local outSec = outTime - human.db.battleOut.itemTs2
  903. local outCnt = math.floor(outSec / BATTLE_HANG_ITEM_OUT_PERIOD)
  904. if outCnt < 1 then
  905. return
  906. end
  907. local guajiID = human.db.guajiID > #BattleExcel.node and #BattleExcel.node or human.db.guajiID
  908. if guajiID == 0 then
  909. return
  910. end
  911. local sec = outCnt * BATTLE_HANG_ITEM_OUT_PERIOD
  912. human.db.battleOut.itemTs2 = human.db.battleOut.itemTs2 + sec
  913. if now - human.db.battleOut.itemTs1 >= maxHangTime then
  914. human.db.battleOut.itemTs2 = now
  915. end
  916. local nodeConfig = BattleExcel.node[guajiID]
  917. local items = getItemOutsByTime(nodeConfig, sec)
  918. for itemID, itemCnt in pairs(items) do
  919. -- 判定是否是装备
  920. if ItemDefine.isEquip(itemID) then
  921. -- 生成装备
  922. local equipGrid = EquipLogic.makeEquip(itemID)
  923. if equipGrid then
  924. human.db.battleOut.equip = human.db.battleOut.equip or { }
  925. human.db.battleOut.equip[#human.db.battleOut.equip + 1] = equipGrid
  926. end
  927. else
  928. human.db.battleOut.items = human.db.battleOut.items or { }
  929. human.db.battleOut.items[itemID] = human.db.battleOut.items[itemID] or 0
  930. human.db.battleOut.items[itemID] = human.db.battleOut.items[itemID] + itemCnt
  931. end
  932. end
  933. DropExchangeLogic.getDropItem(human, outSec, BATTLE_HANG_ITEM_OUT_PERIOD, human.db.battleOut)
  934. end
  935. local function hangExpGet(human,isDiamond)
  936. local needDiamond = 0
  937. -- 是否消耗钻石
  938. if isDiamond then
  939. local now = os.time()
  940. local outSec = now - human.db.battleOut.expTs1
  941. local maxHangTime = getHangMaxTime(human)
  942. outSec = outSec > maxHangTime and maxHangTime or outSec
  943. local minHour = math.floor(outSec / HOUR_SEC)
  944. minHour = (minHour ~= 0) and minHour or 1
  945. local diamondCnt = minHour * DIAMOND_COST_PER_HOUR
  946. if not ObjHuman.checkRMB(human,diamondCnt) then
  947. return
  948. end
  949. needDiamond = -diamondCnt
  950. end
  951. print("==================== needDiamond is ",needDiamond)
  952. calcBattleOut(human,isDiamond)
  953. if human.db.battleOut.exp == 0 then
  954. return 1
  955. end
  956. local jinbiAdd = human.db.battleOut.jinbi
  957. if not ObjHuman.canAddJinbi(human, jinbiAdd) then
  958. return 2
  959. end
  960. -- 检测装备数量
  961. if human.db.battleOut.equip then
  962. local equipCnt = #human.db.battleOut.equip
  963. if not EquipLogic.checkEmptyCnt(human, equipCnt) then
  964. return
  965. end
  966. end
  967. local items = { }
  968. local len = #items
  969. local maxHangTime = getHangMaxTime(human)
  970. if human.db.battleOut.expTs2 - human.db.battleOut.expTs1 >= maxHangTime then
  971. local now = os.time()
  972. human.db.battleOut.expTs2 = now
  973. end
  974. if human.db.battleOut.itemTs2 - human.db.battleOut.itemTs1 >= maxHangTime then
  975. local now = os.time()
  976. human.db.battleOut.itemTs2 = now
  977. end
  978. human.db.battleOut.itemTs1 = human.db.battleOut.itemTs2
  979. -- 改db
  980. local tempTable = human.db.battleOut.items or { }
  981. human.db.battleOut.items = nil
  982. for k, v in pairs(tempTable) do
  983. len = len + 1
  984. items[len] = { }
  985. items[len].id = k
  986. items[len].cnt = v
  987. end
  988. human.db.battleOut.expTs1 = human.db.battleOut.expTs2
  989. local expAdd = human.db.battleOut.exp
  990. local greenExpAdd = human.db.battleOut.greenExp
  991. local qingbaoAdd = human.db.battleOut.qingbao
  992. -- 新手指引 强制经验
  993. local flag = GuideLogic.getGuideSkip(human, GuideLogic.SKIPTYPE_JUMP_BATTLE_EXP)
  994. if not flag then
  995. expAdd = 1510
  996. end
  997. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_BATTLE_EXP)
  998. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_BATTLE_GUAJI)
  999. human.db.battleOut.exp = 0
  1000. human.db.battleOut.jinbi = 0
  1001. human.db.battleOut.greenExp = 0
  1002. human.db.battleOut.qingbao = 0
  1003. len = len + 1
  1004. items[len] = { }
  1005. items[len].id = ItemDefine.ITEM_EXP_ID
  1006. items[len].cnt = expAdd
  1007. len = len + 1
  1008. items[len] = { }
  1009. items[len].id = ItemDefine.ITEM_JINBI_ID
  1010. items[len].cnt = jinbiAdd
  1011. len = len + 1
  1012. items[len] = { }
  1013. items[len].id = ItemDefine.ITEM_GREEN_EXP_ID
  1014. items[len].cnt = greenExpAdd
  1015. len = len + 1
  1016. items[len] = { }
  1017. items[len].id = ItemDefine.ITEM_QINGBAO_ID
  1018. items[len].cnt = qingbaoAdd
  1019. -- 给道具
  1020. for i = 1, #items do
  1021. local tempID = items[i].id
  1022. local tempCnt = items[i].cnt
  1023. BagLogic.addItem(human, tempID, tempCnt, "battle")
  1024. end
  1025. -- 给装备
  1026. if human.db.battleOut.equip then
  1027. for k, equipGrid in ipairs(human.db.battleOut.equip) do
  1028. EquipLogic.addByEquipGrid(human, equipGrid, "battle", true)
  1029. end
  1030. human.db.battleOut.equip = nil
  1031. end
  1032. if needDiamond < 0 then
  1033. ObjHuman.decZuanshi(human,needDiamond,"battle")
  1034. end
  1035. return 0, items
  1036. end
  1037. -- 获取挂机收益
  1038. function hangGet(human,isDiamond)
  1039. local ret, items = hangExpGet(human,false)
  1040. if ret == 1 then
  1041. return Broadcast.sendErr(human, Lang.BATTLE_HANG_GET_EXP_ERR_NONE)
  1042. elseif ret == 2 then
  1043. return Broadcast.sendErr(human, Lang.COMMON_ADD_JINBI_LIMIT)
  1044. elseif ret == 0 then
  1045. query(human)
  1046. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1101)
  1047. end
  1048. end
  1049. -- 挂机节点设置
  1050. function nodeSet(human, battleID)
  1051. local nodeConfig = BattleExcel.node[battleID]
  1052. if nodeConfig == nil then
  1053. return
  1054. end
  1055. -- 前置条件判断
  1056. if battleID > human.db.battleID then
  1057. return Broadcast.sendErr(human, Lang.BATTLE_ID_OVER)
  1058. end
  1059. -- 等级判断
  1060. if human.db.lv < nodeConfig.needLv then
  1061. return Broadcast.sendErr(human, Util.format(Lang.ROLE_LEV_ERROR, nodeConfig.needLv))
  1062. end
  1063. calcBattleOut(human)
  1064. human.db.guajiID = battleID
  1065. setBattleID(human, battleID)
  1066. Msg.send(Msg.gc.GC_BATTLE_NODE_SET, human.fd)
  1067. query(human)
  1068. end
  1069. -- 挂机节点详细信息查询
  1070. function nodeDetailQuery(human, battleID)
  1071. local nodeConfig = BattleExcel.node[battleID]
  1072. if nodeConfig == nil then
  1073. return
  1074. end
  1075. local msgRet = Msg.gc.GC_BATTLE_NODE_DETAIL_QUERY
  1076. msgRet.battleID = battleID
  1077. msgRet.exp = nodeConfig.hangExp
  1078. msgRet.jinbi = nodeConfig.hangJinbi
  1079. msgRet.greenExp = nodeConfig.hangGreenExp
  1080. msgRet.qingbao = nodeConfig.hangQingbao or 0
  1081. msgRet.nodeName = getBattleName(battleID)
  1082. local dropID = nodeConfig.dropID
  1083. local dropConfig = DropExcel.dropBattle[dropID]
  1084. local dropCnt = 0
  1085. local list = DropExchangeLogic.getAbsCanDrop(human)
  1086. if list then
  1087. for k, v in pairs(list) do
  1088. dropCnt = dropCnt + 1
  1089. Grid.makeItem(msgRet.items[dropCnt], k, v)
  1090. end
  1091. end
  1092. for i = 1, #dropConfig.dropRule do
  1093. local tempConfig = dropConfig.dropRule[i]
  1094. local itemID = tempConfig[1]
  1095. local itemCnt = tempConfig[3]
  1096. local itemRate = tempConfig[4]
  1097. if itemCnt > 0 and itemRate > 0 then
  1098. dropCnt = dropCnt + 1
  1099. Grid.makeItem(msgRet.items[dropCnt], itemID, 1)
  1100. end
  1101. end
  1102. for i = 1, #dropConfig.dropRule3 do
  1103. local tempConfig = dropConfig.dropRule3[i]
  1104. local itemID = tempConfig[1]
  1105. local itemCnt = tempConfig[3]
  1106. local itemRate = tempConfig[4]
  1107. if itemCnt > 0 and itemRate > 0 then
  1108. dropCnt = dropCnt + 1
  1109. Grid.makeItem(msgRet.items[dropCnt], itemID, 1)
  1110. end
  1111. end
  1112. msgRet.items[0] = dropCnt
  1113. Msg.send(msgRet, human.fd)
  1114. end
  1115. -- 挑战当前挂机节点
  1116. function fight(human)
  1117. local battleID = human.db.battleID
  1118. if BattleExcel.node[human.db.battleID] == nil then
  1119. local msgRet = Msg.gc.GC_BATTLE_GOBACK_MAIN
  1120. msgRet.panelIDs[0] = 1
  1121. msgRet.panelIDs[1] = PanelDefine.PANEL_ID_1008
  1122. Msg.send(msgRet, human.fd)
  1123. return Broadcast.sendErr(human, Lang.BATTLE_MAX_LEVEL)
  1124. end
  1125. if human.db.lv < BattleExcel.node[human.db.battleID].needLv then
  1126. local msgRet = Msg.gc.GC_BATTLE_GOBACK_MAIN
  1127. msgRet.panelIDs[0] = 1
  1128. msgRet.panelIDs[1] = PanelDefine.PANEL_ID_1008
  1129. Msg.send(msgRet, human.fd)
  1130. return Broadcast.sendErr(human, Util.format(Lang.ROLE_LEV_ERROR, BattleExcel.node[human.db.battleID].needLv))
  1131. end
  1132. local config = BattleExcel.node[battleID]
  1133. local mapConfig = BattleExcel.map[config.mapID]
  1134. local monsterOutID = config.monsterOutID
  1135. local mapID = mapConfig.bg
  1136. CombatLogic.combatBegin(human, config.sceneID, monsterOutID, CombatDefine.COMBAT_TYPE1, battleID)
  1137. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_BATTLE)
  1138. end
  1139. function onFightEnd(human, result, fightTypeID, param1, combatInfo)
  1140. -- 设置一些战斗结算信息
  1141. combatInfo.defender.name = Util.format(Lang.COMBAT_BATTLE_DEFEND_NAME, param1)
  1142. if CombatDefine.RESULT_WIN ~= result then
  1143. return
  1144. end
  1145. local guajiID = human.db.guajiID
  1146. local battleID = human.db.battleID
  1147. if battleID ~= param1 then
  1148. return
  1149. end
  1150. local oldGuajiID = guajiID
  1151. local nextGuajiID = guajiID + 1
  1152. local nextBattleID = battleID + 1
  1153. local nextBattleConfig = BattleExcel.node[nextBattleID]
  1154. local config = BattleExcel.node[battleID]
  1155. -- 如果过大关卡
  1156. if nextBattleConfig and nextBattleConfig.mapID ~= config.mapID then
  1157. -- 清除记录
  1158. BATTLE_LEVEL_PLAYER_LIST[config.mapID] = BATTLE_LEVEL_PLAYER_LIST[config.mapID] or { }
  1159. BATTLE_LEVEL_PLAYER_LIST[config.mapID][human.db._id] = nil
  1160. -- 增加新纪录
  1161. BATTLE_LEVEL_PLAYER_LIST[nextBattleConfig.mapID] = BATTLE_LEVEL_PLAYER_LIST[nextBattleConfig.mapID] or { }
  1162. BATTLE_LEVEL_PLAYER_LIST[nextBattleConfig.mapID][human.db._id] = { }
  1163. RoleLogic.getRoleBase(human, BATTLE_LEVEL_PLAYER_LIST[nextBattleConfig.mapID][human.db._id])
  1164. else
  1165. if config.mapID == 1 then
  1166. BATTLE_LEVEL_PLAYER_LIST[config.mapID] = BATTLE_LEVEL_PLAYER_LIST[config.mapID] or { }
  1167. if BATTLE_LEVEL_PLAYER_LIST[config.mapID][human.db._id] == nil then
  1168. -- 增加新纪录
  1169. BATTLE_LEVEL_PLAYER_LIST[config.mapID][human.db._id] = { }
  1170. RoleLogic.getRoleBase(human, BATTLE_LEVEL_PLAYER_LIST[config.mapID][human.db._id])
  1171. end
  1172. else
  1173. if not BATTLE_LEVEL_PLAYER_LIST[config.mapID] or not BATTLE_LEVEL_PLAYER_LIST[config.mapID][human.db._id] then
  1174. BATTLE_LEVEL_PLAYER_LIST[config.mapID] = BATTLE_LEVEL_PLAYER_LIST[config.mapID] or { }
  1175. BATTLE_LEVEL_PLAYER_LIST[config.mapID][human.db._id] = { }
  1176. RoleLogic.getRoleBase(human, BATTLE_LEVEL_PLAYER_LIST[config.mapID][human.db._id])
  1177. end
  1178. end
  1179. end
  1180. human.db.battleID = battleID + 1
  1181. -- 通过第10关,默认开启二倍速
  1182. if human.db.battleID == 10 then
  1183. human.db.combatSpeed = 2
  1184. end
  1185. combatInfo.attacker.oldLv = human.db.lv
  1186. -- 给奖励
  1187. combatInfo.rewardItem = { }
  1188. for i = 1, #config.winReward do
  1189. local itemID = config.winReward[i][1]
  1190. local itemCnt = config.winReward[i][2]
  1191. -- 装备不在这显示
  1192. combatInfo.rewardItem[i] = combatInfo.rewardItem[i] or { }
  1193. combatInfo.rewardItem[i] = { itemID, itemCnt }
  1194. BagLogic.addItem(human, itemID, itemCnt, "battle_win")
  1195. end
  1196. combatInfo.attacker.lv = human.db.lv
  1197. combatInfo.getEquip = human.getEquip
  1198. human.getEquip = nil
  1199. -- TODO:记录主线关卡
  1200. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, human.db._id, human.db.account, human.db.name, human.db.battleID)
  1201. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1101)
  1202. GuideLogic.onCallback(human)
  1203. JibanLogic.onCallback(human, 1, battleID)
  1204. TuiSongLiBao.tuiSongLiBaoOnTask(
  1205. human,
  1206. TuiSongLiBao.TUISONGLIBAOTASK_ZHENGZHAN,
  1207. human.db.guajiID - 1,
  1208. human.db.guajiID - 2
  1209. )
  1210. ChengjiuLogic.onCallback(human, ChengjiuDefine.CJ_TASK_TYPE_1, nextGuajiID)
  1211. MengxinLogic.onCallBack(human, MengxinLogic.MX_TASK_TYPE_1, nextGuajiID)
  1212. for k, v in pairs(KingWorldLogic.funcID) do
  1213. YunYingLogic.updateIcon(KingWorldLogic.YYInfo[k], human)
  1214. break
  1215. end
  1216. -- 存储战斗记录
  1217. local videoUuid = CombatVideo.saveBattleVideo(human.db._id, combatInfo)
  1218. human.db.battleVideoUuid = videoUuid
  1219. BattleDBLogic.updateBattleDB(combatInfo.attacker, battleID, combatInfo, videoUuid)
  1220. if nextBattleConfig and nextBattleConfig.mapID ~= config.mapID then
  1221. -- 新的地图
  1222. -- 通知客户端
  1223. Msg.send(Msg.gc.GC_BATTLE_NODE_SET, human.fd)
  1224. end
  1225. human.db.guajiID = nextGuajiID
  1226. if nextBattleConfig then
  1227. setBattleID(human, nextGuajiID)
  1228. end
  1229. local showNext = 1
  1230. if BattleExcel.node[human.db.battleID] and human.db.lv < BattleExcel.node[human.db.battleID].needLv then
  1231. showNext = 2
  1232. end
  1233. if human.db.lv < 5 then
  1234. showNext = 0
  1235. end
  1236. nextBattleConfig = BattleExcel.node[human.db.battleID]
  1237. if not nextBattleConfig then
  1238. showNext = 0
  1239. end
  1240. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1105)
  1241. -- 额外奖励
  1242. local needLevel, itemName = getNextRewardName(human)
  1243. if needLevel ~= nil then
  1244. local tb = { needLevel, Lang.BATTLE_FIGHT_GUAN, "|", itemName, "|", showNext }
  1245. local str = table.concat(tb)
  1246. combatInfo.endParam = str
  1247. else
  1248. local tb = { showNext }
  1249. local str = table.concat(tb)
  1250. combatInfo.endParam = str
  1251. end
  1252. -- 触发事件
  1253. --GiftLogic.trigger(human,PRINCIPAL_LINE_EVNET,{id = battleID})
  1254. WarOrder.trigger(human,BATTLE_ORDER_TYPE)
  1255. end
  1256. function setBattleID(human, guajiID)
  1257. if guajiID > human.db.guajiID and human.db.guajiID ~= 0 then
  1258. -- 下发挂机收益升级提示
  1259. local msgRet = Msg.gc.GC_BATTLE_REWARD_UP
  1260. Grid.makeItem(msgRet.itemExp, ItemDefine.ITEM_EXP_ID, 1)
  1261. Grid.makeItem(msgRet.itemJinbi, ItemDefine.ITEM_JINBI_ID, 1)
  1262. Grid.makeItem(msgRet.itemGreenExp, ItemDefine.ITEM_GREEN_EXP_ID, 1)
  1263. Grid.makeItem(msgRet.itemQingbao, ItemDefine.ITEM_QINGBAO_ID, 1)
  1264. local oldConfig = BattleExcel.node[human.db.guajiID]
  1265. local newConfig = BattleExcel.node[guajiID]
  1266. msgRet.expOld = oldConfig.hangExp
  1267. msgRet.expNew = newConfig.hangExp
  1268. msgRet.jinbiOld = oldConfig.hangJinbi
  1269. msgRet.jinbiNew = newConfig.hangJinbi
  1270. msgRet.greenExpOld = oldConfig.hangGreenExp
  1271. msgRet.greenExpNew = newConfig.hangGreenExp
  1272. msgRet.qingbaoOld = oldConfig.hangQingbao
  1273. msgRet.qingbaoNew = newConfig.hangQingbao
  1274. Msg.send(msgRet, human.fd)
  1275. end
  1276. -- 刷新排行榜
  1277. BRoleLogic.updateData(BillboardDefine.TYPE_BATTLE, human.db)
  1278. end
  1279. -- GM
  1280. function setBattleByGm(human, val, maxBattleID)
  1281. val = tonumber(val)
  1282. if not val or val <= 1 then
  1283. return
  1284. end
  1285. local nodeConfig = BattleExcel.node[val]
  1286. if not nodeConfig then
  1287. return
  1288. end
  1289. if maxBattleID then
  1290. maxBattleID = tonumber(maxBattleID)
  1291. else
  1292. maxBattleID = val
  1293. end
  1294. setBattleID(human, val)
  1295. human.db.battleID = val
  1296. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1105)
  1297. end
  1298. function mopupQuery(human)
  1299. ObjHuman.updateDaily(human)
  1300. local msgRet = Msg.gc.GC_BATTLE_MOPUP_QUERY
  1301. local guajiID = human.db.guajiID > #BattleExcel.node and #BattleExcel.node or human.db.guajiID
  1302. if guajiID == 0 then
  1303. return Broadcast.sendErr(human, Lang.BATTLE_MOPUP_ERR)
  1304. end
  1305. human.db.mopupDoCnt = human.db.mopupDoCnt or 0
  1306. local nextDoCnt = human.db.mopupDoCnt + 1
  1307. local nodeConfig = BattleExcel.node[guajiID]
  1308. local dropID = nodeConfig.dropID
  1309. local dropConfig = DropExcel.dropBattle[dropID]
  1310. local dropCnt = 0
  1311. -- ABS掉落活动显示到第一个
  1312. dropCnt = DropExchangeLogic.getDropItemSaoQuery(human, msgRet, dropCnt)
  1313. for i = 1, #dropConfig.dropRule do
  1314. if dropCnt >= #msgRet.item then
  1315. break
  1316. end
  1317. dropCnt = dropCnt + 1
  1318. local tempConfig = dropConfig.dropRule[i]
  1319. local itemID = tempConfig[1]
  1320. Grid.makeItem(msgRet.item[dropCnt], itemID, 1)
  1321. end
  1322. for i = 1, #dropConfig.dropRule3 do
  1323. if dropCnt >= #msgRet.item then
  1324. break
  1325. end
  1326. dropCnt = dropCnt + 1
  1327. local tempConfig = dropConfig.dropRule3[i]
  1328. local itemID = tempConfig[1]
  1329. Grid.makeItem(msgRet.item[dropCnt], itemID, 1)
  1330. end
  1331. local mapConfig = BattleExcel.map[nodeConfig.mapID]
  1332. msgRet.name = mapConfig.name
  1333. msgRet.item[0] = dropCnt
  1334. if TequanShopLogic.isActiveMopup(human) then
  1335. msgRet.leftCnt = BATTLE_MOPUP_CNT_VIP - human.db.mopupDoCnt
  1336. else
  1337. msgRet.leftCnt = BATTLE_MOPUP_CNT - human.db.mopupDoCnt
  1338. end
  1339. local mupopExcel = BattleExcel.mupop[nextDoCnt]
  1340. if mupopExcel then
  1341. if not TequanShopLogic.isActiveMopup(human) then
  1342. msgRet.need = mupopExcel.cost
  1343. if human.db.mopupFreeCnt < BATTLE_MOPUP_FREE_CNT then
  1344. msgRet.need = 0
  1345. end
  1346. else
  1347. msgRet.need = mupopExcel.vipCost
  1348. if human.db.mopupFreeCnt < BATTLE_MOPUP_FREE_CNT_VIP then
  1349. msgRet.need = 0
  1350. end
  1351. end
  1352. else
  1353. msgRet.need = 0
  1354. end
  1355. msgRet.vip = TequanShopLogic.isActiveMopup(human) and 1 or 0
  1356. msgRet.nowCnt = human.db.mopupDoCnt
  1357. msgRet.exp = nodeConfig.hangExp
  1358. msgRet.jinbi = nodeConfig.hangJinbi
  1359. msgRet.greenExp = nodeConfig.hangGreenExp
  1360. msgRet.qingbao = nodeConfig.hangQingbao
  1361. Msg.send(msgRet, human.fd)
  1362. end
  1363. function mopupFight(human)
  1364. -- 等级判断
  1365. ObjHuman.updateDaily(human)
  1366. local need = 0
  1367. human.db.mopupDoCnt = human.db.mopupDoCnt or 0
  1368. human.db.mopupFreeCnt = human.db.mopupFreeCnt or 0
  1369. local nextDoCnt = human.db.mopupDoCnt + 1
  1370. local mupopExcel = BattleExcel.mupop[nextDoCnt]
  1371. if not mupopExcel then
  1372. return Broadcast.sendErr(human, Lang.BATTLE_MOPUP_CNT_OVER)
  1373. end
  1374. if not TequanShopLogic.isActiveMopup(human) then
  1375. if human.db.mopupDoCnt >= BATTLE_MOPUP_CNT then
  1376. return Broadcast.sendErr(human, Lang.BATTLE_MOPUP_CNT_OVER)
  1377. end
  1378. need = mupopExcel.cost
  1379. -- 如果免费次数小于1次,则按免费算
  1380. if human.db.mopupFreeCnt < BATTLE_MOPUP_FREE_CNT then
  1381. need = 0
  1382. end
  1383. else
  1384. if human.db.mopupDoCnt >= BATTLE_MOPUP_CNT_VIP then
  1385. return Broadcast.sendErr(human, Lang.BATTLE_MOPUP_CNT_OVER)
  1386. end
  1387. need = mupopExcel.vipCost
  1388. -- 如果免费次数小于3次,则按免费算
  1389. if human.db.mopupFreeCnt < BATTLE_MOPUP_FREE_CNT_VIP then
  1390. need = 0
  1391. end
  1392. end
  1393. if not ObjHuman.checkRMB(human, need) then
  1394. return
  1395. end
  1396. if need <= 0 then
  1397. human.db.mopupFreeCnt = human.db.mopupFreeCnt + 1
  1398. end
  1399. ObjHuman.decZuanshi(human, - need, "battleMopup")
  1400. local len = #BattleExcel.node
  1401. human.db.mopupDoCnt = human.db.mopupDoCnt + 1
  1402. local guajiID = human.db.guajiID > #BattleExcel.node and #BattleExcel.node or human.db.guajiID
  1403. if guajiID == 0 then
  1404. return Broadcast.sendErr(human, Lang.BATTLE_MOPUP_ERR)
  1405. end
  1406. local config = BattleExcel.node[guajiID]
  1407. local msgRet = Msg.gc.GC_BATTLE_MOPUP_FIGHT
  1408. local vipExpAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER7) or 0) / 100
  1409. local vipJinAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER8) or 0) / 100
  1410. local vipGreenExpAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER9) or 0) / 100
  1411. local vipQingbaoAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER19) or 0) / 100
  1412. local exp = config.hangExp * 120
  1413. local jinbi = config.hangJinbi * 120
  1414. local greenExp = config.hangGreenExp * 120
  1415. local qingbao = config.hangQingbao * 120
  1416. local addExp = math.floor(exp *(1 + vipExpAdd))
  1417. local addJinbi = math.floor(jinbi *(1 + vipJinAdd))
  1418. local addGreenExp = math.floor(greenExp *(1 + vipGreenExpAdd))
  1419. local addQingbao = math.floor(qingbao *(1 + vipQingbaoAdd))
  1420. local time = 7200
  1421. local itemTable = getItemOutsByTime(config, time)
  1422. -- 掉落活动
  1423. DropExchangeLogic.getDropItemSao(human, time, itemTable)
  1424. local flag = GuideLogic.getGuideSkip(human, GuideLogic.SKIPTYPE_JUMP_BATTLE_SD)
  1425. if not flag then
  1426. local equipID = SysParameter.getSysParameter(SysParameter.PARAMETER_10)
  1427. itemTable[equipID] = 1
  1428. end
  1429. itemTable[ItemDefine.ITEM_JINBI_ID] = itemTable[ItemDefine.ITEM_JINBI_ID] or 0
  1430. itemTable[ItemDefine.ITEM_EXP_ID] = itemTable[ItemDefine.ITEM_EXP_ID] or 0
  1431. itemTable[ItemDefine.ITEM_GREEN_EXP_ID] = itemTable[ItemDefine.ITEM_GREEN_EXP_ID] or 0
  1432. itemTable[ItemDefine.ITEM_QINGBAO_ID] = itemTable[ItemDefine.ITEM_QINGBAO_ID] or 0
  1433. itemTable[ItemDefine.ITEM_JINBI_ID] = itemTable[ItemDefine.ITEM_JINBI_ID] + addJinbi
  1434. itemTable[ItemDefine.ITEM_EXP_ID] = itemTable[ItemDefine.ITEM_EXP_ID] + addExp
  1435. itemTable[ItemDefine.ITEM_GREEN_EXP_ID] = itemTable[ItemDefine.ITEM_GREEN_EXP_ID] + addGreenExp
  1436. itemTable[ItemDefine.ITEM_QINGBAO_ID] = itemTable[ItemDefine.ITEM_QINGBAO_ID] + addQingbao
  1437. msgRet.item[0] = 0
  1438. -- 双倍日
  1439. local double = RoleSystemLogic.isDouble(human, RoleSystemDefine.ROLE_SYS_ID_1101)
  1440. local rewardCnt = double and 2 or 1
  1441. for itemID, itemCnt in pairs(itemTable) do
  1442. itemCnt = itemCnt * rewardCnt
  1443. if not ItemDefine.isEquip(itemID) then
  1444. msgRet.item[0] = msgRet.item[0] + 1
  1445. Grid.makeItem(msgRet.item[msgRet.item[0]], itemID, itemCnt)
  1446. end
  1447. BagLogic.addItem(human, itemID, itemCnt, "battle")
  1448. end
  1449. msgRet.item[0] = EquipLogic.makeEquipItem(human, msgRet.item, msgRet.item[0])
  1450. msgRet.double = double and 1 or 0
  1451. msgRet.exp = itemTable[ItemDefine.ITEM_EXP_ID] * rewardCnt
  1452. msgRet.jinbi = itemTable[ItemDefine.ITEM_JINBI_ID] * rewardCnt
  1453. msgRet.greenExp = itemTable[ItemDefine.ITEM_GREEN_EXP_ID] * rewardCnt
  1454. msgRet.qingbao = itemTable[ItemDefine.ITEM_QINGBAO_ID] * rewardCnt
  1455. Msg.send(msgRet, human.fd)
  1456. mopupQuery(human)
  1457. query(human)
  1458. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1101)
  1459. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_BATTLE_SD)
  1460. DailyTaskLogic.recordDailyTaskFinishCnt(human, DailyTaskLogic.DAILY_TASK_ID_12, 1)
  1461. ChengjiuLogic.onCallback(human, ChengjiuDefine.CJ_TASK_TYPE_3, 1)
  1462. HeroLogLogic.finishTaskCB(human, HeroLogLogic.HERO_LOG_TYPE_3, 1)
  1463. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_2001)
  1464. YunYingLogic.onCallBack(human, "onMopup", 1)
  1465. end
  1466. function updateDaily(human)
  1467. human.db.mopupFreeCnt = 0
  1468. human.db.mopupDoCnt = 0
  1469. end
  1470. function getTongGuanReward(human, id)
  1471. local cf = BattleExcel.node[id]
  1472. if not cf then
  1473. return
  1474. end
  1475. if #cf.tongguan < 1 then
  1476. return
  1477. end
  1478. print("human.db.guajiID,id", human.db.guajiID, id)
  1479. if human.db.guajiID < id then
  1480. return
  1481. end
  1482. if isGetReward(human, id) then
  1483. return
  1484. end
  1485. if #cf.tongguan == 1 and cf.tongguan[1][3] then
  1486. -- 英雄
  1487. if HeroLogic.getEmptyCnt(human) < 1 then
  1488. return Broadcast.sendErr(human, Lang.HERO_BAG_FULL)
  1489. end
  1490. local heroID = cf.tongguan[1][1]
  1491. local cnt = cf.tongguan[1][2]
  1492. local star = cf.tongguan[1][3]
  1493. if cnt <= 0 then
  1494. return
  1495. end
  1496. setGetReward(human, id)
  1497. local msg = Msg.gc.GC_SUIPIAN_SUMMON
  1498. for i = 1, cnt do
  1499. local heroGrid = HeroGrid.createHeroGrid(heroID, star)
  1500. HeroLogic.addHeroByGrid(human, heroGrid, "battle_extra_reward")
  1501. SuipianLogic.makeResultItemData(msg.heroList[i], heroID, 1, 1)
  1502. end
  1503. msg.isHero = 1
  1504. msg.list[0] = 0
  1505. msg.heroList[0] = cnt
  1506. msg.fenJieList[0] = 0
  1507. Msg.send(msg, human.fd)
  1508. else
  1509. setGetReward(human, id)
  1510. BagLogic.addItemList(human, cf.tongguan, "tongguan")
  1511. end
  1512. -- 触发国王君临奖励
  1513. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE5, id)
  1514. query(human)
  1515. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1101)
  1516. if id == 80 then
  1517. KingWorldLogic.setState(human, 1)
  1518. end
  1519. end
  1520. function isDot(human)
  1521. -- 通过大关卡奖励
  1522. local chapterReward = human.db.chapterReward or { }
  1523. local battleID = human.db.battleID
  1524. local battleNodeConfig = BattleExcel.node[battleID]
  1525. if not battleNodeConfig then
  1526. local nodeCnt = #BattleExcel.node
  1527. local mapCnt = #BattleExcel.map
  1528. if battleID == nodeCnt + 1 and not chapterReward[mapCnt] then
  1529. return true
  1530. else
  1531. return false
  1532. end
  1533. else
  1534. local mapID = battleNodeConfig.mapID
  1535. for i = mapID - 1, 1, -1 do
  1536. if not chapterReward[i] then
  1537. return true
  1538. end
  1539. end
  1540. end
  1541. return false
  1542. -- if human.db.lv < 9 then
  1543. -- return false
  1544. -- end
  1545. -- -- 有免费扫荡次数的时候有红点
  1546. -- human.db.mopupFreeCnt = human.db.mopupFreeCnt or 0
  1547. -- if TequanShopLogic.isActiveMopup(human) then
  1548. -- if human.db.mopupFreeCnt < 3 then
  1549. -- return true
  1550. -- end
  1551. -- else
  1552. -- if human.db.mopupFreeCnt < 1 then
  1553. -- return true
  1554. -- end
  1555. -- end
  1556. -- -- 有通关奖励可领取的时候有红点
  1557. -- if hasCanGetReward(human) then
  1558. -- return true
  1559. -- end
  1560. -- -- 战役挂机时间超过1小时的时候有红点
  1561. -- if human.db.battleOut ~= nil then
  1562. -- local now = os.time()
  1563. -- local outSec = now - human.db.battleOut.expTs1
  1564. -- if outSec >= 3600 then
  1565. -- return true
  1566. -- end
  1567. -- end
  1568. -- return false
  1569. end
  1570. function clacItemTwoHours(human)
  1571. local items = { }
  1572. local outCnt = math.floor(7200 / BATTLE_HANG_ITEM_OUT_PERIOD)
  1573. local guajiID = human.db.guajiID > #BattleExcel.node and #BattleExcel.node or human.db.guajiID
  1574. if guajiID == 0 then
  1575. return items
  1576. end
  1577. local nodeConfig = BattleExcel.node[guajiID]
  1578. local dropID = nodeConfig.dropID
  1579. local dropConfig = DropExcel.dropBattle[dropID]
  1580. local totalWeight = 0
  1581. for i = 1, #dropConfig.dropRule do
  1582. local tempConfig = dropConfig.dropRule[i]
  1583. totalWeight = totalWeight + tempConfig[4]
  1584. end
  1585. for j = 1, outCnt do
  1586. local randomNum = math.random(1, totalWeight)
  1587. for i = 1, #dropConfig.dropRule do
  1588. local tempConfig = dropConfig.dropRule[i]
  1589. local itemID = tempConfig[1]
  1590. local itemCnt1 = tempConfig[2]
  1591. local itemCnt2 = tempConfig[3]
  1592. local itemRate = tempConfig[4]
  1593. if randomNum <= itemRate then
  1594. local realAdd = math.random(itemCnt1, itemCnt2)
  1595. items[itemID] = realAdd
  1596. break
  1597. end
  1598. randomNum = randomNum - itemRate
  1599. end
  1600. end
  1601. return items
  1602. end
  1603. local MailManager = require("mail.MailManager")
  1604. function clacItemCntGM(human, cnt, guajiID)
  1605. local items = { }
  1606. local outCnt = cnt
  1607. local nodeConfig = BattleExcel.node[guajiID]
  1608. local dropID = nodeConfig.dropID
  1609. local dropConfig = DropExcel.dropBattle[dropID]
  1610. local totalWeight = 0
  1611. for i = 1, #dropConfig.dropRule do
  1612. local tempConfig = dropConfig.dropRule[i]
  1613. totalWeight = totalWeight + tempConfig[4]
  1614. end
  1615. for j = 1, outCnt do
  1616. local randomNum = math.random(1, totalWeight)
  1617. for i = 1, #dropConfig.dropRule do
  1618. local tempConfig = dropConfig.dropRule[i]
  1619. local itemID = tempConfig[1]
  1620. local itemCnt1 = tempConfig[2]
  1621. local itemCnt2 = tempConfig[3]
  1622. local itemRate = tempConfig[4]
  1623. if randomNum <= itemRate then
  1624. local realAdd = math.random(itemCnt1, itemCnt2)
  1625. items[itemID] = items[itemID] or 0
  1626. items[itemID] = items[itemID] + realAdd
  1627. break
  1628. end
  1629. randomNum = randomNum - itemRate
  1630. end
  1631. end
  1632. local item = { }
  1633. local index = 0
  1634. for k, v in pairs(items) do
  1635. index = index + 1
  1636. item[index] = { k, v }
  1637. end
  1638. MailManager.add(MailManager.SYSTEM, human.db._id, "", "", item, "")
  1639. end
  1640. function getBattleID(human)
  1641. local num = 0
  1642. if human.db.guajiID then
  1643. num = human.db.guajiID or 0
  1644. end
  1645. return num
  1646. end
  1647. --------------------------------------------- combat ----------------------------------------------
  1648. function getCombatMonsterOutID(human, side)
  1649. if side ~= CombatDefine.DEFEND_SIDE then
  1650. return
  1651. end
  1652. local config = BattleExcel.node[human.db.battleID]
  1653. if not config then
  1654. return
  1655. end
  1656. return config.monsterOutID
  1657. end
  1658. function getCombatName(human)
  1659. local name = getBattleName(human.db.battleID)
  1660. return Util.format(Lang.COMBAT_BATTLE_EXNAME, name)
  1661. end
  1662. -------------------------------------------combat end--------------------
  1663. function battleSharkQuery(human, nodeID)
  1664. local msgRet = Msg.gc.GC_BATTLE_SHARK_QUERY
  1665. local videoTb = BattleDBLogic.queryBattleDbByNodeID(nodeID)
  1666. if videoTb == nil then
  1667. msgRet.battleShark[0] = 0
  1668. else
  1669. local len = #videoTb.shark
  1670. for i = 1, len do
  1671. local v = videoTb.shark[i]
  1672. RoleLogic.makeRoleBase(v.roleBase, msgRet.battleShark[i].roleBase)
  1673. msgRet.battleShark[i].type = i
  1674. msgRet.battleShark[i].videoUuid = v.videoUuid
  1675. msgRet.battleShark[i].param = v.param or 0
  1676. end
  1677. msgRet.battleShark[0] = len
  1678. end
  1679. -- Msg.trace(msgRet)
  1680. Msg.send(msgRet, human.fd)
  1681. end
  1682. local QueryRoleByNodeID = { }
  1683. function worldMapRoleListQuery(human, worldMapId)
  1684. -- if worldMapId == 1 then return end
  1685. local msgRet = Msg.gc.GC_BATTLE_WORLD_MAP_ROLELIST_QUERY
  1686. local len = 0
  1687. for k, v in pairs(BATTLE_LEVEL_PLAYER_LIST[worldMapId]) do
  1688. len = len + 1
  1689. RoleLogic.makeRoleBase(v, msgRet.roleList[len])
  1690. if len >= 50 then
  1691. break
  1692. end
  1693. end
  1694. msgRet.roleList[0] = len
  1695. Msg.send(msgRet, human.fd)
  1696. end
  1697. -- 章节(地图)掉落列表
  1698. function sendMapDroItemsList(human)
  1699. local battleID = human.db.battleID or 1
  1700. local maxBattleConfig = BattleExcel.node[battleID]
  1701. local maxMapID = maxBattleConfig and maxBattleConfig.mapID or(#BattleExcel.node + 1)
  1702. local msgRet = Msg.gc.GC_BATTLE_MAP_DROPITEMS_LIST
  1703. msgRet.list[0] = 0
  1704. for mapID, mapConfig in ipairs(BattleExcel.map) do
  1705. msgRet.list[0] = msgRet.list[0] + 1
  1706. local net = msgRet.list[msgRet.list[0]]
  1707. net.mapID = mapID
  1708. net.mapName = mapConfig.name
  1709. net.isOpen =(mapID <= maxMapID) and 1 or 0
  1710. end
  1711. -- Msg.trace(msgRet)
  1712. Msg.send(msgRet, human.fd)
  1713. end
  1714. -- 章节(地图)掉落详情
  1715. function sendMapDroItemsDetail(human, mapID)
  1716. local mapConfig = BattleExcel.map[mapID]
  1717. if not mapConfig then
  1718. return
  1719. end
  1720. local msgRet = Msg.gc.GC_BATTLE_MAP_DROPITEMS_DETAIL
  1721. msgRet.mapID = mapID
  1722. msgRet.items[0] = math.min(#mapConfig.dropItemsShow, #msgRet.items)
  1723. for i = 1, msgRet.items[0] do
  1724. local itemID = mapConfig.dropItemsShow[i][1]
  1725. local itemCnt = mapConfig.dropItemsShow[i][2]
  1726. Grid.makeItem(msgRet.items[i], itemID, itemCnt)
  1727. end
  1728. -- Msg.trace(msgRet)
  1729. Msg.send(msgRet, human.fd)
  1730. end
  1731. -- 获取当前战役的 怪物ID
  1732. function getBattleMonsterOutID(human)
  1733. local battleID = human.db.battleID
  1734. local config = BattleExcel.node[battleID]
  1735. return config.monsterOutID
  1736. end
  1737. function onUpdatePos(human)
  1738. BRoleLogic.updateData(BillboardDefine.TYPE_ZHANDOULI, human.db)
  1739. end
  1740. function getNextRewardName(human)
  1741. for i = human.db.guajiID + 1, #BattleExcel.node do
  1742. if #BattleExcel.node[i].tongguan > 0 then
  1743. local itemID = BattleExcel.node[i].tongguan[1][1]
  1744. local itemConfig = ItemDefine.getConfig(itemID)
  1745. if itemConfig == nil then
  1746. return
  1747. else
  1748. return i - human.db.guajiID, itemConfig.name
  1749. end
  1750. end
  1751. end
  1752. end
  1753. --[[
  1754. 通关章节后领取奖励
  1755. ]]
  1756. function battleChapterReward(human, mapID)
  1757. local mapConf = BattleExcel.map[mapID]
  1758. if not mapConf then
  1759. return
  1760. end
  1761. -- 没有通过当前大关卡
  1762. local battleID = human.db.battleID
  1763. local battleNodeConfig = BattleExcel.node[battleID]
  1764. local roleMapId
  1765. if not battleNodeConfig then
  1766. if battleID ~= #BattleExcel.node + 1 then
  1767. return
  1768. else
  1769. roleMapId = #BattleExcel.map
  1770. end
  1771. else
  1772. roleMapId = battleNodeConfig.mapID
  1773. end
  1774. if mapID > roleMapId then
  1775. return
  1776. end
  1777. if not human.db.chapterReward then
  1778. human.db.chapterReward = { }
  1779. end
  1780. -- 判断是否已经领取了当前大关卡的奖励
  1781. local chapterReward = human.db.chapterReward
  1782. if chapterReward[mapID] then
  1783. return Broadcast.sendErr(human, Lang.FRIEND_HEART_GET_HAD)
  1784. end
  1785. human.db.chapterReward[mapID] = true
  1786. ObjHuman.save(human)
  1787. local reward = mapConf.reward
  1788. BagLogic.addItemList(human, reward, "chapterReward")
  1789. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1105)
  1790. local msgRet = Msg.gc.GC_BATTLE_CHAPTER_REWARD
  1791. msgRet.mapID = mapID
  1792. Msg.send(msgRet, human.fd)
  1793. end