BattleLogic.lua 159 KB

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