BattleLogic.lua 139 KB

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