BattleLogic.lua 132 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477
  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 hasCanGetReward(human)
  751. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  752. local nGuaJiID = BattleLogic_GetBattleGuaJiID(human)
  753. if not tBattleConfig or -1 >= nGuaJiID then
  754. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleRewards 参数不正确")
  755. print("[hasCanGetReward] 不存在对应的 奖励配置")
  756. return
  757. end
  758. for id, cf in ipairs(tBattleConfig.node) do
  759. if id > nGuaJiID then
  760. break
  761. end
  762. if #cf.tongguan > 0 and not isGetReward(human, id) then
  763. return true
  764. end
  765. end
  766. end
  767. local BATTLEID_2_NAME = nil
  768. function getBattleName(human, battleID)
  769. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  770. local nBattleType = BattleLogic_GetBattleType(human)
  771. if not tBattleConfig or EliteDefine.COPY_ELITE_ERROR >= nBattleType then
  772. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleRewards 参数不正确")
  773. print("[getBattleName] 不存在对应的 奖励配置")
  774. return
  775. end
  776. if not BATTLEID_2_NAME then
  777. BATTLEID_2_NAME = { }
  778. end
  779. if not BATTLEID_2_NAME[nBattleType] then
  780. BATTLEID_2_NAME[nBattleType] = {}
  781. for id, cf in ipairs(tBattleConfig.node) do
  782. -- BATTLEID_2_NAME[id] = cf.name
  783. BATTLEID_2_NAME[nBattleType][id] = cf.name
  784. end
  785. end
  786. local nodeConfig = tBattleConfig.node[battleID]
  787. local mapConfig = nodeConfig and tBattleConfig.map[nodeConfig.mapID]
  788. local mapName = mapConfig and mapConfig.name or ""
  789. return BATTLEID_2_NAME[nBattleType][battleID] or "", mapName
  790. end
  791. function getBattleNameByType(battleID, nBattleType)
  792. local tBattleConfig = BattleLogic_GetBattleConfigByType( nBattleType)
  793. if not tBattleConfig or EliteDefine.COPY_ELITE_ERROR >= nBattleType then
  794. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "BattleLogic_GetBattleRewards 参数不正确")
  795. print("[getBattleNameByType] 不存在对应的 奖励配置")
  796. return
  797. end
  798. if not BATTLEID_2_NAME then
  799. BATTLEID_2_NAME = { }
  800. end
  801. if not BATTLEID_2_NAME[nBattleType] then
  802. BATTLEID_2_NAME[nBattleType] = {}
  803. for id, cf in ipairs(tBattleConfig.node) do
  804. -- BATTLEID_2_NAME[id] = cf.name
  805. BATTLEID_2_NAME[nBattleType][id] = cf.name
  806. end
  807. end
  808. local nodeConfig = tBattleConfig.node[battleID]
  809. local mapConfig = nodeConfig and tBattleConfig.map[nodeConfig.mapID]
  810. local mapName = mapConfig and mapConfig.name or ""
  811. return BATTLEID_2_NAME[nBattleType][battleID] or "", mapName
  812. end
  813. function hangFightQuery(human)
  814. local nBattleID = BattleLogic_GetBattleBattleID(human)
  815. local tBattleExcel = BattleLogic_GetBattleConfig(human)
  816. if -1 >= nBattleID or not tBattleExcel then
  817. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "hangFightQuery 参数不正确")
  818. print("[hangFightQuery] 不存在对应的 奖励配置 和战斗关卡ID id = "..human.db._id)
  819. return
  820. end
  821. -- local battleID = human.db.battleID > #BattleExcel.node and #BattleExcel.node or human.db.battleID
  822. local battleID = nBattleID > #tBattleExcel.node and #tBattleExcel.node or nBattleID
  823. local nowNodeConfig = tBattleExcel.node[battleID]
  824. local monsterOutID = nowNodeConfig.monsterOutID
  825. local monsterOutConfig = MonsterExcel.monsterOut[monsterOutID]
  826. local msgRet = Msg.gc.GC_BATTLE_HANG_FIGHT
  827. local len = 0
  828. for _, monster in ipairs(monsterOutConfig.member) do
  829. local monsterID = monster[1]
  830. len = len + 1
  831. local monsterConfig = MonsterExcel.monster[monsterID]
  832. local skillConfig = SkillExcel.skill[monsterConfig.normalAtkID]
  833. wrapHangFightNet(msgRet.monsterList[len], monsterConfig, skillConfig)
  834. end
  835. msgRet.monsterList[0] = len
  836. len = 0
  837. if human.db.combatHero[CombatDefine.COMBAT_TYPE1] then
  838. local tb = { }
  839. for i = 1, #human.db.combatHero[CombatDefine.COMBAT_TYPE1] do
  840. tb[#tb + 1] = human.db.combatHero[CombatDefine.COMBAT_TYPE1][i]
  841. end
  842. local tb2 = { }
  843. for i = 1, 3 do
  844. local r = math.ceil(math.random(0, #tb))
  845. r = r == 0 and 1 or r
  846. tb2[#tb2 + 1] = tb[r]
  847. tb[r] = tb[#tb]
  848. tb[#tb] = nil
  849. if not tb[1] then
  850. break
  851. end
  852. end
  853. for i = 1, #tb2 do
  854. len = len + 1
  855. local heroGrid = HeroLogic.getHeroGridByUuid(human, tb2[i])
  856. if heroGrid then
  857. local heroConfig = HeroExcel.hero[heroGrid.id]
  858. local _, skinSkillConf = SkinLogic.getHeroSkin(human, tb2[i])
  859. local skillConfig = SkillExcel.skill[heroConfig.normalAtkID]
  860. if skinSkillConf then
  861. skillConfig = SkillExcel.skill[skinSkillConf.normalAtkID]
  862. end
  863. wrapHangFightNet(msgRet.attackerList[i], heroConfig, skillConfig)
  864. local body, head = SkinLogic.getBody(human, tb2[i])
  865. if body then
  866. msgRet.attackerList[i].body = body
  867. end
  868. end
  869. end
  870. end
  871. msgRet.attackerList[0] = len
  872. -- Msg.trace(msgRet)
  873. Msg.send(msgRet, human.fd)
  874. end
  875. local function getExtraRewardID(human)
  876. local tBattleExcel = BattleLogic_GetBattleConfig(human)
  877. if not tBattleExcel then
  878. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[getExtraRewardID] 参数不正确")
  879. print("[getExtraRewardID] 不存在对应的 奖励配置 id = "..human.db._id)
  880. return nil, nil
  881. end
  882. local config = tBattleExcel.extraReward
  883. local battleExtraReward = human.db.battleExtraReward
  884. for id, data in ipairs(config) do
  885. if not battleExtraReward or not battleExtraReward[id] then
  886. return id, data
  887. end
  888. end
  889. end
  890. local function getExtraRewardState(human, extraRewardID)
  891. local tBattleExcel = BattleLogic_GetBattleConfig(human)
  892. local nGuaJiID = BattleLogic_GetBattleGuaJiID(human)
  893. if not tBattleExcel or -1 >= nGuaJiID then
  894. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[getExtraRewardState] 参数不正确")
  895. print("[getExtraRewardState] 不存在对应的 奖励配置 id = "..human.db._id)
  896. return 0
  897. end
  898. local config = tBattleExcel.extraReward[extraRewardID]
  899. if not config then
  900. return 0
  901. end
  902. if human.db.battleExtraReward and human.db.battleExtraReward[extraRewardID] then
  903. return 0
  904. end
  905. local guajiID = nGuaJiID
  906. if guajiID >= config.needBattleID then
  907. return 1
  908. end
  909. return 0
  910. end
  911. local function makeExtraRewardShow(human, net)
  912. local tBattleExcel = BattleLogic_GetBattleConfig(human)
  913. if not tBattleExcel then
  914. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[makeExtraRewardShow] 参数不正确")
  915. print("[makeExtraRewardShow] 不存在对应的 奖励配置 id = "..human.db._id)
  916. return
  917. end
  918. local config = tBattleExcel.extraReward
  919. local extraID, data = getExtraRewardID(human)
  920. if not extraID or not data then
  921. return
  922. end
  923. net[0] = 1
  924. net[1].needBattleID = data.needBattleID
  925. net[1].descID = data.descID
  926. net[1].desc = data.desc or ""
  927. net[1].extraHero[0] = 0
  928. net[1].extraItem[0] = 0
  929. if data.extraHeroID > 0 then
  930. net[1].extraHero[0] = 1
  931. HeroGrid.makeHeroSimpleByID(net[1].extraHero[1], data.extraHeroID, nil, nil, human)
  932. HeroGrid.makeHeroSimpleByGeneral(net[1].extraHero[1], data.extraHeroID)
  933. else
  934. net[1].extraItem[0] = 1
  935. Grid.makeItem(net[1].extraItem[1], data.extraReward[1], data.extraReward[2])
  936. end
  937. net[1].state = getExtraRewardState(human, extraID)
  938. end
  939. -- 随机道具
  940. local function randItemOut(dropRule, weightSum)
  941. if weightSum < 1 then
  942. return
  943. end
  944. local r = math.random(1, weightSum)
  945. for i = 1, #dropRule do
  946. local itemID = dropRule[i][1]
  947. local itemCnt1 = dropRule[i][2]
  948. local itemCnt2 = dropRule[i][3]
  949. local weight = dropRule[i][4]
  950. if r <= weight then
  951. local itemCnt = math.random(itemCnt1, itemCnt2)
  952. return itemID, itemCnt
  953. end
  954. r = r - weight
  955. end
  956. end
  957. function fontExtraDataSSZH(net, mapID, nowBattleID, human)
  958. local nodeCnt = 0
  959. local tBattleExcel = BattleLogic_GetBattleConfig(human)
  960. if not tBattleExcel then
  961. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[fontExtraDataSSZH] 参数不正确")
  962. print("[fontExtraDataSSZH] 不存在对应的 奖励配置 id = "..human.db._id)
  963. return
  964. end
  965. if ProjectLogic.isSszh() then
  966. for i = 1, #tBattleExcel.node do
  967. local nodeTempConfig = tBattleExcel.node[i]
  968. if nodeTempConfig.mapID == mapID then
  969. nodeCnt = nodeCnt + 1
  970. local posNet = net.posList[nodeCnt]
  971. local pos = nodeTempConfig.pos
  972. posNet.battleID = i
  973. posNet.posX = pos and pos[1] or 0
  974. posNet.posY = pos and pos[2] or 0
  975. posNet.nodeName = getBattleName(human, i)
  976. posNet.roleBase[0] = 0
  977. if i == nowBattleID then
  978. local videoTb = BattleDBLogic.queryBattleDbByNodeID(i)
  979. local sharkData = videoTb and videoTb.shark[2]
  980. if sharkData then
  981. posNet.roleBase[0] = 1
  982. RoleLogic.makeRoleBase(videoTb.roleBase, posNet.roleBase[1])
  983. end
  984. end
  985. posNet.isBig = nodeTempConfig.isBig or 0
  986. end
  987. end
  988. end
  989. net.posList[0] = nodeCnt
  990. end
  991. function fontVideoInfo(human, net, monsterConfig)
  992. local combatHero = CombatPosLogic.getCombatHeros(human, CombatDefine.COMBAT_TYPE1)
  993. local len = #combatHero
  994. -- 自己没队伍时,不显示
  995. if len == 0 then
  996. net.ownBody[0] = 0
  997. net.enemyBody[0] = 0
  998. else
  999. -- 设置真实数据
  1000. local cnt = 0
  1001. for k, v in pairs(combatHero) do
  1002. -- body数据
  1003. if v ~= "0" then
  1004. local heroGird, bagIndex = HeroLogic.getHeroGridByUuid(human, v)
  1005. if heroGird ~= nil then
  1006. cnt = cnt + 1
  1007. local config = HeroExcel.hero[heroGird.id]
  1008. if config then
  1009. local attrConfig = HeroDefine.getAttrConfig(heroGird.id, config.star)
  1010. local normalAtkID = attrConfig.normalAtkID
  1011. local skill = attrConfig.battleSkill
  1012. local body, head = SkinLogic.getBody(human, bagIndex)
  1013. net.ownBody[cnt].body = body or config.body
  1014. fontBattleSkillNet(net.ownBody[cnt].atkId, normalAtkID)
  1015. fontBattleSkillNet(net.ownBody[cnt].skill, skill)
  1016. net.ownBody[cnt].pos = k
  1017. net.ownBody[cnt].atkType = SkillExcel.skill[normalAtkID].areaPara
  1018. local attrs = ObjHuman.getHeroAttrs(human, heroGird.bagIndex)
  1019. net.ownBody[cnt].hp = attrs[RoleDefine.HP]
  1020. end
  1021. end
  1022. end
  1023. end
  1024. net.ownBody[0] = cnt
  1025. cnt = 0
  1026. local memberConfig = monsterConfig.member
  1027. for k, v in pairs(memberConfig) do
  1028. -- body数据
  1029. cnt = cnt + 1
  1030. local config = MonsterExcel.monster[v[1]]
  1031. if config then
  1032. local normalAtkID = config.normalAtkID
  1033. net.enemyBody[cnt].body = config.body
  1034. fontBattleSkillNet(net.enemyBody[cnt].atkId, normalAtkID)
  1035. fontBattleSkillNet(net.enemyBody[cnt].skill, normalAtkID)
  1036. net.enemyBody[cnt].pos = k
  1037. net.enemyBody[cnt].atkType = SkillExcel.skill[normalAtkID].areaPara
  1038. local attrID = monsterConfig.attrID[k]
  1039. local attrConfig = MonsterExcel.monsterAttr[attrID].attrs
  1040. if not attrConfig then
  1041. print("[fontVideoInfo] 根据attrID获取到的 attrConfig 为空 k = "..k.. " attrID = "..attrID)
  1042. end
  1043. for _, value in pairs(attrConfig) do
  1044. if value[1] == RoleDefine.HP then
  1045. net.enemyBody[cnt].hp = value[2]
  1046. break
  1047. end
  1048. end
  1049. end
  1050. end
  1051. net.enemyBody[0] = cnt
  1052. end
  1053. end
  1054. -- 战役主界面查询
  1055. function query(human)
  1056. local msgRet = Msg.gc.GC_BATTLE_QUERY
  1057. local nNowBattleID = BattleLogic_GetBattleBattleID(human)
  1058. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  1059. local nNowGuaJiID = BattleLogic_GetBattleGuaJiID(human)
  1060. local nBattleType = BattleLogic_GetBattleType(human)
  1061. if -1 >= nNowBattleID or not tBattleConfig or -1 >= nNowGuaJiID or -1 >= nBattleType then
  1062. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[query] 获取到的战斗ID或奖励配置不正确")
  1063. print("[query] 获取到的战斗ID或奖励配置不正确 id = "..human.db._id)
  1064. return
  1065. end
  1066. print("[BattleLogic query] nNowGuaJiID ="..nNowGuaJiID.." nNowBattleID ="..nNowBattleID)
  1067. msgRet.nowBattleID = nNowBattleID
  1068. local configNode = #tBattleConfig.node
  1069. if nNowBattleID > configNode then
  1070. print("[query] 玩家的战斗ID不正确,进行纠正 nNowBattleID = "..nNowBattleID.." 最大战斗ID = "..configNode)
  1071. nNowBattleID = configNode
  1072. BattleLogic_SetBattleBattleID(human, nNowBattleID)
  1073. end
  1074. if nNowGuaJiID > configNode then
  1075. print("[query] 玩家的挂机ID不正确,进行纠正 nNowGuaJiID = "..nNowGuaJiID.." 最大挂机ID = "..configNode)
  1076. nNowGuaJiID = configNode
  1077. BattleLogic_SetBattleGuaJiID(human, nNowGuaJiID)
  1078. end
  1079. local nBattleAdopt = BattleLogic_GetBattleAdopt(human, nBattleType)
  1080. if nBattleAdopt == 1 then
  1081. print("[query] nNowBattleID 为最大值 nNowBattleID = "..nNowBattleID.." nNowGuaJiID = "..nNowGuaJiID)
  1082. msgRet.nowBattleID = configNode + 1
  1083. end
  1084. -- local nowBattleID = human.db.battleID > configNode and configNode or human.db.battleID
  1085. local nowNodeConfig = tBattleConfig.node[nNowBattleID]
  1086. if not nowNodeConfig then
  1087. print("[query] 不存在对应的当前战斗ID对应的配置 nNowBattleID = ", nNowBattleID)
  1088. return
  1089. end
  1090. local nowMapConfig = tBattleConfig.map[nowNodeConfig.mapID]
  1091. if not nowMapConfig then
  1092. print("[query] 不存在对应的当前地图对应的地图配置 nNowBattleID = "
  1093. ..nNowBattleID.." mapID ="..nowNodeConfig.mapID)
  1094. return
  1095. end
  1096. local nJudeNum = nNowGuaJiID
  1097. if nNowGuaJiID ~= nNowBattleID then
  1098. if nNowGuaJiID + 1 < nNowBattleID then
  1099. nJudeNum = nNowBattleID - 1
  1100. end
  1101. end
  1102. msgRet.maxBattleID = configNode
  1103. msgRet.mapID = nowNodeConfig.mapID
  1104. msgRet.nodeID = nowNodeConfig.curLevel
  1105. msgRet.sceneID = nowNodeConfig.sceneID
  1106. msgRet.mapName = nowMapConfig.name
  1107. msgRet.nodeName = nowNodeConfig.name
  1108. msgRet.needLv = nowNodeConfig.needLv
  1109. msgRet.bg = nowMapConfig.bg
  1110. msgRet.canBattle = 0
  1111. msgRet.doubleCnt = 0
  1112. if nowNodeConfig.needLv > human.db.lv then
  1113. msgRet.canBattle = nowNodeConfig.needLv
  1114. end
  1115. local double = RoleSystemLogic.isDouble(human, RoleSystemDefine.ROLE_SYS_ID_1104)
  1116. if
  1117. double and human.db.bar and human.db.bar.doubleCnt and
  1118. human.db.bar.doubleCnt <= BarTaskLogic.DEFAULT_MAX_DOUBLE_CNT
  1119. then
  1120. msgRet.doubleCnt = BarTaskLogic.DEFAULT_MAX_DOUBLE_CNT - human.db.bar.doubleCnt
  1121. elseif double and not human.db.bar then
  1122. msgRet.doubleCnt = BarTaskLogic.DEFAULT_MAX_DOUBLE_CNT
  1123. end
  1124. msgRet.tongguan[0] = 0
  1125. local id = getTongguanIndex(human)
  1126. if id == nil then
  1127. msgRet.tongguan[0] = 0
  1128. else
  1129. msgRet.tongguan[0] = 1
  1130. local state = isGetReward(human, id)
  1131. local cf = tBattleConfig.node[id].tongguan
  1132. local net = msgRet.tongguan[1]
  1133. if state == true then
  1134. net.status = STATUS_NONE
  1135. else
  1136. net.status =(id > nJudeNum) and STATUS_CANGET or STATUS_NONE
  1137. end
  1138. net.levelName = getBattleName(human,id)
  1139. net.index = id
  1140. net.nowBattle = getBattleName(human,nJudeNum)
  1141. net.reward[0] = 0
  1142. net.heroReward[0] = 0
  1143. -- 是英雄
  1144. if cf[1][3] then
  1145. net.heroReward[0] = 1
  1146. local other = { }
  1147. other.star = cf[1][3]
  1148. HeroGrid.makeHeroSimpleByID(net.heroReward[1], cf[1][1], nil, other, human)
  1149. HeroGrid.makeHeroSimpleByGeneral(net.heroReward[1], cf[1][1])
  1150. else
  1151. net.reward[0] = 1
  1152. for i = 1, net.reward[0] do
  1153. local itemID = cf[i][1]
  1154. local itemCnt = cf[i][2]
  1155. Grid.makeItem(net.reward[i], itemID, itemCnt)
  1156. end
  1157. end
  1158. end
  1159. local outSec = 0
  1160. local tBattleOut = BattleLogic_GetBattleOut(human)
  1161. --if human.db.battleOut ~= nil then
  1162. if tBattleOut ~= nil then
  1163. local now = os.time()
  1164. outSec = now - tBattleOut.expTs1
  1165. end
  1166. local maxHangTime = getHangMaxTime(human)
  1167. msgRet.maxTime = maxHangTime
  1168. if maxHangTime >= outSec then
  1169. msgRet.time = outSec
  1170. else
  1171. msgRet.time = maxHangTime
  1172. end
  1173. -- 悬赏情报数量
  1174. msgRet.xushang = human.db.bar and human.db.bar.qingbao or 0
  1175. msgRet.xushangMax = RoleExcel.exp[human.db.lv].qingBaoMax
  1176. -- 悬赏红点
  1177. msgRet.xsDot = 0
  1178. if BarTaskLogic.isDot(human) then
  1179. msgRet.xsDot = 1
  1180. end
  1181. msgRet.canMopup = 0
  1182. if TequanShopLogic.isActiveMopup(human) then
  1183. msgRet.canMopup = human.db.mopupDoCnt < BATTLE_MOPUP_CNT_VIP and 1 or 0
  1184. else
  1185. msgRet.canMopup = human.db.mopupDoCnt < BATTLE_MOPUP_CNT and 1 or 0
  1186. end
  1187. local monsterOutId = nowNodeConfig.monsterOutID
  1188. if not monsterOutId then
  1189. print("[BattleLogic query] monsterOutId 为空")
  1190. return
  1191. end
  1192. local monsterConfig = MonsterExcel.monsterOut[monsterOutId]
  1193. if not monsterConfig then
  1194. print("[BattleLogic query] 获取到的 monsterConfig 为空 monsterOutId = "..monsterOutId)
  1195. return
  1196. end
  1197. fontVideoInfo(human, msgRet.videoInfo, monsterConfig)
  1198. fontExtraDataSSZH(msgRet.extraDataSSZH, nowNodeConfig.mapID, nNowBattleID, human)
  1199. -- Msg.trace(msgRet)
  1200. Msg.send(msgRet, human.fd)
  1201. hangFightQuery(human)
  1202. end
  1203. -- 获取当前地图ID
  1204. function getMapID(human, args)
  1205. local nNowBattleID = BattleLogic_GetBattleBattleID(human)
  1206. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  1207. if -1 >= nNowBattleID or not tBattleConfig then
  1208. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[getMapID] 获取到的战斗ID或奖励配置不正确")
  1209. print("[getMapID] 获取到的战斗ID或奖励配置不正确 id = "..human.db._id)
  1210. return
  1211. end
  1212. -- local battleID = human.db.battleID
  1213. -- local config = BattleExcel.node[battleID]
  1214. local config = tBattleConfig.node[nNowBattleID]
  1215. if not config then
  1216. return
  1217. end
  1218. local mapConfig = tBattleConfig.map[config.mapID]
  1219. if not mapConfig then
  1220. return
  1221. end
  1222. return config.sceneID
  1223. end
  1224. -- 战役挂机界面查询
  1225. function onHookQuery(human)
  1226. local msgRet = Msg.gc.GC_BATTLE_HANG_QUERY
  1227. calcBattleOut(human)
  1228. local tBattleOut = BattleLogic_GetBattleOut(human)
  1229. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  1230. local nGuaJiID = BattleLogic_GetBattleGuaJiID(human)
  1231. if not tBattleConfig or 0 > nGuaJiID or not tBattleOut then
  1232. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[onHookQuery] 获取到的战斗挂机奖励配置不正确 或 配置信息、挂机ID不正确 id = "..human.db._id)
  1233. print("[onHookQuery] 获取到的战斗挂机奖励配置不正确 或 配置信息、挂机ID不正确 id = "..human.db._id)
  1234. return
  1235. end
  1236. -- local expAdd = human.db.battleOut.exp
  1237. -- local jinbiAdd = human.db.battleOut.jinbi
  1238. -- local greenExpAdd = human.db.battleOut.greenExp
  1239. -- local qingbaoAdd = human.db.battleOut.qingbao
  1240. local expAdd = tBattleOut.exp
  1241. local jinbiAdd = tBattleOut.jinbi
  1242. local greenExpAdd = tBattleOut.greenExp
  1243. local qingbaoAdd = tBattleOut.qingbao
  1244. local skip = GuideLogic.getGuideSkip(human, GuideLogic.SKIPTYPE_JUMP_BATTLE_EXP)
  1245. if not skip then
  1246. expAdd = 1510
  1247. end
  1248. local items = { }
  1249. local len = #items
  1250. local tempTable = { }
  1251. if tBattleOut.items then
  1252. tempTable = Util.copyTable(tBattleOut.items)
  1253. end
  1254. tempTable[ItemDefine.ITEM_EXP_ID] = tempTable[ItemDefine.ITEM_EXP_ID] or 0
  1255. tempTable[ItemDefine.ITEM_EXP_ID] = expAdd
  1256. tempTable[ItemDefine.ITEM_JINBI_ID] = tempTable[ItemDefine.ITEM_JINBI_ID] or 0
  1257. tempTable[ItemDefine.ITEM_JINBI_ID] = jinbiAdd
  1258. tempTable[ItemDefine.ITEM_GREEN_EXP_ID] = tempTable[ItemDefine.ITEM_GREEN_EXP_ID] or 0
  1259. tempTable[ItemDefine.ITEM_GREEN_EXP_ID] = greenExpAdd
  1260. tempTable[ItemDefine.ITEM_QINGBAO_ID] = tempTable[ItemDefine.ITEM_QINGBAO_ID] or 0
  1261. tempTable[ItemDefine.ITEM_QINGBAO_ID] = qingbaoAdd
  1262. local list = DropExchangeLogic.getAbsCanDrop(human)
  1263. if list then
  1264. for k, v in pairs(list) do
  1265. if tempTable[k] and tempTable[k] > 0 then
  1266. len = len + 1
  1267. items[len] = { }
  1268. items[len].id = k
  1269. items[len].cnt = tempTable[k]
  1270. end
  1271. end
  1272. end
  1273. for k, v in pairs(tempTable) do
  1274. if not list or not list[k] then
  1275. len = len + 1
  1276. items[len] = { }
  1277. items[len].id = k
  1278. items[len].cnt = v
  1279. end
  1280. end
  1281. -- 发消息
  1282. local guajiID = nGuaJiID > #tBattleConfig.node and #tBattleConfig.node or nGuaJiID
  1283. if guajiID == 0 then
  1284. return Broadcast.sendErr(human, Lang.BATTLE_GUAJI_ERR)
  1285. end
  1286. local nodeConfig = tBattleConfig.node[guajiID]
  1287. local now = os.time()
  1288. local outSec = now - human.db.battleOut.expTs1
  1289. local maxHangTime = getHangMaxTime(human)
  1290. local idx = 1
  1291. for i = 1, #items do
  1292. Grid.makeItem(msgRet.items[i], items[i].id, items[i].cnt)
  1293. end
  1294. local len = #items
  1295. if human.db.battleOut.equip then
  1296. for k, equipGrid in ipairs(tBattleOut.equip) do
  1297. if len >= 10 then
  1298. msgRet.items[0] = len
  1299. msgRet.isEnd = 0
  1300. msgRet.index = idx
  1301. msgRet.maxTime = maxHangTime
  1302. if maxHangTime >= outSec then
  1303. msgRet.time = outSec
  1304. else
  1305. msgRet.time = maxHangTime
  1306. end
  1307. local minHour = math.floor(msgRet.time / HOUR_SEC)
  1308. minHour = (minHour ~= 0) and minHour or 1
  1309. msgRet.diamond = minHour * DIAMOND_COST_PER_HOUR
  1310. msgRet.exp = nodeConfig.hangExp
  1311. msgRet.jinbi = nodeConfig.hangJinbi
  1312. msgRet.greenExp = nodeConfig.hangGreenExp
  1313. msgRet.qingbao = nodeConfig.hangQingbao or 0
  1314. Msg.send(msgRet, human.fd)
  1315. len = 0
  1316. idx = idx + 1
  1317. msgRet = Msg.gc.GC_BATTLE_HANG_QUERY
  1318. end
  1319. len = len + 1
  1320. Grid.makeItem(msgRet.items[len], equipGrid.id, 1, nil, equipGrid)
  1321. end
  1322. end
  1323. msgRet.isEnd = 1
  1324. msgRet.index = idx
  1325. msgRet.items[0] = len
  1326. msgRet.maxTime = maxHangTime
  1327. if maxHangTime >= outSec then
  1328. msgRet.time = outSec
  1329. else
  1330. msgRet.time = maxHangTime
  1331. end
  1332. local minHour = math.floor(msgRet.time / HOUR_SEC)
  1333. minHour = (minHour ~= 0) and minHour or 1
  1334. msgRet.diamond = minHour * DIAMOND_COST_PER_HOUR
  1335. msgRet.exp = nodeConfig.hangExp
  1336. msgRet.jinbi = nodeConfig.hangJinbi
  1337. msgRet.greenExp = nodeConfig.hangGreenExp
  1338. msgRet.qingbao = nodeConfig.hangQingbao or 0
  1339. Msg.send(msgRet, human.fd)
  1340. end
  1341. local function isChapterDot(human, mapID)
  1342. local chapterReward = BattleLogic_GetChapterReward(human)
  1343. local nBattleID = BattleLogic_GetBattleBattleID(human)
  1344. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  1345. if not chapterReward or not tBattleConfig or -1 >= nBattleID or chapterReward[mapID] then
  1346. return false
  1347. end
  1348. local battleID = nBattleID
  1349. local battleNodeConfig = tBattleConfig.node[battleID]
  1350. if not battleNodeConfig then
  1351. if battleID == #tBattleConfig.node + 1 then
  1352. return true
  1353. else
  1354. return false
  1355. end
  1356. else
  1357. local roleMapId = battleNodeConfig.mapID
  1358. if roleMapId <= mapID then
  1359. return false
  1360. end
  1361. end
  1362. return true
  1363. end
  1364. function battleWorldMapQuery(human)
  1365. -- 先取配置
  1366. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  1367. local nBattleID = BattleLogic_GetBattleBattleID(human)
  1368. if not tBattleConfig or -1 >= nBattleID then
  1369. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[battleWorldMapQuery] 获取到的战斗挂机奖励配置不正确 或 配置信息、战斗关卡ID不正确 id = "..human.db._id)
  1370. print("[battleWorldMapQuery] 获取到的战斗挂机奖励配置不正确 或 配置信息、挂机ID不正确 id = "..human.db._id)
  1371. return
  1372. end
  1373. local msgRet = Msg.gc.GC_BATTLE_WORLD_MAP_QUERY
  1374. local worldMapConfig = tBattleConfig.map
  1375. local battleID = nBattleID > #tBattleConfig.node and #tBattleConfig.node or nBattleID
  1376. local battleNodeConfig = tBattleConfig.node[battleID]
  1377. local len = #worldMapConfig
  1378. for i = 1, len do
  1379. local v = worldMapConfig[i]
  1380. msgRet.worldMap[i].mapID = i
  1381. msgRet.worldMap[i].mapName = v.name or ""
  1382. msgRet.worldMap[i].mapBuild = v.build or 0
  1383. msgRet.worldMap[i].mapBg = v.bg or 0
  1384. msgRet.worldMap[i].mapPos[0] = 2
  1385. msgRet.worldMap[i].mapPos[1] = v.pos[1]
  1386. msgRet.worldMap[i].mapPos[2] = v.pos[2]
  1387. msgRet.worldMap[i].status =(battleNodeConfig.mapID >= i) and 1 or 0
  1388. msgRet.worldMap[i].story = v.des or ""
  1389. if battleNodeConfig.mapID == i then
  1390. msgRet.worldMap[i].maxLevel = battleNodeConfig.maxLevel
  1391. msgRet.worldMap[i].curLevel = battleNodeConfig.curLevel
  1392. else
  1393. msgRet.worldMap[i].maxLevel = 0
  1394. msgRet.worldMap[i].curLevel = 0
  1395. end
  1396. local reward = v.reward
  1397. local l = 0
  1398. msgRet.worldMap[i].chapterReward[0] = #reward
  1399. for _, rewardData in pairs(reward) do
  1400. l = l + 1
  1401. Grid.makeItem(msgRet.worldMap[i].chapterReward[l], rewardData[1], rewardData[2])
  1402. end
  1403. msgRet.worldMap[i].chapterDot = 0
  1404. if isChapterDot(human, i) then
  1405. msgRet.worldMap[i].chapterDot = 1
  1406. end
  1407. local cnt = 0
  1408. BATTLE_LEVEL_PLAYER_LIST[i] = BATTLE_LEVEL_PLAYER_LIST[i] or { }
  1409. for s, t in pairs(BATTLE_LEVEL_PLAYER_LIST[i]) do
  1410. cnt = cnt + 1
  1411. RoleLogic.makeRoleBase(t, msgRet.worldMap[i].roleList[cnt])
  1412. if cnt >= 3 then
  1413. break
  1414. end
  1415. end
  1416. msgRet.worldMap[i].roleList[0] = cnt
  1417. end
  1418. msgRet.worldMap[0] = len
  1419. Msg.send(msgRet, human.fd)
  1420. end
  1421. function battleNodeQuery(human, mapID)
  1422. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  1423. local nBattleID = BattleLogic_GetBattleBattleID(human)
  1424. if not tBattleConfig or -1 >= nBattleID then
  1425. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[battleNodeQuery] 获取到的战斗挂机奖励配置不正确 或 配置信息、战斗关卡ID不正确 id = "..human.db._id)
  1426. print("[battleNodeQuery] 获取到的战斗挂机奖励配置不正确 或 配置信息、挂机ID不正确 id = "..human.db._id)
  1427. return
  1428. end
  1429. local msgRet = Msg.gc.GC_BATTLE_NODE_QUERY
  1430. local nodeConfig = tBattleConfig.node
  1431. local lenConfig = #nodeConfig
  1432. local len = 0
  1433. msgRet.battleID = nBattleID or 0
  1434. for i = 1, lenConfig do
  1435. local v = nodeConfig[i]
  1436. if v.mapID == mapID then
  1437. len = len + 1
  1438. msgRet.nodeInfo[len].nodeName = v.name
  1439. msgRet.nodeInfo[len].battleID = i
  1440. msgRet.nodeInfo[len].needLv = v.needLv
  1441. msgRet.nodeInfo[len].needZDL = v.needZDL
  1442. msgRet.nodeInfo[len].hasSuipian = v.hasSuipian
  1443. end
  1444. end
  1445. msgRet.nodeInfo[0] = len
  1446. Msg.send(msgRet, human.fd)
  1447. end
  1448. function initBattleOut(human, now)
  1449. if human.db.battleOut then
  1450. return
  1451. end
  1452. if false == BattleLogic_InitAllBattleOut(human, now) then
  1453. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "initBattleOut 初始化挂机奖励表失败 id = "
  1454. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  1455. return
  1456. end
  1457. -- human.db.battleOut = { }
  1458. -- human.db.battleOut.expTs1 = now
  1459. -- -- 经验开始产出时间戳
  1460. -- human.db.battleOut.expTs2 = now
  1461. -- -- 经验产出结算时间戳
  1462. -- human.db.battleOut.itemTs1 = now
  1463. -- -- 道具产出时间戳
  1464. -- human.db.battleOut.itemTs2 = now
  1465. -- -- 道具产出结算时间戳
  1466. -- human.db.battleOut.exp = 0
  1467. -- human.db.battleOut.jinbi = 0
  1468. -- human.db.battleOut.greenExp = 0
  1469. -- human.db.battleOut.qingbao = 0
  1470. -- human.db.battleOut.items = nil
  1471. -- -- 产出的待收获的战利品
  1472. -- human.db.battleOut.equip = nil
  1473. -- -- 产出的待收获的装备
  1474. end
  1475. function calcBattleOut(human,isDiamond)
  1476. local now = os.time()
  1477. initBattleOut(human, now)
  1478. calcBattleExpOut(human, now)
  1479. calcBattleItemOut(human, now)
  1480. if isDiamond then -- 钻石消耗 所有产出翻1.5倍
  1481. local tBattleOut = BattleLogic_GetBattleOut(human)
  1482. if not tBattleOut then
  1483. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "calcBattleOut 获取挂机奖励列表失败 id = "
  1484. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  1485. return
  1486. end
  1487. -- human.db.battleOut.exp = math.floor(human.db.battleOut.exp * DIAMOND_ADDITION)
  1488. -- human.db.battleOut.jinbi = math.floor(human.db.battleOut.jinbi * DIAMOND_ADDITION)
  1489. -- human.db.battleOut.greenExp = math.floor(human.db.battleOut.greenExp * DIAMOND_ADDITION)
  1490. -- human.db.battleOut.qingbao = math.floor(human.db.battleOut.qingbao * DIAMOND_ADDITION)
  1491. -- local items = human.db.battleOut.items or {}
  1492. tBattleOut.exp = math.floor(tBattleOut.exp * DIAMOND_ADDITION)
  1493. tBattleOut.jinbi = math.floor(tBattleOut.jinbi * DIAMOND_ADDITION)
  1494. tBattleOut.greenExp = math.floor(tBattleOut.greenExp * DIAMOND_ADDITION)
  1495. tBattleOut.qingbao = math.floor(tBattleOut.qingbao * DIAMOND_ADDITION)
  1496. local items = tBattleOut.items or {}
  1497. for id,cnt in pairs(items) do
  1498. items[id] = math.floor(cnt * DIAMOND_ADDITION)
  1499. end
  1500. -- local equipList = human.db.battleOut.equip or {}
  1501. local equipList = tBattleOut.equip or {}
  1502. local equipMap = {}
  1503. for _,equip in ipairs(equipList) do
  1504. equipMap[equip.id] = equipMap[equip.id] or 0
  1505. equipMap[equip.id] = equipMap[equip.id] + 1
  1506. end
  1507. for id,cnt in pairs(equipMap) do
  1508. local count = math.floor(cnt * DIAMOND_ADDITION)
  1509. for i = cnt,count do
  1510. local equipGrid = EquipLogic.makeEquip(id)
  1511. equipList[#equipList + 1] = equipGrid
  1512. end
  1513. end
  1514. end
  1515. end
  1516. -- 获取正确的剩余可收益的结算时间
  1517. function getSurMaxHangTime(maxHangTime, ts1, now)
  1518. if ts1 + maxHangTime > now then
  1519. return now
  1520. else
  1521. return ts1 + maxHangTime
  1522. end
  1523. end
  1524. -- function calcBattleExpOut(human, now)
  1525. -- local maxHangTime = getHangMaxTime(human)
  1526. -- if human.db.battleOut.expTs2 - human.db.battleOut.expTs1 >= maxHangTime then
  1527. -- return
  1528. -- end
  1529. -- local outTime = getSurMaxHangTime(maxHangTime, human.db.battleOut.expTs1, now)
  1530. -- local outSec = outTime - human.db.battleOut.expTs2
  1531. -- local outCnt = math.floor(outSec / BATTLE_HANG_EXP_OUT_PERIOD)
  1532. -- if outCnt < 1 then
  1533. -- return
  1534. -- end
  1535. -- local guajiID = human.db.guajiID > #BattleExcel.node and #BattleExcel.node or human.db.guajiID
  1536. -- if guajiID == 0 then
  1537. -- return
  1538. -- end
  1539. -- local nowNodeConfig = BattleExcel.node[guajiID]
  1540. -- human.db.battleOut.expTs2 = human.db.battleOut.expTs2 + outCnt * BATTLE_HANG_EXP_OUT_PERIOD
  1541. -- if now - human.db.battleOut.expTs1 >= maxHangTime then
  1542. -- human.db.battleOut.expTs2 = now
  1543. -- end
  1544. -- local vipExpAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER7) or 0) / 100
  1545. -- local vipJinAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER8) or 0) / 100
  1546. -- local vipGreenExpAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER9) or 0) / 100
  1547. -- local vipQingbaoAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER19) or 0) / 100
  1548. -- local exp = nowNodeConfig.hangExp
  1549. -- local jinbi = nowNodeConfig.hangJinbi
  1550. -- local greenExp = nowNodeConfig.hangGreenExp
  1551. -- local qingbao = nowNodeConfig.hangQingbao
  1552. -- human.db.battleOut.exp = human.db.battleOut.exp + math.floor(outCnt * exp *(1 + vipExpAdd))
  1553. -- human.db.battleOut.jinbi = human.db.battleOut.jinbi + math.floor(outCnt * jinbi *(1 + vipJinAdd))
  1554. -- human.db.battleOut.greenExp = human.db.battleOut.greenExp + math.floor(outCnt * greenExp *(1 + vipGreenExpAdd))
  1555. -- human.db.battleOut.qingbao = human.db.battleOut.qingbao + math.floor(outCnt * qingbao *(1 + vipQingbaoAdd))
  1556. -- end
  1557. function calcBattleExpOut(human, now)
  1558. local tBattleOut = BattleLogic_GetBattleOut(human)
  1559. if not tBattleOut then
  1560. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "calcBattleExpOut 获取挂机奖励列表失败 id = "
  1561. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  1562. return
  1563. end
  1564. local maxHangTime = getHangMaxTime(human)
  1565. if tBattleOut.expTs2 - tBattleOut.expTs1 >= maxHangTime then
  1566. return
  1567. end
  1568. local outTime = getSurMaxHangTime(maxHangTime, tBattleOut.expTs1, now)
  1569. local outSec = outTime - tBattleOut.expTs2
  1570. local outCnt = math.floor(outSec / BATTLE_HANG_EXP_OUT_PERIOD)
  1571. if outCnt < 1 then
  1572. return
  1573. end
  1574. local tBattleNodeConfig = BattleLogic_GetBattleConfig(human)
  1575. local nGuaJiID = BattleLogic_GetBattleGuaJiID(human)
  1576. if not tBattleNodeConfig or 0 > nGuaJiID then
  1577. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "calcBattleExpOut 获取到的配置表不正确或挂机ID不正确 id = "
  1578. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  1579. return
  1580. end
  1581. local guajiID = nGuaJiID > #tBattleNodeConfig.node and #tBattleNodeConfig.node or nGuaJiID
  1582. if guajiID == 0 then
  1583. return
  1584. end
  1585. local nowNodeConfig = tBattleNodeConfig.node[guajiID]
  1586. tBattleOut.expTs2 = tBattleOut.expTs2 + outCnt * BATTLE_HANG_EXP_OUT_PERIOD
  1587. if now - tBattleOut.expTs1 >= maxHangTime then
  1588. tBattleOut.expTs2 = now
  1589. end
  1590. local vipExpAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER7) or 0) / 100
  1591. local vipJinAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER8) or 0) / 100
  1592. local vipGreenExpAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER9) or 0) / 100
  1593. local vipQingbaoAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER19) or 0) / 100
  1594. local exp = nowNodeConfig.hangExp
  1595. local jinbi = nowNodeConfig.hangJinbi
  1596. local greenExp = nowNodeConfig.hangGreenExp
  1597. local qingbao = nowNodeConfig.hangQingbao
  1598. tBattleOut.exp = tBattleOut.exp + math.floor(outCnt * exp *(1 + vipExpAdd))
  1599. tBattleOut.jinbi = tBattleOut.jinbi + math.floor(outCnt * jinbi *(1 + vipJinAdd))
  1600. tBattleOut.greenExp = tBattleOut.greenExp + math.floor(outCnt * greenExp *(1 + vipGreenExpAdd))
  1601. tBattleOut.qingbao = tBattleOut.qingbao + math.floor(outCnt * qingbao *(1 + vipQingbaoAdd))
  1602. end
  1603. -- 根据时间计算道具产出
  1604. local ITEM_OUT_LIST = { }
  1605. function getItemOutsByTime(config, sec)
  1606. Util.cleanTable(ITEM_OUT_LIST)
  1607. local outCnt = math.floor(sec / BATTLE_HANG_ITEM_OUT_PERIOD)
  1608. if outCnt < 1 then
  1609. return ITEM_OUT_LIST
  1610. end
  1611. -- 普通掉落
  1612. local dropID = config.dropID
  1613. local dropConfig = DropExcel.dropBattle[dropID]
  1614. local weightSum = 0
  1615. for i = 1, #dropConfig.dropRule do
  1616. local tempConfig = dropConfig.dropRule[i]
  1617. weightSum = weightSum + tempConfig[4]
  1618. end
  1619. for i = 1, outCnt do
  1620. local itemID, itemCnt = randItemOut(dropConfig.dropRule, weightSum)
  1621. if itemID and itemCnt and itemCnt > 0 then
  1622. ITEM_OUT_LIST[itemID] =(ITEM_OUT_LIST[itemID] or 0) + itemCnt
  1623. end
  1624. end
  1625. for i = 1, #dropConfig.dropRule2 do
  1626. local tempConfig = dropConfig.dropRule2[i]
  1627. local itemID = tempConfig[1]
  1628. local itemMin = tempConfig[2]
  1629. local itemMax = tempConfig[3]
  1630. local itemCnt = math.random(itemMin, itemMax) * outCnt
  1631. if itemCnt > 0 then
  1632. ITEM_OUT_LIST[itemID] =(ITEM_OUT_LIST[itemID] or 0) + itemCnt
  1633. end
  1634. end
  1635. -- 三小时掉落
  1636. outCnt = math.floor(sec / BATTLE_HANG_ITEM_OUT_PERIOD_2)
  1637. if outCnt < 1 then
  1638. return ITEM_OUT_LIST
  1639. end
  1640. weightSum = 0
  1641. for i = 1, #dropConfig.dropRule3 do
  1642. local tempConfig = dropConfig.dropRule3[i]
  1643. weightSum = weightSum + tempConfig[4]
  1644. end
  1645. for i = 1, outCnt do
  1646. local itemID, itemCnt = randItemOut(dropConfig.dropRule3, weightSum)
  1647. if itemID and itemCnt and itemCnt > 0 then
  1648. ITEM_OUT_LIST[itemID] =(ITEM_OUT_LIST[itemID] or 0) + itemCnt
  1649. end
  1650. end
  1651. return ITEM_OUT_LIST
  1652. end
  1653. -- function calcBattleItemOut(human, now,isDiamond)
  1654. -- local maxHangTime = getHangMaxTime(human)
  1655. -- if human.db.battleOut.itemTs2 - human.db.battleOut.itemTs1 >= maxHangTime then
  1656. -- return
  1657. -- end
  1658. -- local outTime = getSurMaxHangTime(maxHangTime, human.db.battleOut.itemTs1, now)
  1659. -- local outSec = outTime - human.db.battleOut.itemTs2
  1660. -- local outCnt = math.floor(outSec / BATTLE_HANG_ITEM_OUT_PERIOD)
  1661. -- if outCnt < 1 then
  1662. -- return
  1663. -- end
  1664. -- local guajiID = human.db.guajiID > #BattleExcel.node and #BattleExcel.node or human.db.guajiID
  1665. -- if guajiID == 0 then
  1666. -- return
  1667. -- end
  1668. -- local sec = outCnt * BATTLE_HANG_ITEM_OUT_PERIOD
  1669. -- human.db.battleOut.itemTs2 = human.db.battleOut.itemTs2 + sec
  1670. -- if now - human.db.battleOut.itemTs1 >= maxHangTime then
  1671. -- human.db.battleOut.itemTs2 = now
  1672. -- end
  1673. -- local nodeConfig = BattleExcel.node[guajiID]
  1674. -- local items = getItemOutsByTime(nodeConfig, sec)
  1675. -- for itemID, itemCnt in pairs(items) do
  1676. -- -- 判定是否是装备
  1677. -- if ItemDefine.isEquip(itemID) then
  1678. -- -- 生成装备
  1679. -- local equipGrid = EquipLogic.makeEquip(itemID)
  1680. -- if equipGrid then
  1681. -- human.db.battleOut.equip = human.db.battleOut.equip or { }
  1682. -- human.db.battleOut.equip[#human.db.battleOut.equip + 1] = equipGrid
  1683. -- end
  1684. -- else
  1685. -- human.db.battleOut.items = human.db.battleOut.items or { }
  1686. -- human.db.battleOut.items[itemID] = human.db.battleOut.items[itemID] or 0
  1687. -- human.db.battleOut.items[itemID] = human.db.battleOut.items[itemID] + itemCnt
  1688. -- end
  1689. -- end
  1690. -- DropExchangeLogic.getDropItem(human, outSec, BATTLE_HANG_ITEM_OUT_PERIOD, human.db.battleOut)
  1691. -- end
  1692. function calcBattleItemOut(human, now,isDiamond)
  1693. local tBattleOut = BattleLogic_GetBattleOut(human)
  1694. if not tBattleOut then
  1695. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "calcBattleItemOut 获取挂机奖励列表失败 id = "
  1696. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  1697. return
  1698. end
  1699. local maxHangTime = getHangMaxTime(human)
  1700. if tBattleOut.itemTs2 - tBattleOut.itemTs1 >= maxHangTime then
  1701. return
  1702. end
  1703. local outTime = getSurMaxHangTime(maxHangTime, tBattleOut.itemTs1, now)
  1704. local outSec = outTime - tBattleOut.itemTs2
  1705. local outCnt = math.floor(outSec / BATTLE_HANG_ITEM_OUT_PERIOD)
  1706. if outCnt < 1 then
  1707. return
  1708. end
  1709. local tBattleNodeConfig = BattleLogic_GetBattleConfig(human)
  1710. local nGuaJiID = BattleLogic_GetBattleGuaJiID(human)
  1711. if not tBattleNodeConfig or 0 > nGuaJiID then
  1712. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "calcBattleItemOut 获取到的配置表不正确或挂机ID不正确 id = "
  1713. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  1714. return
  1715. end
  1716. local guajiID = nGuaJiID > #tBattleNodeConfig.node and #tBattleNodeConfig.node or nGuaJiID
  1717. if guajiID == 0 then
  1718. return
  1719. end
  1720. local sec = outCnt * BATTLE_HANG_ITEM_OUT_PERIOD
  1721. tBattleOut.itemTs2 = tBattleOut.itemTs2 + sec
  1722. if now - tBattleOut.itemTs1 >= maxHangTime then
  1723. tBattleOut.itemTs2 = now
  1724. end
  1725. local nodeConfig = tBattleNodeConfig.node[guajiID]
  1726. local items = getItemOutsByTime(nodeConfig, sec)
  1727. for itemID, itemCnt in pairs(items) do
  1728. -- 判定是否是装备
  1729. if ItemDefine.isEquip(itemID) then
  1730. -- 生成装备
  1731. local equipGrid = EquipLogic.makeEquip(itemID)
  1732. if equipGrid then
  1733. tBattleOut.equip = tBattleOut.equip or { }
  1734. tBattleOut.equip[#tBattleOut.equip + 1] = equipGrid
  1735. end
  1736. else
  1737. tBattleOut.items = tBattleOut.items or { }
  1738. tBattleOut.items[itemID] = tBattleOut.items[itemID] or 0
  1739. tBattleOut.items[itemID] = tBattleOut.items[itemID] + itemCnt
  1740. end
  1741. end
  1742. DropExchangeLogic.getDropItem(human, outSec, BATTLE_HANG_ITEM_OUT_PERIOD, tBattleOut)
  1743. end
  1744. local function hangExpGet(human,isDiamond)
  1745. local tBattleOut = BattleLogic_GetBattleOut(human)
  1746. if not tBattleOut then
  1747. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "hangExpGet 获取挂机奖励列表失败 id = "
  1748. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  1749. return
  1750. end
  1751. local needDiamond = 0
  1752. -- 是否消耗钻石
  1753. if isDiamond then
  1754. local now = os.time()
  1755. local outSec = now - tBattleOut.expTs1
  1756. local maxHangTime = getHangMaxTime(human)
  1757. outSec = outSec > maxHangTime and maxHangTime or outSec
  1758. local minHour = math.floor(outSec / HOUR_SEC)
  1759. minHour = (minHour ~= 0) and minHour or 1
  1760. local diamondCnt = minHour * DIAMOND_COST_PER_HOUR
  1761. if not ObjHuman.checkRMB(human,diamondCnt) then
  1762. return
  1763. end
  1764. needDiamond = -diamondCnt
  1765. end
  1766. print("==================== needDiamond is ",needDiamond)
  1767. calcBattleOut(human,isDiamond)
  1768. if tBattleOut.exp == 0 then
  1769. return 1
  1770. end
  1771. local jinbiAdd = tBattleOut.jinbi
  1772. if not ObjHuman.canAddJinbi(human, jinbiAdd) then
  1773. return 2
  1774. end
  1775. -- 检测装备数量
  1776. if tBattleOut.equip then
  1777. local equipCnt = #htBattleOut.equip
  1778. if not EquipLogic.checkEmptyCnt(human, equipCnt) then
  1779. return
  1780. end
  1781. end
  1782. local items = { }
  1783. local len = #items
  1784. local maxHangTime = getHangMaxTime(human)
  1785. if tBattleOut.expTs2 - tBattleOut.expTs1 >= maxHangTime then
  1786. local now = os.time()
  1787. tBattleOut.expTs2 = now
  1788. end
  1789. if tBattleOut.itemTs2 - tBattleOut.itemTs1 >= maxHangTime then
  1790. local now = os.time()
  1791. tBattleOut.itemTs2 = now
  1792. end
  1793. tBattleOut.itemTs1 = tBattleOut.itemTs2
  1794. -- 改db
  1795. local tempTable = tBattleOut.items or { }
  1796. tBattleOut.items = nil
  1797. for k, v in pairs(tempTable) do
  1798. len = len + 1
  1799. items[len] = { }
  1800. items[len].id = k
  1801. items[len].cnt = v
  1802. end
  1803. tBattleOut.expTs1 = tBattleOut.expTs2
  1804. local expAdd = tBattleOut.exp
  1805. local greenExpAdd = tBattleOut.greenExp
  1806. local qingbaoAdd = tBattleOut.qingbao
  1807. -- 新手指引 强制经验
  1808. local flag = GuideLogic.getGuideSkip(human, GuideLogic.SKIPTYPE_JUMP_BATTLE_EXP)
  1809. if not flag then
  1810. expAdd = 1510
  1811. end
  1812. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_BATTLE_EXP)
  1813. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_BATTLE_GUAJI)
  1814. tBattleOut.exp = 0
  1815. tBattleOut.jinbi = 0
  1816. tBattleOut.greenExp = 0
  1817. tBattleOut.qingbao = 0
  1818. len = len + 1
  1819. items[len] = { }
  1820. items[len].id = ItemDefine.ITEM_EXP_ID
  1821. items[len].cnt = expAdd
  1822. len = len + 1
  1823. items[len] = { }
  1824. items[len].id = ItemDefine.ITEM_JINBI_ID
  1825. items[len].cnt = jinbiAdd
  1826. len = len + 1
  1827. items[len] = { }
  1828. items[len].id = ItemDefine.ITEM_GREEN_EXP_ID
  1829. items[len].cnt = greenExpAdd
  1830. len = len + 1
  1831. items[len] = { }
  1832. items[len].id = ItemDefine.ITEM_QINGBAO_ID
  1833. items[len].cnt = qingbaoAdd
  1834. -- 给道具
  1835. for i = 1, #items do
  1836. local tempID = items[i].id
  1837. local tempCnt = items[i].cnt
  1838. BagLogic.addItem(human, tempID, tempCnt, "battle")
  1839. end
  1840. -- 给装备
  1841. if tBattleOut.equip then
  1842. for k, equipGrid in ipairs(tBattleOut.equip) do
  1843. EquipLogic.addByEquipGrid(human, equipGrid, "battle", true)
  1844. end
  1845. tBattleOut.equip = nil
  1846. end
  1847. if needDiamond < 0 then
  1848. ObjHuman.decZuanshi(human,needDiamond,"battle")
  1849. end
  1850. return 0, items
  1851. end
  1852. -- 获取挂机收益
  1853. function hangGet(human,isDiamond)
  1854. local ret, items = hangExpGet(human,false)
  1855. if ret == 1 then
  1856. return Broadcast.sendErr(human, Lang.BATTLE_HANG_GET_EXP_ERR_NONE)
  1857. elseif ret == 2 then
  1858. return Broadcast.sendErr(human, Lang.COMMON_ADD_JINBI_LIMIT)
  1859. elseif ret == 0 then
  1860. query(human)
  1861. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1101)
  1862. end
  1863. end
  1864. -- 挂机节点设置
  1865. function nodeSet(human, battleID)
  1866. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  1867. local nNowBattleID = BattleLogic_GetBattleBattleID(human)
  1868. if not tBattleConfig or -1 >= nNowBattleID then
  1869. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "hangExpGet 获取挂机奖励列表失败 id = "
  1870. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  1871. print("[nodeSet] 获取不到战斗配置")
  1872. return
  1873. end
  1874. local nodeConfig = tBattleConfig.node[battleID]
  1875. if nodeConfig == nil then
  1876. return
  1877. end
  1878. -- 前置条件判断
  1879. if battleID > nNowBattleID then
  1880. return Broadcast.sendErr(human, Lang.BATTLE_ID_OVER)
  1881. end
  1882. -- 等级判断
  1883. if human.db.lv < nodeConfig.needLv then
  1884. return Broadcast.sendErr(human, Util.format(Lang.ROLE_LEV_ERROR, nodeConfig.needLv))
  1885. end
  1886. calcBattleOut(human)
  1887. print("[nodeSet] 玩家进行了挂机节点设置 battleID = ".. battleID)
  1888. BattleLogic_SetBattleGuaJiID(human ,battleID)
  1889. --human.db.guajiID = battleID
  1890. setBattleID(human, battleID)
  1891. Msg.send(Msg.gc.GC_BATTLE_NODE_SET, human.fd)
  1892. query(human)
  1893. end
  1894. -- 挂机节点详细信息查询
  1895. function nodeDetailQuery(human, battleID)
  1896. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  1897. local nNowBattleID = BattleLogic_GetBattleBattleID(human)
  1898. if not tBattleConfig or -1 >= nNowBattleID then
  1899. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "nodeDetailQuery 获取挂机奖励列表失败 id = "
  1900. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  1901. print("[nodeDetailQuery] 获取不到战斗配置")
  1902. return
  1903. end
  1904. -- local nodeConfig = BattleExcel.node[battleID]
  1905. local nodeConfig = tBattleConfig.node[battleID]
  1906. if nodeConfig == nil then
  1907. return
  1908. end
  1909. local msgRet = Msg.gc.GC_BATTLE_NODE_DETAIL_QUERY
  1910. msgRet.battleID = battleID
  1911. msgRet.exp = nodeConfig.hangExp
  1912. msgRet.jinbi = nodeConfig.hangJinbi
  1913. msgRet.greenExp = nodeConfig.hangGreenExp
  1914. msgRet.qingbao = nodeConfig.hangQingbao or 0
  1915. msgRet.nodeName = getBattleName(human, battleID)
  1916. local dropID = nodeConfig.dropID
  1917. local dropConfig = DropExcel.dropBattle[dropID]
  1918. local dropCnt = 0
  1919. local list = DropExchangeLogic.getAbsCanDrop(human)
  1920. if list then
  1921. for k, v in pairs(list) do
  1922. dropCnt = dropCnt + 1
  1923. Grid.makeItem(msgRet.items[dropCnt], k, v)
  1924. end
  1925. end
  1926. for i = 1, #dropConfig.dropRule do
  1927. local tempConfig = dropConfig.dropRule[i]
  1928. local itemID = tempConfig[1]
  1929. local itemCnt = tempConfig[3]
  1930. local itemRate = tempConfig[4]
  1931. if itemCnt > 0 and itemRate > 0 then
  1932. dropCnt = dropCnt + 1
  1933. Grid.makeItem(msgRet.items[dropCnt], itemID, 1)
  1934. end
  1935. end
  1936. for i = 1, #dropConfig.dropRule3 do
  1937. local tempConfig = dropConfig.dropRule3[i]
  1938. local itemID = tempConfig[1]
  1939. local itemCnt = tempConfig[3]
  1940. local itemRate = tempConfig[4]
  1941. if itemCnt > 0 and itemRate > 0 then
  1942. dropCnt = dropCnt + 1
  1943. Grid.makeItem(msgRet.items[dropCnt], itemID, 1)
  1944. end
  1945. end
  1946. msgRet.items[0] = dropCnt
  1947. Msg.send(msgRet, human.fd)
  1948. end
  1949. -- 挑战当前挂机节点
  1950. function fight(human)
  1951. local battleID = BattleLogic_GetBattleBattleID(human)
  1952. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  1953. if not tBattleConfig or -1 >= battleID then
  1954. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "nodeDetailQuery 获取挂机奖励列表失败 id = "
  1955. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  1956. print("[nodeDetailQuery] 获取不到战斗配置")
  1957. return
  1958. end
  1959. -- local battleID = human.db.battleID
  1960. -- if BattleExcel.node[human.db.battleID] == nil then
  1961. if tBattleConfig.node[battleID] == nil then
  1962. local msgRet = Msg.gc.GC_BATTLE_GOBACK_MAIN
  1963. msgRet.panelIDs[0] = 1
  1964. msgRet.panelIDs[1] = PanelDefine.PANEL_ID_1008
  1965. Msg.send(msgRet, human.fd)
  1966. return Broadcast.sendErr(human, Lang.BATTLE_MAX_LEVEL)
  1967. end
  1968. -- if human.db.lv < BattleExcel.node[human.db.battleID].needLv then
  1969. if human.db.lv < tBattleConfig.node[battleID].needLv then
  1970. local msgRet = Msg.gc.GC_BATTLE_GOBACK_MAIN
  1971. msgRet.panelIDs[0] = 1
  1972. msgRet.panelIDs[1] = PanelDefine.PANEL_ID_1008
  1973. Msg.send(msgRet, human.fd)
  1974. return Broadcast.sendErr(human, Util.format(Lang.ROLE_LEV_ERROR, tBattleConfig.node[battleID].needLv))
  1975. end
  1976. local config = tBattleConfig.node[battleID]
  1977. local mapConfig = tBattleConfig.map[config.mapID]
  1978. local monsterOutID = config.monsterOutID
  1979. local mapID = mapConfig.bg
  1980. CombatLogic.combatBegin(human, config.sceneID, monsterOutID, CombatDefine.COMBAT_TYPE1, battleID)
  1981. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_BATTLE)
  1982. end
  1983. function onFightEnd(human, result, fightTypeID, param1, combatInfo)
  1984. -- 设置一些战斗结算信息
  1985. combatInfo.defender.name = Util.format(Lang.COMBAT_BATTLE_DEFEND_NAME, param1)
  1986. if CombatDefine.RESULT_WIN ~= result then
  1987. return
  1988. end
  1989. local nBattleType = BattleLogic_GetBattleType(human)
  1990. local guajiID = BattleLogic_GetBattleGuaJiID(human)
  1991. local battleID = BattleLogic_GetBattleBattleID(human)
  1992. if EliteDefine.COPY_ELITE_ERROR == nBattleType or -1 >= guajiID or -1 >= battleID then
  1993. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "onFightEnd 获取战斗类型、挂机ID、战斗关卡ID失败 id = "
  1994. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  1995. print("[onFightEnd] 获取战斗类型、挂机ID、战斗关卡ID失败")
  1996. return
  1997. end
  1998. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  1999. if not tBattleConfig then
  2000. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "onFightEnd 获取战斗配置失败 id = "
  2001. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  2002. print("[onFightEnd] 获取战斗配置失败")
  2003. return
  2004. end
  2005. -- local guajiID = human.db.guajiID
  2006. -- local battleID = human.db.battleID
  2007. if battleID ~= param1 then
  2008. return
  2009. end
  2010. local nAllFightLen = #tBattleConfig.node
  2011. local nextGuajiID = (guajiID + 1) > nAllFightLen and nAllFightLen or guajiID + 1
  2012. local nextBattleID = (battleID + 1) > nAllFightLen and nAllFightLen or battleID + 1
  2013. -- local nextBattleConfig = BattleExcel.node[nextBattleID]
  2014. -- local config = BattleExcel.node[battleID]
  2015. if (battleID + 1) > nAllFightLen then
  2016. BattleLogic_SetBattleAdopt(human, nBattleType, 1)
  2017. end
  2018. local nextBattleConfig = tBattleConfig.node[nextBattleID]
  2019. local config = tBattleConfig.node[battleID]
  2020. if not BATTLE_LEVEL_PLAYER_LIST[nBattleType] then
  2021. BATTLE_LEVEL_PLAYER_LIST[nBattleType] = {}
  2022. end
  2023. local tBattleLevelPlayerList = BATTLE_LEVEL_PLAYER_LIST[nBattleType]
  2024. -- 如果过大关卡
  2025. if nextBattleConfig and nextBattleConfig.mapID ~= config.mapID then
  2026. -- 清除记录
  2027. tBattleLevelPlayerList[config.mapID] = tBattleLevelPlayerList[config.mapID] or { }
  2028. tBattleLevelPlayerList[config.mapID][human.db._id] = nil
  2029. -- 增加新纪录
  2030. tBattleLevelPlayerList[nextBattleConfig.mapID] = tBattleLevelPlayerList[nextBattleConfig.mapID] or { }
  2031. tBattleLevelPlayerList[nextBattleConfig.mapID][human.db._id] = { }
  2032. RoleLogic.getRoleBase(human, tBattleLevelPlayerList[nextBattleConfig.mapID][human.db._id])
  2033. else
  2034. if config.mapID == 1 then
  2035. tBattleLevelPlayerList[config.mapID] = tBattleLevelPlayerList[config.mapID] or { }
  2036. if tBattleLevelPlayerList[config.mapID][human.db._id] == nil then
  2037. -- 增加新纪录
  2038. tBattleLevelPlayerList[config.mapID][human.db._id] = { }
  2039. RoleLogic.getRoleBase(human, tBattleLevelPlayerList[config.mapID][human.db._id])
  2040. end
  2041. else
  2042. if not tBattleLevelPlayerList[config.mapID] or not tBattleLevelPlayerList[config.mapID][human.db._id] then
  2043. tBattleLevelPlayerList[config.mapID] = tBattleLevelPlayerList[config.mapID] or { }
  2044. tBattleLevelPlayerList[config.mapID][human.db._id] = { }
  2045. RoleLogic.getRoleBase(human, tBattleLevelPlayerList[config.mapID][human.db._id])
  2046. end
  2047. end
  2048. end
  2049. -- -- 如果过大关卡
  2050. -- if nextBattleConfig and nextBattleConfig.mapID ~= config.mapID then
  2051. -- -- 清除记录
  2052. -- BATTLE_LEVEL_PLAYER_LIST[config.mapID] = BATTLE_LEVEL_PLAYER_LIST[config.mapID] or { }
  2053. -- BATTLE_LEVEL_PLAYER_LIST[config.mapID][human.db._id] = nil
  2054. -- -- 增加新纪录
  2055. -- BATTLE_LEVEL_PLAYER_LIST[nextBattleConfig.mapID] = BATTLE_LEVEL_PLAYER_LIST[nextBattleConfig.mapID] or { }
  2056. -- BATTLE_LEVEL_PLAYER_LIST[nextBattleConfig.mapID][human.db._id] = { }
  2057. -- RoleLogic.getRoleBase(human, BATTLE_LEVEL_PLAYER_LIST[nextBattleConfig.mapID][human.db._id])
  2058. -- else
  2059. -- if config.mapID == 1 then
  2060. -- BATTLE_LEVEL_PLAYER_LIST[config.mapID] = BATTLE_LEVEL_PLAYER_LIST[config.mapID] or { }
  2061. -- if BATTLE_LEVEL_PLAYER_LIST[config.mapID][human.db._id] == nil then
  2062. -- -- 增加新纪录
  2063. -- BATTLE_LEVEL_PLAYER_LIST[config.mapID][human.db._id] = { }
  2064. -- RoleLogic.getRoleBase(human, BATTLE_LEVEL_PLAYER_LIST[config.mapID][human.db._id])
  2065. -- end
  2066. -- else
  2067. -- if not BATTLE_LEVEL_PLAYER_LIST[config.mapID] or not BATTLE_LEVEL_PLAYER_LIST[config.mapID][human.db._id] then
  2068. -- BATTLE_LEVEL_PLAYER_LIST[config.mapID] = BATTLE_LEVEL_PLAYER_LIST[config.mapID] or { }
  2069. -- BATTLE_LEVEL_PLAYER_LIST[config.mapID][human.db._id] = { }
  2070. -- RoleLogic.getRoleBase(human, BATTLE_LEVEL_PLAYER_LIST[config.mapID][human.db._id])
  2071. -- end
  2072. -- end
  2073. -- end
  2074. BattleLogic_SetBattleBattleID(human, nextBattleID)
  2075. -- human.db.battleID = battleID + 1
  2076. -- 通过第10关,默认开启二倍速
  2077. if nextBattleID == 10 and EliteDefine.COPY_ELITE_NORMAL == nBattleType then
  2078. human.db.combatSpeed = 2
  2079. end
  2080. combatInfo.attacker.oldLv = human.db.lv
  2081. -- 给奖励
  2082. combatInfo.rewardItem = { }
  2083. for i = 1, #config.winReward do
  2084. local itemID = config.winReward[i][1]
  2085. local itemCnt = config.winReward[i][2]
  2086. -- 装备不在这显示
  2087. combatInfo.rewardItem[i] = combatInfo.rewardItem[i] or { }
  2088. combatInfo.rewardItem[i] = { itemID, itemCnt }
  2089. BagLogic.addItem(human, itemID, itemCnt, "battle_win")
  2090. end
  2091. combatInfo.attacker.lv = human.db.lv
  2092. combatInfo.getEquip = human.getEquip
  2093. human.getEquip = nil
  2094. -- TODO:记录主线关卡
  2095. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, human.db._id, human.db.account, human.db.name, human.db.battleID)
  2096. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1101)
  2097. GuideLogic.onCallback(human)
  2098. JibanLogic.onCallback(human, 1, battleID)
  2099. TuiSongLiBao.tuiSongLiBaoOnTask(
  2100. human,
  2101. TuiSongLiBao.TUISONGLIBAOTASK_ZHENGZHAN,
  2102. -- human.db.guajiID - 1,
  2103. -- human.db.guajiID - 2
  2104. guajiID - 1,
  2105. guajiID - 2
  2106. )
  2107. ChengjiuLogic.onCallback(human, ChengjiuDefine.CJ_TASK_TYPE_1, nextGuajiID)
  2108. MengxinLogic.onCallBack(human, MengxinLogic.MX_TASK_TYPE_1, nextGuajiID)
  2109. for k, v in pairs(KingWorldLogic.funcID) do
  2110. YunYingLogic.updateIcon(KingWorldLogic.YYInfo[k], human)
  2111. break
  2112. end
  2113. -- 存储战斗记录
  2114. local videoUuid = CombatVideo.saveBattleVideo(human.db._id, combatInfo)
  2115. human.db.battleVideoUuid = videoUuid
  2116. BattleDBLogic.updateBattleDB(combatInfo.attacker, battleID, combatInfo, videoUuid, nBattleType)
  2117. if nextBattleConfig and nextBattleConfig.mapID ~= config.mapID then
  2118. -- 新的地图
  2119. -- 通知客户端
  2120. Msg.send(Msg.gc.GC_BATTLE_NODE_SET, human.fd)
  2121. end
  2122. BattleLogic_SetBattleGuaJiID(human, nextGuajiID)
  2123. --human.db.guajiID = nextGuajiID
  2124. if nextBattleConfig then
  2125. setBattleID(human, nextGuajiID)
  2126. end
  2127. local showNext = 1
  2128. -- if BattleExcel.node[human.db.battleID] and human.db.lv < BattleExcel.node[human.db.battleID].needLv then
  2129. if tBattleConfig.node[nextBattleID] and human.db.lv < tBattleConfig.node[nextBattleID].needLv then
  2130. showNext = 2
  2131. end
  2132. if human.db.lv < 5 then
  2133. showNext = 0
  2134. end
  2135. -- nextBattleConfig = BattleExcel.node[human.db.battleID]
  2136. nextBattleConfig = tBattleConfig.node[nextBattleID]
  2137. if not nextBattleConfig then
  2138. showNext = 0
  2139. end
  2140. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1105)
  2141. -- 额外奖励
  2142. local needLevel, itemName = getNextRewardName(human)
  2143. if needLevel ~= nil then
  2144. local tb = { needLevel, Lang.BATTLE_FIGHT_GUAN, "|", itemName, "|", showNext }
  2145. local str = table.concat(tb)
  2146. combatInfo.endParam = str
  2147. else
  2148. local tb = { showNext }
  2149. local str = table.concat(tb)
  2150. combatInfo.endParam = str
  2151. end
  2152. -- 触发事件
  2153. GiftLogic.trigger(human,PRINCIPAL_LINE_EVNET,{id = battleID})
  2154. WarOrder.trigger(human,BATTLE_ORDER_TYPE)
  2155. end
  2156. function setBattleID(human, guajiID)
  2157. local nNowGuaJiID = BattleLogic_GetBattleGuaJiID(human)
  2158. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  2159. if -1 >= nNowGuaJiID or not tBattleConfig then
  2160. return
  2161. end
  2162. -- if guajiID > human.db.guajiID and human.db.guajiID ~= 0 then
  2163. if guajiID > nNowGuaJiID and nNowGuaJiID ~= 0 then
  2164. -- 下发挂机收益升级提示
  2165. local msgRet = Msg.gc.GC_BATTLE_REWARD_UP
  2166. Grid.makeItem(msgRet.itemExp, ItemDefine.ITEM_EXP_ID, 1)
  2167. Grid.makeItem(msgRet.itemJinbi, ItemDefine.ITEM_JINBI_ID, 1)
  2168. Grid.makeItem(msgRet.itemGreenExp, ItemDefine.ITEM_GREEN_EXP_ID, 1)
  2169. Grid.makeItem(msgRet.itemQingbao, ItemDefine.ITEM_QINGBAO_ID, 1)
  2170. -- local oldConfig = BattleExcel.node[human.db.guajiID]
  2171. -- local newConfig = BattleExcel.node[guajiID]
  2172. local oldConfig = tBattleConfig.node[human.db.guajiID]
  2173. local newConfig = tBattleConfig.node[guajiID]
  2174. msgRet.expOld = oldConfig.hangExp
  2175. msgRet.expNew = newConfig.hangExp
  2176. msgRet.jinbiOld = oldConfig.hangJinbi
  2177. msgRet.jinbiNew = newConfig.hangJinbi
  2178. msgRet.greenExpOld = oldConfig.hangGreenExp
  2179. msgRet.greenExpNew = newConfig.hangGreenExp
  2180. msgRet.qingbaoOld = oldConfig.hangQingbao
  2181. msgRet.qingbaoNew = newConfig.hangQingbao
  2182. Msg.send(msgRet, human.fd)
  2183. end
  2184. -- 刷新排行榜
  2185. BRoleLogic.updateData(BillboardDefine.TYPE_BATTLE, human.db)
  2186. end
  2187. -- GM
  2188. function setBattleByGm(human, val, maxBattleID)
  2189. val = tonumber(val)
  2190. if not val or val <= 1 then
  2191. return
  2192. end
  2193. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  2194. if not tBattleConfig then
  2195. return
  2196. end
  2197. local nodeConfig = tBattleConfig.node[val]
  2198. if not nodeConfig then
  2199. return
  2200. end
  2201. if maxBattleID then
  2202. maxBattleID = tonumber(maxBattleID)
  2203. else
  2204. maxBattleID = val
  2205. end
  2206. BattleLogic_SetBattleBattleID(human, val)
  2207. BattleLogic_SetBattleGuaJiID(human, val)
  2208. setBattleID(human, val)
  2209. --human.db.battleID = val
  2210. BattleLogic_QueryDifficulty(human)
  2211. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1105)
  2212. end
  2213. function mopupQuery(human)
  2214. ObjHuman.updateDaily(human)
  2215. local nNowGuaJiID = BattleLogic_GetBattleGuaJiID(human)
  2216. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  2217. if -1 >= nNowGuaJiID or not tBattleConfig then
  2218. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "mopupQuery 获取战斗配置、挂机ID 失败 id = "
  2219. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  2220. print("[mopupQuery] 获取战斗配置、挂机ID 失败")
  2221. return
  2222. end
  2223. local msgRet = Msg.gc.GC_BATTLE_MOPUP_QUERY
  2224. -- local guajiID = human.db.guajiID > #BattleExcel.node and #BattleExcel.node or human.db.guajiID
  2225. local guajiID = nNowGuaJiID > #tBattleConfig.node and #tBattleConfig.node or nNowGuaJiID
  2226. if guajiID == 0 then
  2227. return Broadcast.sendErr(human, Lang.BATTLE_MOPUP_ERR)
  2228. end
  2229. human.db.mopupDoCnt = human.db.mopupDoCnt or 0
  2230. local nextDoCnt = human.db.mopupDoCnt + 1
  2231. -- local nodeConfig = BattleExcel.node[guajiID]
  2232. local nodeConfig = tBattleConfig.node[guajiID]
  2233. local dropID = nodeConfig.dropID
  2234. local dropConfig = DropExcel.dropBattle[dropID]
  2235. local dropCnt = 0
  2236. -- ABS掉落活动显示到第一个
  2237. dropCnt = DropExchangeLogic.getDropItemSaoQuery(human, msgRet, dropCnt)
  2238. for i = 1, #dropConfig.dropRule do
  2239. if dropCnt >= #msgRet.item then
  2240. break
  2241. end
  2242. dropCnt = dropCnt + 1
  2243. local tempConfig = dropConfig.dropRule[i]
  2244. local itemID = tempConfig[1]
  2245. Grid.makeItem(msgRet.item[dropCnt], itemID, 1)
  2246. end
  2247. for i = 1, #dropConfig.dropRule3 do
  2248. if dropCnt >= #msgRet.item then
  2249. break
  2250. end
  2251. dropCnt = dropCnt + 1
  2252. local tempConfig = dropConfig.dropRule3[i]
  2253. local itemID = tempConfig[1]
  2254. Grid.makeItem(msgRet.item[dropCnt], itemID, 1)
  2255. end
  2256. -- local mapConfig = BattleExcel.map[nodeConfig.mapID]
  2257. local mapConfig = tBattleConfig.map[nodeConfig.mapID]
  2258. msgRet.name = mapConfig.name
  2259. msgRet.item[0] = dropCnt
  2260. if TequanShopLogic.isActiveMopup(human) then
  2261. msgRet.leftCnt = BATTLE_MOPUP_CNT_VIP - human.db.mopupDoCnt
  2262. else
  2263. msgRet.leftCnt = BATTLE_MOPUP_CNT - human.db.mopupDoCnt
  2264. end
  2265. -- local mupopExcel = BattleExcel.mupop[nextDoCnt]
  2266. local mupopExcel = tBattleConfig.mupop[nextDoCnt]
  2267. if mupopExcel then
  2268. if not TequanShopLogic.isActiveMopup(human) then
  2269. msgRet.need = mupopExcel.cost
  2270. if human.db.mopupFreeCnt < BATTLE_MOPUP_FREE_CNT then
  2271. msgRet.need = 0
  2272. end
  2273. else
  2274. msgRet.need = mupopExcel.vipCost
  2275. if human.db.mopupFreeCnt < BATTLE_MOPUP_FREE_CNT_VIP then
  2276. msgRet.need = 0
  2277. end
  2278. end
  2279. else
  2280. msgRet.need = 0
  2281. end
  2282. msgRet.vip = TequanShopLogic.isActiveMopup(human) and 1 or 0
  2283. msgRet.nowCnt = human.db.mopupDoCnt
  2284. msgRet.exp = nodeConfig.hangExp
  2285. msgRet.jinbi = nodeConfig.hangJinbi
  2286. msgRet.greenExp = nodeConfig.hangGreenExp
  2287. msgRet.qingbao = nodeConfig.hangQingbao
  2288. Msg.send(msgRet, human.fd)
  2289. end
  2290. function mopupFight(human)
  2291. -- 等级判断
  2292. ObjHuman.updateDaily(human)
  2293. local nNowGuaJiID = BattleLogic_GetBattleGuaJiID(human)
  2294. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  2295. if -1 >= nNowGuaJiID or not tBattleConfig then
  2296. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "mopupFight 获取战斗配置、挂机ID 失败 id = "
  2297. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  2298. print("[mopupFight] 获取战斗配置、挂机ID 失败")
  2299. return
  2300. end
  2301. local need = 0
  2302. human.db.mopupDoCnt = human.db.mopupDoCnt or 0
  2303. human.db.mopupFreeCnt = human.db.mopupFreeCnt or 0
  2304. local nextDoCnt = human.db.mopupDoCnt + 1
  2305. -- local mupopExcel = BattleExcel.mupop[nextDoCnt]
  2306. local mupopExcel = tBattleConfig.mupop[nextDoCnt]
  2307. if not mupopExcel then
  2308. return Broadcast.sendErr(human, Lang.BATTLE_MOPUP_CNT_OVER)
  2309. end
  2310. if not TequanShopLogic.isActiveMopup(human) then
  2311. if human.db.mopupDoCnt >= BATTLE_MOPUP_CNT then
  2312. return Broadcast.sendErr(human, Lang.BATTLE_MOPUP_CNT_OVER)
  2313. end
  2314. need = mupopExcel.cost
  2315. -- 如果免费次数小于1次,则按免费算
  2316. if human.db.mopupFreeCnt < BATTLE_MOPUP_FREE_CNT then
  2317. need = 0
  2318. end
  2319. else
  2320. if human.db.mopupDoCnt >= BATTLE_MOPUP_CNT_VIP then
  2321. return Broadcast.sendErr(human, Lang.BATTLE_MOPUP_CNT_OVER)
  2322. end
  2323. need = mupopExcel.vipCost
  2324. -- 如果免费次数小于3次,则按免费算
  2325. if human.db.mopupFreeCnt < BATTLE_MOPUP_FREE_CNT_VIP then
  2326. need = 0
  2327. end
  2328. end
  2329. if not ObjHuman.checkRMB(human, need) then
  2330. return
  2331. end
  2332. if need <= 0 then
  2333. human.db.mopupFreeCnt = human.db.mopupFreeCnt + 1
  2334. end
  2335. ObjHuman.decZuanshi(human, - need, "battleMopup")
  2336. human.db.mopupDoCnt = human.db.mopupDoCnt + 1
  2337. -- local guajiID = human.db.guajiID > #BattleExcel.node and #BattleExcel.node or human.db.guajiID
  2338. local guajiID = nNowGuaJiID > #tBattleConfig.node and #tBattleConfig.node or nNowGuaJiID
  2339. if guajiID == 0 then
  2340. return Broadcast.sendErr(human, Lang.BATTLE_MOPUP_ERR)
  2341. end
  2342. -- local config = BattleExcel.node[guajiID]
  2343. local config = tBattleConfig.node[guajiID]
  2344. local msgRet = Msg.gc.GC_BATTLE_MOPUP_FIGHT
  2345. local vipExpAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER7) or 0) / 100
  2346. local vipJinAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER8) or 0) / 100
  2347. local vipGreenExpAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER9) or 0) / 100
  2348. local vipQingbaoAdd =(VipLogic.getPowerArgs(human, VipLogic.VIP_POWER19) or 0) / 100
  2349. local exp = config.hangExp * 120
  2350. local jinbi = config.hangJinbi * 120
  2351. local greenExp = config.hangGreenExp * 120
  2352. local qingbao = config.hangQingbao * 120
  2353. local addExp = math.floor(exp *(1 + vipExpAdd))
  2354. local addJinbi = math.floor(jinbi *(1 + vipJinAdd))
  2355. local addGreenExp = math.floor(greenExp *(1 + vipGreenExpAdd))
  2356. local addQingbao = math.floor(qingbao *(1 + vipQingbaoAdd))
  2357. local time = 7200
  2358. local itemTable = getItemOutsByTime(config, time)
  2359. -- 掉落活动
  2360. DropExchangeLogic.getDropItemSao(human, time, itemTable)
  2361. local flag = GuideLogic.getGuideSkip(human, GuideLogic.SKIPTYPE_JUMP_BATTLE_SD)
  2362. if not flag then
  2363. local equipID = SysParameter.getSysParameter(SysParameter.PARAMETER_10)
  2364. itemTable[equipID] = 1
  2365. end
  2366. itemTable[ItemDefine.ITEM_JINBI_ID] = itemTable[ItemDefine.ITEM_JINBI_ID] or 0
  2367. itemTable[ItemDefine.ITEM_EXP_ID] = itemTable[ItemDefine.ITEM_EXP_ID] or 0
  2368. itemTable[ItemDefine.ITEM_GREEN_EXP_ID] = itemTable[ItemDefine.ITEM_GREEN_EXP_ID] or 0
  2369. itemTable[ItemDefine.ITEM_QINGBAO_ID] = itemTable[ItemDefine.ITEM_QINGBAO_ID] or 0
  2370. itemTable[ItemDefine.ITEM_JINBI_ID] = itemTable[ItemDefine.ITEM_JINBI_ID] + addJinbi
  2371. itemTable[ItemDefine.ITEM_EXP_ID] = itemTable[ItemDefine.ITEM_EXP_ID] + addExp
  2372. itemTable[ItemDefine.ITEM_GREEN_EXP_ID] = itemTable[ItemDefine.ITEM_GREEN_EXP_ID] + addGreenExp
  2373. itemTable[ItemDefine.ITEM_QINGBAO_ID] = itemTable[ItemDefine.ITEM_QINGBAO_ID] + addQingbao
  2374. msgRet.item[0] = 0
  2375. -- 双倍日
  2376. local double = RoleSystemLogic.isDouble(human, RoleSystemDefine.ROLE_SYS_ID_1101)
  2377. local rewardCnt = double and 2 or 1
  2378. for itemID, itemCnt in pairs(itemTable) do
  2379. itemCnt = itemCnt * rewardCnt
  2380. if not ItemDefine.isEquip(itemID) then
  2381. msgRet.item[0] = msgRet.item[0] + 1
  2382. Grid.makeItem(msgRet.item[msgRet.item[0]], itemID, itemCnt)
  2383. end
  2384. BagLogic.addItem(human, itemID, itemCnt, "battle")
  2385. end
  2386. msgRet.item[0] = EquipLogic.makeEquipItem(human, msgRet.item, msgRet.item[0])
  2387. msgRet.double = double and 1 or 0
  2388. msgRet.exp = itemTable[ItemDefine.ITEM_EXP_ID] * rewardCnt
  2389. msgRet.jinbi = itemTable[ItemDefine.ITEM_JINBI_ID] * rewardCnt
  2390. msgRet.greenExp = itemTable[ItemDefine.ITEM_GREEN_EXP_ID] * rewardCnt
  2391. msgRet.qingbao = itemTable[ItemDefine.ITEM_QINGBAO_ID] * rewardCnt
  2392. Msg.send(msgRet, human.fd)
  2393. mopupQuery(human)
  2394. query(human)
  2395. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1101)
  2396. GuideLogic.setDoSpecialGuide(human, GuideLogic.SKIPTYPE_JUMP_BATTLE_SD)
  2397. DailyTaskLogic.recordDailyTaskFinishCnt(human, DailyTaskLogic.DAILY_TASK_ID_12, 1)
  2398. ChengjiuLogic.onCallback(human, ChengjiuDefine.CJ_TASK_TYPE_3, 1)
  2399. HeroLogLogic.finishTaskCB(human, HeroLogLogic.HERO_LOG_TYPE_3, 1)
  2400. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_2001)
  2401. YunYingLogic.onCallBack(human, "onMopup", 1)
  2402. end
  2403. function updateDaily(human)
  2404. human.db.mopupFreeCnt = 0
  2405. human.db.mopupDoCnt = 0
  2406. end
  2407. function getTongGuanReward(human, id)
  2408. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  2409. local nNowGuaJiID = BattleLogic_GetBattleGuaJiID(human)
  2410. local nBattleID = BattleLogic_GetBattleBattleID(human)
  2411. if not tBattleConfig or -1 >= nNowGuaJiID or -1 >= nBattleID then
  2412. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[getTongGuanReward] 获取战斗配置、挂机ID、战斗节点ID 失败 id = "
  2413. ..human.db._id.. "account = "..human.db.account.." name = "..human.db.name)
  2414. print("[getTongGuanReward] 获取战斗配置、挂机ID 失败")
  2415. return
  2416. end
  2417. local cf = tBattleConfig.node[id]
  2418. if not cf then
  2419. return
  2420. end
  2421. if #cf.tongguan < 1 then
  2422. return
  2423. end
  2424. print("[getTongGuanReward] 玩家请求领取奖励 当前的节点信息 id = "
  2425. ..id.." nNowGuaJiID = "..nNowGuaJiID.." nBattleID = "..nBattleID)
  2426. if nBattleID < id then
  2427. return
  2428. end
  2429. if isGetReward(human, id) then
  2430. return
  2431. end
  2432. if #cf.tongguan == 1 and cf.tongguan[1][3] then
  2433. -- 英雄
  2434. if HeroLogic.getEmptyCnt(human) < 1 then
  2435. return Broadcast.sendErr(human, Lang.HERO_BAG_FULL)
  2436. end
  2437. local heroID = cf.tongguan[1][1]
  2438. local cnt = cf.tongguan[1][2]
  2439. local star = cf.tongguan[1][3]
  2440. if cnt <= 0 then
  2441. return
  2442. end
  2443. setGetReward(human, id)
  2444. local msg = Msg.gc.GC_SUIPIAN_SUMMON
  2445. for i = 1, cnt do
  2446. local heroGrid = HeroGrid.createHeroGrid(heroID, star)
  2447. HeroLogic.addHeroByGrid(human, heroGrid, "battle_extra_reward")
  2448. SuipianLogic.makeResultItemData(msg.heroList[i], heroID, 1, 1)
  2449. end
  2450. msg.isHero = 1
  2451. msg.list[0] = 0
  2452. msg.heroList[0] = cnt
  2453. msg.fenJieList[0] = 0
  2454. Msg.send(msg, human.fd)
  2455. else
  2456. setGetReward(human, id)
  2457. BagLogic.addItemList(human, cf.tongguan, "tongguan")
  2458. end
  2459. -- 触发国王君临奖励
  2460. ChatPaoMaLogic.broadcast(human, ChatPaoMaLogic.PAOMA_TYPE_BROAD_TYPE5, id)
  2461. query(human)
  2462. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1101)
  2463. if id == 80 then
  2464. KingWorldLogic.setState(human, 1)
  2465. end
  2466. end
  2467. function isDot(human)
  2468. -- 通过大关卡奖励
  2469. local chapterReward = BattleLogic_GetChapterReward(human)
  2470. local nBattleID = BattleLogic_GetBattleBattleID(human)
  2471. local tBattleExcel = BattleLogic_GetBattleConfig(human)
  2472. if -1 >= nBattleID or not tBattleExcel or not chapterReward then
  2473. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[isDot] 获取不到对应的大关卡奖励表 或配置表、战斗ID")
  2474. print("[isDot] 获取不到对应的大关卡奖励表 或配置表、战斗ID id = "..human.db._id)
  2475. return
  2476. end
  2477. -- local chapterReward = human.db.chapterReward or { }
  2478. -- local battleID = human.db.battleID
  2479. -- local battleNodeConfig = BattleExcel.node[battleID]
  2480. local battleID = nBattleID
  2481. local battleNodeConfig = tBattleExcel.node[battleID]
  2482. if not battleNodeConfig then
  2483. local nodeCnt = #tBattleExcel.node
  2484. local mapCnt = #tBattleExcel.map
  2485. if battleID == nodeCnt + 1 and not chapterReward[mapCnt] then
  2486. return true
  2487. else
  2488. return false
  2489. end
  2490. else
  2491. local mapID = battleNodeConfig.mapID
  2492. for i = mapID - 1, 1, -1 do
  2493. if not chapterReward[i] then
  2494. return true
  2495. end
  2496. end
  2497. end
  2498. return false
  2499. -- if human.db.lv < 9 then
  2500. -- return false
  2501. -- end
  2502. -- -- 有免费扫荡次数的时候有红点
  2503. -- human.db.mopupFreeCnt = human.db.mopupFreeCnt or 0
  2504. -- if TequanShopLogic.isActiveMopup(human) then
  2505. -- if human.db.mopupFreeCnt < 3 then
  2506. -- return true
  2507. -- end
  2508. -- else
  2509. -- if human.db.mopupFreeCnt < 1 then
  2510. -- return true
  2511. -- end
  2512. -- end
  2513. -- -- 有通关奖励可领取的时候有红点
  2514. -- if hasCanGetReward(human) then
  2515. -- return true
  2516. -- end
  2517. -- -- 战役挂机时间超过1小时的时候有红点
  2518. -- if human.db.battleOut ~= nil then
  2519. -- local now = os.time()
  2520. -- local outSec = now - human.db.battleOut.expTs1
  2521. -- if outSec >= 3600 then
  2522. -- return true
  2523. -- end
  2524. -- end
  2525. -- return false
  2526. end
  2527. function clacItemTwoHours(human)
  2528. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  2529. local nGuaJiID = BattleLogic_GetBattleGuaJiID(human)
  2530. if not tBattleConfig or -1 >= nGuaJiID then
  2531. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[clacItemTwoHours] 获取到的挂机ID、战斗配置不正确 id = "..human.db._id)
  2532. print("[clacItemTwoHours] 获取到的挂机ID、战斗配置不正确 id = "..human.db._id)
  2533. return
  2534. end
  2535. local items = { }
  2536. local outCnt = math.floor(7200 / BATTLE_HANG_ITEM_OUT_PERIOD)
  2537. -- local guajiID = human.db.guajiID > #BattleExcel.node and #BattleExcel.node or human.db.guajiID
  2538. local guajiID = nGuaJiID > #tBattleConfig.node and #tBattleConfig.node or nGuaJiID
  2539. if guajiID == 0 then
  2540. return items
  2541. end
  2542. -- local nodeConfig = BattleExcel.node[guajiID]
  2543. local nodeConfig = tBattleConfig.node[guajiID]
  2544. local dropID = nodeConfig.dropID
  2545. local dropConfig = DropExcel.dropBattle[dropID]
  2546. local totalWeight = 0
  2547. for i = 1, #dropConfig.dropRule do
  2548. local tempConfig = dropConfig.dropRule[i]
  2549. totalWeight = totalWeight + tempConfig[4]
  2550. end
  2551. for j = 1, outCnt do
  2552. local randomNum = math.random(1, totalWeight)
  2553. for i = 1, #dropConfig.dropRule do
  2554. local tempConfig = dropConfig.dropRule[i]
  2555. local itemID = tempConfig[1]
  2556. local itemCnt1 = tempConfig[2]
  2557. local itemCnt2 = tempConfig[3]
  2558. local itemRate = tempConfig[4]
  2559. if randomNum <= itemRate then
  2560. local realAdd = math.random(itemCnt1, itemCnt2)
  2561. items[itemID] = realAdd
  2562. break
  2563. end
  2564. randomNum = randomNum - itemRate
  2565. end
  2566. end
  2567. return items
  2568. end
  2569. local MailManager = require("mail.MailManager")
  2570. function clacItemCntGM(human, cnt, guajiID)
  2571. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  2572. if not tBattleConfig then
  2573. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[clacItemCntGM] 获取到战斗配置不正确 id = "..human.db._id)
  2574. print("[clacItemTwoHours] 获取到的战斗配置不正确 id = "..human.db._id)
  2575. return
  2576. end
  2577. local items = { }
  2578. local outCnt = cnt
  2579. local nodeConfig = tBattleConfig.node[guajiID]
  2580. local dropID = nodeConfig.dropID
  2581. local dropConfig = DropExcel.dropBattle[dropID]
  2582. local totalWeight = 0
  2583. for i = 1, #dropConfig.dropRule do
  2584. local tempConfig = dropConfig.dropRule[i]
  2585. totalWeight = totalWeight + tempConfig[4]
  2586. end
  2587. for j = 1, outCnt do
  2588. local randomNum = math.random(1, totalWeight)
  2589. for i = 1, #dropConfig.dropRule do
  2590. local tempConfig = dropConfig.dropRule[i]
  2591. local itemID = tempConfig[1]
  2592. local itemCnt1 = tempConfig[2]
  2593. local itemCnt2 = tempConfig[3]
  2594. local itemRate = tempConfig[4]
  2595. if randomNum <= itemRate then
  2596. local realAdd = math.random(itemCnt1, itemCnt2)
  2597. items[itemID] = items[itemID] or 0
  2598. items[itemID] = items[itemID] + realAdd
  2599. break
  2600. end
  2601. randomNum = randomNum - itemRate
  2602. end
  2603. end
  2604. local item = { }
  2605. local index = 0
  2606. for k, v in pairs(items) do
  2607. index = index + 1
  2608. item[index] = { k, v }
  2609. end
  2610. MailManager.add(MailManager.SYSTEM, human.db._id, "", "", item, "")
  2611. end
  2612. function getBattleID(human)
  2613. local num = 0
  2614. local nGuaJiID = BattleLogic_GetBattleGuaJiID(human)
  2615. if -1 < nGuaJiID then
  2616. num = nGuaJiID
  2617. end
  2618. -- if human.db.guajiID then
  2619. -- num = human.db.guajiID or 0
  2620. -- end
  2621. return num
  2622. end
  2623. --------------------------------------------- combat ----------------------------------------------
  2624. function getCombatMonsterOutID(human, side)
  2625. if side ~= CombatDefine.DEFEND_SIDE then
  2626. return
  2627. end
  2628. local nBattleID = BattleLogic_GetBattleBattleID(human)
  2629. local tBattleExcel = BattleLogic_GetBattleConfig(human)
  2630. if not tBattleExcel or -1 >= nBattleID then
  2631. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[getCombatMonsterOutID] 获取到的战斗配置、或战斗ID不正确 id = "..human.db._id)
  2632. print("[getCombatMonsterOutID] 获取到的战斗配置、或战斗ID不正确 id = "..human.db._id)
  2633. return
  2634. end
  2635. -- local config = BattleExcel.node[human.db.battleID]
  2636. local config = tBattleExcel.node[nBattleID]
  2637. if not config then
  2638. return
  2639. end
  2640. return config.monsterOutID
  2641. end
  2642. function getCombatName(human)
  2643. local nBattleID = BattleLogic_GetBattleBattleID(human)
  2644. if -1 >= nBattleID then
  2645. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[getCombatMonsterOutID] 获取到的战斗ID不正确 id = "..human.db._id)
  2646. print("[getCombatMonsterOutID] 获取到的战斗ID不正确 id = "..human.db._id)
  2647. return ""
  2648. end
  2649. local name = getBattleName(human, nBattleID)
  2650. return Util.format(Lang.COMBAT_BATTLE_EXNAME, name)
  2651. end
  2652. -------------------------------------------combat end--------------------
  2653. function battleSharkQuery(human, nodeID)
  2654. local msgRet = Msg.gc.GC_BATTLE_SHARK_QUERY
  2655. local videoTb = BattleDBLogic.queryBattleDbByNodeID(nodeID)
  2656. if videoTb == nil then
  2657. msgRet.battleShark[0] = 0
  2658. else
  2659. local len = #videoTb.shark
  2660. for i = 1, len do
  2661. local v = videoTb.shark[i]
  2662. RoleLogic.makeRoleBase(v.roleBase, msgRet.battleShark[i].roleBase)
  2663. msgRet.battleShark[i].type = i
  2664. msgRet.battleShark[i].videoUuid = v.videoUuid
  2665. msgRet.battleShark[i].param = v.param or 0
  2666. end
  2667. msgRet.battleShark[0] = len
  2668. end
  2669. -- Msg.trace(msgRet)
  2670. Msg.send(msgRet, human.fd)
  2671. end
  2672. local QueryRoleByNodeID = { }
  2673. function worldMapRoleListQuery(human, worldMapId)
  2674. -- if worldMapId == 1 then return end
  2675. local msgRet = Msg.gc.GC_BATTLE_WORLD_MAP_ROLELIST_QUERY
  2676. local len = 0
  2677. for k, v in pairs(BATTLE_LEVEL_PLAYER_LIST[worldMapId]) do
  2678. len = len + 1
  2679. RoleLogic.makeRoleBase(v, msgRet.roleList[len])
  2680. if len >= 50 then
  2681. break
  2682. end
  2683. end
  2684. msgRet.roleList[0] = len
  2685. Msg.send(msgRet, human.fd)
  2686. end
  2687. -- 章节(地图)掉落列表
  2688. function sendMapDroItemsList(human)
  2689. local nBattleID = BattleLogic_GetBattleBattleID(human)
  2690. local tBattleExcel = BattleLogic_GetBattleConfig(human)
  2691. if not tBattleExcel then
  2692. print("[sendMapDroItemsList] 获取当前战斗配置失败 id = "..human.db._id)
  2693. return
  2694. end
  2695. local battleID = 1
  2696. if -1 < nBattleID then
  2697. battleID = nBattleID
  2698. end
  2699. local maxBattleConfig = tBattleExcel.node[battleID]
  2700. local maxMapID = maxBattleConfig and maxBattleConfig.mapID or(#tBattleExcel.node + 1)
  2701. local msgRet = Msg.gc.GC_BATTLE_MAP_DROPITEMS_LIST
  2702. msgRet.list[0] = 0
  2703. for mapID, mapConfig in ipairs(tBattleExcel.map) do
  2704. msgRet.list[0] = msgRet.list[0] + 1
  2705. local net = msgRet.list[msgRet.list[0]]
  2706. net.mapID = mapID
  2707. net.mapName = mapConfig.name
  2708. net.isOpen =(mapID <= maxMapID) and 1 or 0
  2709. end
  2710. -- Msg.trace(msgRet)
  2711. Msg.send(msgRet, human.fd)
  2712. end
  2713. -- 章节(地图)掉落详情
  2714. function sendMapDroItemsDetail(human, mapID)
  2715. local tBattleExcel = BattleLogic_GetBattleConfig(human)
  2716. if not tBattleExcel then
  2717. print("[sendMapDroItemsDetail] 获取当前战斗配置失败 id = "..human.db._id)
  2718. return
  2719. end
  2720. local mapConfig = tBattleExcel.map[mapID]
  2721. if not mapConfig then
  2722. return
  2723. end
  2724. local msgRet = Msg.gc.GC_BATTLE_MAP_DROPITEMS_DETAIL
  2725. msgRet.mapID = mapID
  2726. msgRet.items[0] = math.min(#mapConfig.dropItemsShow, #msgRet.items)
  2727. for i = 1, msgRet.items[0] do
  2728. local itemID = mapConfig.dropItemsShow[i][1]
  2729. local itemCnt = mapConfig.dropItemsShow[i][2]
  2730. Grid.makeItem(msgRet.items[i], itemID, itemCnt)
  2731. end
  2732. -- Msg.trace(msgRet)
  2733. Msg.send(msgRet, human.fd)
  2734. end
  2735. -- 获取当前战役的 怪物ID
  2736. function getBattleMonsterOutID(human)
  2737. local nBattleID = BattleLogic_GetBattleBattleID(human)
  2738. local tBattleExcel = BattleLogic_GetBattleConfig(human)
  2739. if -1 >= nBattleID or not tBattleExcel then
  2740. print("[getBattleMonsterOutID] 获取当前战斗ID、配置失败 id = "..human.db._id)
  2741. return 0
  2742. end
  2743. -- local battleID = human.db.battleID
  2744. -- local config = BattleExcel.node[battleID]
  2745. local config = tBattleExcel.node[nBattleID]
  2746. return config.monsterOutID
  2747. end
  2748. function onUpdatePos(human)
  2749. BRoleLogic.updateData(BillboardDefine.TYPE_ZHANDOULI, human.db)
  2750. end
  2751. function getNextRewardName(human)
  2752. local guajiID = BattleLogic_GetBattleGuaJiID(human)
  2753. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  2754. if not tBattleConfig or -1 >= guajiID then
  2755. return nil, nil
  2756. end
  2757. -- for i = human.db.guajiID + 1, #BattleExcel.node do
  2758. for i = guajiID + 1, #tBattleConfig.node do
  2759. if #tBattleConfig.node[i].tongguan > 0 then
  2760. local itemID = tBattleConfig.node[i].tongguan[1][1]
  2761. local itemConfig = ItemDefine.getConfig(itemID)
  2762. if itemConfig == nil then
  2763. return
  2764. else
  2765. return i - guajiID, itemConfig.name
  2766. end
  2767. end
  2768. end
  2769. end
  2770. --[[
  2771. 通关章节后领取奖励
  2772. ]]
  2773. function battleChapterReward(human, mapID)
  2774. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  2775. local nBattleID = BattleLogic_GetBattleBattleID(human)
  2776. local tChapterReward = BattleLogic_GetChapterReward(human)
  2777. if not tBattleConfig or -1 >= nBattleID or not tChapterReward then
  2778. print("[battleChapterReward] 获取到的战斗ID、配置、通关章节奖励表 不正确 id = "..human.db._id)
  2779. return
  2780. end
  2781. local mapConf = tBattleConfig.map[mapID]
  2782. if not mapConf then
  2783. return
  2784. end
  2785. -- 没有通过当前大关卡
  2786. local battleID = nBattleID
  2787. local battleNodeConfig = tBattleConfig.node[battleID]
  2788. local roleMapId
  2789. if not battleNodeConfig then
  2790. if battleID ~= #tBattleConfig.node + 1 then
  2791. return
  2792. else
  2793. roleMapId = #tBattleConfig.map
  2794. end
  2795. else
  2796. roleMapId = battleNodeConfig.mapID
  2797. end
  2798. if mapID > roleMapId then
  2799. return
  2800. end
  2801. -- if not human.db.chapterReward then
  2802. -- human.db.chapterReward = { }
  2803. -- end
  2804. -- 判断是否已经领取了当前大关卡的奖励
  2805. -- local chapterReward = human.db.chapterReward
  2806. local chapterReward = tChapterReward
  2807. if chapterReward[mapID] then
  2808. return Broadcast.sendErr(human, Lang.FRIEND_HEART_GET_HAD)
  2809. end
  2810. chapterReward[mapID] = true
  2811. ObjHuman.save(human)
  2812. local reward = mapConf.reward
  2813. BagLogic.addItemList(human, reward, "chapterReward")
  2814. RoleSystemLogic.onDot(human, RoleSystemDefine.ROLE_SYS_ID_1105)
  2815. local msgRet = Msg.gc.GC_BATTLE_CHAPTER_REWARD
  2816. msgRet.mapID = mapID
  2817. Msg.send(msgRet, human.fd)
  2818. end
  2819. -- 判断难度是否解锁
  2820. local function BattleLogic_CheckDiffIsOK(human, nSelectDiff)
  2821. -- 默认难度直接通过
  2822. if EliteDefine.COPY_ELITE_NORMAL == nSelectDiff then
  2823. return EliteDefine.COPY_SELECT_SUCC
  2824. end
  2825. -- 等级不够
  2826. if human.db.lv < EliteDefine.COPY_ELITE_ULEV then
  2827. return EliteDefine.COPY_SELECT_LEV
  2828. end
  2829. local nChoseBattleID = (EliteDefine.COPY_LEVEL_ELITE == nSelectDiff) and human.db.battleID or human.db.battleID_elite
  2830. return nChoseBattleID > EliteDefine.COPY_ELITE_LEVEL and EliteDefine.COPY_SELECT_SUCC or EliteDefine.COPY_SELECT_MAIN
  2831. end
  2832. -- 获取未领取奖励
  2833. local function BattleLogic_GetNorewardReceived(human, nBattleType, cIndex)
  2834. print("1:[BattleLogic_GetNorewardReceived] id = "..human.db._id.." nBattleType = "..nBattleType)
  2835. local nBattleID = BattleLogic_GetBattleIDByType(human, nBattleType)
  2836. local tBattleConfig = BattleLogic_GetBattleConfigByType(nBattleType)
  2837. local nGuaJiID = BattleLogic_GetBattleGuaJiIDByType(human, nBattleType)
  2838. if -1 >= nBattleID or not tBattleConfig or -1 >= nGuaJiID then
  2839. print("[BattleLogic_GetNorewardReceived] 获取配置失败")
  2840. return
  2841. end
  2842. local msgRet = Msg.gc.GC_BATTLE_QUERY_ALL
  2843. msgRet.index = nBattleType
  2844. msgRet.list[0] = 0
  2845. msgRet.isEnd = 0
  2846. msgRet.curIndex = 0
  2847. local curIndex = 1
  2848. -- human.db.battleID = human.db.battleID or 1
  2849. -- if human.db.battleID == 0 then
  2850. -- human.db.battleID = 1
  2851. -- end
  2852. human.db.mopupDoCnt = human.db.mopupDoCnt or 0
  2853. local curBattleNumber = cIndex
  2854. local curTotalNumber = 0
  2855. local battleNumber = #tBattleConfig.node
  2856. -- local nGuajiID = human.db.guajiID or 0
  2857. print("[BattleLogic_GetNorewardReceived] nGuajiID = "..nGuaJiID.. " nBattleID = "..nBattleID)
  2858. -- 判断ID得用战斗ID-1, 因为挂机ID可以设置
  2859. local nJudeNum = nGuaJiID
  2860. if nGuaJiID ~= nBattleID then
  2861. if nGuaJiID + 1 < nBattleID then
  2862. nJudeNum = nBattleID - 1
  2863. end
  2864. end
  2865. print("[BattleLogic_GetNorewardReceived] nJudeNum = "..nJudeNum)
  2866. for k,v in ipairs(tBattleConfig.node) do
  2867. if #v.tongguan ~= 0 then
  2868. -- 领取状态
  2869. local state = false
  2870. if k <= nJudeNum then
  2871. state = isGetRewardByType(human, k, nBattleType)
  2872. end
  2873. if not (state == true) then
  2874. local r = STATUS_CANGET
  2875. --(k > nGuaJiID) and STATUS_CANGET or STATUS_NONE
  2876. --未领取
  2877. if r == STATUS_CANGET then
  2878. curTotalNumber = curTotalNumber + 1
  2879. if curTotalNumber > curBattleNumber then
  2880. --构造
  2881. local cf = tBattleConfig.node[k].tongguan
  2882. local net = msgRet.list[curIndex]
  2883. net.status = k <= nJudeNum and STATUS_CANGET or STATUS_NONE
  2884. net.levelName = getBattleNameByType(k, nBattleType)
  2885. net.index = k
  2886. net.nowBattle = getBattleNameByType(nJudeNum, nBattleType)
  2887. net.reward[0] = 0
  2888. net.heroReward[0] = 0
  2889. if cf[1][3] then
  2890. net.heroReward[0] = 1
  2891. local other = { }
  2892. other.star = cf[1][3]
  2893. HeroGrid.makeHeroSimpleByID(net.heroReward[1], cf[1][1], nil, other, human)
  2894. HeroGrid.makeHeroSimpleByGeneral(net.heroReward[1], cf[1][1])
  2895. local tHeroInfo = Util.printTable(net.heroReward)
  2896. -- print("[BattleLogic_GetNorewardReceived] 英雄数据 k = "..k.." 获取的数据 = "..tHeroInfo)
  2897. else
  2898. net.reward[0] = 1
  2899. for i = 1, net.reward[0] do
  2900. local itemID = cf[i][1]
  2901. local itemCnt = cf[i][2]
  2902. Grid.makeItem(net.reward[i], itemID, itemCnt)
  2903. end
  2904. end
  2905. curIndex = curIndex + 1
  2906. msgRet.list[0] = msgRet.list[0] + 1
  2907. if msgRet.list[0] >= 15 then
  2908. local ret = 0
  2909. if k < battleNumber then
  2910. for kk, vv in ipairs(tBattleConfig.node) do
  2911. if kk > k then
  2912. if v.tongguan ~= 0 then
  2913. local nNextstate = isGetRewardByType(human,kk, nBattleType)
  2914. if not (nNextstate == true) then
  2915. local rr =(kk > nGuaJiID) and STATUS_CANGET or STATUS_NONE
  2916. --未领取
  2917. if rr == STATUS_CANGET then
  2918. ret = 1
  2919. break
  2920. end
  2921. end
  2922. end
  2923. end
  2924. end
  2925. end
  2926. if ret == 1 then
  2927. --没有结束
  2928. msgRet.isEnd = 0
  2929. else
  2930. msgRet.isEnd = 1
  2931. end
  2932. msgRet.curIndex=curTotalNumber
  2933. -- curIndex = 1
  2934. Msg.send(msgRet, human.fd)
  2935. print("[BattleLogic_GetNorewardReceived] send client msgRet.curIndex:"..msgRet.curIndex.." msgRet.isEnd:"..msgRet.isEnd.." msgRet.list[0]:"..msgRet.list[0])
  2936. --local info=Util.printTable(msgRet)
  2937. --print("getNorewardReceived0->>:"..info)
  2938. return
  2939. end
  2940. end
  2941. end
  2942. else
  2943. print("[BattleLogic_GetNorewardReceived] 奖励已领取:"..k)
  2944. end
  2945. end
  2946. end
  2947. --结束
  2948. msgRet.isEnd = 1
  2949. msgRet.curIndex=0
  2950. Msg.send(msgRet, human.fd)
  2951. end
  2952. -- 客户端请求查询难度
  2953. function CG_ELITE_OPEN(human)
  2954. BattleLogic_QueryDifficulty(human)
  2955. end
  2956. -- 客户端请求切换难度
  2957. function CG_ELITE_SELECT(human, nSelectDiff)
  2958. if EliteDefine.COPY_ELITE_NORMAL > nSelectDiff or EliteDefine.COPY_ELITE_DIFFICULTY < nSelectDiff then
  2959. Log.write(Log.LOGID_OSS_BATTLE_MAINGATE, "[CG_ELITE_SELECT] 客户端传入的参数不正确 id = "..human.db._id .. "nSelectDiff = "..nSelectDiff)
  2960. print("[CG_ELITE_SELECT] 客户端选择难度,上传的难度不正确 id = "..human.db._id .. "nSelectDiff = "..nSelectDiff)
  2961. return
  2962. end
  2963. local nStatus = BattleLogic_CheckDiffIsOK(human, nSelectDiff)
  2964. print("[CG_ELITE_SELECT] nStatus = "..nStatus.. " 选择的难度 nSelectDiff = "..nSelectDiff)
  2965. -- 设置类型
  2966. if EliteDefine.COPY_SELECT_SUCC == nStatus then
  2967. BattleLogic_SetBattleType(human,nSelectDiff)
  2968. end
  2969. local msgRet = Msg.gc.GC_ELITE_SELECT
  2970. msgRet.status = nStatus
  2971. Msg.send(msgRet,human.fd)
  2972. end
  2973. -- 客户端请求领取奖励
  2974. function CG_BATTLE_TONGGUAN_REWARD_GET_COPY(human, nBattleType, nBattleID)
  2975. local tBattleConfig = BattleLogic_GetBattleConfig(human)
  2976. local nGuaJiID = BattleLogic_GetBattleGuaJiIDByType(human, nBattleType)
  2977. if not tBattleConfig or -1 >= nGuaJiID then
  2978. return
  2979. end
  2980. local tMsgRet = Msg.gc.GC_BATTLE_TONGGUAN_REWARD_GET_COPY
  2981. local tConfig = tBattleConfig.node[nBattleID].tongguan
  2982. if #tConfig < 1 then
  2983. tMsgRet.status = 0
  2984. Msg.send(tMsgRet, human.fd)
  2985. return
  2986. end
  2987. tMsgRet.status = 1
  2988. getTongGuanReward(human, nBattleID)
  2989. tMsgRet.tongguan[0] = 0
  2990. if #tConfig ~= 0 then
  2991. tMsgRet.tongguan[0] = 1
  2992. local tNet = tMsgRet.tongguan[1]
  2993. tNet.status = STATUS_NONE
  2994. tNet.levelName = getBattleNameByType(nBattleID, nBattleType)
  2995. tNet.index = nBattleID
  2996. tNet.nowBattle = getBattleNameByType(nGuaJiID, nBattleType)
  2997. tNet.reward[0] = 0
  2998. tNet.heroReward[0] = 0
  2999. if tConfig[1][3] then
  3000. tNet.heroReward[0] = 1
  3001. local other = { }
  3002. other.star = tConfig[1][3]
  3003. HeroGrid.makeHeroSimpleByID(tNet.heroReward[1], tConfig[1][1], nil, other, human)
  3004. HeroGrid.makeHeroSimpleByGeneral(tNet.heroReward[1], tConfig[1][1])
  3005. else
  3006. tNet.reward[0] = 1
  3007. for i = 1, tNet.reward[0] do
  3008. local itemID = tConfig[i][1]
  3009. local itemCnt = tConfig[i][2]
  3010. Grid.makeItem(tNet.reward[i], itemID, itemCnt)
  3011. end
  3012. end
  3013. end
  3014. Msg.send(tMsgRet, human.fd)
  3015. end
  3016. -- 客户端请求查询所有未领取奖励
  3017. function CG_BATTLE_QUERY_ALL(human, nBattleType, curIndex)
  3018. if EliteDefine.COPY_ELITE_NORMAL > nBattleType or EliteDefine.COPY_ELITE_DIFFICULTY < nBattleType then
  3019. print("[CG_BATTLE_QUERY_ALL] 客户端请求的战斗类型不正确 id = "..human.db._id.." nType = "..nBattleType)
  3020. return
  3021. end
  3022. BattleLogic_GetNorewardReceived(human, nBattleType, curIndex)
  3023. end
  3024. -- 判断是否是最后一关
  3025. function BattleLogic_IsLastLevels(human, nBattleType)
  3026. local tBattleConfig = BattleLogic_GetBattleConfigByType(nBattleType)
  3027. local nBattleType = BattleLogic_GetBattleType(human)
  3028. if not tBattleConfig or -1 >= nBattleType then
  3029. return false
  3030. end
  3031. local nValue = BattleLogic_GetBattleAdopt(human, nBattleType)
  3032. return nValue == 1
  3033. end