BattleLogic.lua 149 KB

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