BattleLogic.lua 142 KB

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