BattleLogic.lua 136 KB

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