BattleLogic.lua 142 KB

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