BattleLogic.lua 179 KB

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