BattleLogic.lua 142 KB

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