BattleLogic.lua 178 KB

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