BattleLogic.lua 149 KB

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