BattleLogic.lua 174 KB

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