BattleLogic.lua 139 KB

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