BattleLogic.lua 134 KB

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