BattleLogic.lua 175 KB

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