BattleLogic.lua 166 KB

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