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