BattleLogic.lua 178 KB

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