BattleLogic.lua 160 KB

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