BattleLogic.lua 141 KB

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