BattleLogic.lua 179 KB

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