BattleLogic.lua 143 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760
  1. local Lang = require("common.Lang")
  2. local BattleExcel = require("excel.battle")
  3. local BattleExcel_Elite = require("excel.battle_elite")
  4. local BattleExcel_Hard = require("excel.battle_hard")
  5. local MonsterExcel = require("excel.monster")
  6. local DropExcel = require("excel.drop")
  7. local Msg = require("core.Msg")
  8. local ObjHuman = require("core.ObjHuman")
  9. local Grid = require("bag.Grid")
  10. local BagLogic = require("bag.BagLogic")
  11. local ItemDefine = require("bag.ItemDefine")
  12. local Broadcast = require("broadcast.Broadcast")
  13. local CombatDefine = require("combat.CombatDefine")
  14. local CombatPosLogic = require("combat.CombatPosLogic")
  15. local CombatLogic = require("combat.CombatLogic")
  16. local DailyTaskLogic = require("dailyTask.DailyTaskLogic")
  17. local RoleDefine = require("role.RoleDefine")
  18. local ChengjiuLogic = require("chengjiu.ChengjiuLogic")
  19. local ChengjiuDefine = require("chengjiu.ChengjiuDefine")
  20. local HeroExcel = require("excel.hero")
  21. local SkillExcel = require("excel.skill")
  22. local MonthactExcel = require("excel.monthAct")
  23. local Util = require("common.Util")
  24. local KingWorldLogic = require("present.KingWorldLogic")
  25. local ChatPaoMaLogic = require("chat.ChatPaoMaLogic")
  26. local BRoleLogic = require("billboard.BRoleLogic")
  27. local BillboardDefine = require("billboard.BillboardDefine")
  28. local SkinLogic = require("skin.SkinLogic")
  29. local RoleSystemLogic = require("roleSystem.RoleSystemLogic")
  30. local RoleSystemDefine = require("roleSystem.RoleSystemDefine")
  31. local GuideLogic = require("guide.GuideLogic")
  32. local PanelDefine = require("broadcast.PanelDefine")
  33. local HeroGrid = require("hero.HeroGrid")
  34. local TuiSongLiBao = require("present.TuiSongLiBao")
  35. local CombatVideo = require("combat.CombatVideo")
  36. local RoleLogic = require("role.RoleLogic")
  37. local BattleDBLogic = require("battle.BattleDBLogic")
  38. local ProjectLogic = require("platform.ProjectLogic")
  39. local LuaMongo = _G.lua_mongo
  40. local DB = require("common.DB")
  41. local VipLogic = require("vip.VipLogic")
  42. local MoshouLogic = require("moshou.MoshouLogic")
  43. local RoleExcel = require("excel.role")
  44. local TequanShopLogic = require("present.TequanShopLogic")
  45. local HeroDefine = require("hero.HeroDefine")
  46. local BarTaskLogic = require("bar.BarTaskLogic")
  47. local ItemExcel = require("excel.item").item
  48. local EquipExcel = require("excel.equip").equip
  49. local HeroLogic = require("hero.HeroLogic")
  50. local SuipianLogic = require("bag.SuipianLogic")
  51. local JibanLogic = require("combat.JibanLogic")
  52. local YunYingLogic = require("yunying.YunYingLogic")
  53. local PanelDefine = require("broadcast.PanelDefine")
  54. local YyHandler = require("yunying.Handler")
  55. local EquipLogic = require("equip.EquipLogic")
  56. local SysParameter = require("common.SysParameter")
  57. local XingYaoGongMing = require("xingYaoMen.XingYaoGongMing")
  58. local AbsActLogic = require("absAct.AbsActLogic")
  59. local HeroLogLogic = require("absAct.HeroLogLogic")
  60. local DropExchangeLogic = require("absAct.DropExchangeLogic")
  61. local MengxinLogic = require("present.MengxinLogic")
  62. local GiftLogic = require("topup.GiftLogic")
  63. local WarOrder = require("shop.WarOrder")
  64. local Log = require("common.Log")
  65. local EliteDefine = require("battle.EliteDefine")
  66. local MaiDianDefine = require("MaiDian.MaiDianDefine")
  67. local MainDianLogic = require("MaiDian.MaiDianLogic")
  68. local TalismanLogic = require("talisman.TalismanLogic")
  69. BATTLE_HANG_EXP_OUT_PERIOD = 60 -- 经验产出时间间隔
  70. BATTLE_HANG_ITEM_OUT_PERIOD = 300 -- 战利品道具产出时间间隔
  71. BATTLE_HANG_ITEM_OUT_PERIOD_2 = 7200 -- 战利品道具产出时间间隔2小时掉落一次
  72. BATTLE_LOGIN_LEV_TIPS = 50 -- 登录检测挂机时间过久提示 最高等级
  73. BATTLE_LOGIN_TIME_TIPS = 10 * 60 -- 登录检测挂机超过多久提示
  74. BATTLE_MOPUP_CNT = 4
  75. BATTLE_MOPUP_CNT_VIP = 11
  76. BATTLE_MOPUP_FREE_CNT = 1
  77. BATTLE_MOPUP_FREE_CNT_VIP = 3
  78. BATTLE_LEVEL_PLAYER_LIST = { }
  79. local STATUS_NONE = 1 -- 不可领
  80. local STATUS_CANGET = 2 -- 可领
  81. local DIAMOND_COST_PER_HOUR = 20
  82. local HOUR_SEC = 60 * 60
  83. local DIAMOND_ADDITION = 1.5
  84. -- @mafei 是否需要集中定义一个define 枚举
  85. local PRINCIPAL_LINE_EVNET = 1
  86. local BATTLE_ORDER_TYPE = 1
  87. -- 挂机收益最多累计x秒
  88. function getHangMaxTime(human)
  89. local hour = VipLogic.getPowerArgs(human, VipLogic.VIP_POWER10)
  90. local talismanAdd_HangHours = TalismanLogic.getTalismanAdd(human, TalismanLogic.OTHER_EFFECT_TBL.GJ_HANG_HOURS) or 0
  91. hour = hour + talismanAdd_HangHours
  92. return(hour or 0) * 3600
  93. end
  94. local function wrapHangFightNet(net, heroConfig, skillConfig)
  95. net.body = heroConfig.body
  96. net.height = heroConfig.height
  97. net.weight = heroConfig.width
  98. net.fireType = skillConfig and skillConfig.fireType or 0
  99. net.attackEffect = skillConfig and skillConfig.attackEffect or ""
  100. net.flyEffect = skillConfig and skillConfig.flyEffect or ""
  101. net.flyCoords = skillConfig and skillConfig.flyCoords or ""
  102. net.hitEffect = skillConfig and skillConfig.hitEffect or ""
  103. net.hitSound = skillConfig and skillConfig.hitSound or ""
  104. end
  105. local function fontBattleSkillNet(skillNet, skillID)
  106. local skillConfig = SkillExcel.skill[skillID]
  107. if not skillConfig then
  108. return
  109. end
  110. skillNet.skillID = skillID
  111. skillNet.fireType = skillConfig.fireType
  112. skillNet.readyAction = skillConfig.readyAction
  113. skillNet.attackPart = skillConfig.attackPart
  114. skillNet.attackAction = skillConfig.attackAction
  115. skillNet.readyEffect = skillConfig.readyEffect
  116. skillNet.attackEffect = skillConfig.attackEffect
  117. skillNet.hitEffect = skillConfig.hitEffect
  118. skillNet.flyEffect = skillConfig.flyEffect
  119. skillNet.flyCoords = skillConfig.flyCoords
  120. skillNet.hitBack = skillConfig.hitBack
  121. skillNet.effectTime = skillConfig.effectTime
  122. skillNet.contentType = skillConfig.contentType
  123. skillNet.content = skillConfig.content
  124. skillNet.movieEffect = skillConfig.movieEffect
  125. skillNet.quake = skillConfig.quake
  126. skillNet.flySound = skillConfig.flySound
  127. skillNet.fireSound = skillConfig.fireSound
  128. skillNet.hitSound = skillConfig.hitSound
  129. skillNet.cvSound = skillConfig.cvSound
  130. skillNet.screenMask = skillConfig.screenMask
  131. skillNet.screenCam = skillConfig.screenCam
  132. skillNet.largeEffect = skillConfig.largeEffect
  133. skillNet.lie = skillConfig.lie
  134. skillNet.cuoZhen = skillConfig.cuoZhen
  135. skillNet.skillDelay = skillConfig.skillDelay
  136. skillNet.isFraming = skillConfig.isFraming
  137. return true
  138. end
  139. -- 获取当前战役类型
  140. local function BattleLogic_GetBattleType(human)
  141. if not human then
  142. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleType human is null")
  143. return EliteDefine.COPY_ELITE_ERROR
  144. end
  145. return human.db.battleType
  146. end
  147. -- 设置当前战役类型
  148. local function BattleLogic_SetBattleType(human, nBattleType)
  149. if not human or EliteDefine.COPY_ELITE_NORMAL > nBattleType or EliteDefine.COPY_ELITE_DIFFICULTY < nBattleType then
  150. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_SetBattleType 参数不正确!!!")
  151. return false
  152. end
  153. human.db.battleType = nBattleType
  154. print("[BattleLogic_SetBattleType] 玩家设置战役类型成功 id = "
  155. ..human.db._id.." nBattleType1 = "..nBattleType.." nBattleType2 = "..human.db.battleType)
  156. return true
  157. end
  158. -- 获取战役即将战斗id
  159. local function BattleLogic_GetBattleBattleID(human)
  160. if not human then
  161. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[BattleLogic_GetBattleBattleID] human is null")
  162. return -1
  163. end
  164. local nBattleType = BattleLogic_GetBattleType(human)
  165. --print("[BattleLogic_GetBattleBattleID] 获取到的战斗类型信息 id = "..human.db._id.." nBattleType = "..nBattleType)
  166. if EliteDefine.COPY_ELITE_ERROR >= nBattleType or EliteDefine.COPY_ELITE_DIFFICULTY < nBattleType then
  167. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleBattleID 获取到的战斗类型不正确 id = "
  168. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name.." nBattleType = "..nBattleType)
  169. return -1
  170. end
  171. if EliteDefine.COPY_ELITE_NORMAL == nBattleType then
  172. return human.db.battleID
  173. elseif EliteDefine.COPY_LEVEL_ELITE == nBattleType then
  174. return human.db.battleID_elite
  175. elseif EliteDefine.COPY_ELITE_DIFFICULTY == nBattleType then
  176. return human.db.battleID_hard
  177. else
  178. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleBattleID 未处理的战斗类型 id = "
  179. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name.." nBattleType = "..nBattleType)
  180. return -1
  181. end
  182. end
  183. -- 根据类型获取战斗ID
  184. local function BattleLogic_GetBattleIDByType(human, nBattleType)
  185. if not human or EliteDefine.COPY_ELITE_ERROR >= nBattleType or EliteDefine.COPY_ELITE_DIFFICULTY < nBattleType then
  186. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleIDByType 传入的参数不正确 id = "
  187. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name.." nBattleType = "..nBattleType)
  188. return -1
  189. end
  190. if EliteDefine.COPY_ELITE_NORMAL == nBattleType then
  191. return human.db.battleID
  192. elseif EliteDefine.COPY_LEVEL_ELITE == nBattleType then
  193. return human.db.battleID_elite
  194. elseif EliteDefine.COPY_ELITE_DIFFICULTY == nBattleType then
  195. return human.db.battleID_hard
  196. end
  197. return -1
  198. end
  199. -- 设置 战役即将战斗id
  200. local function BattleLogic_SetBattleBattleID(human, nValue)
  201. if not human or 0 > nValue then
  202. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_SetBattleBattleID 参数不正确")
  203. return false
  204. end
  205. local nBattleType = BattleLogic_GetBattleType(human)
  206. if EliteDefine.COPY_ELITE_ERROR >= nBattleType or EliteDefine.COPY_ELITE_DIFFICULTY < nBattleType then
  207. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_SetBattleBattleID 获取到的战斗类型不正确 id = "
  208. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name.." nBattleType = "..nBattleType)
  209. return false
  210. end
  211. if EliteDefine.COPY_ELITE_NORMAL == nBattleType then
  212. human.db.battleID = nValue
  213. elseif EliteDefine.COPY_LEVEL_ELITE == nBattleType then
  214. human.db.battleID_elite = nValue
  215. elseif EliteDefine.COPY_ELITE_DIFFICULTY == nBattleType then
  216. human.db.battleID_hard = nValue
  217. else
  218. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleGuaJiID 未处理的战斗类型 id = "
  219. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name.." nBattleType = "..nBattleType)
  220. return false
  221. end
  222. return true
  223. end
  224. -- 获取当前战役 已通关关卡/挂机关卡
  225. local function BattleLogic_GetBattleGuaJiID(human)
  226. if not human then
  227. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleGuaJiID human is null")
  228. return -1
  229. end
  230. local nBattleType = BattleLogic_GetBattleType(human)
  231. print("[BattleLogic_GetBattleGuaJiID] 获取到的战斗类型信息 id = "..human.db._id.." nBattleType = "..nBattleType)
  232. if EliteDefine.COPY_ELITE_ERROR >= nBattleType or EliteDefine.COPY_ELITE_DIFFICULTY < nBattleType then
  233. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleGuaJiID 获取到的战斗类型不正确 id = "
  234. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name.." nBattleType = "..nBattleType)
  235. return -1
  236. end
  237. if EliteDefine.COPY_ELITE_NORMAL == nBattleType then
  238. return human.db.guajiID
  239. elseif EliteDefine.COPY_LEVEL_ELITE == nBattleType then
  240. return human.db.guajiID_elite
  241. elseif EliteDefine.COPY_ELITE_DIFFICULTY == nBattleType then
  242. return human.db.guajiID_hard
  243. else
  244. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleGuaJiID 未处理的战斗类型 id = "
  245. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name.." nBattleType = "..nBattleType)
  246. return -1
  247. end
  248. end
  249. -- 通过战斗类型获取当前战役 已通关关卡/挂机关卡
  250. local function BattleLogic_GetBattleGuaJiIDByType(human, nBattleType)
  251. if not human or EliteDefine.COPY_ELITE_ERROR >= nBattleType or EliteDefine.COPY_ELITE_DIFFICULTY < nBattleType then
  252. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleGuaJiIDByType 传入的参数不正确 id = "
  253. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name.." nBattleType = "..nBattleType)
  254. return -1
  255. end
  256. if EliteDefine.COPY_ELITE_NORMAL == nBattleType then
  257. return human.db.guajiID
  258. elseif EliteDefine.COPY_LEVEL_ELITE == nBattleType then
  259. return human.db.guajiID_elite
  260. elseif EliteDefine.COPY_ELITE_DIFFICULTY == nBattleType then
  261. return human.db.guajiID_hard
  262. else
  263. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleGuaJiIDByType 未处理的战斗类型 id = "
  264. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name.." nBattleType = "..nBattleType)
  265. return -1
  266. end
  267. end
  268. -- 设置当前战役 已通关关卡/挂机关卡
  269. local function BattleLogic_SetBattleGuaJiID(human, nValue)
  270. if not human or 0 > nValue then
  271. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_SetBattleGuaJiID 参数不正确")
  272. return false
  273. end
  274. local nBattleType = BattleLogic_GetBattleType(human)
  275. if EliteDefine.COPY_ELITE_ERROR >= nBattleType or EliteDefine.COPY_ELITE_DIFFICULTY < nBattleType then
  276. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_SetBattleGuaJiID 获取到的战斗类型不正确 id = "
  277. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name.." nBattleType = "..nBattleType)
  278. return false
  279. end
  280. if EliteDefine.COPY_ELITE_NORMAL == nBattleType then
  281. human.db.guajiID = nValue
  282. elseif EliteDefine.COPY_LEVEL_ELITE == nBattleType then
  283. human.db.guajiID_elite = nValue
  284. elseif EliteDefine.COPY_ELITE_DIFFICULTY == nBattleType then
  285. human.db.guajiID_hard = nValue
  286. else
  287. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleGuaJiID 未处理的战斗类型 id = "
  288. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name.." nBattleType = "..nBattleType)
  289. return false
  290. end
  291. return true
  292. end
  293. -- 获取奖励信息
  294. local function BattleLogic_GetBattleRewards(human)
  295. if not human then
  296. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleRewards 参数不正确")
  297. return nil
  298. end
  299. local nBattleType = BattleLogic_GetBattleType(human)
  300. if EliteDefine.COPY_ELITE_ERROR >= nBattleType or EliteDefine.COPY_ELITE_DIFFICULTY < nBattleType then
  301. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleRewards 获取到的战斗类型不正确 id = "
  302. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name.." nBattleType = "..nBattleType)
  303. return nil
  304. end
  305. local tRewards = nil
  306. if EliteDefine.COPY_ELITE_NORMAL == nBattleType then
  307. if not human.db.battleRewards then
  308. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleRewards 玩家普通奖励未初始化进行初始化 id = "
  309. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name.." nBattleType = "..nBattleType)
  310. human.db.battleRewards = {}
  311. end
  312. tRewards = human.db.battleRewards
  313. elseif EliteDefine.COPY_LEVEL_ELITE == nBattleType then
  314. if not human.db.battleRewards_elite then
  315. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleRewards 玩家精英奖励未初始化进行初始化 id = "
  316. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name.." nBattleType = "..nBattleType)
  317. human.db.battleRewards_elite = {}
  318. end
  319. tRewards = human.db.battleRewards_elite
  320. elseif EliteDefine.COPY_ELITE_DIFFICULTY == nBattleType then
  321. if not human.db.battleRewards_hard then
  322. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleRewards 玩家困难奖励未初始化进行初始化 id = "
  323. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name.." nBattleType = "..nBattleType)
  324. human.db.battleRewards_hard = {}
  325. end
  326. tRewards = human.db.battleRewards_hard
  327. else
  328. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleRewards 未处理的战斗类型 id = "
  329. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name.." nBattleType = "..nBattleType)
  330. end
  331. return tRewards
  332. end
  333. -- 根据类型获取奖励信息
  334. local function BattleLogic_GetBattleRewardsByType(human, nBattleType)
  335. if not human or EliteDefine.COPY_ELITE_ERROR >= nBattleType or EliteDefine.COPY_ELITE_DIFFICULTY < nBattleType then
  336. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[BattleLogic_GetBattleRewardsByType] 参数不正确")
  337. return nil
  338. end
  339. local tRewards = nil
  340. if EliteDefine.COPY_ELITE_NORMAL == nBattleType then
  341. if not human.db.battleRewards then
  342. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[BattleLogic_GetBattleRewardsByType] 玩家普通奖励未初始化进行初始化 id = "
  343. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name.." nBattleType = "..nBattleType)
  344. human.db.battleRewards = {}
  345. end
  346. --print("[BattleLogic_GetBattleRewardsByType] 返回普通奖励表")
  347. tRewards = human.db.battleRewards
  348. elseif EliteDefine.COPY_LEVEL_ELITE == nBattleType then
  349. if not human.db.battleRewards_elite then
  350. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[BattleLogic_GetBattleRewardsByType] 玩家精英奖励未初始化进行初始化 id = "
  351. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name.." nBattleType = "..nBattleType)
  352. human.db.battleRewards_elite = {}
  353. end
  354. --print("[BattleLogic_GetBattleRewardsByType] 返回精英奖励表")
  355. tRewards = human.db.battleRewards_elite
  356. elseif EliteDefine.COPY_ELITE_DIFFICULTY == nBattleType then
  357. if not human.db.battleRewards_hard then
  358. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[BattleLogic_GetBattleRewardsByType] 玩家困难奖励未初始化进行初始化 id = "
  359. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name.." nBattleType = "..nBattleType)
  360. human.db.battleRewards_hard = {}
  361. end
  362. --print("[BattleLogic_GetBattleRewardsByType] 返回困难奖励表")
  363. tRewards = human.db.battleRewards_hard
  364. else
  365. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[BattleLogic_GetBattleRewardsByType] 未处理的战斗类型 id = "
  366. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name.." nBattleType = "..nBattleType)
  367. end
  368. return tRewards
  369. end
  370. local WeiLen = 30
  371. -- 设置奖励信息
  372. local function BattleLogic_SetBattleRewards(human, id)
  373. if not human or 0 >= id then
  374. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_SetBattleRewards 参数不正确")
  375. return false
  376. end
  377. local tRewards = BattleLogic_GetBattleRewards(human)
  378. if not tRewards then
  379. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_SetBattleRewards 获取到的奖励为空 id = "
  380. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  381. return false
  382. end
  383. local intIndex = math.ceil(id / WeiLen)
  384. local byteIndex = id % WeiLen
  385. tRewards[intIndex] = tRewards[intIndex] or 0
  386. tRewards[intIndex] = Util.setBit(tRewards[intIndex], byteIndex)
  387. return true
  388. end
  389. -- 获取挂机奖励表
  390. local function BattleLogic_GetBattleOut(human)
  391. if not human then
  392. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleOut 参数不正确")
  393. return nil
  394. end
  395. local nBattleType = BattleLogic_GetBattleType(human)
  396. if EliteDefine.COPY_ELITE_ERROR >= nBattleType or EliteDefine.COPY_ELITE_DIFFICULTY < nBattleType then
  397. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleOut 获取到的战斗类型不正确 id = "
  398. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name.." nBattleType = "..nBattleType)
  399. return nil
  400. end
  401. return human.db.battleOut
  402. -- if EliteDefine.COPY_ELITE_NORMAL == nBattleType then
  403. -- -- if not human.db.battleRewards then
  404. -- -- Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleRewards 玩家普通奖励未初始化进行初始化 id = "
  405. -- -- ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name.." nBattleType = "..nBattleType)
  406. -- -- human.db.battleOut = {}
  407. -- -- end
  408. -- tRewards = human.db.battleOut
  409. -- elseif EliteDefine.COPY_LEVEL_ELITE == nBattleType then
  410. -- -- if not human.db.battleRewards_elite then
  411. -- -- Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleRewards 玩家精英奖励未初始化进行初始化 id = "
  412. -- -- ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name.." nBattleType = "..nBattleType)
  413. -- -- human.db.battleRewards_elite = {}
  414. -- -- end
  415. -- tRewards = human.db.battleOut_elite
  416. -- elseif EliteDefine.COPY_ELITE_DIFFICULTY == nBattleType then
  417. -- -- if not human.db.battleRewards_hard then
  418. -- -- Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleRewards 玩家困难奖励未初始化进行初始化 id = "
  419. -- -- ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name.." nBattleType = "..nBattleType)
  420. -- -- human.db.battleRewards_hard = {}
  421. -- -- end
  422. -- tRewards = human.db.battleOut_hard
  423. -- else
  424. -- Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleOut 未处理的战斗类型 id = "
  425. -- ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name.." nBattleType = "..nBattleType)
  426. -- end
  427. end
  428. function BattleLogic_InitOneBattleOut(human, now)
  429. human.db.battleOut = { }
  430. human.db.battleOut.expTs1 = now
  431. -- 经验开始产出时间戳
  432. human.db.battleOut.expTs2 = now
  433. -- 经验产出结算时间戳
  434. human.db.battleOut.itemTs1 = now
  435. -- 道具产出时间戳
  436. human.db.battleOut.itemTs2 = now
  437. -- 道具产出结算时间戳
  438. human.db.battleOut.exp = 0
  439. human.db.battleOut.jinbi = 0
  440. human.db.battleOut.greenExp = 0
  441. human.db.battleOut.qingbao = 0
  442. human.db.battleOut.items = nil
  443. -- 产出的待收获的战利品
  444. human.db.battleOut.equip = nil
  445. -- 产出的待收获的装备
  446. return true
  447. end
  448. -- 初始化所有挂机奖励领取列表
  449. local function BattleLogic_InitAllBattleOut(human, now)
  450. if not human then
  451. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_InitAllBattleOut 参数不正确")
  452. return false
  453. end
  454. if not human.db.battleOut then
  455. BattleLogic_InitOneBattleOut(human, now)
  456. end
  457. -- if not human.db.battleOut_elite then
  458. -- human.db.battleOut_elite = {}
  459. -- BattleLogic_InitOneBattleOut(human.db.battleOut_elite, now)
  460. -- end
  461. -- if not human.db.battleOut_hard then
  462. -- human.db.battleOut_hard = {}
  463. -- BattleLogic_InitOneBattleOut(human.db.battleOut_hard, now)
  464. -- end
  465. return true
  466. end
  467. -- 获取配置信息
  468. local function BattleLogic_GetBattleConfig(human)
  469. if not human then
  470. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleConfig 参数不正确")
  471. return nil
  472. end
  473. local nBattleType = BattleLogic_GetBattleType(human)
  474. if EliteDefine.COPY_ELITE_ERROR >= nBattleType or EliteDefine.COPY_ELITE_DIFFICULTY < nBattleType then
  475. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleConfig 获取到的战斗类型不正确 id = "
  476. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name.." nBattleType = "..nBattleType)
  477. return nil
  478. end
  479. if EliteDefine.COPY_ELITE_NORMAL == nBattleType then
  480. return BattleExcel
  481. elseif EliteDefine.COPY_LEVEL_ELITE == nBattleType then
  482. return BattleExcel_Elite
  483. elseif EliteDefine.COPY_ELITE_DIFFICULTY == nBattleType then
  484. return BattleExcel_Hard
  485. else
  486. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleGuaJiID 未处理的战斗类型 id = "
  487. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name.." nBattleType = "..nBattleType)
  488. return nil
  489. end
  490. end
  491. -- 根据战斗类型获取配置
  492. local function BattleLogic_GetBattleConfigByType(nBattleType)
  493. if EliteDefine.COPY_ELITE_ERROR >= nBattleType or EliteDefine.COPY_ELITE_DIFFICULTY < nBattleType then
  494. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleConfigByType 参数不正确")
  495. return nil
  496. end
  497. if EliteDefine.COPY_ELITE_NORMAL == nBattleType then
  498. return BattleExcel
  499. elseif EliteDefine.COPY_LEVEL_ELITE == nBattleType then
  500. return BattleExcel_Elite
  501. elseif EliteDefine.COPY_ELITE_DIFFICULTY == nBattleType then
  502. return BattleExcel_Hard
  503. end
  504. return nil
  505. end
  506. -- 获取章节奖励
  507. local function BattleLogic_GetChapterReward(human)
  508. if not human then
  509. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetChapterReward 参数不正确")
  510. return nil
  511. end
  512. local nBattleType = BattleLogic_GetBattleType(human)
  513. print("[BattleLogic_GetChapterReward] nBattleType = "..nBattleType)
  514. if EliteDefine.COPY_ELITE_ERROR >= nBattleType or EliteDefine.COPY_ELITE_DIFFICULTY < nBattleType then
  515. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetChapterReward 获取到的战斗类型不正确 id = "
  516. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name.." nBattleType = "..nBattleType)
  517. return nil
  518. end
  519. if EliteDefine.COPY_ELITE_NORMAL == nBattleType then
  520. if not human.db.chapterReward then
  521. human.db.chapterReward = {}
  522. end
  523. return human.db.chapterReward
  524. elseif EliteDefine.COPY_LEVEL_ELITE == nBattleType then
  525. if not human.db.chapterReward_Elite then
  526. human.db.chapterReward_Elite = {}
  527. end
  528. return human.db.chapterReward_Elite
  529. elseif EliteDefine.COPY_ELITE_DIFFICULTY == nBattleType then
  530. if not human.db.chapterReward_Hard then
  531. human.db.chapterReward_Hard = {}
  532. end
  533. return human.db.chapterReward_Hard
  534. else
  535. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetChapterReward 未处理的战斗类型 id = "
  536. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name.." nBattleType = "..nBattleType)
  537. return nil
  538. end
  539. end
  540. -- 查询难度
  541. local function BattleLogic_QueryDifficulty(human)
  542. local nNowBattleType = BattleLogic_GetBattleType(human)
  543. if EliteDefine.COPY_ELITE_ERROR >= nNowBattleType then
  544. print("[BattleLogic_QueryDifficulty] 查询难度获取到的战斗ID数值、战斗类型不正确 id = "
  545. ..human.db._id.." nNowBattleType = "..nNowBattleType)
  546. return
  547. end
  548. local msgRet = Msg.gc.GC_ELITE_OPEN
  549. msgRet.curCopyType = nNowBattleType
  550. msgRet.copyOpenType[0]=0
  551. --精英副本开启, 普通关卡符合条件
  552. local nBattleID = human.db.battleID
  553. local nIndex = EliteDefine.COPY_LEVEL_ELITE - 1
  554. if human.db.lv >= EliteDefine.COPY_ELITE_ULEV and
  555. nBattleID > EliteDefine.COPY_ELITE_LEVEL then
  556. msgRet.copyOpenType[0] = msgRet.copyOpenType[0]+1
  557. msgRet.copyOpenType[nIndex] = 1
  558. else
  559. msgRet.copyOpenType[0] = msgRet.copyOpenType[0]+1
  560. msgRet.copyOpenType[nIndex] = 0
  561. end
  562. --困难副本开启,精英关卡符合条件
  563. local nBattleIDElite = human.db.battleID_elite
  564. nIndex = EliteDefine.COPY_ELITE_DIFFICULTY - 1
  565. if human.db.lv >= EliteDefine.COPY_ELITE_ULEV and
  566. nBattleIDElite > EliteDefine.COPY_ELITE_LEVEL then
  567. msgRet.copyOpenType[0] = msgRet.copyOpenType[0]+1
  568. msgRet.copyOpenType[nIndex] = 1
  569. else
  570. msgRet.copyOpenType[0] = msgRet.copyOpenType[0]+1
  571. msgRet.copyOpenType[nIndex] = 0
  572. end
  573. Msg.send(msgRet,human.fd)
  574. local info=Util.printTable(msgRet)
  575. print(info)
  576. end
  577. -- 设置战役通关标记
  578. local function BattleLogic_SetBattleAdopt(human, nBattleType, nValue)
  579. if not human or EliteDefine.COPY_ELITE_ERROR >= nBattleType or EliteDefine.COPY_ELITE_DIFFICULTY < nBattleType then
  580. return
  581. end
  582. print("[BattleLogic_SetBattleAdopt] 玩家通过战役 nBattleType = "..nBattleType.." nValue = "..nValue)
  583. if EliteDefine.COPY_ELITE_NORMAL == nBattleType then
  584. human.db.battleadopt = nValue
  585. elseif EliteDefine.COPY_LEVEL_ELITE == nBattleType then
  586. human.db.battleadopt_elite = nValue
  587. elseif EliteDefine.COPY_ELITE_DIFFICULTY == nBattleType then
  588. human.db.battleadopt_haed = nValue
  589. end
  590. end
  591. -- 获取战役通关标记
  592. local function BattleLogic_GetBattleAdopt(human, nBattleType)
  593. if not human or EliteDefine.COPY_ELITE_ERROR >= nBattleType or EliteDefine.COPY_ELITE_DIFFICULTY < nBattleType then
  594. return 0
  595. end
  596. if EliteDefine.COPY_ELITE_NORMAL == nBattleType then
  597. return human.db.battleadopt
  598. elseif EliteDefine.COPY_LEVEL_ELITE == nBattleType then
  599. return human.db.battleadopt_elite
  600. elseif EliteDefine.COPY_ELITE_DIFFICULTY == nBattleType then
  601. return human.db.battleadopt_haed
  602. end
  603. end
  604. -- 获取额外增加扫荡次数
  605. local function BattleLogic_GetAddFreeMopupNum(human)
  606. if not human then
  607. return -1
  608. end
  609. if not human.db.mopupAddFreeCnt then
  610. human.db.mopupAddFreeCnt = 0
  611. end
  612. return human.db.mopupAddFreeCnt
  613. end
  614. -- 设置额外增加扫荡次数
  615. local function BattleLogic_SetAddFreeMopupNum(human, nValue)
  616. if not human then
  617. return
  618. end
  619. print("[BattleLogic_SetAddFreeMopupNum] 消耗的额外次数 nValue = "..nValue)
  620. human.db.mopupAddFreeCnt = human.db.mopupAddFreeCnt + nValue
  621. -- if 0 > human.db.mopupAddFreeCnt then
  622. -- human.db.mopupAddFreeCnt = 0
  623. -- end
  624. end
  625. function getBattleRoleList(nBattleType, worldMapId)
  626. if not BATTLE_LEVEL_PLAYER_LIST then
  627. BATTLE_LEVEL_PLAYER_LIST = {}
  628. end
  629. if not BATTLE_LEVEL_PLAYER_LIST[nBattleType] then
  630. BATTLE_LEVEL_PLAYER_LIST[nBattleType] = {}
  631. end
  632. BATTLE_LEVEL_PLAYER_LIST[nBattleType][worldMapId] = BATTLE_LEVEL_PLAYER_LIST[nBattleType][worldMapId] or { }
  633. local tBattleConfig = BattleLogic_GetBattleConfigByType(nBattleType)
  634. if not tBattleConfig then
  635. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[getBattleRoleList] 获取不到对应的配置 nBattleType = "
  636. ..nBattleType.." worldMapId ="..worldMapId)
  637. print("[getBattleRoleList] 获取配置失败")
  638. return
  639. end
  640. -- local config = BattleExcel.map[worldMapId]
  641. local config = tBattleConfig.map[worldMapId]
  642. QueryRoleByNodeID = { guajiID = { ["$gte"] = config.minLevel, ["$lte"] = config.maxLevel }, nBattleType = nBattleType}
  643. local fields = { }
  644. RoleLogic.makeRoleBaseFields(fields)
  645. LuaMongo.find(DB.db_char, QueryRoleByNodeID, fields, 50)
  646. local len = 0
  647. while true do
  648. local charDb = { }
  649. if not LuaMongo.next(charDb) then
  650. break
  651. end
  652. len = len + 1
  653. BATTLE_LEVEL_PLAYER_LIST[nBattleType][worldMapId][charDb._id] = { }
  654. RoleLogic.makeRoleBase(charDb, BATTLE_LEVEL_PLAYER_LIST[nBattleType][worldMapId][charDb._id])
  655. if len >= 50 then
  656. return
  657. end
  658. end
  659. end
  660. function initAfterStart()
  661. local len = #BattleExcel.map
  662. for i = 1, len do
  663. getBattleRoleList(EliteDefine.COPY_ELITE_NORMAL, i)
  664. end
  665. len = #BattleExcel_Elite.map
  666. for i = 1, len do
  667. getBattleRoleList(EliteDefine.COPY_LEVEL_ELITE, i)
  668. end
  669. len = #BattleExcel_Hard.map
  670. for i = 1, len do
  671. getBattleRoleList(EliteDefine.COPY_ELITE_DIFFICULTY, i)
  672. end
  673. end
  674. function onLogin(human)
  675. if human.db.lv >= BATTLE_LOGIN_LEV_TIPS then
  676. return
  677. end
  678. calcBattleOut(human)
  679. local now = os.time()
  680. -- local expTime = now - human.db.battleOut.expTs1
  681. local tBattleOut = BattleLogic_GetBattleOut(human)
  682. if tBattleOut then
  683. local expTime = now - tBattleOut.expTs1
  684. if expTime >= BATTLE_LOGIN_TIME_TIPS then
  685. local msgRet = Msg.gc.GC_BATTLE_HANG_TIME_SPILL
  686. msgRet.time = expTime
  687. Msg.send(msgRet, human.fd)
  688. end
  689. else
  690. print("[BattleLogic_onLogin] 获取不到奖励数据 id = "
  691. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  692. end
  693. end
  694. -- 是否领取
  695. -- local WeiLen = 30
  696. function isGetReward(human, id)
  697. local flags = BattleLogic_GetBattleRewards(human)
  698. if not flags then
  699. return false
  700. end
  701. -- if not human.db.battleRewards then
  702. -- return
  703. -- end
  704. --local flags = human.db.battleRewards
  705. local intIndex = math.ceil(id / WeiLen)
  706. if not flags[intIndex] then
  707. return
  708. end
  709. local byteIndex = id % WeiLen
  710. if Util.getBit(flags[intIndex], byteIndex) > 0 then
  711. return true
  712. end
  713. end
  714. -- 通过类型获取奖励 判断是否领取
  715. function isGetRewardByType(human, id, nBattleType)
  716. local flags = BattleLogic_GetBattleRewardsByType(human, nBattleType)
  717. if not flags then
  718. print("[isGetRewardByType] 获取不到对应的奖励表 id = "..human.db._id .. " nBattleType = "..nBattleType)
  719. return false
  720. end
  721. local intIndex = math.ceil(id / WeiLen)
  722. if not flags[intIndex] then
  723. print("[isGetRewardByType] 没有对对应的ID领取奖励 intIndex id = "..id .. " nBattleType = "..nBattleType)
  724. return false
  725. end
  726. local byteIndex = id % WeiLen
  727. -- if Util.getBit(flags[intIndex], byteIndex) > 0 then
  728. -- return true
  729. -- end
  730. local nBit = Util.getBit(flags[intIndex], byteIndex)
  731. -- print("[isGetRewardByType] nBit = ".. nBit)
  732. return Util.getBit(flags[intIndex], byteIndex) > 0 and true or false
  733. end
  734. function getTongguanIndex(human)
  735. local tBattleRewards = BattleLogic_GetBattleRewards(human)
  736. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  737. if not tBattleRewards or not tBattleConfig then
  738. return 1
  739. end
  740. --local flags = human.db.battleRewards
  741. -- for id, v in ipairs(BattleExcel.node) do
  742. for id, v in ipairs(tBattleConfig.node) do
  743. if #v.tongguan ~= 0 then
  744. local intIndex = math.ceil(id / WeiLen)
  745. -- if not flags[intIndex] then
  746. if not tBattleRewards[intIndex] then
  747. return id
  748. end
  749. local byteIndex = id % WeiLen
  750. -- if Util.getBit(flags[intIndex], byteIndex) == 0 then
  751. if Util.getBit(tBattleRewards[intIndex], byteIndex) == 0 then
  752. return id
  753. end
  754. end
  755. end
  756. return
  757. end
  758. -- 设置领取
  759. function setGetReward(human, id)
  760. local tBattleRewards = BattleLogic_GetBattleRewards(human)
  761. if not tBattleRewards then
  762. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleRewards 参数不正确")
  763. print("[setGetReward] 不存在对应的 奖励配置")
  764. return
  765. end
  766. -- if not human.db.battleRewards then
  767. -- human.db.battleRewards = { }
  768. -- end
  769. -- local flags = human.db.battleRewards
  770. local intIndex = math.ceil(id / WeiLen)
  771. local byteIndex = id % WeiLen
  772. tBattleRewards[intIndex] = tBattleRewards[intIndex] or 0
  773. tBattleRewards[intIndex] = Util.setBit(tBattleRewards[intIndex], byteIndex)
  774. end
  775. -- 通过类型设置领取
  776. function setGetRewardByType(human, id, nBattleType)
  777. local tBattleRewards = BattleLogic_GetBattleRewardsByType(human, nBattleType)
  778. if not tBattleRewards then
  779. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleRewards 参数不正确")
  780. print("[setGetReward] 不存在对应的 奖励配置")
  781. return
  782. end
  783. local intIndex = math.ceil(id / WeiLen)
  784. local byteIndex = id % WeiLen
  785. tBattleRewards[intIndex] = tBattleRewards[intIndex] or 0
  786. tBattleRewards[intIndex] = Util.setBit(tBattleRewards[intIndex], byteIndex)
  787. end
  788. -- 是否有可领取的
  789. function hasCanGetReward(human)
  790. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  791. local nGuaJiID = BattleLogic_GetBattleGuaJiID(human)
  792. if not tBattleConfig or -1 >= nGuaJiID then
  793. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleRewards 参数不正确")
  794. print("[hasCanGetReward] 不存在对应的 奖励配置")
  795. return
  796. end
  797. for id, cf in ipairs(tBattleConfig.node) do
  798. if id > nGuaJiID then
  799. break
  800. end
  801. if #cf.tongguan > 0 and not isGetReward(human, id) then
  802. return true
  803. end
  804. end
  805. end
  806. local BATTLEID_2_NAME = nil
  807. function getBattleName(human, battleID)
  808. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  809. local nBattleType = BattleLogic_GetBattleType(human)
  810. if not tBattleConfig or EliteDefine.COPY_ELITE_ERROR >= nBattleType then
  811. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleRewards 参数不正确")
  812. print("[getBattleName] 不存在对应的 奖励配置")
  813. return
  814. end
  815. if not BATTLEID_2_NAME then
  816. BATTLEID_2_NAME = { }
  817. end
  818. if not BATTLEID_2_NAME[nBattleType] then
  819. BATTLEID_2_NAME[nBattleType] = {}
  820. for id, cf in ipairs(tBattleConfig.node) do
  821. -- BATTLEID_2_NAME[id] = cf.name
  822. BATTLEID_2_NAME[nBattleType][id] = cf.name
  823. end
  824. end
  825. local nodeConfig = tBattleConfig.node[battleID]
  826. local mapConfig = nodeConfig and tBattleConfig.map[nodeConfig.mapID]
  827. local mapName = mapConfig and mapConfig.name or ""
  828. return BATTLEID_2_NAME[nBattleType][battleID] or "", mapName
  829. end
  830. function getBattleNameByType(battleID, nBattleType)
  831. local tBattleConfig = BattleLogic_GetBattleConfigByType( nBattleType)
  832. if not tBattleConfig or EliteDefine.COPY_ELITE_ERROR >= nBattleType then
  833. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleRewards 参数不正确")
  834. print("[getBattleNameByType] 不存在对应的 奖励配置")
  835. return
  836. end
  837. if not BATTLEID_2_NAME then
  838. BATTLEID_2_NAME = { }
  839. end
  840. if not BATTLEID_2_NAME[nBattleType] then
  841. BATTLEID_2_NAME[nBattleType] = {}
  842. for id, cf in ipairs(tBattleConfig.node) do
  843. -- BATTLEID_2_NAME[id] = cf.name
  844. BATTLEID_2_NAME[nBattleType][id] = cf.name
  845. end
  846. end
  847. local nodeConfig = tBattleConfig.node[battleID]
  848. local mapConfig = nodeConfig and tBattleConfig.map[nodeConfig.mapID]
  849. local mapName = mapConfig and mapConfig.name or ""
  850. return BATTLEID_2_NAME[nBattleType][battleID] or "", mapName
  851. end
  852. function hangFightQuery(human)
  853. local nBattleID = BattleLogic_GetBattleBattleID(human)
  854. local tBattleExcel = BattleLogic_GetBattleConfig(human)
  855. if -1 >= nBattleID or not tBattleExcel then
  856. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "hangFightQuery 参数不正确")
  857. print("[hangFightQuery] 不存在对应的 奖励配置 和战斗关卡ID id = "..human.db._id)
  858. return
  859. end
  860. -- local battleID = human.db.battleID > #BattleExcel.node and #BattleExcel.node or human.db.battleID
  861. local battleID = nBattleID > #tBattleExcel.node and #tBattleExcel.node or nBattleID
  862. local nowNodeConfig = tBattleExcel.node[battleID]
  863. local monsterOutID = nowNodeConfig.monsterOutID
  864. local monsterOutConfig = MonsterExcel.monsterOut[monsterOutID]
  865. local msgRet = Msg.gc.GC_BATTLE_HANG_FIGHT
  866. local len = 0
  867. for _, monster in ipairs(monsterOutConfig.member) do
  868. local monsterID = monster[1]
  869. len = len + 1
  870. local monsterConfig = MonsterExcel.monster[monsterID]
  871. local skillConfig = SkillExcel.skill[monsterConfig.normalAtkID]
  872. wrapHangFightNet(msgRet.monsterList[len], monsterConfig, skillConfig)
  873. end
  874. msgRet.monsterList[0] = len
  875. len = 0
  876. if human.db.combatHero[CombatDefine.COMBAT_TYPE1] then
  877. local tb = { }
  878. for i = 1, #human.db.combatHero[CombatDefine.COMBAT_TYPE1] do
  879. tb[#tb + 1] = human.db.combatHero[CombatDefine.COMBAT_TYPE1][i]
  880. end
  881. local tb2 = { }
  882. for i = 1, 3 do
  883. local r = math.ceil(math.random(0, #tb))
  884. r = r == 0 and 1 or r
  885. tb2[#tb2 + 1] = tb[r]
  886. tb[r] = tb[#tb]
  887. tb[#tb] = nil
  888. if not tb[1] then
  889. break
  890. end
  891. end
  892. for i = 1, #tb2 do
  893. len = len + 1
  894. local heroGrid = HeroLogic.getHeroGridByUuid(human, tb2[i])
  895. if heroGrid then
  896. local heroConfig = HeroExcel.hero[heroGrid.id]
  897. local _, skinSkillConf = SkinLogic.getHeroSkin(human, tb2[i])
  898. local skillConfig = SkillExcel.skill[heroConfig.normalAtkID]
  899. if skinSkillConf then
  900. skillConfig = SkillExcel.skill[skinSkillConf.normalAtkID]
  901. end
  902. wrapHangFightNet(msgRet.attackerList[i], heroConfig, skillConfig)
  903. local body, head = SkinLogic.getBody(human, tb2[i])
  904. if body then
  905. msgRet.attackerList[i].body = body
  906. end
  907. end
  908. end
  909. end
  910. msgRet.attackerList[0] = len
  911. -- Msg.trace(msgRet)
  912. Msg.send(msgRet, human.fd)
  913. end
  914. local function getExtraRewardID(human)
  915. local tBattleExcel = BattleLogic_GetBattleConfig(human)
  916. if not tBattleExcel then
  917. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[getExtraRewardID] 参数不正确")
  918. print("[getExtraRewardID] 不存在对应的 奖励配置 id = "..human.db._id)
  919. return nil, nil
  920. end
  921. local config = tBattleExcel.extraReward
  922. local battleExtraReward = human.db.battleExtraReward
  923. for id, data in ipairs(config) do
  924. if not battleExtraReward or not battleExtraReward[id] then
  925. return id, data
  926. end
  927. end
  928. end
  929. local function getExtraRewardState(human, extraRewardID)
  930. local tBattleExcel = BattleLogic_GetBattleConfig(human)
  931. local nGuaJiID = BattleLogic_GetBattleGuaJiID(human)
  932. if not tBattleExcel or -1 >= nGuaJiID then
  933. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[getExtraRewardState] 参数不正确")
  934. print("[getExtraRewardState] 不存在对应的 奖励配置 id = "..human.db._id)
  935. return 0
  936. end
  937. local config = tBattleExcel.extraReward[extraRewardID]
  938. if not config then
  939. return 0
  940. end
  941. if human.db.battleExtraReward and human.db.battleExtraReward[extraRewardID] then
  942. return 0
  943. end
  944. local guajiID = nGuaJiID
  945. if guajiID >= config.needBattleID then
  946. return 1
  947. end
  948. return 0
  949. end
  950. local function makeExtraRewardShow(human, net)
  951. local tBattleExcel = BattleLogic_GetBattleConfig(human)
  952. if not tBattleExcel then
  953. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[makeExtraRewardShow] 参数不正确")
  954. print("[makeExtraRewardShow] 不存在对应的 奖励配置 id = "..human.db._id)
  955. return
  956. end
  957. local config = tBattleExcel.extraReward
  958. local extraID, data = getExtraRewardID(human)
  959. if not extraID or not data then
  960. return
  961. end
  962. net[0] = 1
  963. net[1].needBattleID = data.needBattleID
  964. net[1].descID = data.descID
  965. net[1].desc = data.desc or ""
  966. net[1].extraHero[0] = 0
  967. net[1].extraItem[0] = 0
  968. if data.extraHeroID > 0 then
  969. net[1].extraHero[0] = 1
  970. HeroGrid.makeHeroSimpleByID(net[1].extraHero[1], data.extraHeroID, nil, nil, human)
  971. HeroGrid.makeHeroSimpleByGeneral(net[1].extraHero[1], data.extraHeroID)
  972. else
  973. net[1].extraItem[0] = 1
  974. Grid.makeItem(net[1].extraItem[1], data.extraReward[1], data.extraReward[2])
  975. end
  976. net[1].state = getExtraRewardState(human, extraID)
  977. end
  978. -- 随机道具
  979. local function randItemOut(dropRule, weightSum)
  980. if weightSum < 1 then
  981. return
  982. end
  983. local r = math.random(1, weightSum)
  984. for i = 1, #dropRule do
  985. local itemID = dropRule[i][1]
  986. local itemCnt1 = dropRule[i][2]
  987. local itemCnt2 = dropRule[i][3]
  988. local weight = dropRule[i][4]
  989. if r <= weight then
  990. local itemCnt = math.random(itemCnt1, itemCnt2)
  991. return itemID, itemCnt
  992. end
  993. r = r - weight
  994. end
  995. end
  996. function fontExtraDataSSZH(net, mapID, nowBattleID, human)
  997. local nodeCnt = 0
  998. local tBattleExcel = BattleLogic_GetBattleConfig(human)
  999. if not tBattleExcel then
  1000. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[fontExtraDataSSZH] 参数不正确")
  1001. print("[fontExtraDataSSZH] 不存在对应的 奖励配置 id = "..human.db._id)
  1002. return
  1003. end
  1004. if ProjectLogic.isSszh() then
  1005. for i = 1, #tBattleExcel.node do
  1006. local nodeTempConfig = tBattleExcel.node[i]
  1007. if nodeTempConfig.mapID == mapID then
  1008. nodeCnt = nodeCnt + 1
  1009. local posNet = net.posList[nodeCnt]
  1010. local pos = nodeTempConfig.pos
  1011. posNet.battleID = i
  1012. posNet.posX = pos and pos[1] or 0
  1013. posNet.posY = pos and pos[2] or 0
  1014. posNet.nodeName = getBattleName(human, i)
  1015. posNet.roleBase[0] = 0
  1016. if i == nowBattleID then
  1017. local videoTb = BattleDBLogic.queryBattleDbByNodeID(i)
  1018. local sharkData = videoTb and videoTb.shark[2]
  1019. if sharkData then
  1020. posNet.roleBase[0] = 1
  1021. RoleLogic.makeRoleBase(videoTb.roleBase, posNet.roleBase[1])
  1022. end
  1023. end
  1024. posNet.isBig = nodeTempConfig.isBig or 0
  1025. end
  1026. end
  1027. end
  1028. net.posList[0] = nodeCnt
  1029. end
  1030. function fontVideoInfo(human, net, monsterConfig)
  1031. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE1)
  1032. local len = #combatHero
  1033. -- 自己没队伍时,不显示
  1034. if len == 0 then
  1035. net.ownBody[0] = 0
  1036. net.enemyBody[0] = 0
  1037. else
  1038. -- 设置真实数据
  1039. local cnt = 0
  1040. for k, v in pairs(combatHero) do
  1041. -- body数据
  1042. if v ~= "0" then
  1043. local heroGird, bagIndex = HeroLogic.getHeroGridByUuid(human, v)
  1044. if heroGird ~= nil then
  1045. cnt = cnt + 1
  1046. local config = HeroExcel.hero[heroGird.id]
  1047. if config then
  1048. local attrConfig = HeroDefine.getAttrConfig(heroGird.id, config.star)
  1049. local normalAtkID = attrConfig.normalAtkID
  1050. local skill = attrConfig.battleSkill
  1051. local body, head = SkinLogic.getBody(human, bagIndex)
  1052. net.ownBody[cnt].body = body or config.body
  1053. fontBattleSkillNet(net.ownBody[cnt].atkId, normalAtkID)
  1054. fontBattleSkillNet(net.ownBody[cnt].skill, skill)
  1055. net.ownBody[cnt].pos = k
  1056. net.ownBody[cnt].atkType = SkillExcel.skill[normalAtkID].areaPara
  1057. local attrs = ObjHuman.getHeroAttrs(human, heroGird.bagIndex)
  1058. net.ownBody[cnt].hp = attrs[RoleDefine.HP]
  1059. end
  1060. end
  1061. end
  1062. end
  1063. net.ownBody[0] = cnt
  1064. cnt = 0
  1065. local memberConfig = monsterConfig.member
  1066. for k, v in pairs(memberConfig) do
  1067. -- body数据
  1068. cnt = cnt + 1
  1069. local config = MonsterExcel.monster[v[1]]
  1070. if config then
  1071. local normalAtkID = config.normalAtkID
  1072. net.enemyBody[cnt].body = config.body
  1073. fontBattleSkillNet(net.enemyBody[cnt].atkId, normalAtkID)
  1074. fontBattleSkillNet(net.enemyBody[cnt].skill, normalAtkID)
  1075. net.enemyBody[cnt].pos = k
  1076. net.enemyBody[cnt].atkType = SkillExcel.skill[normalAtkID].areaPara
  1077. local attrID = monsterConfig.attrID[k]
  1078. local attrConfig = MonsterExcel.monsterAttr[attrID].attrs
  1079. if not attrConfig then
  1080. print("[fontVideoInfo] 根据attrID获取到的 attrConfig 为空 k = "..k.. " attrID = "..attrID)
  1081. end
  1082. for _, value in pairs(attrConfig) do
  1083. if value[1] == RoleDefine.HP then
  1084. net.enemyBody[cnt].hp = value[2]
  1085. break
  1086. end
  1087. end
  1088. end
  1089. end
  1090. net.enemyBody[0] = cnt
  1091. end
  1092. end
  1093. -- 战役主界面查询
  1094. function query(human)
  1095. local msgRet = Msg.gc.GC_BATTLE_QUERY
  1096. local nNowBattleID = BattleLogic_GetBattleBattleID(human)
  1097. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  1098. local nNowGuaJiID = BattleLogic_GetBattleGuaJiID(human)
  1099. local nBattleType = BattleLogic_GetBattleType(human)
  1100. if -1 >= nNowBattleID or not tBattleConfig or -1 >= nNowGuaJiID or -1 >= nBattleType then
  1101. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[query] 获取到的战斗ID或奖励配置不正确")
  1102. print("[query] 获取到的战斗ID或奖励配置不正确 id = "..human.db._id)
  1103. return
  1104. end
  1105. print("[BattleLogic query] nNowGuaJiID ="..nNowGuaJiID.." nNowBattleID ="..nNowBattleID)
  1106. msgRet.nowBattleID = nNowBattleID
  1107. local configNode = #tBattleConfig.node
  1108. if nNowBattleID > configNode then
  1109. print("[query] 玩家的战斗ID不正确,进行纠正 nNowBattleID = "..nNowBattleID.." 最大战斗ID = "..configNode)
  1110. nNowBattleID = configNode
  1111. BattleLogic_SetBattleBattleID(human, nNowBattleID)
  1112. end
  1113. if nNowGuaJiID > configNode then
  1114. print("[query] 玩家的挂机ID不正确,进行纠正 nNowGuaJiID = "..nNowGuaJiID.." 最大挂机ID = "..configNode)
  1115. nNowGuaJiID = configNode
  1116. BattleLogic_SetBattleGuaJiID(human, nNowGuaJiID)
  1117. end
  1118. local nBattleAdopt = BattleLogic_GetBattleAdopt(human, nBattleType)
  1119. if nBattleAdopt == 1 then
  1120. print("[query] nNowBattleID 为最大值 nNowBattleID = "
  1121. ..nNowBattleID.." nNowGuaJiID = "..nNowGuaJiID.." nBattleType = "..nBattleType)
  1122. msgRet.nowBattleID = configNode + 1
  1123. end
  1124. -- local nowBattleID = human.db.battleID > configNode and configNode or human.db.battleID
  1125. local nowNodeConfig = tBattleConfig.node[nNowBattleID]
  1126. if not nowNodeConfig then
  1127. print("[query] 不存在对应的当前战斗ID对应的配置 nNowBattleID = ", nNowBattleID)
  1128. return
  1129. end
  1130. local nowMapConfig = tBattleConfig.map[nowNodeConfig.mapID]
  1131. if not nowMapConfig then
  1132. print("[query] 不存在对应的当前地图对应的地图配置 nNowBattleID = "
  1133. ..nNowBattleID.." mapID ="..nowNodeConfig.mapID)
  1134. return
  1135. end
  1136. local nJudeNum = nNowGuaJiID
  1137. -- 已通关
  1138. if nBattleAdopt == 1 then
  1139. nJudeNum = configNode
  1140. else
  1141. nJudeNum = nNowBattleID - 1
  1142. end
  1143. msgRet.maxBattleID = configNode
  1144. msgRet.mapID = nowNodeConfig.mapID
  1145. msgRet.nodeID = nowNodeConfig.curLevel
  1146. msgRet.sceneID = nowNodeConfig.sceneID
  1147. msgRet.mapName = nowMapConfig.name
  1148. msgRet.nodeName = nowNodeConfig.name
  1149. msgRet.needLv = nowNodeConfig.needLv
  1150. msgRet.bg = nowMapConfig.bg
  1151. msgRet.canBattle = 0
  1152. msgRet.doubleCnt = 0
  1153. if nowNodeConfig.needLv > human.db.lv then
  1154. msgRet.canBattle = nowNodeConfig.needLv
  1155. end
  1156. local double = RoleSystemLogic.isDouble(human, RoleSystemDefine.ROLE_SYS_ID_1104)
  1157. if
  1158. double and human.db.bar and human.db.bar.doubleCnt and
  1159. human.db.bar.doubleCnt <= BarTaskLogic.DEFAULT_MAX_DOUBLE_CNT
  1160. then
  1161. msgRet.doubleCnt = BarTaskLogic.DEFAULT_MAX_DOUBLE_CNT - human.db.bar.doubleCnt
  1162. elseif double and not human.db.bar then
  1163. msgRet.doubleCnt = BarTaskLogic.DEFAULT_MAX_DOUBLE_CNT
  1164. end
  1165. msgRet.tongguan[0] = 0
  1166. local id = getTongguanIndex(human)
  1167. if id == nil then
  1168. msgRet.tongguan[0] = 0
  1169. else
  1170. msgRet.tongguan[0] = 1
  1171. local state = isGetReward(human, id)
  1172. local cf = tBattleConfig.node[id].tongguan
  1173. local net = msgRet.tongguan[1]
  1174. if state == true then
  1175. net.status = STATUS_NONE
  1176. else
  1177. net.status =(id > nJudeNum) and STATUS_CANGET or STATUS_NONE
  1178. end
  1179. net.levelName = getBattleName(human,id)
  1180. net.index = id
  1181. net.nowBattle = getBattleName(human,nJudeNum)
  1182. net.reward[0] = 0
  1183. net.heroReward[0] = 0
  1184. -- 是英雄
  1185. if cf[1][3] then
  1186. net.heroReward[0] = 1
  1187. local other = { }
  1188. other.star = cf[1][3]
  1189. HeroGrid.makeHeroSimpleByID(net.heroReward[1], cf[1][1], nil, other, human)
  1190. HeroGrid.makeHeroSimpleByGeneral(net.heroReward[1], cf[1][1])
  1191. else
  1192. net.reward[0] = 1
  1193. for i = 1, net.reward[0] do
  1194. local itemID = cf[i][1]
  1195. local itemCnt = cf[i][2]
  1196. Grid.makeItem(net.reward[i], itemID, itemCnt)
  1197. end
  1198. end
  1199. end
  1200. local outSec = 0
  1201. local tBattleOut = BattleLogic_GetBattleOut(human)
  1202. --if human.db.battleOut ~= nil then
  1203. if tBattleOut ~= nil then
  1204. local now = os.time()
  1205. outSec = now - tBattleOut.expTs1
  1206. end
  1207. local maxHangTime = getHangMaxTime(human)
  1208. msgRet.maxTime = maxHangTime
  1209. if maxHangTime >= outSec then
  1210. msgRet.time = outSec
  1211. else
  1212. msgRet.time = maxHangTime
  1213. end
  1214. -- 悬赏情报数量
  1215. msgRet.xushang = human.db.bar and human.db.bar.qingbao or 0
  1216. msgRet.xushangMax = RoleExcel.exp[human.db.lv].qingBaoMax
  1217. --秘宝对悬赏情报上限加成
  1218. local qingBaoAdd = TalismanLogic.getTalismanAdd(human, TalismanLogic.OTHER_EFFECT_TBL.XUANSHANG_QB_MAX) or 0
  1219. msgRet.xushangMax = msgRet.xushangMax + qingBaoAdd
  1220. -- 悬赏红点
  1221. msgRet.xsDot = 0
  1222. if BarTaskLogic.isDot(human) then
  1223. msgRet.xsDot = 1
  1224. end
  1225. msgRet.canMopup = 0
  1226. if TequanShopLogic.isActiveMopup(human) then
  1227. msgRet.canMopup = human.db.mopupDoCnt < BATTLE_MOPUP_CNT_VIP and 1 or 0
  1228. else
  1229. msgRet.canMopup = human.db.mopupDoCnt < BATTLE_MOPUP_CNT and 1 or 0
  1230. end
  1231. -- 判断额外增加的扫荡次数
  1232. --秘宝增加免费扫荡次数
  1233. local talismanAdd_dailyFeeCnt = TalismanLogic.getTalismanAdd(human, TalismanLogic.OTHER_EFFECT_TBL.GJ_SD_FREE_CNT) or 0
  1234. if 0 < (BattleLogic_GetAddFreeMopupNum(human) + talismanAdd_dailyFeeCnt) and 0 == msgRet.canMopup then
  1235. msgRet.canMopup = 1
  1236. end
  1237. local monsterOutId = nowNodeConfig.monsterOutID
  1238. if not monsterOutId then
  1239. print("[BattleLogic query] monsterOutId 为空")
  1240. return
  1241. end
  1242. local monsterConfig = MonsterExcel.monsterOut[monsterOutId]
  1243. if not monsterConfig then
  1244. print("[BattleLogic query] 获取到的 monsterConfig 为空 monsterOutId = "..monsterOutId)
  1245. return
  1246. end
  1247. fontVideoInfo(human, msgRet.videoInfo, monsterConfig)
  1248. fontExtraDataSSZH(msgRet.extraDataSSZH, nowNodeConfig.mapID, nNowBattleID, human)
  1249. -- Msg.trace(msgRet)
  1250. Msg.send(msgRet, human.fd)
  1251. hangFightQuery(human)
  1252. end
  1253. -- 获取当前地图ID
  1254. function getMapID(human, args)
  1255. local nNowBattleID = BattleLogic_GetBattleBattleID(human)
  1256. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  1257. if -1 >= nNowBattleID or not tBattleConfig then
  1258. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[getMapID] 获取到的战斗ID或奖励配置不正确")
  1259. print("[getMapID] 获取到的战斗ID或奖励配置不正确 id = "..human.db._id)
  1260. return
  1261. end
  1262. -- local battleID = human.db.battleID
  1263. -- local config = BattleExcel.node[battleID]
  1264. local config = tBattleConfig.node[nNowBattleID]
  1265. if not config then
  1266. return
  1267. end
  1268. local mapConfig = tBattleConfig.map[config.mapID]
  1269. if not mapConfig then
  1270. return
  1271. end
  1272. return config.sceneID
  1273. end
  1274. -- 战役挂机界面查询
  1275. function onHookQuery(human)
  1276. local msgRet = Msg.gc.GC_BATTLE_HANG_QUERY
  1277. calcBattleOut(human)
  1278. local tBattleOut = BattleLogic_GetBattleOut(human)
  1279. local tBattleConfig = BattleExcel
  1280. local nGuaJiID = human.db.guajiID
  1281. if not tBattleConfig or -1 >= nGuaJiID or not tBattleOut then
  1282. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[onHookQuery] 获取到的战斗挂机奖励配置不正确 或 配置信息、挂机ID不正确 id = "..human.db._id)
  1283. print("[onHookQuery] 获取到的战斗挂机奖励配置不正确 或 配置信息、挂机ID不正确 id = "..human.db._id)
  1284. return
  1285. end
  1286. -- local expAdd = human.db.battleOut.exp
  1287. -- local jinbiAdd = human.db.battleOut.jinbi
  1288. -- local greenExpAdd = human.db.battleOut.greenExp
  1289. -- local qingbaoAdd = human.db.battleOut.qingbao
  1290. local expAdd = tBattleOut.exp
  1291. local jinbiAdd = tBattleOut.jinbi
  1292. local greenExpAdd = tBattleOut.greenExp
  1293. local qingbaoAdd = tBattleOut.qingbao
  1294. local skip = GuideLogic.getGuideSkip(human, GuideLogic.SKIPTYPE_JUMP_BATTLE_EXP)
  1295. if not skip then
  1296. expAdd = 1510
  1297. end
  1298. local items = { }
  1299. local len = #items
  1300. local tempTable = { }
  1301. if tBattleOut.items then
  1302. tempTable = Util.copyTable(tBattleOut.items)
  1303. end
  1304. tempTable[ItemDefine.ITEM_EXP_ID] = tempTable[ItemDefine.ITEM_EXP_ID] or 0
  1305. tempTable[ItemDefine.ITEM_EXP_ID] = expAdd
  1306. tempTable[ItemDefine.ITEM_JINBI_ID] = tempTable[ItemDefine.ITEM_JINBI_ID] or 0
  1307. tempTable[ItemDefine.ITEM_JINBI_ID] = jinbiAdd
  1308. tempTable[ItemDefine.ITEM_GREEN_EXP_ID] = tempTable[ItemDefine.ITEM_GREEN_EXP_ID] or 0
  1309. tempTable[ItemDefine.ITEM_GREEN_EXP_ID] = greenExpAdd
  1310. tempTable[ItemDefine.ITEM_QINGBAO_ID] = tempTable[ItemDefine.ITEM_QINGBAO_ID] or 0
  1311. tempTable[ItemDefine.ITEM_QINGBAO_ID] = qingbaoAdd
  1312. local list = DropExchangeLogic.getAbsCanDrop(human)
  1313. if list then
  1314. for k, v in pairs(list) do
  1315. if tempTable[k] and tempTable[k] > 0 then
  1316. len = len + 1
  1317. items[len] = { }
  1318. items[len].id = k
  1319. items[len].cnt = tempTable[k]
  1320. end
  1321. end
  1322. end
  1323. for k, v in pairs(tempTable) do
  1324. if not list or not list[k] then
  1325. len = len + 1
  1326. items[len] = { }
  1327. items[len].id = k
  1328. items[len].cnt = v
  1329. end
  1330. end
  1331. -- 发消息
  1332. local guajiID = nGuaJiID > #tBattleConfig.node and #tBattleConfig.node or nGuaJiID
  1333. if guajiID == 0 then
  1334. return Broadcast.sendErr(human, Lang.BATTLE_GUAJI_ERR)
  1335. end
  1336. local nodeConfig = tBattleConfig.node[guajiID]
  1337. local now = os.time()
  1338. local outSec = now - human.db.battleOut.expTs1
  1339. local maxHangTime = getHangMaxTime(human)
  1340. local idx = 1
  1341. for i = 1, #items do
  1342. Grid.makeItem(msgRet.items[i], items[i].id, items[i].cnt)
  1343. end
  1344. local len = #items
  1345. if human.db.battleOut.equip then
  1346. for k, equipGrid in ipairs(tBattleOut.equip) do
  1347. if len >= 10 then
  1348. msgRet.items[0] = len
  1349. msgRet.isEnd = 0
  1350. msgRet.index = idx
  1351. msgRet.maxTime = maxHangTime
  1352. if maxHangTime >= outSec then
  1353. msgRet.time = outSec
  1354. else
  1355. msgRet.time = maxHangTime
  1356. end
  1357. local minHour = math.floor(msgRet.time / HOUR_SEC)
  1358. minHour = (minHour ~= 0) and minHour or 1
  1359. msgRet.diamond = minHour * DIAMOND_COST_PER_HOUR
  1360. msgRet.exp = nodeConfig.hangExp
  1361. msgRet.jinbi = nodeConfig.hangJinbi
  1362. msgRet.greenExp = nodeConfig.hangGreenExp
  1363. msgRet.qingbao = nodeConfig.hangQingbao or 0
  1364. Msg.send(msgRet, human.fd)
  1365. len = 0
  1366. idx = idx + 1
  1367. msgRet = Msg.gc.GC_BATTLE_HANG_QUERY
  1368. end
  1369. len = len + 1
  1370. Grid.makeItem(msgRet.items[len], equipGrid.id, 1, nil, equipGrid)
  1371. end
  1372. end
  1373. msgRet.isEnd = 1
  1374. msgRet.index = idx
  1375. msgRet.items[0] = len
  1376. msgRet.maxTime = maxHangTime
  1377. if maxHangTime >= outSec then
  1378. msgRet.time = outSec
  1379. else
  1380. msgRet.time = maxHangTime
  1381. end
  1382. local minHour = math.floor(msgRet.time / HOUR_SEC)
  1383. minHour = (minHour ~= 0) and minHour or 1
  1384. msgRet.diamond = minHour * DIAMOND_COST_PER_HOUR
  1385. msgRet.exp = nodeConfig.hangExp
  1386. msgRet.jinbi = nodeConfig.hangJinbi
  1387. msgRet.greenExp = nodeConfig.hangGreenExp
  1388. msgRet.qingbao = nodeConfig.hangQingbao or 0
  1389. Msg.send(msgRet, human.fd)
  1390. end
  1391. local function isChapterDot(human, mapID)
  1392. local chapterReward = BattleLogic_GetChapterReward(human)
  1393. local nBattleID = BattleLogic_GetBattleBattleID(human)
  1394. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  1395. if not chapterReward or not tBattleConfig or -1 >= nBattleID or chapterReward[mapID] then
  1396. return false
  1397. end
  1398. local battleID = nBattleID
  1399. local battleNodeConfig = tBattleConfig.node[battleID]
  1400. if not battleNodeConfig then
  1401. if battleID == #tBattleConfig.node + 1 then
  1402. return true
  1403. else
  1404. return false
  1405. end
  1406. else
  1407. local roleMapId = battleNodeConfig.mapID
  1408. if roleMapId <= mapID then
  1409. return false
  1410. end
  1411. end
  1412. return true
  1413. end
  1414. function battleWorldMapQuery(human)
  1415. -- 先取配置
  1416. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  1417. local nBattleID = BattleLogic_GetBattleBattleID(human)
  1418. local nBattleType = BattleLogic_GetBattleType(human)
  1419. if not tBattleConfig or -1 >= nBattleID or -1 >= nBattleType then
  1420. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[battleWorldMapQuery] 获取到的战斗挂机奖励配置不正确 或 配置信息、战斗关卡ID不正确 id = "..human.db._id)
  1421. print("[battleWorldMapQuery] 获取到的战斗挂机奖励配置不正确 或 配置信息、挂机ID不正确 id = "..human.db._id)
  1422. return
  1423. end
  1424. local msgRet = Msg.gc.GC_BATTLE_WORLD_MAP_QUERY
  1425. local worldMapConfig = tBattleConfig.map
  1426. local battleID = nBattleID > #tBattleConfig.node and #tBattleConfig.node or nBattleID
  1427. local battleNodeConfig = tBattleConfig.node[battleID]
  1428. local len = #worldMapConfig
  1429. if not BATTLE_LEVEL_PLAYER_LIST[nBattleType] then
  1430. BATTLE_LEVEL_PLAYER_LIST[nBattleType] = {}
  1431. end
  1432. local tBattleLevelPlayerList = BATTLE_LEVEL_PLAYER_LIST[nBattleType]
  1433. for i = 1, len do
  1434. local v = worldMapConfig[i]
  1435. msgRet.worldMap[i].mapID = i
  1436. msgRet.worldMap[i].mapName = v.name or ""
  1437. msgRet.worldMap[i].mapBuild = v.build or 0
  1438. msgRet.worldMap[i].mapBg = v.bg or 0
  1439. msgRet.worldMap[i].mapPos[0] = 2
  1440. msgRet.worldMap[i].mapPos[1] = v.pos[1]
  1441. msgRet.worldMap[i].mapPos[2] = v.pos[2]
  1442. msgRet.worldMap[i].status =(battleNodeConfig.mapID >= i) and 1 or 0
  1443. msgRet.worldMap[i].story = v.des or ""
  1444. if battleNodeConfig.mapID == i then
  1445. msgRet.worldMap[i].maxLevel = battleNodeConfig.maxLevel
  1446. msgRet.worldMap[i].curLevel = battleNodeConfig.curLevel
  1447. else
  1448. msgRet.worldMap[i].maxLevel = 0
  1449. msgRet.worldMap[i].curLevel = 0
  1450. end
  1451. local reward = v.reward
  1452. local l = 0
  1453. msgRet.worldMap[i].chapterReward[0] = #reward
  1454. for _, rewardData in pairs(reward) do
  1455. l = l + 1
  1456. Grid.makeItem(msgRet.worldMap[i].chapterReward[l], rewardData[1], rewardData[2])
  1457. end
  1458. msgRet.worldMap[i].chapterDot = 0
  1459. if isChapterDot(human, i) then
  1460. msgRet.worldMap[i].chapterDot = 1
  1461. end
  1462. local cnt = 0
  1463. -- BATTLE_LEVEL_PLAYER_LIST[i] = BATTLE_LEVEL_PLAYER_LIST[i] or { }
  1464. tBattleLevelPlayerList[i] = tBattleLevelPlayerList[i] or { }
  1465. -- for s, t in pairs(BATTLE_LEVEL_PLAYER_LIST[i]) do
  1466. for s, t in pairs(tBattleLevelPlayerList[i]) do
  1467. cnt = cnt + 1
  1468. RoleLogic.makeRoleBase(t, msgRet.worldMap[i].roleList[cnt])
  1469. if cnt >= 3 then
  1470. break
  1471. end
  1472. end
  1473. msgRet.worldMap[i].roleList[0] = cnt
  1474. end
  1475. msgRet.worldMap[0] = len
  1476. Msg.send(msgRet, human.fd)
  1477. end
  1478. function battleNodeQuery(human, mapID)
  1479. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  1480. local nBattleID = BattleLogic_GetBattleBattleID(human)
  1481. if not tBattleConfig or -1 >= nBattleID then
  1482. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[battleNodeQuery] 获取到的战斗挂机奖励配置不正确 或 配置信息、战斗关卡ID不正确 id = "..human.db._id)
  1483. print("[battleNodeQuery] 获取到的战斗挂机奖励配置不正确 或 配置信息、挂机ID不正确 id = "..human.db._id)
  1484. return
  1485. end
  1486. local msgRet = Msg.gc.GC_BATTLE_NODE_QUERY
  1487. local nodeConfig = tBattleConfig.node
  1488. local lenConfig = #nodeConfig
  1489. local len = 0
  1490. msgRet.battleID = nBattleID or 0
  1491. for i = 1, lenConfig do
  1492. local v = nodeConfig[i]
  1493. if v.mapID == mapID then
  1494. len = len + 1
  1495. msgRet.nodeInfo[len].nodeName = v.name
  1496. msgRet.nodeInfo[len].battleID = i
  1497. msgRet.nodeInfo[len].needLv = v.needLv
  1498. msgRet.nodeInfo[len].needZDL = v.needZDL
  1499. msgRet.nodeInfo[len].hasSuipian = v.hasSuipian
  1500. end
  1501. end
  1502. msgRet.nodeInfo[0] = len
  1503. Msg.send(msgRet, human.fd)
  1504. end
  1505. function initBattleOut(human, now)
  1506. if human.db.battleOut then
  1507. return
  1508. end
  1509. if false == BattleLogic_InitAllBattleOut(human, now) then
  1510. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "initBattleOut 初始化挂机奖励表失败 id = "
  1511. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  1512. return
  1513. end
  1514. -- human.db.battleOut = { }
  1515. -- human.db.battleOut.expTs1 = now
  1516. -- -- 经验开始产出时间戳
  1517. -- human.db.battleOut.expTs2 = now
  1518. -- -- 经验产出结算时间戳
  1519. -- human.db.battleOut.itemTs1 = now
  1520. -- -- 道具产出时间戳
  1521. -- human.db.battleOut.itemTs2 = now
  1522. -- -- 道具产出结算时间戳
  1523. -- human.db.battleOut.exp = 0
  1524. -- human.db.battleOut.jinbi = 0
  1525. -- human.db.battleOut.greenExp = 0
  1526. -- human.db.battleOut.qingbao = 0
  1527. -- human.db.battleOut.items = nil
  1528. -- -- 产出的待收获的战利品
  1529. -- human.db.battleOut.equip = nil
  1530. -- -- 产出的待收获的装备
  1531. end
  1532. function calcBattleOut(human,isDiamond)
  1533. local now = os.time()
  1534. initBattleOut(human, now)
  1535. calcBattleExpOut(human, now)
  1536. calcBattleItemOut(human, now)
  1537. if isDiamond then -- 钻石消耗 所有产出翻1.5倍
  1538. local tBattleOut = BattleLogic_GetBattleOut(human)
  1539. if not tBattleOut then
  1540. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "calcBattleOut 获取挂机奖励列表失败 id = "
  1541. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  1542. return
  1543. end
  1544. -- human.db.battleOut.exp = math.floor(human.db.battleOut.exp * DIAMOND_ADDITION)
  1545. -- human.db.battleOut.jinbi = math.floor(human.db.battleOut.jinbi * DIAMOND_ADDITION)
  1546. -- human.db.battleOut.greenExp = math.floor(human.db.battleOut.greenExp * DIAMOND_ADDITION)
  1547. -- human.db.battleOut.qingbao = math.floor(human.db.battleOut.qingbao * DIAMOND_ADDITION)
  1548. -- local items = human.db.battleOut.items or {}
  1549. tBattleOut.exp = math.floor(tBattleOut.exp * DIAMOND_ADDITION)
  1550. tBattleOut.jinbi = math.floor(tBattleOut.jinbi * DIAMOND_ADDITION)
  1551. tBattleOut.greenExp = math.floor(tBattleOut.greenExp * DIAMOND_ADDITION)
  1552. tBattleOut.qingbao = math.floor(tBattleOut.qingbao * DIAMOND_ADDITION)
  1553. local items = tBattleOut.items or {}
  1554. for id,cnt in pairs(items) do
  1555. items[id] = math.floor(cnt * DIAMOND_ADDITION)
  1556. end
  1557. -- local equipList = human.db.battleOut.equip or {}
  1558. local equipList = tBattleOut.equip or {}
  1559. local equipMap = {}
  1560. for _,equip in ipairs(equipList) do
  1561. equipMap[equip.id] = equipMap[equip.id] or 0
  1562. equipMap[equip.id] = equipMap[equip.id] + 1
  1563. end
  1564. for id,cnt in pairs(equipMap) do
  1565. local count = math.floor(cnt * DIAMOND_ADDITION)
  1566. for i = cnt,count do
  1567. local equipGrid = EquipLogic.makeEquip(id)
  1568. equipList[#equipList + 1] = equipGrid
  1569. end
  1570. end
  1571. end
  1572. end
  1573. -- 获取正确的剩余可收益的结算时间
  1574. function getSurMaxHangTime(maxHangTime, ts1, now)
  1575. if ts1 + maxHangTime > now then
  1576. return now
  1577. else
  1578. return ts1 + maxHangTime
  1579. end
  1580. end
  1581. -- function calcBattleExpOut(human, now)
  1582. -- local maxHangTime = getHangMaxTime(human)
  1583. -- if human.db.battleOut.expTs2 - human.db.battleOut.expTs1 >= maxHangTime then
  1584. -- return
  1585. -- end
  1586. -- local outTime = getSurMaxHangTime(maxHangTime, human.db.battleOut.expTs1, now)
  1587. -- local outSec = outTime - human.db.battleOut.expTs2
  1588. -- local outCnt = math.floor(outSec / BATTLE_HANG_EXP_OUT_PERIOD)
  1589. -- if outCnt < 1 then
  1590. -- return
  1591. -- end
  1592. -- local guajiID = human.db.guajiID > #BattleExcel.node and #BattleExcel.node or human.db.guajiID
  1593. -- if guajiID == 0 then
  1594. -- return
  1595. -- end
  1596. -- local nowNodeConfig = BattleExcel.node[guajiID]
  1597. -- human.db.battleOut.expTs2 = human.db.battleOut.expTs2 + outCnt * BATTLE_HANG_EXP_OUT_PERIOD
  1598. -- if now - human.db.battleOut.expTs1 >= maxHangTime then
  1599. -- human.db.battleOut.expTs2 = now
  1600. -- end
  1601. -- local vipExpAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER7) or 0) / 100
  1602. -- local vipJinAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER8) or 0) / 100
  1603. -- local vipGreenExpAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER9) or 0) / 100
  1604. -- local vipQingbaoAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER19) or 0) / 100
  1605. -- local exp = nowNodeConfig.hangExp
  1606. -- local jinbi = nowNodeConfig.hangJinbi
  1607. -- local greenExp = nowNodeConfig.hangGreenExp
  1608. -- local qingbao = nowNodeConfig.hangQingbao
  1609. -- human.db.battleOut.exp = human.db.battleOut.exp + math.floor(outCnt * exp *(1 + vipExpAdd))
  1610. -- human.db.battleOut.jinbi = human.db.battleOut.jinbi + math.floor(outCnt * jinbi *(1 + vipJinAdd))
  1611. -- human.db.battleOut.greenExp = human.db.battleOut.greenExp + math.floor(outCnt * greenExp *(1 + vipGreenExpAdd))
  1612. -- human.db.battleOut.qingbao = human.db.battleOut.qingbao + math.floor(outCnt * qingbao *(1 + vipQingbaoAdd))
  1613. -- end
  1614. function calcBattleExpOut(human, now)
  1615. local tBattleOut = BattleLogic_GetBattleOut(human)
  1616. if not tBattleOut then
  1617. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "calcBattleExpOut 获取挂机奖励列表失败 id = "
  1618. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  1619. return
  1620. end
  1621. local maxHangTime = getHangMaxTime(human)
  1622. if tBattleOut.expTs2 - tBattleOut.expTs1 >= maxHangTime then
  1623. return
  1624. end
  1625. local outTime = getSurMaxHangTime(maxHangTime, tBattleOut.expTs1, now)
  1626. local outSec = outTime - tBattleOut.expTs2
  1627. local outCnt = math.floor(outSec / BATTLE_HANG_EXP_OUT_PERIOD)
  1628. if outCnt < 1 then
  1629. return
  1630. end
  1631. local tBattleNodeConfig = BattleExcel
  1632. local nGuaJiID = human.db.guajiID
  1633. if not tBattleNodeConfig or 0 > nGuaJiID then
  1634. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "calcBattleExpOut 获取到的配置表不正确或挂机ID不正确 id = "
  1635. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  1636. return
  1637. end
  1638. local guajiID = nGuaJiID > #tBattleNodeConfig.node and #tBattleNodeConfig.node or nGuaJiID
  1639. if guajiID == 0 then
  1640. return
  1641. end
  1642. local nowNodeConfig = tBattleNodeConfig.node[guajiID]
  1643. tBattleOut.expTs2 = tBattleOut.expTs2 + outCnt * BATTLE_HANG_EXP_OUT_PERIOD
  1644. if now - tBattleOut.expTs1 >= maxHangTime then
  1645. tBattleOut.expTs2 = now
  1646. end
  1647. local vipExpAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER7) or 0) / 100
  1648. local vipJinAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER8) or 0) / 100
  1649. local vipGreenExpAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER9) or 0) / 100
  1650. local vipQingbaoAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER19) or 0) / 100
  1651. --秘宝方面的加成
  1652. local talismanAdd_qb = (TalismanLogic.getTalismanAdd(human, TalismanLogic.OTHER_EFFECT_TBL.GJ_QB) or 0) / 100
  1653. local talismanAdd_hero_exp = (TalismanLogic.getTalismanAdd(human, TalismanLogic.OTHER_EFFECT_TBL.GJ_HERO_EXP) or 0) / 100
  1654. local exp = nowNodeConfig.hangExp
  1655. local jinbi = nowNodeConfig.hangJinbi
  1656. local greenExp = nowNodeConfig.hangGreenExp
  1657. local qingbao = nowNodeConfig.hangQingbao
  1658. tBattleOut.exp = tBattleOut.exp + math.floor(outCnt * exp *(1 + vipExpAdd))
  1659. tBattleOut.jinbi = tBattleOut.jinbi + math.floor(outCnt * jinbi *(1 + vipJinAdd))
  1660. tBattleOut.greenExp = tBattleOut.greenExp + math.floor(outCnt * greenExp *(1 + vipGreenExpAdd))
  1661. tBattleOut.qingbao = tBattleOut.qingbao + math.floor(outCnt * qingbao *(1 + vipQingbaoAdd))
  1662. tBattleOut.qingbao = tBattleOut.qingbao + math.ceil(tBattleOut.qingbao * talismanAdd_qb)
  1663. tBattleOut.greenExp = tBattleOut.greenExp + math.ceil(tBattleOut.greenExp * talismanAdd_hero_exp)
  1664. end
  1665. -- 根据时间计算道具产出
  1666. local ITEM_OUT_LIST = { }
  1667. function getItemOutsByTime(config, sec)
  1668. Util.cleanTable(ITEM_OUT_LIST)
  1669. local outCnt = math.floor(sec / BATTLE_HANG_ITEM_OUT_PERIOD)
  1670. if outCnt < 1 then
  1671. return ITEM_OUT_LIST
  1672. end
  1673. -- 普通掉落
  1674. local dropID = config.dropID
  1675. local dropConfig = DropExcel.dropBattle[dropID]
  1676. local weightSum = 0
  1677. for i = 1, #dropConfig.dropRule do
  1678. local tempConfig = dropConfig.dropRule[i]
  1679. weightSum = weightSum + tempConfig[4]
  1680. end
  1681. for i = 1, outCnt do
  1682. local itemID, itemCnt = randItemOut(dropConfig.dropRule, weightSum)
  1683. if itemID and itemCnt and itemCnt > 0 then
  1684. ITEM_OUT_LIST[itemID] =(ITEM_OUT_LIST[itemID] or 0) + itemCnt
  1685. end
  1686. end
  1687. for i = 1, #dropConfig.dropRule2 do
  1688. local tempConfig = dropConfig.dropRule2[i]
  1689. local itemID = tempConfig[1]
  1690. local itemMin = tempConfig[2]
  1691. local itemMax = tempConfig[3]
  1692. local itemCnt = math.random(itemMin, itemMax) * outCnt
  1693. if itemCnt > 0 then
  1694. ITEM_OUT_LIST[itemID] =(ITEM_OUT_LIST[itemID] or 0) + itemCnt
  1695. end
  1696. end
  1697. -- 三小时掉落
  1698. outCnt = math.floor(sec / BATTLE_HANG_ITEM_OUT_PERIOD_2)
  1699. if outCnt < 1 then
  1700. return ITEM_OUT_LIST
  1701. end
  1702. weightSum = 0
  1703. for i = 1, #dropConfig.dropRule3 do
  1704. local tempConfig = dropConfig.dropRule3[i]
  1705. weightSum = weightSum + tempConfig[4]
  1706. end
  1707. for i = 1, outCnt do
  1708. local itemID, itemCnt = randItemOut(dropConfig.dropRule3, weightSum)
  1709. if itemID and itemCnt and itemCnt > 0 then
  1710. ITEM_OUT_LIST[itemID] =(ITEM_OUT_LIST[itemID] or 0) + itemCnt
  1711. end
  1712. end
  1713. return ITEM_OUT_LIST
  1714. end
  1715. -- function calcBattleItemOut(human, now,isDiamond)
  1716. -- local maxHangTime = getHangMaxTime(human)
  1717. -- if human.db.battleOut.itemTs2 - human.db.battleOut.itemTs1 >= maxHangTime then
  1718. -- return
  1719. -- end
  1720. -- local outTime = getSurMaxHangTime(maxHangTime, human.db.battleOut.itemTs1, now)
  1721. -- local outSec = outTime - human.db.battleOut.itemTs2
  1722. -- local outCnt = math.floor(outSec / BATTLE_HANG_ITEM_OUT_PERIOD)
  1723. -- if outCnt < 1 then
  1724. -- return
  1725. -- end
  1726. -- local guajiID = human.db.guajiID > #BattleExcel.node and #BattleExcel.node or human.db.guajiID
  1727. -- if guajiID == 0 then
  1728. -- return
  1729. -- end
  1730. -- local sec = outCnt * BATTLE_HANG_ITEM_OUT_PERIOD
  1731. -- human.db.battleOut.itemTs2 = human.db.battleOut.itemTs2 + sec
  1732. -- if now - human.db.battleOut.itemTs1 >= maxHangTime then
  1733. -- human.db.battleOut.itemTs2 = now
  1734. -- end
  1735. -- local nodeConfig = BattleExcel.node[guajiID]
  1736. -- local items = getItemOutsByTime(nodeConfig, sec)
  1737. -- for itemID, itemCnt in pairs(items) do
  1738. -- -- 判定是否是装备
  1739. -- if ItemDefine.isEquip(itemID) then
  1740. -- -- 生成装备
  1741. -- local equipGrid = EquipLogic.makeEquip(itemID)
  1742. -- if equipGrid then
  1743. -- human.db.battleOut.equip = human.db.battleOut.equip or { }
  1744. -- human.db.battleOut.equip[#human.db.battleOut.equip + 1] = equipGrid
  1745. -- end
  1746. -- else
  1747. -- human.db.battleOut.items = human.db.battleOut.items or { }
  1748. -- human.db.battleOut.items[itemID] = human.db.battleOut.items[itemID] or 0
  1749. -- human.db.battleOut.items[itemID] = human.db.battleOut.items[itemID] + itemCnt
  1750. -- end
  1751. -- end
  1752. -- DropExchangeLogic.getDropItem(human, outSec, BATTLE_HANG_ITEM_OUT_PERIOD, human.db.battleOut)
  1753. -- end
  1754. function calcBattleItemOut(human, now,isDiamond)
  1755. local tBattleOut = BattleLogic_GetBattleOut(human)
  1756. if not tBattleOut then
  1757. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "calcBattleItemOut 获取挂机奖励列表失败 id = "
  1758. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  1759. return
  1760. end
  1761. local maxHangTime = getHangMaxTime(human)
  1762. if tBattleOut.itemTs2 - tBattleOut.itemTs1 >= maxHangTime then
  1763. return
  1764. end
  1765. local outTime = getSurMaxHangTime(maxHangTime, tBattleOut.itemTs1, now)
  1766. local outSec = outTime - tBattleOut.itemTs2
  1767. local outCnt = math.floor(outSec / BATTLE_HANG_ITEM_OUT_PERIOD)
  1768. if outCnt < 1 then
  1769. return
  1770. end
  1771. local tBattleNodeConfig = BattleExcel
  1772. local nGuaJiID = human.db.guajiID
  1773. if not tBattleNodeConfig or 0 > nGuaJiID then
  1774. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "calcBattleItemOut 获取到的配置表不正确或挂机ID不正确 id = "
  1775. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  1776. return
  1777. end
  1778. local guajiID = nGuaJiID > #tBattleNodeConfig.node and #tBattleNodeConfig.node or nGuaJiID
  1779. if guajiID == 0 then
  1780. return
  1781. end
  1782. local sec = outCnt * BATTLE_HANG_ITEM_OUT_PERIOD
  1783. tBattleOut.itemTs2 = tBattleOut.itemTs2 + sec
  1784. if now - tBattleOut.itemTs1 >= maxHangTime then
  1785. tBattleOut.itemTs2 = now
  1786. end
  1787. local talismanAdd_zs = (TalismanLogic.getTalismanAdd(human, TalismanLogic.OTHER_EFFECT_TBL.GJ_ZS) or 0) / 100
  1788. local nodeConfig = tBattleNodeConfig.node[guajiID]
  1789. local items = getItemOutsByTime(nodeConfig, sec)
  1790. for itemID, itemCnt in pairs(items) do
  1791. -- 判定是否是装备
  1792. if ItemDefine.isEquip(itemID) then
  1793. -- 生成装备
  1794. local equipGrid = EquipLogic.makeEquip(itemID)
  1795. if equipGrid then
  1796. tBattleOut.equip = tBattleOut.equip or { }
  1797. tBattleOut.equip[#tBattleOut.equip + 1] = equipGrid
  1798. end
  1799. else
  1800. tBattleOut.items = tBattleOut.items or { }
  1801. tBattleOut.items[itemID] = tBattleOut.items[itemID] or 0
  1802. if itemID == ItemDefine.ITEM_ZUANSHI_ID and talismanAdd_zs > 0 then
  1803. itemCnt = itemCnt + math.ceil(itemCnt * talismanAdd_zs)
  1804. end
  1805. tBattleOut.items[itemID] = tBattleOut.items[itemID] + itemCnt
  1806. end
  1807. end
  1808. DropExchangeLogic.getDropItem(human, outSec, BATTLE_HANG_ITEM_OUT_PERIOD, tBattleOut)
  1809. end
  1810. local function hangExpGet(human,isDiamond)
  1811. local tBattleOut = BattleLogic_GetBattleOut(human)
  1812. if not tBattleOut then
  1813. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "hangExpGet 获取挂机奖励列表失败 id = "
  1814. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  1815. return
  1816. end
  1817. local needDiamond = 0
  1818. -- 是否消耗钻石
  1819. if isDiamond then
  1820. local now = os.time()
  1821. local outSec = now - tBattleOut.expTs1
  1822. local maxHangTime = getHangMaxTime(human)
  1823. outSec = outSec > maxHangTime and maxHangTime or outSec
  1824. local minHour = math.floor(outSec / HOUR_SEC)
  1825. minHour = (minHour ~= 0) and minHour or 1
  1826. local diamondCnt = minHour * DIAMOND_COST_PER_HOUR
  1827. if not ObjHuman.checkRMB(human,diamondCnt) then
  1828. return
  1829. end
  1830. needDiamond = -diamondCnt
  1831. end
  1832. print("==================== needDiamond is ",needDiamond)
  1833. calcBattleOut(human,isDiamond)
  1834. if tBattleOut.exp == 0 then
  1835. return 1
  1836. end
  1837. local jinbiAdd = tBattleOut.jinbi
  1838. if not ObjHuman.canAddJinbi(human, jinbiAdd) then
  1839. return 2
  1840. end
  1841. -- 检测装备数量
  1842. if tBattleOut.equip then
  1843. local equipCnt = #tBattleOut.equip
  1844. if not EquipLogic.checkEmptyCnt(human, equipCnt) then
  1845. return
  1846. end
  1847. end
  1848. local items = { }
  1849. local len = #items
  1850. local maxHangTime = getHangMaxTime(human)
  1851. if tBattleOut.expTs2 - tBattleOut.expTs1 >= maxHangTime then
  1852. local now = os.time()
  1853. tBattleOut.expTs2 = now
  1854. end
  1855. if tBattleOut.itemTs2 - tBattleOut.itemTs1 >= maxHangTime then
  1856. local now = os.time()
  1857. tBattleOut.itemTs2 = now
  1858. end
  1859. tBattleOut.itemTs1 = tBattleOut.itemTs2
  1860. -- 改db
  1861. local tempTable = tBattleOut.items or { }
  1862. tBattleOut.items = nil
  1863. for k, v in pairs(tempTable) do
  1864. len = len + 1
  1865. items[len] = { }
  1866. items[len].id = k
  1867. items[len].cnt = v
  1868. end
  1869. tBattleOut.expTs1 = tBattleOut.expTs2
  1870. local expAdd = tBattleOut.exp
  1871. local greenExpAdd = tBattleOut.greenExp
  1872. local qingbaoAdd = tBattleOut.qingbao
  1873. -- 新手指引 强制经验
  1874. local flag = GuideLogic.getGuideSkip(human, GuideLogic.SKIPTYPE_JUMP_BATTLE_EXP)
  1875. if not flag then
  1876. expAdd = 1510
  1877. end
  1878. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_BATTLE_EXP)
  1879. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_BATTLE_GUAJI)
  1880. tBattleOut.exp = 0
  1881. tBattleOut.jinbi = 0
  1882. tBattleOut.greenExp = 0
  1883. tBattleOut.qingbao = 0
  1884. len = len + 1
  1885. items[len] = { }
  1886. items[len].id = ItemDefine.ITEM_EXP_ID
  1887. items[len].cnt = expAdd
  1888. len = len + 1
  1889. items[len] = { }
  1890. items[len].id = ItemDefine.ITEM_JINBI_ID
  1891. items[len].cnt = jinbiAdd
  1892. len = len + 1
  1893. items[len] = { }
  1894. items[len].id = ItemDefine.ITEM_GREEN_EXP_ID
  1895. items[len].cnt = greenExpAdd
  1896. len = len + 1
  1897. items[len] = { }
  1898. items[len].id = ItemDefine.ITEM_QINGBAO_ID
  1899. items[len].cnt = qingbaoAdd
  1900. -- 给道具
  1901. for i = 1, #items do
  1902. local tempID = items[i].id
  1903. local tempCnt = items[i].cnt
  1904. BagLogic.addItem(human, tempID, tempCnt, "battle")
  1905. end
  1906. -- 给装备
  1907. if tBattleOut.equip then
  1908. for k, equipGrid in ipairs(tBattleOut.equip) do
  1909. EquipLogic.addByEquipGrid(human, equipGrid, "battle", true)
  1910. end
  1911. tBattleOut.equip = nil
  1912. end
  1913. if needDiamond < 0 then
  1914. ObjHuman.decZuanshi(human,needDiamond,"battle")
  1915. end
  1916. return 0, items
  1917. end
  1918. -- 获取挂机收益
  1919. function hangGet(human,isDiamond)
  1920. local ret, items = hangExpGet(human,false)
  1921. if ret == 1 then
  1922. return Broadcast.sendErr(human, Lang.BATTLE_HANG_GET_EXP_ERR_NONE)
  1923. elseif ret == 2 then
  1924. return Broadcast.sendErr(human, Lang.COMMON_ADD_JINBI_LIMIT)
  1925. elseif ret == 0 then
  1926. query(human)
  1927. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1101)
  1928. end
  1929. end
  1930. -- 挂机节点设置
  1931. function nodeSet(human, battleID)
  1932. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  1933. local nNowBattleID = BattleLogic_GetBattleBattleID(human)
  1934. if not tBattleConfig or -1 >= nNowBattleID then
  1935. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "hangExpGet 获取挂机奖励列表失败 id = "
  1936. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  1937. print("[nodeSet] 获取不到战斗配置")
  1938. return
  1939. end
  1940. local nodeConfig = tBattleConfig.node[battleID]
  1941. if nodeConfig == nil then
  1942. return
  1943. end
  1944. -- 前置条件判断
  1945. if battleID > nNowBattleID then
  1946. return Broadcast.sendErr(human, Lang.BATTLE_ID_OVER)
  1947. end
  1948. -- 等级判断
  1949. if human.db.lv < nodeConfig.needLv then
  1950. return Broadcast.sendErr(human, Util.format(Lang.ROLE_LEV_ERROR, nodeConfig.needLv))
  1951. end
  1952. calcBattleOut(human)
  1953. print("[nodeSet] 玩家进行了挂机节点设置 battleID = ".. battleID)
  1954. BattleLogic_SetBattleGuaJiID(human ,battleID)
  1955. --human.db.guajiID = battleID
  1956. setBattleID(human, battleID)
  1957. Msg.send(Msg.gc.GC_BATTLE_NODE_SET, human.fd)
  1958. query(human)
  1959. end
  1960. -- 挂机节点详细信息查询
  1961. function nodeDetailQuery(human, battleID)
  1962. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  1963. local nNowBattleID = BattleLogic_GetBattleBattleID(human)
  1964. if not tBattleConfig or -1 >= nNowBattleID then
  1965. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "nodeDetailQuery 获取挂机奖励列表失败 id = "
  1966. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  1967. print("[nodeDetailQuery] 获取不到战斗配置")
  1968. return
  1969. end
  1970. -- local nodeConfig = BattleExcel.node[battleID]
  1971. local nodeConfig = tBattleConfig.node[battleID]
  1972. if nodeConfig == nil then
  1973. return
  1974. end
  1975. local msgRet = Msg.gc.GC_BATTLE_NODE_DETAIL_QUERY
  1976. msgRet.battleID = battleID
  1977. msgRet.exp = nodeConfig.hangExp
  1978. msgRet.jinbi = nodeConfig.hangJinbi
  1979. msgRet.greenExp = nodeConfig.hangGreenExp
  1980. msgRet.qingbao = nodeConfig.hangQingbao or 0
  1981. msgRet.nodeName = getBattleName(human, battleID)
  1982. local dropID = nodeConfig.dropID
  1983. local dropConfig = DropExcel.dropBattle[dropID]
  1984. local dropCnt = 0
  1985. local list = DropExchangeLogic.getAbsCanDrop(human)
  1986. if list then
  1987. for k, v in pairs(list) do
  1988. dropCnt = dropCnt + 1
  1989. Grid.makeItem(msgRet.items[dropCnt], k, v)
  1990. end
  1991. end
  1992. for i = 1, #dropConfig.dropRule do
  1993. local tempConfig = dropConfig.dropRule[i]
  1994. local itemID = tempConfig[1]
  1995. local itemCnt = tempConfig[3]
  1996. local itemRate = tempConfig[4]
  1997. if itemCnt > 0 and itemRate > 0 then
  1998. dropCnt = dropCnt + 1
  1999. Grid.makeItem(msgRet.items[dropCnt], itemID, 1)
  2000. end
  2001. end
  2002. for i = 1, #dropConfig.dropRule3 do
  2003. local tempConfig = dropConfig.dropRule3[i]
  2004. local itemID = tempConfig[1]
  2005. local itemCnt = tempConfig[3]
  2006. local itemRate = tempConfig[4]
  2007. if itemCnt > 0 and itemRate > 0 then
  2008. dropCnt = dropCnt + 1
  2009. Grid.makeItem(msgRet.items[dropCnt], itemID, 1)
  2010. end
  2011. end
  2012. msgRet.items[0] = dropCnt
  2013. Msg.send(msgRet, human.fd)
  2014. end
  2015. -- 挑战当前挂机节点
  2016. function fight(human)
  2017. local battleID = BattleLogic_GetBattleBattleID(human)
  2018. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  2019. if not tBattleConfig or -1 >= battleID then
  2020. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "nodeDetailQuery 获取挂机奖励列表失败 id = "
  2021. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  2022. print("[nodeDetailQuery] 获取不到战斗配置")
  2023. return
  2024. end
  2025. -- local battleID = human.db.battleID
  2026. -- if BattleExcel.node[human.db.battleID] == nil then
  2027. if tBattleConfig.node[battleID] == nil then
  2028. local msgRet = Msg.gc.GC_BATTLE_GOBACK_MAIN
  2029. msgRet.panelIDs[0] = 1
  2030. msgRet.panelIDs[1] = PanelDefine.PANEL_ID_1008
  2031. Msg.send(msgRet, human.fd)
  2032. return Broadcast.sendErr(human, Lang.BATTLE_MAX_LEVEL)
  2033. end
  2034. -- if human.db.lv < BattleExcel.node[human.db.battleID].needLv then
  2035. if human.db.lv < tBattleConfig.node[battleID].needLv then
  2036. local msgRet = Msg.gc.GC_BATTLE_GOBACK_MAIN
  2037. msgRet.panelIDs[0] = 1
  2038. msgRet.panelIDs[1] = PanelDefine.PANEL_ID_1008
  2039. Msg.send(msgRet, human.fd)
  2040. return Broadcast.sendErr(human, Util.format(Lang.ROLE_LEV_ERROR, tBattleConfig.node[battleID].needLv))
  2041. end
  2042. local config = tBattleConfig.node[battleID]
  2043. local mapConfig = tBattleConfig.map[config.mapID]
  2044. local monsterOutID = config.monsterOutID
  2045. local mapID = mapConfig.bg
  2046. CombatLogic.combatBegin(human, config.sceneID, monsterOutID, CombatDefine.COMBAT_TYPE1, battleID)
  2047. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_BATTLE)
  2048. end
  2049. function onFightEnd(human, result, fightTypeID, param1, combatInfo)
  2050. -- 设置一些战斗结算信息
  2051. combatInfo.defender.name = Util.format(Lang.COMBAT_BATTLE_DEFEND_NAME, param1)
  2052. if CombatDefine.RESULT_WIN ~= result then
  2053. return
  2054. end
  2055. local nBattleType = BattleLogic_GetBattleType(human)
  2056. local guajiID = BattleLogic_GetBattleGuaJiID(human)
  2057. local battleID = BattleLogic_GetBattleBattleID(human)
  2058. if EliteDefine.COPY_ELITE_ERROR == nBattleType or -1 >= guajiID or -1 >= battleID then
  2059. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "onFightEnd 获取战斗类型、挂机ID、战斗关卡ID失败 id = "
  2060. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  2061. print("[onFightEnd] 获取战斗类型、挂机ID、战斗关卡ID失败")
  2062. return
  2063. end
  2064. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  2065. if not tBattleConfig then
  2066. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "onFightEnd 获取战斗配置失败 id = "
  2067. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  2068. print("[onFightEnd] 获取战斗配置失败")
  2069. return
  2070. end
  2071. -- local guajiID = human.db.guajiID
  2072. -- local battleID = human.db.battleID
  2073. if battleID ~= param1 then
  2074. return
  2075. end
  2076. if EliteDefine.COPY_ELITE_NORMAL == nBattleType then
  2077. MainDianLogic.MaiDian_Begin(human, MaiDianDefine.MAIDIAN_TYPE_BATTLE, {nValue = battleID})
  2078. end
  2079. local nAllFightLen = #tBattleConfig.node
  2080. local nextGuajiID = (guajiID + 1) > nAllFightLen and nAllFightLen or guajiID + 1
  2081. local nextBattleID = (battleID + 1) > nAllFightLen and nAllFightLen or battleID + 1
  2082. -- local nextBattleConfig = BattleExcel.node[nextBattleID]
  2083. -- local config = BattleExcel.node[battleID]
  2084. if (battleID + 1) > nAllFightLen then
  2085. BattleLogic_SetBattleAdopt(human, nBattleType, 1)
  2086. end
  2087. local nextBattleConfig = tBattleConfig.node[nextBattleID]
  2088. local config = tBattleConfig.node[battleID]
  2089. if not BATTLE_LEVEL_PLAYER_LIST[nBattleType] then
  2090. BATTLE_LEVEL_PLAYER_LIST[nBattleType] = {}
  2091. end
  2092. local tBattleLevelPlayerList = BATTLE_LEVEL_PLAYER_LIST[nBattleType]
  2093. -- 如果过大关卡
  2094. if nextBattleConfig and nextBattleConfig.mapID ~= config.mapID then
  2095. -- 清除记录
  2096. tBattleLevelPlayerList[config.mapID] = tBattleLevelPlayerList[config.mapID] or { }
  2097. tBattleLevelPlayerList[config.mapID][human.db._id] = nil
  2098. -- 增加新纪录
  2099. tBattleLevelPlayerList[nextBattleConfig.mapID] = tBattleLevelPlayerList[nextBattleConfig.mapID] or { }
  2100. tBattleLevelPlayerList[nextBattleConfig.mapID][human.db._id] = { }
  2101. RoleLogic.getRoleBase(human, tBattleLevelPlayerList[nextBattleConfig.mapID][human.db._id])
  2102. else
  2103. if config.mapID == 1 then
  2104. tBattleLevelPlayerList[config.mapID] = tBattleLevelPlayerList[config.mapID] or { }
  2105. if tBattleLevelPlayerList[config.mapID][human.db._id] == nil then
  2106. -- 增加新纪录
  2107. tBattleLevelPlayerList[config.mapID][human.db._id] = { }
  2108. RoleLogic.getRoleBase(human, tBattleLevelPlayerList[config.mapID][human.db._id])
  2109. end
  2110. else
  2111. if not tBattleLevelPlayerList[config.mapID] or not tBattleLevelPlayerList[config.mapID][human.db._id] then
  2112. tBattleLevelPlayerList[config.mapID] = tBattleLevelPlayerList[config.mapID] or { }
  2113. tBattleLevelPlayerList[config.mapID][human.db._id] = { }
  2114. RoleLogic.getRoleBase(human, tBattleLevelPlayerList[config.mapID][human.db._id])
  2115. end
  2116. end
  2117. end
  2118. -- -- 如果过大关卡
  2119. -- if nextBattleConfig and nextBattleConfig.mapID ~= config.mapID then
  2120. -- -- 清除记录
  2121. -- BATTLE_LEVEL_PLAYER_LIST[config.mapID] = BATTLE_LEVEL_PLAYER_LIST[config.mapID] or { }
  2122. -- BATTLE_LEVEL_PLAYER_LIST[config.mapID][human.db._id] = nil
  2123. -- -- 增加新纪录
  2124. -- BATTLE_LEVEL_PLAYER_LIST[nextBattleConfig.mapID] = BATTLE_LEVEL_PLAYER_LIST[nextBattleConfig.mapID] or { }
  2125. -- BATTLE_LEVEL_PLAYER_LIST[nextBattleConfig.mapID][human.db._id] = { }
  2126. -- RoleLogic.getRoleBase(human, BATTLE_LEVEL_PLAYER_LIST[nextBattleConfig.mapID][human.db._id])
  2127. -- else
  2128. -- if config.mapID == 1 then
  2129. -- BATTLE_LEVEL_PLAYER_LIST[config.mapID] = BATTLE_LEVEL_PLAYER_LIST[config.mapID] or { }
  2130. -- if BATTLE_LEVEL_PLAYER_LIST[config.mapID][human.db._id] == nil then
  2131. -- -- 增加新纪录
  2132. -- BATTLE_LEVEL_PLAYER_LIST[config.mapID][human.db._id] = { }
  2133. -- RoleLogic.getRoleBase(human, BATTLE_LEVEL_PLAYER_LIST[config.mapID][human.db._id])
  2134. -- end
  2135. -- else
  2136. -- if not BATTLE_LEVEL_PLAYER_LIST[config.mapID] or not BATTLE_LEVEL_PLAYER_LIST[config.mapID][human.db._id] then
  2137. -- BATTLE_LEVEL_PLAYER_LIST[config.mapID] = BATTLE_LEVEL_PLAYER_LIST[config.mapID] or { }
  2138. -- BATTLE_LEVEL_PLAYER_LIST[config.mapID][human.db._id] = { }
  2139. -- RoleLogic.getRoleBase(human, BATTLE_LEVEL_PLAYER_LIST[config.mapID][human.db._id])
  2140. -- end
  2141. -- end
  2142. -- end
  2143. BattleLogic_SetBattleBattleID(human, nextBattleID)
  2144. -- human.db.battleID = battleID + 1
  2145. -- 通过第10关,默认开启二倍速
  2146. if nextBattleID == 10 and EliteDefine.COPY_ELITE_NORMAL == nBattleType then
  2147. human.db.combatSpeed = 2
  2148. end
  2149. combatInfo.attacker.oldLv = human.db.lv
  2150. -- 给奖励
  2151. combatInfo.rewardItem = { }
  2152. for i = 1, #config.winReward do
  2153. local itemID = config.winReward[i][1]
  2154. local itemCnt = config.winReward[i][2]
  2155. -- 装备不在这显示
  2156. combatInfo.rewardItem[i] = combatInfo.rewardItem[i] or { }
  2157. combatInfo.rewardItem[i] = { itemID, itemCnt }
  2158. BagLogic.addItem(human, itemID, itemCnt, "battle_win")
  2159. end
  2160. combatInfo.attacker.lv = human.db.lv
  2161. combatInfo.getEquip = human.getEquip
  2162. human.getEquip = nil
  2163. -- TODO:记录主线关卡
  2164. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, human.db._id, human.db.account, human.db.name, human.db.battleID)
  2165. if nBattleType == EliteDefine.COPY_ELITE_NORMAL then
  2166. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1101)
  2167. GuideLogic.onCallback(human)
  2168. JibanLogic.onCallback(human, 1, battleID)
  2169. TuiSongLiBao.tuiSongLiBaoOnTask(
  2170. human,
  2171. TuiSongLiBao.TUISONGLIBAOTASK_ZHENGZHAN,
  2172. -- human.db.guajiID - 1,
  2173. -- human.db.guajiID - 2
  2174. guajiID - 1,
  2175. guajiID - 2
  2176. )
  2177. ChengjiuLogic.onCallback(human, ChengjiuDefine.CJ_TASK_TYPE_1, nextGuajiID)
  2178. MengxinLogic.onCallBack(human, MengxinLogic.MX_TASK_TYPE_1, nextGuajiID)
  2179. for k, v in pairs(KingWorldLogic.funcID) do
  2180. YunYingLogic.updateIcon(KingWorldLogic.YYInfo[k], human)
  2181. break
  2182. end
  2183. end
  2184. -- 存储战斗记录
  2185. local videoUuid = CombatVideo.saveBattleVideo(human.db._id, combatInfo)
  2186. human.db.battleVideoUuid = videoUuid
  2187. BattleDBLogic.updateBattleDB(combatInfo.attacker, battleID, combatInfo, videoUuid, nBattleType)
  2188. if nextBattleConfig and nextBattleConfig.mapID ~= config.mapID then
  2189. -- 新的地图
  2190. -- 通知客户端
  2191. Msg.send(Msg.gc.GC_BATTLE_NODE_SET, human.fd)
  2192. end
  2193. BattleLogic_SetBattleGuaJiID(human, nextGuajiID)
  2194. --human.db.guajiID = nextGuajiID
  2195. if nextBattleConfig then
  2196. setBattleID(human, nextGuajiID)
  2197. end
  2198. local showNext = 1
  2199. -- if BattleExcel.node[human.db.battleID] and human.db.lv < BattleExcel.node[human.db.battleID].needLv then
  2200. if tBattleConfig.node[nextBattleID] and human.db.lv < tBattleConfig.node[nextBattleID].needLv then
  2201. showNext = 2
  2202. end
  2203. if human.db.lv < 5 then
  2204. showNext = 0
  2205. end
  2206. -- nextBattleConfig = BattleExcel.node[human.db.battleID]
  2207. nextBattleConfig = tBattleConfig.node[nextBattleID]
  2208. if not nextBattleConfig then
  2209. showNext = 0
  2210. end
  2211. if battleID == 3 then
  2212. showNext = 0
  2213. end
  2214. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1105)
  2215. -- 额外奖励
  2216. local needLevel, itemName = getNextRewardName(human)
  2217. if needLevel ~= nil then
  2218. local tb = { needLevel, Lang.BATTLE_FIGHT_GUAN, "|", itemName, "|", showNext }
  2219. local str = table.concat(tb)
  2220. combatInfo.endParam = str
  2221. else
  2222. local tb = { showNext }
  2223. local str = table.concat(tb)
  2224. combatInfo.endParam = str
  2225. end
  2226. -- 触发事件
  2227. GiftLogic.trigger(human,PRINCIPAL_LINE_EVNET,{id = battleID})
  2228. WarOrder.trigger(human,BATTLE_ORDER_TYPE)
  2229. end
  2230. function setBattleID(human, guajiID)
  2231. local nNowGuaJiID = BattleLogic_GetBattleGuaJiID(human)
  2232. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  2233. if -1 >= nNowGuaJiID or not tBattleConfig then
  2234. return
  2235. end
  2236. -- if guajiID > human.db.guajiID and human.db.guajiID ~= 0 then
  2237. if guajiID > nNowGuaJiID and nNowGuaJiID ~= 0 then
  2238. -- 下发挂机收益升级提示
  2239. local msgRet = Msg.gc.GC_BATTLE_REWARD_UP
  2240. Grid.makeItem(msgRet.itemExp, ItemDefine.ITEM_EXP_ID, 1)
  2241. Grid.makeItem(msgRet.itemJinbi, ItemDefine.ITEM_JINBI_ID, 1)
  2242. Grid.makeItem(msgRet.itemGreenExp, ItemDefine.ITEM_GREEN_EXP_ID, 1)
  2243. Grid.makeItem(msgRet.itemQingbao, ItemDefine.ITEM_QINGBAO_ID, 1)
  2244. -- local oldConfig = BattleExcel.node[human.db.guajiID]
  2245. -- local newConfig = BattleExcel.node[guajiID]
  2246. local oldConfig = tBattleConfig.node[human.db.guajiID]
  2247. local newConfig = tBattleConfig.node[guajiID]
  2248. msgRet.expOld = oldConfig.hangExp
  2249. msgRet.expNew = newConfig.hangExp
  2250. msgRet.jinbiOld = oldConfig.hangJinbi
  2251. msgRet.jinbiNew = newConfig.hangJinbi
  2252. msgRet.greenExpOld = oldConfig.hangGreenExp
  2253. msgRet.greenExpNew = newConfig.hangGreenExp
  2254. msgRet.qingbaoOld = oldConfig.hangQingbao
  2255. msgRet.qingbaoNew = newConfig.hangQingbao
  2256. Msg.send(msgRet, human.fd)
  2257. end
  2258. -- 刷新排行榜
  2259. human.db.maxBattleTime = os.time()
  2260. BRoleLogic.updateData(BillboardDefine.TYPE_BATTLE, human.db)
  2261. end
  2262. -- GM
  2263. function setBattleByGm(human, val, maxBattleID)
  2264. val = tonumber(val)
  2265. if not val or val <= 1 then
  2266. return
  2267. end
  2268. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  2269. if not tBattleConfig then
  2270. return
  2271. end
  2272. local nodeConfig = tBattleConfig.node[val]
  2273. if not nodeConfig then
  2274. return
  2275. end
  2276. if maxBattleID then
  2277. maxBattleID = tonumber(maxBattleID)
  2278. else
  2279. maxBattleID = val
  2280. end
  2281. BattleLogic_SetBattleBattleID(human, val)
  2282. BattleLogic_SetBattleGuaJiID(human, val)
  2283. setBattleID(human, val)
  2284. --human.db.battleID = val
  2285. BattleLogic_QueryDifficulty(human)
  2286. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1105)
  2287. end
  2288. --GM命令, 增加挂机时间,hourVal单位为:h
  2289. --如果超过最大可挂机时间,那么就增加最大挂机时间
  2290. function gmSetHangTime(human, hourVal)
  2291. local tBattleOut = BattleLogic_GetBattleOut(human)
  2292. if not tBattleOut then
  2293. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "gmSetHangTime func calcBattleExpOut 获取挂机奖励列表失败 id = "
  2294. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  2295. return
  2296. end
  2297. if not hourVal then
  2298. return
  2299. end
  2300. local setHandTime = hourVal * 3600
  2301. local maxHangTime = getHangMaxTime(human)
  2302. if setHandTime > maxHangTime then
  2303. setHandTime = maxHangTime
  2304. end
  2305. tBattleOut.expTs1 = tBattleOut.expTs1 - setHandTime
  2306. tBattleOut.expTs2 = tBattleOut.expTs2 - setHandTime
  2307. tBattleOut.itemTs1 = tBattleOut.itemTs1 - setHandTime
  2308. tBattleOut.itemTs2 = tBattleOut.itemTs2 - setHandTime
  2309. end
  2310. function mopupQuery(human)
  2311. ObjHuman.updateDaily(human)
  2312. local nNowGuaJiID = human.db.guajiID
  2313. local tBattleConfig = BattleExcel
  2314. if -1 >= nNowGuaJiID or not tBattleConfig then
  2315. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "mopupQuery 获取战斗配置、挂机ID 失败 id = "
  2316. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  2317. print("[mopupQuery] 获取战斗配置、挂机ID 失败")
  2318. return
  2319. end
  2320. local msgRet = Msg.gc.GC_BATTLE_MOPUP_QUERY
  2321. -- local guajiID = human.db.guajiID > #BattleExcel.node and #BattleExcel.node or human.db.guajiID
  2322. local guajiID = nNowGuaJiID > #tBattleConfig.node and #tBattleConfig.node or nNowGuaJiID
  2323. if guajiID == 0 then
  2324. return Broadcast.sendErr(human, Lang.BATTLE_MOPUP_ERR)
  2325. end
  2326. human.db.mopupDoCnt = human.db.mopupDoCnt or 0
  2327. local nextDoCnt = human.db.mopupDoCnt + 1
  2328. nextDoCnt = nextDoCnt >= EliteDefine.BATTLE_MOPUP_MAX_LEN and EliteDefine.BATTLE_MOPUP_MAX_LEN or nextDoCnt
  2329. -- local nodeConfig = BattleExcel.node[guajiID]
  2330. local nodeConfig = tBattleConfig.node[guajiID]
  2331. local dropID = nodeConfig.dropID
  2332. local dropConfig = DropExcel.dropBattle[dropID]
  2333. local dropCnt = 0
  2334. --秘宝加成
  2335. local talismanAdd_qb = (TalismanLogic.getTalismanAdd(human, TalismanLogic.OTHER_EFFECT_TBL.GJ_QB) or 0) / 100
  2336. local talismanAdd_hero_exp = (TalismanLogic.getTalismanAdd(human, TalismanLogic.OTHER_EFFECT_TBL.GJ_HERO_EXP) or 0) / 100
  2337. local talismanAdd_zs = (TalismanLogic.getTalismanAdd(human, TalismanLogic.OTHER_EFFECT_TBL.GJ_ZS) or 0) / 100
  2338. local talismanAdd_dailyFeeCnt = TalismanLogic.getTalismanAdd(human, TalismanLogic.OTHER_EFFECT_TBL.GJ_SD_FREE_CNT) or 0
  2339. -- ABS掉落活动显示到第一个
  2340. dropCnt = DropExchangeLogic.getDropItemSaoQuery(human, msgRet, dropCnt)
  2341. for i = 1, #dropConfig.dropRule do
  2342. if dropCnt >= #msgRet.item then
  2343. break
  2344. end
  2345. dropCnt = dropCnt + 1
  2346. local tempConfig = dropConfig.dropRule[i]
  2347. local itemID = tempConfig[1]
  2348. local itemCnt = 1
  2349. if itemID == ItemDefine.ITEM_ZUANSHI_ID and talismanAdd_zs > 0 then
  2350. itemCnt = itemCnt + math.ceil(itemCnt * talismanAdd_zs)
  2351. end
  2352. Grid.makeItem(msgRet.item[dropCnt], itemID, itemCnt)
  2353. end
  2354. for i = 1, #dropConfig.dropRule3 do
  2355. if dropCnt >= #msgRet.item then
  2356. break
  2357. end
  2358. dropCnt = dropCnt + 1
  2359. local tempConfig = dropConfig.dropRule3[i]
  2360. local itemID = tempConfig[1]
  2361. local itemCnt = 1
  2362. if itemID == ItemDefine.ITEM_ZUANSHI_ID and talismanAdd_zs > 0 then
  2363. itemCnt = itemCnt + math.ceil(itemCnt * talismanAdd_zs)
  2364. end
  2365. Grid.makeItem(msgRet.item[dropCnt], itemID, itemCnt)
  2366. end
  2367. -- local mapConfig = BattleExcel.map[nodeConfig.mapID]
  2368. local mapConfig = tBattleConfig.map[nodeConfig.mapID]
  2369. msgRet.name = mapConfig.name
  2370. msgRet.item[0] = dropCnt
  2371. local nNowAddFreeCnt = BattleLogic_GetAddFreeMopupNum(human)
  2372. nNowAddFreeCnt = nNowAddFreeCnt + talismanAdd_dailyFeeCnt
  2373. if TequanShopLogic.isActiveMopup(human) then
  2374. msgRet.leftCnt = BATTLE_MOPUP_CNT_VIP - human.db.mopupDoCnt
  2375. else
  2376. msgRet.leftCnt = BATTLE_MOPUP_CNT - human.db.mopupDoCnt
  2377. end
  2378. -- 剩余次数小于0则为0,再加额外的
  2379. msgRet.leftCnt = msgRet.leftCnt < 0 and 0 or msgRet.leftCnt
  2380. -- 增加额外次数
  2381. msgRet.leftCnt = msgRet.leftCnt + nNowAddFreeCnt
  2382. msgRet.leftCnt = math.max(msgRet.leftCnt, 0)
  2383. -- local mupopExcel = BattleExcel.mupop[nextDoCnt]
  2384. local mupopExcel = tBattleConfig.mupop[nextDoCnt]
  2385. if mupopExcel then
  2386. if not TequanShopLogic.isActiveMopup(human) then
  2387. msgRet.need = mupopExcel.cost
  2388. if human.db.mopupFreeCnt < BATTLE_MOPUP_FREE_CNT then
  2389. msgRet.need = 0
  2390. end
  2391. else
  2392. msgRet.need = mupopExcel.vipCost
  2393. if human.db.mopupFreeCnt < BATTLE_MOPUP_FREE_CNT_VIP then
  2394. msgRet.need = 0
  2395. end
  2396. end
  2397. else
  2398. msgRet.need = 0
  2399. end
  2400. -- 如果有额外增加次数则需要为0
  2401. if 0 < nNowAddFreeCnt then
  2402. msgRet.need = 0
  2403. end
  2404. msgRet.vip = TequanShopLogic.isActiveMopup(human) and 1 or 0
  2405. msgRet.nowCnt = human.db.mopupDoCnt
  2406. msgRet.exp = nodeConfig.hangExp
  2407. msgRet.jinbi = nodeConfig.hangJinbi
  2408. --msgRet.greenExp = nodeConfig.hangGreenExp
  2409. msgRet.greenExp = nodeConfig.hangGreenExp + math.ceil(nodeConfig.hangGreenExp * talismanAdd_hero_exp)
  2410. msgRet.qingbao = nodeConfig.hangQingbao + math.ceil(nodeConfig.hangQingbao * talismanAdd_qb)
  2411. print("[mopupQuery] nowCnt = "..msgRet.nowCnt.." leftCnt = "..msgRet.leftCnt.." nNowAddFreeCnt = "..nNowAddFreeCnt)
  2412. Msg.send(msgRet, human.fd)
  2413. end
  2414. function mopupFight(human)
  2415. -- 等级判断
  2416. ObjHuman.updateDaily(human)
  2417. local nNowGuaJiID = human.db.guajiID
  2418. local tBattleConfig = BattleExcel
  2419. if -1 >= nNowGuaJiID or not tBattleConfig then
  2420. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "mopupFight 获取战斗配置、挂机ID 失败 id = "
  2421. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  2422. print("[mopupFight] 获取战斗配置、挂机ID 失败")
  2423. return
  2424. end
  2425. local need = 0
  2426. human.db.mopupDoCnt = human.db.mopupDoCnt or 0
  2427. human.db.mopupFreeCnt = human.db.mopupFreeCnt or 0
  2428. local nextDoCnt = human.db.mopupDoCnt + 1
  2429. nextDoCnt = nextDoCnt >= EliteDefine.BATTLE_MOPUP_MAX_LEN and EliteDefine.BATTLE_MOPUP_MAX_LEN or nextDoCnt
  2430. -- local mupopExcel = BattleExcel.mupop[nextDoCnt]
  2431. local mupopExcel = tBattleConfig.mupop[nextDoCnt]
  2432. local talismanAdd_dailyFeeCnt = TalismanLogic.getTalismanAdd(human, TalismanLogic.OTHER_EFFECT_TBL.GJ_SD_FREE_CNT) or 0
  2433. local nNowAddFreeCnt = BattleLogic_GetAddFreeMopupNum(human)
  2434. nNowAddFreeCnt = nNowAddFreeCnt + talismanAdd_dailyFeeCnt
  2435. if not mupopExcel then
  2436. return Broadcast.sendErr(human, Lang.BATTLE_MOPUP_CNT_OVER)
  2437. end
  2438. local bUseFree = false
  2439. if not TequanShopLogic.isActiveMopup(human) then
  2440. if human.db.mopupDoCnt >= BATTLE_MOPUP_CNT and 0 >= nNowAddFreeCnt then
  2441. return Broadcast.sendErr(human, Lang.BATTLE_MOPUP_CNT_OVER)
  2442. end
  2443. need = mupopExcel.cost
  2444. -- 如果免费次数小于1次,则按免费算
  2445. if human.db.mopupFreeCnt < BATTLE_MOPUP_FREE_CNT then
  2446. bUseFree = true
  2447. need = 0
  2448. end
  2449. else
  2450. if human.db.mopupDoCnt >= BATTLE_MOPUP_CNT_VIP and 0 >= nNowAddFreeCnt then
  2451. return Broadcast.sendErr(human, Lang.BATTLE_MOPUP_CNT_OVER)
  2452. end
  2453. need = mupopExcel.vipCost
  2454. -- 如果免费次数小于3次,则按免费算
  2455. if human.db.mopupFreeCnt < BATTLE_MOPUP_FREE_CNT_VIP then
  2456. bUseFree = true
  2457. need = 0
  2458. end
  2459. end
  2460. local bUseAddFree = false
  2461. if need <= 0 and bUseFree == true then
  2462. human.db.mopupFreeCnt = human.db.mopupFreeCnt + 1
  2463. else
  2464. if nNowAddFreeCnt > 0 then
  2465. need = 0
  2466. BattleLogic_SetAddFreeMopupNum(human, -1)
  2467. bUseAddFree = true
  2468. end
  2469. end
  2470. if need > 0 then
  2471. if not ObjHuman.checkRMB(human, need) then
  2472. return
  2473. end
  2474. ObjHuman.decZuanshi(human, - need, "battleMopup")
  2475. end
  2476. human.db.mopupDoCnt = bUseAddFree == true and human.db.mopupDoCnt or human.db.mopupDoCnt + 1
  2477. -- local guajiID = human.db.guajiID > #BattleExcel.node and #BattleExcel.node or human.db.guajiID
  2478. local guajiID = nNowGuaJiID > #tBattleConfig.node and #tBattleConfig.node or nNowGuaJiID
  2479. if guajiID == 0 then
  2480. return Broadcast.sendErr(human, Lang.BATTLE_MOPUP_ERR)
  2481. end
  2482. -- local config = BattleExcel.node[guajiID]
  2483. local config = tBattleConfig.node[guajiID]
  2484. local msgRet = Msg.gc.GC_BATTLE_MOPUP_FIGHT
  2485. local vipExpAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER7) or 0) / 100
  2486. local vipJinAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER8) or 0) / 100
  2487. local vipGreenExpAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER9) or 0) / 100
  2488. local vipQingbaoAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER19) or 0) / 100
  2489. --秘宝加成
  2490. local talismanAdd_qb = (TalismanLogic.getTalismanAdd(human, TalismanLogic.OTHER_EFFECT_TBL.GJ_QB) or 0) / 100
  2491. local talismanAdd_hero_exp = (TalismanLogic.getTalismanAdd(human, TalismanLogic.OTHER_EFFECT_TBL.GJ_HERO_EXP) or 0) / 100
  2492. local talismanAdd_zs = (TalismanLogic.getTalismanAdd(human, TalismanLogic.OTHER_EFFECT_TBL.GJ_ZS) or 0) / 100
  2493. local exp = config.hangExp * 120
  2494. local jinbi = config.hangJinbi * 120
  2495. local greenExp = config.hangGreenExp * 120
  2496. local qingbao = config.hangQingbao * 120
  2497. local addExp = math.floor(exp *(1 + vipExpAdd))
  2498. local addJinbi = math.floor(jinbi *(1 + vipJinAdd))
  2499. local addGreenExp = math.floor(greenExp *(1 + vipGreenExpAdd))
  2500. local addQingbao = math.floor(qingbao *(1 + vipQingbaoAdd))
  2501. addQingbao = addQingbao + math.ceil(addQingbao * talismanAdd_qb)
  2502. addGreenExp = addGreenExp + math.ceil(addGreenExp * talismanAdd_hero_exp)
  2503. local time = 7200
  2504. local itemTable = getItemOutsByTime(config, time)
  2505. -- 掉落活动
  2506. DropExchangeLogic.getDropItemSao(human, time, itemTable)
  2507. local flag = GuideLogic.getGuideSkip(human, GuideLogic.SKIPTYPE_JUMP_BATTLE_SD)
  2508. if not flag then
  2509. local equipID = SysParameter.getSysParameter(SysParameter.PARAMETER_10)
  2510. itemTable[equipID] = 1
  2511. end
  2512. itemTable[ItemDefine.ITEM_JINBI_ID] = itemTable[ItemDefine.ITEM_JINBI_ID] or 0
  2513. itemTable[ItemDefine.ITEM_EXP_ID] = itemTable[ItemDefine.ITEM_EXP_ID] or 0
  2514. itemTable[ItemDefine.ITEM_GREEN_EXP_ID] = itemTable[ItemDefine.ITEM_GREEN_EXP_ID] or 0
  2515. itemTable[ItemDefine.ITEM_QINGBAO_ID] = itemTable[ItemDefine.ITEM_QINGBAO_ID] or 0
  2516. itemTable[ItemDefine.ITEM_JINBI_ID] = itemTable[ItemDefine.ITEM_JINBI_ID] + addJinbi
  2517. itemTable[ItemDefine.ITEM_EXP_ID] = itemTable[ItemDefine.ITEM_EXP_ID] + addExp
  2518. itemTable[ItemDefine.ITEM_GREEN_EXP_ID] = itemTable[ItemDefine.ITEM_GREEN_EXP_ID] + addGreenExp
  2519. itemTable[ItemDefine.ITEM_QINGBAO_ID] = itemTable[ItemDefine.ITEM_QINGBAO_ID] + addQingbao
  2520. msgRet.item[0] = 0
  2521. -- 双倍日
  2522. local double = RoleSystemLogic.isDouble(human, RoleSystemDefine.ROLE_SYS_ID_1101)
  2523. local rewardCnt = double and 2 or 1
  2524. for itemID, itemCnt in pairs(itemTable) do
  2525. itemCnt = itemCnt * rewardCnt
  2526. if itemID == ItemDefine.ITEM_ZUANSHI_ID and talismanAdd_zs > 0 then
  2527. itemCnt = itemCnt + math.ceil(itemCnt * talismanAdd_zs)
  2528. end
  2529. if not ItemDefine.isEquip(itemID) then
  2530. msgRet.item[0] = msgRet.item[0] + 1
  2531. Grid.makeItem(msgRet.item[msgRet.item[0]], itemID, itemCnt)
  2532. end
  2533. BagLogic.addItem(human, itemID, itemCnt, "battle")
  2534. end
  2535. msgRet.item[0] = EquipLogic.makeEquipItem(human, msgRet.item, msgRet.item[0])
  2536. msgRet.double = double and 1 or 0
  2537. msgRet.exp = itemTable[ItemDefine.ITEM_EXP_ID] * rewardCnt
  2538. msgRet.jinbi = itemTable[ItemDefine.ITEM_JINBI_ID] * rewardCnt
  2539. msgRet.greenExp = itemTable[ItemDefine.ITEM_GREEN_EXP_ID] * rewardCnt
  2540. msgRet.qingbao = itemTable[ItemDefine.ITEM_QINGBAO_ID] * rewardCnt
  2541. Msg.send(msgRet, human.fd)
  2542. mopupQuery(human)
  2543. query(human)
  2544. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1101)
  2545. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_BATTLE_SD)
  2546. DailyTaskLogic.recordDailyTaskFinishCnt(human, DailyTaskLogic.DAILY_TASK_ID_12, 1)
  2547. ChengjiuLogic.onCallback(human, ChengjiuDefine.CJ_TASK_TYPE_3, 1)
  2548. HeroLogLogic.finishTaskCB(human, HeroLogLogic.HERO_LOG_TYPE_3, 1)
  2549. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_2001)
  2550. YunYingLogic.onCallBack(human, "onMopup", 1)
  2551. end
  2552. function updateDaily(human)
  2553. human.db.mopupFreeCnt = 0
  2554. human.db.mopupDoCnt = 0
  2555. human.db.mopupAddFreeCnt = 0
  2556. end
  2557. function getTongGuanReward(human, id)
  2558. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  2559. local nNowGuaJiID = BattleLogic_GetBattleGuaJiID(human)
  2560. local nBattleID = BattleLogic_GetBattleBattleID(human)
  2561. if not tBattleConfig or -1 >= nNowGuaJiID or -1 >= nBattleID then
  2562. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[getTongGuanReward] 获取战斗配置、挂机ID、战斗节点ID 失败 id = "
  2563. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  2564. print("[getTongGuanReward] 获取战斗配置、挂机ID 失败")
  2565. return
  2566. end
  2567. local cf = tBattleConfig.node[id]
  2568. if not cf then
  2569. return
  2570. end
  2571. if #cf.tongguan < 1 then
  2572. return
  2573. end
  2574. print("[getTongGuanReward] 玩家请求领取奖励 当前的节点信息 id = "
  2575. ..id.." nNowGuaJiID = "..nNowGuaJiID.." nBattleID = "..nBattleID)
  2576. if nBattleID < id then
  2577. return
  2578. end
  2579. if isGetReward(human, id) then
  2580. return
  2581. end
  2582. if #cf.tongguan == 1 and cf.tongguan[1][3] then
  2583. -- 英雄
  2584. if HeroLogic.getEmptyCnt(human) < 1 then
  2585. return Broadcast.sendErr(human, Lang.HERO_BAG_FULL)
  2586. end
  2587. local heroID = cf.tongguan[1][1]
  2588. local cnt = cf.tongguan[1][2]
  2589. local star = cf.tongguan[1][3]
  2590. if cnt <= 0 then
  2591. return
  2592. end
  2593. setGetReward(human, id)
  2594. local msg = Msg.gc.GC_SUIPIAN_SUMMON
  2595. for i = 1, cnt do
  2596. local heroGrid = HeroGrid.createHeroGrid(heroID, star)
  2597. HeroLogic.addHeroByGrid(human, heroGrid, "battle_extra_reward")
  2598. SuipianLogic.makeResultItemData(msg.heroList[i], heroID, 1, 1)
  2599. end
  2600. msg.isHero = 1
  2601. msg.list[0] = 0
  2602. msg.heroList[0] = cnt
  2603. msg.fenJieList[0] = 0
  2604. Msg.send(msg, human.fd)
  2605. else
  2606. setGetReward(human, id)
  2607. BagLogic.addItemList(human, cf.tongguan, "tongguan")
  2608. end
  2609. -- 触发国王君临奖励
  2610. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE5, id)
  2611. query(human)
  2612. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1101)
  2613. if id == 80 then
  2614. KingWorldLogic.setState(human, 1)
  2615. end
  2616. end
  2617. function isDot(human)
  2618. -- 通过大关卡奖励
  2619. local chapterReward = BattleLogic_GetChapterReward(human)
  2620. local nBattleID = BattleLogic_GetBattleBattleID(human)
  2621. local tBattleExcel = BattleLogic_GetBattleConfig(human)
  2622. if -1 >= nBattleID or not tBattleExcel or not chapterReward then
  2623. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[isDot] 获取不到对应的大关卡奖励表 或配置表、战斗ID")
  2624. print("[isDot] 获取不到对应的大关卡奖励表 或配置表、战斗ID id = "..human.db._id)
  2625. return
  2626. end
  2627. -- local chapterReward = human.db.chapterReward or { }
  2628. -- local battleID = human.db.battleID
  2629. -- local battleNodeConfig = BattleExcel.node[battleID]
  2630. local battleID = nBattleID
  2631. local battleNodeConfig = tBattleExcel.node[battleID]
  2632. if not battleNodeConfig then
  2633. local nodeCnt = #tBattleExcel.node
  2634. local mapCnt = #tBattleExcel.map
  2635. if battleID == nodeCnt + 1 and not chapterReward[mapCnt] then
  2636. return true
  2637. else
  2638. return false
  2639. end
  2640. else
  2641. local mapID = battleNodeConfig.mapID
  2642. for i = mapID - 1, 1, -1 do
  2643. if not chapterReward[i] then
  2644. return true
  2645. end
  2646. end
  2647. end
  2648. return false
  2649. -- if human.db.lv < 9 then
  2650. -- return false
  2651. -- end
  2652. -- -- 有免费扫荡次数的时候有红点
  2653. -- human.db.mopupFreeCnt = human.db.mopupFreeCnt or 0
  2654. -- if TequanShopLogic.isActiveMopup(human) then
  2655. -- if human.db.mopupFreeCnt < 3 then
  2656. -- return true
  2657. -- end
  2658. -- else
  2659. -- if human.db.mopupFreeCnt < 1 then
  2660. -- return true
  2661. -- end
  2662. -- end
  2663. -- -- 有通关奖励可领取的时候有红点
  2664. -- if hasCanGetReward(human) then
  2665. -- return true
  2666. -- end
  2667. -- -- 战役挂机时间超过1小时的时候有红点
  2668. -- if human.db.battleOut ~= nil then
  2669. -- local now = os.time()
  2670. -- local outSec = now - human.db.battleOut.expTs1
  2671. -- if outSec >= 3600 then
  2672. -- return true
  2673. -- end
  2674. -- end
  2675. -- return false
  2676. end
  2677. function clacItemTwoHours(human)
  2678. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  2679. local nGuaJiID = BattleLogic_GetBattleGuaJiID(human)
  2680. if not tBattleConfig or -1 >= nGuaJiID then
  2681. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[clacItemTwoHours] 获取到的挂机ID、战斗配置不正确 id = "..human.db._id)
  2682. print("[clacItemTwoHours] 获取到的挂机ID、战斗配置不正确 id = "..human.db._id)
  2683. return
  2684. end
  2685. local items = { }
  2686. local outCnt = math.floor(7200 / BATTLE_HANG_ITEM_OUT_PERIOD)
  2687. -- local guajiID = human.db.guajiID > #BattleExcel.node and #BattleExcel.node or human.db.guajiID
  2688. local guajiID = nGuaJiID > #tBattleConfig.node and #tBattleConfig.node or nGuaJiID
  2689. if guajiID == 0 then
  2690. return items
  2691. end
  2692. -- local nodeConfig = BattleExcel.node[guajiID]
  2693. local nodeConfig = tBattleConfig.node[guajiID]
  2694. local dropID = nodeConfig.dropID
  2695. local dropConfig = DropExcel.dropBattle[dropID]
  2696. local totalWeight = 0
  2697. for i = 1, #dropConfig.dropRule do
  2698. local tempConfig = dropConfig.dropRule[i]
  2699. totalWeight = totalWeight + tempConfig[4]
  2700. end
  2701. for j = 1, outCnt do
  2702. local randomNum = math.random(1, totalWeight)
  2703. for i = 1, #dropConfig.dropRule do
  2704. local tempConfig = dropConfig.dropRule[i]
  2705. local itemID = tempConfig[1]
  2706. local itemCnt1 = tempConfig[2]
  2707. local itemCnt2 = tempConfig[3]
  2708. local itemRate = tempConfig[4]
  2709. if randomNum <= itemRate then
  2710. local realAdd = math.random(itemCnt1, itemCnt2)
  2711. items[itemID] = realAdd
  2712. break
  2713. end
  2714. randomNum = randomNum - itemRate
  2715. end
  2716. end
  2717. return items
  2718. end
  2719. local MailManager = require("mail.MailManager")
  2720. function clacItemCntGM(human, cnt, guajiID)
  2721. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  2722. if not tBattleConfig then
  2723. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[clacItemCntGM] 获取到战斗配置不正确 id = "..human.db._id)
  2724. print("[clacItemTwoHours] 获取到的战斗配置不正确 id = "..human.db._id)
  2725. return
  2726. end
  2727. local items = { }
  2728. local outCnt = cnt
  2729. local nodeConfig = tBattleConfig.node[guajiID]
  2730. local dropID = nodeConfig.dropID
  2731. local dropConfig = DropExcel.dropBattle[dropID]
  2732. local totalWeight = 0
  2733. for i = 1, #dropConfig.dropRule do
  2734. local tempConfig = dropConfig.dropRule[i]
  2735. totalWeight = totalWeight + tempConfig[4]
  2736. end
  2737. for j = 1, outCnt do
  2738. local randomNum = math.random(1, totalWeight)
  2739. for i = 1, #dropConfig.dropRule do
  2740. local tempConfig = dropConfig.dropRule[i]
  2741. local itemID = tempConfig[1]
  2742. local itemCnt1 = tempConfig[2]
  2743. local itemCnt2 = tempConfig[3]
  2744. local itemRate = tempConfig[4]
  2745. if randomNum <= itemRate then
  2746. local realAdd = math.random(itemCnt1, itemCnt2)
  2747. items[itemID] = items[itemID] or 0
  2748. items[itemID] = items[itemID] + realAdd
  2749. break
  2750. end
  2751. randomNum = randomNum - itemRate
  2752. end
  2753. end
  2754. local item = { }
  2755. local index = 0
  2756. for k, v in pairs(items) do
  2757. index = index + 1
  2758. item[index] = { k, v }
  2759. end
  2760. MailManager.add(MailManager.SYSTEM, human.db._id, "", "", item, "")
  2761. end
  2762. function getBattleID(human)
  2763. local num = 0
  2764. local nGuaJiID = BattleLogic_GetBattleGuaJiID(human)
  2765. if -1 < nGuaJiID then
  2766. num = nGuaJiID
  2767. end
  2768. -- if human.db.guajiID then
  2769. -- num = human.db.guajiID or 0
  2770. -- end
  2771. return num
  2772. end
  2773. --------------------------------------------- combat ----------------------------------------------
  2774. function getCombatMonsterOutID(human, side)
  2775. if side ~= CombatDefine.DEFEND_SIDE then
  2776. return
  2777. end
  2778. local nBattleID = BattleLogic_GetBattleBattleID(human)
  2779. local tBattleExcel = BattleLogic_GetBattleConfig(human)
  2780. if not tBattleExcel or -1 >= nBattleID then
  2781. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[getCombatMonsterOutID] 获取到的战斗配置、或战斗ID不正确 id = "..human.db._id)
  2782. print("[getCombatMonsterOutID] 获取到的战斗配置、或战斗ID不正确 id = "..human.db._id)
  2783. return
  2784. end
  2785. -- local config = BattleExcel.node[human.db.battleID]
  2786. local config = tBattleExcel.node[nBattleID]
  2787. if not config then
  2788. return
  2789. end
  2790. return config.monsterOutID
  2791. end
  2792. function getCombatName(human)
  2793. local nBattleID = BattleLogic_GetBattleBattleID(human)
  2794. if -1 >= nBattleID then
  2795. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[getCombatMonsterOutID] 获取到的战斗ID不正确 id = "..human.db._id)
  2796. print("[getCombatMonsterOutID] 获取到的战斗ID不正确 id = "..human.db._id)
  2797. return ""
  2798. end
  2799. local name = getBattleName(human, nBattleID)
  2800. return Util.format(Lang.COMBAT_BATTLE_EXNAME, name)
  2801. end
  2802. -------------------------------------------combat end--------------------
  2803. function battleSharkQuery(human, nodeID)
  2804. local msgRet = Msg.gc.GC_BATTLE_SHARK_QUERY
  2805. local videoTb = BattleDBLogic.queryBattleDbByNodeID(nodeID)
  2806. if videoTb == nil then
  2807. msgRet.battleShark[0] = 0
  2808. else
  2809. local len = #videoTb.shark
  2810. for i = 1, len do
  2811. local v = videoTb.shark[i]
  2812. RoleLogic.makeRoleBase(v.roleBase, msgRet.battleShark[i].roleBase)
  2813. msgRet.battleShark[i].type = i
  2814. msgRet.battleShark[i].videoUuid = v.videoUuid
  2815. msgRet.battleShark[i].param = v.param or 0
  2816. end
  2817. msgRet.battleShark[0] = len
  2818. end
  2819. -- Msg.trace(msgRet)
  2820. Msg.send(msgRet, human.fd)
  2821. end
  2822. local QueryRoleByNodeID = { }
  2823. function worldMapRoleListQuery(human, worldMapId)
  2824. -- if worldMapId == 1 then return end
  2825. local nNowBattleType = BattleLogic_GetBattleType(human)
  2826. if EliteDefine.COPY_ELITE_ERROR >= nNowBattleType then
  2827. nNowBattleType = EliteDefine.COPY_ELITE_NORMAL
  2828. end
  2829. local msgRet = Msg.gc.GC_BATTLE_WORLD_MAP_ROLELIST_QUERY
  2830. local len = 0
  2831. for k, v in pairs(BATTLE_LEVEL_PLAYER_LIST[nNowBattleType][worldMapId]) do
  2832. len = len + 1
  2833. RoleLogic.makeRoleBase(v, msgRet.roleList[len])
  2834. if len >= 50 then
  2835. break
  2836. end
  2837. end
  2838. msgRet.roleList[0] = len
  2839. Msg.send(msgRet, human.fd)
  2840. end
  2841. -- 章节(地图)掉落列表
  2842. function sendMapDroItemsList(human)
  2843. local nBattleID = BattleLogic_GetBattleBattleID(human)
  2844. local tBattleExcel = BattleLogic_GetBattleConfig(human)
  2845. if not tBattleExcel then
  2846. print("[sendMapDroItemsList] 获取当前战斗配置失败 id = "..human.db._id)
  2847. return
  2848. end
  2849. local battleID = 1
  2850. if -1 < nBattleID then
  2851. battleID = nBattleID
  2852. end
  2853. local maxBattleConfig = tBattleExcel.node[battleID]
  2854. local maxMapID = maxBattleConfig and maxBattleConfig.mapID or(#tBattleExcel.node + 1)
  2855. local msgRet = Msg.gc.GC_BATTLE_MAP_DROPITEMS_LIST
  2856. msgRet.list[0] = 0
  2857. for mapID, mapConfig in ipairs(tBattleExcel.map) do
  2858. msgRet.list[0] = msgRet.list[0] + 1
  2859. local net = msgRet.list[msgRet.list[0]]
  2860. net.mapID = mapID
  2861. net.mapName = mapConfig.name
  2862. net.isOpen =(mapID <= maxMapID) and 1 or 0
  2863. end
  2864. -- Msg.trace(msgRet)
  2865. Msg.send(msgRet, human.fd)
  2866. end
  2867. -- 章节(地图)掉落详情
  2868. function sendMapDroItemsDetail(human, mapID)
  2869. local tBattleExcel = BattleLogic_GetBattleConfig(human)
  2870. if not tBattleExcel then
  2871. print("[sendMapDroItemsDetail] 获取当前战斗配置失败 id = "..human.db._id)
  2872. return
  2873. end
  2874. local mapConfig = tBattleExcel.map[mapID]
  2875. if not mapConfig then
  2876. return
  2877. end
  2878. local msgRet = Msg.gc.GC_BATTLE_MAP_DROPITEMS_DETAIL
  2879. msgRet.mapID = mapID
  2880. msgRet.items[0] = math.min(#mapConfig.dropItemsShow, #msgRet.items)
  2881. for i = 1, msgRet.items[0] do
  2882. local itemID = mapConfig.dropItemsShow[i][1]
  2883. local itemCnt = mapConfig.dropItemsShow[i][2]
  2884. Grid.makeItem(msgRet.items[i], itemID, itemCnt)
  2885. end
  2886. -- Msg.trace(msgRet)
  2887. Msg.send(msgRet, human.fd)
  2888. end
  2889. -- 获取当前战役的 怪物ID
  2890. function getBattleMonsterOutID(human)
  2891. local nBattleID = BattleLogic_GetBattleBattleID(human)
  2892. local tBattleExcel = BattleLogic_GetBattleConfig(human)
  2893. if -1 >= nBattleID or not tBattleExcel then
  2894. print("[getBattleMonsterOutID] 获取当前战斗ID、配置失败 id = "..human.db._id)
  2895. return 0
  2896. end
  2897. -- local battleID = human.db.battleID
  2898. -- local config = BattleExcel.node[battleID]
  2899. local config = tBattleExcel.node[nBattleID]
  2900. return config.monsterOutID
  2901. end
  2902. function onUpdatePos(human)
  2903. BRoleLogic.updateData(BillboardDefine.TYPE_ZHANDOULI, human.db)
  2904. end
  2905. function getNextRewardName(human)
  2906. local guajiID = BattleLogic_GetBattleGuaJiID(human)
  2907. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  2908. if not tBattleConfig or -1 >= guajiID then
  2909. return nil, nil
  2910. end
  2911. -- for i = human.db.guajiID + 1, #BattleExcel.node do
  2912. for i = guajiID + 1, #tBattleConfig.node do
  2913. if #tBattleConfig.node[i].tongguan > 0 then
  2914. local itemID = tBattleConfig.node[i].tongguan[1][1]
  2915. local itemConfig = ItemDefine.getConfig(itemID)
  2916. if itemConfig == nil then
  2917. return
  2918. else
  2919. return i - guajiID, itemConfig.name
  2920. end
  2921. end
  2922. end
  2923. end
  2924. --[[
  2925. 通关章节后领取奖励
  2926. ]]
  2927. function battleChapterReward(human, mapID)
  2928. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  2929. local nBattleID = BattleLogic_GetBattleBattleID(human)
  2930. local tChapterReward = BattleLogic_GetChapterReward(human)
  2931. if not tBattleConfig or -1 >= nBattleID or not tChapterReward then
  2932. print("[battleChapterReward] 获取到的战斗ID、配置、通关章节奖励表 不正确 id = "..human.db._id)
  2933. return
  2934. end
  2935. local mapConf = tBattleConfig.map[mapID]
  2936. if not mapConf then
  2937. return
  2938. end
  2939. -- 没有通过当前大关卡
  2940. local battleID = nBattleID
  2941. local battleNodeConfig = tBattleConfig.node[battleID]
  2942. local roleMapId
  2943. if not battleNodeConfig then
  2944. if battleID ~= #tBattleConfig.node + 1 then
  2945. return
  2946. else
  2947. roleMapId = #tBattleConfig.map
  2948. end
  2949. else
  2950. roleMapId = battleNodeConfig.mapID
  2951. end
  2952. if mapID > roleMapId then
  2953. return
  2954. end
  2955. -- if not human.db.chapterReward then
  2956. -- human.db.chapterReward = { }
  2957. -- end
  2958. -- 判断是否已经领取了当前大关卡的奖励
  2959. -- local chapterReward = human.db.chapterReward
  2960. local chapterReward = tChapterReward
  2961. if chapterReward[mapID] then
  2962. return Broadcast.sendErr(human, Lang.FRIEND_HEART_GET_HAD)
  2963. end
  2964. chapterReward[mapID] = true
  2965. ObjHuman.save(human)
  2966. local reward = mapConf.reward
  2967. BagLogic.addItemList(human, reward, "chapterReward")
  2968. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1105)
  2969. local msgRet = Msg.gc.GC_BATTLE_CHAPTER_REWARD
  2970. msgRet.mapID = mapID
  2971. Msg.send(msgRet, human.fd)
  2972. end
  2973. -- 判断难度是否解锁
  2974. local function BattleLogic_CheckDiffIsOK(human, nSelectDiff)
  2975. -- 默认难度直接通过
  2976. if EliteDefine.COPY_ELITE_NORMAL == nSelectDiff then
  2977. return EliteDefine.COPY_SELECT_SUCC
  2978. end
  2979. -- 等级不够
  2980. if human.db.lv < EliteDefine.COPY_ELITE_ULEV then
  2981. return EliteDefine.COPY_SELECT_LEV
  2982. end
  2983. local nChoseBattleID = (EliteDefine.COPY_LEVEL_ELITE == nSelectDiff) and human.db.battleID or human.db.battleID_elite
  2984. return nChoseBattleID > EliteDefine.COPY_ELITE_LEVEL and EliteDefine.COPY_SELECT_SUCC or EliteDefine.COPY_SELECT_MAIN
  2985. end
  2986. -- 获取未领取奖励
  2987. local function BattleLogic_GetNorewardReceived(human, nBattleType, cIndex)
  2988. print("1:[BattleLogic_GetNorewardReceived] id = "..human.db._id.." nBattleType = "..nBattleType)
  2989. local nBattleID = BattleLogic_GetBattleIDByType(human, nBattleType)
  2990. local tBattleConfig = BattleLogic_GetBattleConfigByType(nBattleType)
  2991. local nGuaJiID = BattleLogic_GetBattleGuaJiIDByType(human, nBattleType)
  2992. if -1 >= nBattleID or not tBattleConfig or -1 >= nGuaJiID then
  2993. print("[BattleLogic_GetNorewardReceived] 获取配置失败")
  2994. return
  2995. end
  2996. local msgRet = Msg.gc.GC_BATTLE_QUERY_ALL
  2997. msgRet.index = nBattleType
  2998. msgRet.list[0] = 0
  2999. msgRet.isEnd = 0
  3000. msgRet.curIndex = 0
  3001. local curIndex = 1
  3002. -- human.db.battleID = human.db.battleID or 1
  3003. -- if human.db.battleID == 0 then
  3004. -- human.db.battleID = 1
  3005. -- end
  3006. human.db.mopupDoCnt = human.db.mopupDoCnt or 0
  3007. local curBattleNumber = cIndex
  3008. local curTotalNumber = 0
  3009. local battleNumber = #tBattleConfig.node
  3010. -- local nGuajiID = human.db.guajiID or 0
  3011. print("[BattleLogic_GetNorewardReceived] nGuajiID = "..nGuaJiID.. " nBattleID = "..nBattleID)
  3012. -- 判断ID得用战斗ID-1, 因为挂机ID可以设置
  3013. local nJudeNum = nGuaJiID
  3014. local nBattleAdopt = BattleLogic_GetBattleAdopt(human, nBattleType)
  3015. -- 已通过
  3016. if nBattleAdopt == 1 then
  3017. nJudeNum = battleNumber
  3018. else
  3019. nJudeNum = nBattleID - 1
  3020. end
  3021. print("[BattleLogic_GetNorewardReceived] nJudeNum = "..nJudeNum)
  3022. for k,v in ipairs(tBattleConfig.node) do
  3023. if #v.tongguan ~= 0 then
  3024. -- 领取状态
  3025. local state = false
  3026. if k <= nJudeNum then
  3027. state = isGetRewardByType(human, k, nBattleType)
  3028. end
  3029. if not (state == true) then
  3030. local r = STATUS_CANGET
  3031. --(k > nGuaJiID) and STATUS_CANGET or STATUS_NONE
  3032. --未领取
  3033. if r == STATUS_CANGET then
  3034. curTotalNumber = curTotalNumber + 1
  3035. if curTotalNumber > curBattleNumber then
  3036. --构造
  3037. local cf = tBattleConfig.node[k].tongguan
  3038. local net = msgRet.list[curIndex]
  3039. net.status = k <= nJudeNum and STATUS_CANGET or STATUS_NONE
  3040. net.levelName = getBattleNameByType(k, nBattleType)
  3041. net.index = k
  3042. net.nowBattle = getBattleNameByType(nJudeNum, nBattleType)
  3043. net.reward[0] = 0
  3044. net.heroReward[0] = 0
  3045. if cf[1][3] then
  3046. net.heroReward[0] = 1
  3047. local other = { }
  3048. other.star = cf[1][3]
  3049. HeroGrid.makeHeroSimpleByID(net.heroReward[1], cf[1][1], nil, other, human)
  3050. HeroGrid.makeHeroSimpleByGeneral(net.heroReward[1], cf[1][1])
  3051. local tHeroInfo = Util.printTable(net.heroReward)
  3052. -- print("[BattleLogic_GetNorewardReceived] 英雄数据 k = "..k.." 获取的数据 = "..tHeroInfo)
  3053. else
  3054. net.reward[0] = 1
  3055. for i = 1, net.reward[0] do
  3056. local itemID = cf[i][1]
  3057. local itemCnt = cf[i][2]
  3058. Grid.makeItem(net.reward[i], itemID, itemCnt)
  3059. end
  3060. end
  3061. curIndex = curIndex + 1
  3062. msgRet.list[0] = msgRet.list[0] + 1
  3063. if msgRet.list[0] >= 15 then
  3064. local ret = 0
  3065. if k < battleNumber then
  3066. for kk, vv in ipairs(tBattleConfig.node) do
  3067. if kk > k then
  3068. if v.tongguan ~= 0 then
  3069. local nNextstate = isGetRewardByType(human,kk, nBattleType)
  3070. if not (nNextstate == true) then
  3071. local rr =(kk > nGuaJiID) and STATUS_CANGET or STATUS_NONE
  3072. --未领取
  3073. if rr == STATUS_CANGET then
  3074. ret = 1
  3075. break
  3076. end
  3077. end
  3078. end
  3079. end
  3080. end
  3081. end
  3082. if ret == 1 then
  3083. --没有结束
  3084. msgRet.isEnd = 0
  3085. else
  3086. msgRet.isEnd = 1
  3087. end
  3088. msgRet.curIndex=curTotalNumber
  3089. -- curIndex = 1
  3090. Msg.send(msgRet, human.fd)
  3091. --local info=Util.printTable(msgRet)
  3092. --print("getNorewardReceived0->>:"..info)
  3093. return
  3094. end
  3095. end
  3096. end
  3097. else
  3098. print("[BattleLogic_GetNorewardReceived] 奖励已领取:"..k)
  3099. end
  3100. end
  3101. end
  3102. --结束
  3103. msgRet.isEnd = 1
  3104. msgRet.curIndex=0
  3105. Msg.send(msgRet, human.fd)
  3106. end
  3107. -- 客户端请求查询难度
  3108. function CG_ELITE_OPEN(human)
  3109. BattleLogic_QueryDifficulty(human)
  3110. end
  3111. -- 客户端请求切换难度
  3112. function CG_ELITE_SELECT(human, nSelectDiff)
  3113. if EliteDefine.COPY_ELITE_NORMAL > nSelectDiff or EliteDefine.COPY_ELITE_DIFFICULTY < nSelectDiff then
  3114. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[CG_ELITE_SELECT] 客户端传入的参数不正确 id = "..human.db._id .. "nSelectDiff = "..nSelectDiff)
  3115. print("[CG_ELITE_SELECT] 客户端选择难度,上传的难度不正确 id = "..human.db._id .. "nSelectDiff = "..nSelectDiff)
  3116. return
  3117. end
  3118. local nStatus = BattleLogic_CheckDiffIsOK(human, nSelectDiff)
  3119. print("[CG_ELITE_SELECT] nStatus = "..nStatus.. " 选择的难度 nSelectDiff = "..nSelectDiff)
  3120. -- 设置类型
  3121. if EliteDefine.COPY_SELECT_SUCC == nStatus then
  3122. BattleLogic_SetBattleType(human,nSelectDiff)
  3123. end
  3124. local msgRet = Msg.gc.GC_ELITE_SELECT
  3125. msgRet.status = nStatus
  3126. Msg.send(msgRet,human.fd)
  3127. end
  3128. -- 客户端请求领取奖励
  3129. function CG_BATTLE_TONGGUAN_REWARD_GET_COPY(human, nBattleType)
  3130. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  3131. local nGuaJiID = BattleLogic_GetBattleGuaJiIDByType(human, nBattleType)
  3132. local nBattleID = BattleLogic_GetBattleIDByType(human, nBattleType)
  3133. if not tBattleConfig or -1 >= nGuaJiID or -1 >= nBattleID then
  3134. return
  3135. end
  3136. local tMsgRet = Msg.gc.GC_BATTLE_TONGGUAN_REWARD_GET_COPY
  3137. local nAdopt = BattleLogic_GetBattleAdopt(human, nBattleType)
  3138. local nChoseLen = nBattleID - 1
  3139. local nConfigLen = #tBattleConfig.node
  3140. if 1 == nAdopt then
  3141. nChoseLen = nBattleID
  3142. else
  3143. if 0 >= nChoseLen or nChoseLen > nConfigLen then
  3144. tMsgRet.status = 0
  3145. Msg.send(tMsgRet, human.fd)
  3146. return
  3147. end
  3148. end
  3149. print("[CG_BATTLE_TONGGUAN_REWARD_GET_COPY] nChoseLen = "..nChoseLen.. " nBattleID = "..nBattleID)
  3150. tMsgRet.status = 1
  3151. local tItemList = {}
  3152. for id = 1, nChoseLen, 1 do
  3153. local tNodeCofig = tBattleConfig.node[id]
  3154. if tNodeCofig and #tNodeCofig.tongguan >= 1 then
  3155. -- 未领取
  3156. if false == isGetRewardByType(human, id, nBattleType) then
  3157. print("[CG_BATTLE_TONGGUAN_REWARD_GET_COPY] 未领取的 id = "..id)
  3158. if #tNodeCofig.tongguan == 1 and tNodeCofig.tongguan[1][3] then
  3159. -- 英雄
  3160. if HeroLogic.getEmptyCnt(human) < 1 then
  3161. return Broadcast.sendErr(human, Lang.HERO_BAG_FULL)
  3162. end
  3163. local heroID = tNodeCofig.tongguan[1][1]
  3164. local cnt = tNodeCofig.tongguan[1][2]
  3165. local star = tNodeCofig.tongguan[1][3]
  3166. if cnt > 0 then
  3167. -- 设置已领取
  3168. setGetRewardByType(human, id, nBattleType)
  3169. local msg = Msg.gc.GC_SUIPIAN_SUMMON
  3170. for i = 1, cnt do
  3171. local heroGrid = HeroGrid.createHeroGrid(heroID, star)
  3172. HeroLogic.addHeroByGrid(human, heroGrid, "battle_extra_reward")
  3173. SuipianLogic.makeResultItemData(msg.heroList[i], heroID, 1, 1)
  3174. end
  3175. msg.isHero = 1
  3176. msg.list[0] = 0
  3177. msg.heroList[0] = cnt
  3178. msg.fenJieList[0] = 0
  3179. Msg.send(msg, human.fd)
  3180. else
  3181. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[CG_BATTLE_TONGGUAN_REWARD_GET_COPY] 领取奖励配置的英雄cnt为<= 0 id = "..human.db.name)
  3182. print("[CG_BATTLE_TONGGUAN_REWARD_GET_COPY] 不正确的 英雄碎片数量")
  3183. end
  3184. else
  3185. setGetRewardByType(human, id, nBattleType)
  3186. for k, v in ipairs(tNodeCofig.tongguan) do
  3187. local nItemID = v[1]
  3188. local nItemNum = v[2]
  3189. tItemList[nItemID] = tItemList[nItemID] or 0
  3190. tItemList[nItemID] = tItemList[nItemID] + nItemNum
  3191. end
  3192. --BagLogic.addItemList(human, tNodeCofig.tongguan, "tongguan")
  3193. end
  3194. -- 触发国王君临奖励
  3195. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE5, id)
  3196. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1101)
  3197. if id == 80 then
  3198. KingWorldLogic.setState(human, 1)
  3199. end
  3200. end
  3201. end
  3202. end
  3203. if nil ~= _G.next(tItemList) then
  3204. local tPrize = {}
  3205. for k, v in pairs(tItemList) do
  3206. table.insert(tPrize, {k,v})
  3207. end
  3208. BagLogic.addItemList(human, tPrize, "tongguan")
  3209. end
  3210. query(human)
  3211. Msg.send(tMsgRet, human.fd)
  3212. end
  3213. -- 客户端请求查询所有未领取奖励
  3214. function CG_BATTLE_QUERY_ALL(human, nBattleType, curIndex)
  3215. if EliteDefine.COPY_ELITE_NORMAL > nBattleType or EliteDefine.COPY_ELITE_DIFFICULTY < nBattleType then
  3216. print("[CG_BATTLE_QUERY_ALL] 客户端请求的战斗类型不正确 id = "..human.db._id.." nType = "..nBattleType)
  3217. return
  3218. end
  3219. BattleLogic_GetNorewardReceived(human, nBattleType, curIndex)
  3220. end
  3221. -- 判断是否是最后一关
  3222. function BattleLogic_IsLastLevels(human, nBattleType)
  3223. local tBattleConfig = BattleLogic_GetBattleConfigByType(nBattleType)
  3224. local nBattleType = BattleLogic_GetBattleType(human)
  3225. if not tBattleConfig or -1 >= nBattleType then
  3226. return false
  3227. end
  3228. local nValue = BattleLogic_GetBattleAdopt(human, nBattleType)
  3229. return nValue == 1
  3230. end
  3231. -- 增加扫荡次数
  3232. function BattleLogic_AddMopup(human, nGoodsID, nGoodsNum)
  3233. if not human or 0 >= nGoodsID or 0 >= nGoodsNum then
  3234. return
  3235. end
  3236. if EliteDefine.BATTLE_ADD_MOPUP_GOODID ~= nGoodsID then
  3237. return
  3238. end
  3239. -- -- 检测数量
  3240. -- if false == BagLogic.checkItemCnt(human, nGoodsID, nGoodsNum) then
  3241. -- return
  3242. -- end
  3243. -- -- 消耗物品
  3244. -- BagLogic.delItem(human, nGoodsID, nGoodsNum, "battle")
  3245. -- 增加次数
  3246. BattleLogic_SetAddFreeMopupNum(human, nGoodsNum)
  3247. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[BattleLogic_AddMopup] 增加扫荡次数 name = "
  3248. ..human.db.name.." nAddNum ="..nGoodsNum)
  3249. print("[BattleLogic_AddMopup] 玩家增加扫荡次数 name = "
  3250. ..human.db.name.." nAddNum ="..nGoodsNum)
  3251. end