BattleLogic.lua 175 KB

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