BattleLogic.lua 167 KB

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