BattleLogic.lua 139 KB

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