BattleLogic.lua 158 KB

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