BattleLogic.lua 142 KB

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