BattleLogic.lua 142 KB

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