LuaBattleMgr.lua 68 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897
  1. local LuaBattleMgr = class("LuaBattleMgr")
  2. local RoleViewSystem = require("RoleViewSystem")
  3. local ExpeditionBuff = require("Expedition/ExpeditionBuff")
  4. local NextMapState =
  5. {
  6. None = 0, -- 不需要进入下一地图
  7. WaitServer = 1, -- 客户端表现走到需要表现进入下一地图,而服务器消息还未下发
  8. WaitShow = 2, -- 服务端消息需要进入下一地图,而等待客户端表现
  9. }
  10. local firstLevelId = 10001
  11. local battleStateTimer
  12. local reconnected = false
  13. local CompetitionRefreshLevelLimit
  14. function LuaBattleMgr:ctor()
  15. self.rageLeftTime = 0;
  16. self.rageLeftTimeTimer = nil;
  17. self.lastInComeTime = 0; --上次领取收益时间
  18. self.rewardNum = 0 --累计奖励次数
  19. self.curLevelId = 0; --当前关卡id
  20. self.curMapId = 0; --当前地图id
  21. self.lastLevelId = 0; --当前关卡id
  22. self.lastMapId = 0; --当前地图id
  23. self.lastMapRewardCount = 0;
  24. self.mapRewardCount = 0; --当前未领取次数
  25. self.rewardItemList = nil;
  26. self.accumIncomeTime = 0;
  27. self.maxEvilExp = 0; --魔魂值上限
  28. self.lastMapMode = 0 -- 普通模式
  29. self.difficulty = 0 -- 普通模式 0 普通 1 困难 2 噩梦
  30. if self.simpleLvData == nil then
  31. self.simpleLvData ={1,1}--普通关卡数据
  32. end
  33. if self.difficultyLvData == nil then
  34. self.difficultyLvData ={1,1}--困难关卡数据
  35. end
  36. if self.difficulty_S_LvData == nil then
  37. self.difficulty_S_LvData ={1,1}--噩梦关卡数据
  38. end
  39. self.curSimpleLvCgf ={}
  40. self.maxInComeTime = 0 --最大可累计的收益时间
  41. self.maxQuickBattleTimes = 0;
  42. self.usedQuickBattleTimes = 0;
  43. self.nextMapState = NextMapState.None
  44. self.needEnterNextMap = false -- 客户端表现已到,等待服务器进入下一个地图的消息
  45. self.waitEnterNextMap = false -- 服务器消息已到,等待进入下一个地图中 (有其它切换地图的表现,则真正切换地图需要等待)
  46. self.bKillBoss = false
  47. self.isBattling = false
  48. self.lastMapRankPercent = 0
  49. self.LastStartOnlineTime = 0--上次时间
  50. self.LastTotalOnlineTime = 0--上次累计时间
  51. self.CurTotalOnlineTime = 0 --本地累计时间
  52. self.LastOnlineRewardId = 0--上一次领取的奖励ID
  53. self.IsOverTime = false
  54. self.isAutochallenge = false
  55. --初始化 资源效率 默认取第一个关卡的效率
  56. local levelData = ManagerContainer.CfgMgr:GetLevelDataById(firstLevelId)
  57. self.lastLevelZeny = levelData.ZenyOl;
  58. self.lastLevelExp = levelData.BaseExpOl;
  59. self.lastLevelPartnerExp = levelData.ParterOl;
  60. self.lastLevelCruise = levelData.CruiseOl;
  61. self.roleViewSystem = RoleViewSystem:new()
  62. self:RegisterNetEvents();
  63. end
  64. function LuaBattleMgr:SetBattleMode(mode)
  65. LogError("==================设置 mode"..mode)
  66. self.lastMapMode = self.difficulty
  67. self.difficulty = mode
  68. end
  69. function LuaBattleMgr:GetBattleMode()
  70. return self.difficulty
  71. end
  72. function LuaBattleMgr:GetLastMapRankPercent()
  73. return self.lastMapRankPercent
  74. end
  75. function LuaBattleMgr:SetLastMapRankPercent(val)
  76. self.lastMapRankPercent = val
  77. end
  78. function LuaBattleMgr:Destroy()
  79. if self.roleViewSystem then
  80. self.roleViewSystem:Dispose()
  81. end
  82. self.roleViewSystem = nil
  83. if tolua.getpeer(self) ~= nil then
  84. tolua.setpeer(self, nil)
  85. end
  86. self.lastMapMode = 0 -- 普通模式
  87. self.difficulty = 0 -- 普通模式
  88. --LogError("------------Destroy-----------")
  89. end
  90. function LuaBattleMgr:ResetBattleMode()
  91. self.lastMapMode = 0 -- 普通模式
  92. self.difficulty = 0 -- 普通模式
  93. --LogError("------------ResetBattleMode-----------")
  94. end
  95. function LuaBattleMgr:RegisterNetEvents()
  96. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_PLAYER_INCOME_ACK,self.OnBattleIncomeAck,self)
  97. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_PLAYER_BOSS_REWARD_ACK,self.OnBossRewardAck,self)
  98. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_PLAYER_BATTLE_DATA_CHANGE_NTF,self.OnBattleDataChangeNtf,self)
  99. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_QUICK_BATTLE_INCOME_ACK,self.OnQuickBattleIncomeAck,self)
  100. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_BATTLE_BOSS_FIGHT_ACK,self.OnChallengeBossFightAck,self)
  101. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_PLAYER_BATTLE_RECORD_DETAIL_SAVE_NTF,self.OnBattleRecordDetalSaveNtf,self)
  102. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_PLAYER_BATTLE_RECORD_ACK,self.OnBattleRecordAck,self)
  103. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_PLAYER_BATTLE_RECORD_DETAIL_ACK,self.OnBattleRecordDetailAck,self)
  104. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_MAP_LEVEL_TYPE_CHANGE_ACK,self.OnChangeMapLevelTypeAct,self)
  105. --在线奖励
  106. self:RegisterOnlineRecordNet()
  107. end
  108. ------------------------------------------------------在线奖励
  109. --GetState
  110. function LuaBattleMgr:GetOnlineState()
  111. local IsFinished = self:IsFinishedOnlineTime()
  112. if IsFinished then
  113. local IsOver = self:IsOverOnlineDay()--是否领完当天
  114. if IsOver then
  115. return Enum.EnumOnineState.ToDayFinished
  116. else
  117. return Enum.EnumOnineState.Receive
  118. end
  119. else
  120. return Enum.EnumOnineState.RunTime
  121. end
  122. end
  123. --注册在线奖励
  124. function LuaBattleMgr:RegisterOnlineRecordNet()
  125. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_ONLINE_TIME_REWARD_ACK,self.OnOnLineTimeRecordAck,self)
  126. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_ONLINE_TIME_REWARD_NTF,self.OnOnLineTimeRecordNtf,self)
  127. end
  128. --移除在线奖励
  129. function LuaBattleMgr:UnRegisterOnlineRecordNet()
  130. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_ONLINE_TIME_REWARD_ACK)
  131. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_ONLINE_TIME_REWARD_NTF)
  132. end
  133. --请求领取在线奖励
  134. function LuaBattleMgr:SendOnlineTimeRecord()
  135. --金币是否足够
  136. if self:GetOnlineState() == Enum.EnumOnineState.ToDayFinished then
  137. return
  138. end
  139. if self:GetOnlineState() == Enum.EnumOnineState.Receive or self:IsCanUseGoldOnline() then
  140. --LogError("Send Record")
  141. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_ONLINE_TIME_REWARD_REQ, {})
  142. end
  143. end
  144. --在线奖励返回
  145. function LuaBattleMgr:OnOnLineTimeRecordAck(data)
  146. --LogError(Inspect(data))
  147. -- int32 error = 1; //错误码
  148. -- repeated KeyValueType reward_item_list = 2; //奖励物品
  149. --show item
  150. end
  151. --在线奖励变化
  152. function LuaBattleMgr:OnOnLineTimeRecordNtf(data)
  153. --LogError(Inspect(data))
  154. self:SyncOnlineTime(data)
  155. end
  156. function LuaBattleMgr:SyncOnlineTime(role_base)
  157. if role_base then
  158. --local Onlinetime = ManagerContainer.LuaTimerMgr:ParseSeconds2Time(role_base.total_online_time)
  159. --LogError("OnlineTime"..Onlinetime)
  160. --LogError("RewardId"..tostring(role_base.online_reward_id))
  161. self.LastStartOnlineTime = role_base.online_stamp / 1000
  162. self.LastStartOnlineTime = type(self.LastStartOnlineTime) == "number" and self.LastStartOnlineTime or #self.LastStartOnlineTime
  163. self.LastTotalOnlineTime = role_base.total_online_time
  164. self.LastOnlineRewardId = role_base.online_reward_id
  165. end
  166. if self.LastOnlineRewardId <= 0 then --当天未领取 计算领取上一期领取ID
  167. local OnlineDay = self:GetTotalDay() + 1 --注册当天就算1天
  168. local Pre_reward_id = self:GetPreDayIdx(OnlineDay)
  169. self.StartOnlineIdx = Pre_reward_id
  170. else
  171. self.StartOnlineIdx = self.LastOnlineRewardId
  172. end
  173. --LogError("Sync = "..tostring(self.StartOnlineIdx))
  174. self.CurTotalOnlineTime = 0
  175. self.IsOverTime = false
  176. self:UpdateOnlineTime()
  177. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_REFRESH_ONLINETIME_CHANGESTATE);
  178. if not self:IsFinishedOnlineTime() then
  179. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.RED_POINT_MGR_NOTICE, Enum.RPNotifyType.OnlineRewards, false)
  180. end
  181. end
  182. function LuaBattleMgr:FinishedOnlineTime()
  183. self.IsOverTime = true
  184. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.RED_POINT_MGR_NOTICE, Enum.RPNotifyType.OnlineRewards, true)
  185. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_REFRESH_ONLINETIME_CHANGESTATE);
  186. end
  187. --是否可以领取当前
  188. function LuaBattleMgr:IsFinishedOnlineTime()
  189. return self.IsOverTime
  190. end
  191. --获取online数据 根据天数
  192. function LuaBattleMgr:GetDayOnlineData(Day)
  193. local CurDay = Day
  194. if CurDay == 0 then
  195. CurDay = 1
  196. end
  197. local cfgRwards = ManagerContainer.CfgMgr:GetOnlineRwards()
  198. local tbRwards = {}
  199. for i=1,#cfgRwards do
  200. if cfgRwards[i].Day == CurDay then
  201. table.insert(tbRwards,cfgRwards[i])
  202. end
  203. end
  204. --未取到 取最后表最后一天
  205. if #tbRwards <= 0 then
  206. return self:GetLastOnlineRwards()
  207. end
  208. return tbRwards
  209. end
  210. --获取上一次领取ID根据天数
  211. function LuaBattleMgr:GetPreDayIdx(CurDay)
  212. local tbRwards = self:GetDayOnlineData(CurDay)
  213. if tbRwards then
  214. if #tbRwards >= 1 then
  215. return tbRwards[1].Id - 1
  216. end
  217. end
  218. return 0
  219. end
  220. --是否领取完当天
  221. function LuaBattleMgr:IsOverOnlineDay()
  222. if self.LastOnlineRewardId <= 0 then
  223. return false
  224. end
  225. local cfgRwards = ManagerContainer.CfgMgr:GetOnlineRwards()
  226. local OverDay = cfgRwards[self.LastOnlineRewardId].Day
  227. local LastId = self.LastOnlineRewardId + 1
  228. if LastId > #cfgRwards then --超出 结束
  229. return true
  230. end
  231. for i=LastId,#cfgRwards do
  232. if cfgRwards[i].Day == OverDay then
  233. return false
  234. end
  235. end
  236. return true
  237. end
  238. function LuaBattleMgr:UpdateOnlineTime()
  239. if nil == self.IsOverTime or self.IsOverTime then
  240. return true,ManagerContainer.LuaTimerMgr:ParseSeconds2Time(0)
  241. end
  242. local LastStartTime = self.LastStartOnlineTime - self.LastTotalOnlineTime
  243. local CurTime = ManagerContainer.LuaTimerMgr:GetTimeSecond()
  244. local totaTime = self:GetNextTotalOnlineTime() - self.LastTotalOnlineTime --剩余秒数
  245. if totaTime <= 0 then
  246. totaTime = 0
  247. end
  248. local finishlTime = self.LastStartOnlineTime + totaTime --结束时间
  249. local DeltaTime = finishlTime - CurTime
  250. if self:IsOverOnlineDay() then
  251. DeltaTime = 0
  252. end
  253. if DeltaTime <= 0 then
  254. DeltaTime = 0
  255. self:FinishedOnlineTime()
  256. end
  257. local str = tostring(math.modf(DeltaTime/60))..I18N.T("MINS")..tostring(DeltaTime%60)..I18N.T("S")
  258. --local str = ManagerContainer.LuaTimerMgr:ParseSeconds2Time(DeltaTime)
  259. -- local strCur = ManagerContainer.LuaTimerMgr:ParseTimeStamp2Format(CurTime, "%H:%M")
  260. -- local strLast = ManagerContainer.LuaTimerMgr:ParseTimeStamp2Format(LastTime, "%H:%M")
  261. -- LogError(strCur)
  262. -- LogError(strLast)
  263. return false,str
  264. end
  265. --累计创角天数获取
  266. function LuaBattleMgr:GetTotalDay()
  267. local CreateTime = ManagerContainer.DataMgr.UserData:GetCreateTime()
  268. CreateTime = CreateTime / 1000
  269. CreateTime = type(CreateTime) == "number" and CreateTime or #CreateTime
  270. local TotalTime = tonumber(self.LastStartOnlineTime) - tonumber(CreateTime)
  271. local DeltaD = math.modf(TotalTime/3600/24)
  272. local DeltaS = TotalTime - DeltaD*3600*24
  273. --获取注册时间戳小时
  274. local CreateHour = tonumber(ManagerContainer.LuaTimerMgr:Getstamp2TimeH("%H",CreateTime))
  275. --下一天时间戳计算
  276. local NextDayTime = tonumber(CreateTime) --小于5点 求当天5点时间戳
  277. if CreateHour > 5 then --大于5点 求下一天5点时间戳
  278. NextDayTime = tonumber(CreateTime) + 24 * 3600
  279. end
  280. local Y = tonumber(ManagerContainer.LuaTimerMgr:Getstamp2TimeH("%Y",NextDayTime))
  281. local M = tonumber(ManagerContainer.LuaTimerMgr:Getstamp2TimeH("%m",NextDayTime))
  282. local D = tonumber(ManagerContainer.LuaTimerMgr:Getstamp2TimeH("%d",NextDayTime))
  283. local Data = {year=Y, month=M, day=D, hour=5, minute=0, second=0}
  284. local DayEndStamp = ManagerContainer.LuaTimerMgr:GetTime2StampS(Data)
  285. --注册当天距离第二天总秒
  286. local TotalEndTime = DayEndStamp - CreateTime
  287. ---剩余秒数 是否大于第二天总秒数
  288. if DeltaS > TotalEndTime then --剩余时间是否过了凌晨5点 过了+1天
  289. DeltaD = DeltaD + 1
  290. end
  291. -- LogError("DeltaD"..tostring(DeltaD))
  292. -- LogError("DeltaS"..tostring(DeltaS))
  293. -- LogError("CreateDay"..ManagerContainer.LuaTimerMgr:Getstamp2TimeH("%Y-%m-%d %H:%M:%S",CreateTime))
  294. -- LogError("CreateDay"..ManagerContainer.LuaTimerMgr:Getstamp2TimeH("%Y-%m-%d %H:%M:%S",DayEndStamp))
  295. -- LogError("LastStartOnlineTime"..ManagerContainer.LuaTimerMgr:Getstamp2TimeH("%Y-%m-%d %H:%M:%S",self.LastStartOnlineTime))
  296. -- LogError(tostring(DeltaD))
  297. return DeltaD
  298. end
  299. --最后一天数据
  300. function LuaBattleMgr:GetLastOnlineRwards()
  301. local tbRwards = {}
  302. local cfgRwards = ManagerContainer.CfgMgr:GetOnlineRwards()
  303. local OverDay = cfgRwards[#cfgRwards].Day
  304. for i=1,#cfgRwards do
  305. if cfgRwards[i].Day == OverDay then
  306. table.insert(tbRwards,cfgRwards[i])
  307. end
  308. end
  309. return tbRwards
  310. end
  311. --获取ID的天数数据
  312. function LuaBattleMgr:GetOnlineRwardsById(Id)
  313. local tbRwards = {}
  314. local cfgRwards = ManagerContainer.CfgMgr:GetOnlineRwards()
  315. if Id > #cfgRwards then --ID超出 获取超出后一天数据
  316. return self:GetLastOnlineRwards()
  317. end
  318. -- LogError("GetOnlineRwardsById"..tostring(Id))
  319. -- LogError(Inspect(cfgRwards[Id]))
  320. local OverDay = cfgRwards[Id].Day
  321. for i=1,#cfgRwards do
  322. if cfgRwards[i].Day == OverDay then
  323. table.insert(tbRwards,cfgRwards[i])
  324. end
  325. end
  326. return tbRwards
  327. end
  328. --下一个数据时间 跟 奖励
  329. function LuaBattleMgr:GetNextTotalOnlineTime()
  330. local cfgRwards = ManagerContainer.CfgMgr:GetOnlineRwards()
  331. local TotalTime = 0
  332. local Rewards = {}
  333. if cfgRwards then
  334. local NextId = self.StartOnlineIdx + 1
  335. local Cfg = self:GetOnlineRwardsById(NextId)
  336. if Cfg then
  337. for i = 1,#Cfg do
  338. if NextId > #cfgRwards then --超出范围 取最后一天第1个开始
  339. TotalTime = Cfg[1].Time
  340. Rewards = Cfg[1].Rewards
  341. else--未超出范围 累计获取时间
  342. if Cfg[i].Id == NextId then
  343. --不累计
  344. --TotalTime = TotalTime + Cfg[i].Time --* 60
  345. TotalTime = Cfg[i].Time
  346. Rewards = Cfg[i].Rewards
  347. end
  348. end
  349. end
  350. end
  351. end
  352. return TotalTime + 3,Rewards --3秒延迟 防止服务器时间差
  353. end
  354. --是否可以用金币加速当前
  355. function LuaBattleMgr:IsCanUseGoldOnline()
  356. local Goldcount = CommonUtil.GetOwnResCountByItemId(Enum.ItemType.Diamond)
  357. local NeedItem = self:GetOnlineTimeGlod()
  358. if NeedItem <= Goldcount then
  359. return true
  360. end
  361. return false
  362. end
  363. --获取领取当前金币数据
  364. function LuaBattleMgr:GetOnlineTimeGlod()
  365. local cfgRwards = ManagerContainer.CfgMgr:GetOnlineRwards()
  366. local GoldNum = 0
  367. if cfgRwards then
  368. local NextId = self.StartOnlineIdx +1
  369. local Cfg = self:GetOnlineRwardsById(NextId)
  370. if Cfg then
  371. for i = 1,#Cfg do
  372. if Cfg[i].Id == NextId then
  373. GoldNum = Cfg[i].SpeedUp
  374. end
  375. end
  376. end
  377. end
  378. return GoldNum
  379. end
  380. -------------------------------------------------------------------
  381. function LuaBattleMgr:UnRegisterNetEvents()
  382. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_PLAYER_INCOME_ACK)
  383. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_PLAYER_BOSS_REWARD_ACK)
  384. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_PLAYER_BATTLE_DATA_CHANGE_NTF)
  385. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_QUICK_BATTLE_INCOME_ACK)
  386. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_BATTLE_BOSS_FIGHT_ACK)
  387. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_MAP_LEVEL_TYPE_CHANGE_ACK)
  388. self:UnRegisterOnlineRecordNet()
  389. end
  390. function LuaBattleMgr:SendChallengeBossReq()
  391. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_BATTLE_BOSS_FIGHT_REQ, {})
  392. end
  393. function LuaBattleMgr:OnChallengeBossFightAck(data)
  394. --LogError("=========OnChallengeBossFightAck========"..Inspect(data))
  395. if data.error == Enum.NetErrorCode.ERROR_OK then
  396. self.isBattling = true
  397. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Challenge_Boss_Fight_ACK,data.factor_list)
  398. elseif data.error == 618 then
  399. return
  400. else
  401. if data.left_cd_time > 0 then
  402. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.BATTLE_CHALLENGE_TIME_REFRESH, data.left_cd_time)
  403. else
  404. LogError("---------OnChallengeBossFightAck---------"..Inspect(data))
  405. self.isBattling = true
  406. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Challenge_Boss_Fight_ACK,data.factor_list)
  407. end
  408. end
  409. end
  410. function LuaBattleMgr:SendChangeMapLevelTypeReq(type)
  411. --LogError("==================="..type)
  412. self.LevelChangeType = type
  413. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_MAP_LEVEL_TYPE_CHANGE_REQ, {type = type})
  414. end
  415. function LuaBattleMgr:OnChangeMapLevelTypeAct(data)
  416. LogError("========OnChangeMapLevelTypeAct=====模式變化請求回復=="..Inspect(data))
  417. --local mapMode = data.type < 0 and Enum.MapModeType.Simple or Enum.MapModeType.Difficulty
  418. if data.error ~= 0 then
  419. return
  420. end
  421. local mapMode = data.type
  422. if mapMode == -1 and self.LevelChangeType ~= nil then
  423. mapMode = self.LevelChangeType
  424. self.LevelChangeType = nil
  425. end
  426. self.NeedChangeMapMode = mapMode
  427. --local mapMode = ManagerContainer.LuaBattleMgr:GetBattleMode() == Enum.MapModeType.Difficulty and Enum.MapModeType.Simple or Enum.MapModeType.Difficulty
  428. --self:SetBattleMode(mapMode)
  429. -- ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.MAP_MODE_CHANGE,mapMode)
  430. end
  431. function LuaBattleMgr:SendQuickBattleReq()
  432. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_QUICK_BATTLE_INCOME_REQ, {})
  433. end
  434. function LuaBattleMgr:SendBattleIncomeReq()
  435. local _isOverFlow, _evilExp = self:JudgeEvilExpOverFlow();
  436. if _isOverFlow then
  437. ManagerContainer.LuaUIMgr:ShowMessageBox("EvilOverFlowTips",{_evilExp, self.maxEvilExp},nil,self,self.CSPlayerIncomeReq,nil)
  438. else
  439. self:CSPlayerIncomeReq();
  440. end
  441. end
  442. function LuaBattleMgr:OnBattleIncomeAck(playerIncomeAck)
  443. if playerIncomeAck.error == 0 then
  444. self.rewardItemList = playerIncomeAck.item_list
  445. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_BATTLE_INCOME_ACK,0);
  446. end
  447. end
  448. function LuaBattleMgr:OnQuickBattleIncomeAck(playerIncomeAck)
  449. if playerIncomeAck.error == 0 then
  450. self.rewardItemList = playerIncomeAck.item_list
  451. local itemIcons = {};
  452. for i =1, #self.rewardItemList do
  453. local item = self.rewardItemList[i];
  454. if item.key >= 100 then
  455. local itemCfg = ManagerContainer.CfgMgr:GetItemById(item.key)
  456. if itemCfg~= nil then
  457. itemIcons[#itemIcons+1] = itemCfg.Icon
  458. end
  459. end
  460. end
  461. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIBattleReward,1)
  462. end
  463. end
  464. function LuaBattleMgr:GetRewardCnt(type)
  465. if self.rewardItemList == nil then
  466. return 0
  467. end
  468. for i =1, #self.rewardItemList do
  469. local item = self.rewardItemList[i];
  470. if item.key == type then
  471. return item.value;
  472. end
  473. end
  474. return 0;
  475. end
  476. function LuaBattleMgr:SendBossRewardReq(killedBossTime,recordTimeStamp)
  477. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_PLAYER_BOSS_REWARD_REQ, {challenge_time = killedBossTime,map_id =self.curMapId ,map_level=self.curLevelId,record_time_stamp=recordTimeStamp})
  478. end
  479. function LuaBattleMgr:OnBossRewardAck(playerBossRewardAck)
  480. LogError("OnBossRewardAck -- " .. Inspect(playerBossRewardAck))
  481. if battleStateTimer then
  482. ManagerContainer.LuaTimerMgr:RemoveTimer(battleStateTimer)
  483. battleStateTimer = nil
  484. end
  485. if playerBossRewardAck.error == 0 then
  486. ManagerContainer.LuaUIMgr:ClosePage(Enum.UIPageName.UIChat)
  487. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIBattle)
  488. self.rewardItemList = playerBossRewardAck.item_list
  489. local rewards = clone(self.rewardItemList)
  490. if self:IsNewMap() then
  491. --LogError("========Open==UIBattleBossBox========")
  492. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIBattleBossBox)
  493. else
  494. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIBattleWin,rewards)
  495. end
  496. else
  497. -- LogError("----------------OnBattleIncomeAck---- " .. playerBossRewardAck.error)
  498. self:ClearRageTimer()
  499. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_BATTLE_FAILED);
  500. end
  501. end
  502. function LuaBattleMgr:OnBattleDataChangeNtf(data)
  503. local curlevelMode = data.map_mode
  504. local isshow = false
  505. if curlevelMode ~= nil then
  506. isshow = self.difficulty ~= curlevelMode
  507. if isshow then
  508. LogError("-----------切换模式--------")
  509. self.difficulty = curlevelMode
  510. self.lastMapMode = self.difficulty
  511. end
  512. end
  513. --isshow = self.difficulty ~= self.lastMapMode
  514. self:OnBattleDataChange(data,isshow)
  515. end
  516. function LuaBattleMgr:OnBattleDataChange(data,IsShowEnterNextMap)
  517. self:SetBattleData(data,false,IsShowEnterNextMap)
  518. LogError("OnBattleDataChangeNtf -- " .. Inspect(data))
  519. -- LogError("self.lastInComeTime -- " .. self.lastInComeTime)
  520. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_REFRESH_REWARD_TIME);
  521. end
  522. function LuaBattleMgr:GetRewardMapCount()
  523. return self.lastMapRewardCount
  524. end
  525. -- 模擬數據
  526. function LuaBattleMgr:GetSimulationBattleData(mapId,mapLv)
  527. return {
  528. last_income_time = self.lastInComeTime,
  529. map_id = mapId,
  530. map_level = mapLv,
  531. max_income_time = 216000000,
  532. quick_battle = {
  533. day_times = self.usedQuickBattleTimes,
  534. draw_time = 1728939602,
  535. max_times = self.maxQuickBattleTimes
  536. },
  537. reward_map_count = self.mapRewardCount
  538. }
  539. end
  540. -- 設置苦難模式下配置
  541. function LuaBattleMgr:SetCurDifAttr()
  542. ManagerContainer.LuaGameMgr:ClearDifAttr()
  543. if self.difficulty == 1 or self.difficulty == 2 then
  544. --ManagerContainer.LuaGameMgr:AddDifAttr(7,100)
  545. local enemyAttrAddCfg = nil
  546. if self.difficulty == 1 then
  547. local curDiffID = self:GetCurDiffLvID()
  548. enemyAttrAddCfg = ManagerContainer.CfgMgr:GetLevelEnemyAttributeAdditionCfgById(curDiffID)
  549. else
  550. local curDiffID = self:GetCurDiff_S_LvID()
  551. enemyAttrAddCfg = ManagerContainer.CfgMgr:GetLevelEnemyAttributeAddition_S_CfgById(curDiffID)
  552. end
  553. local CurAttrAdd = enemyAttrAddCfg.AttrAdd
  554. for _, v in pairs(CurAttrAdd) do
  555. ManagerContainer.LuaGameMgr:AddDifAttr(v[1],v[2])
  556. end
  557. if enemyAttrAddCfg.NewLv > 0 then
  558. ManagerContainer.LuaGameMgr:AddDifAttr(-156,enemyAttrAddCfg.NewLv )
  559. end
  560. end
  561. end
  562. function LuaBattleMgr:SetBattleData(data,first,IsShowEnterNextMap)
  563. LogError("SetBattleData -- " .. Inspect(data))
  564. local preMapId = self.curMapId;
  565. self.lastLevelId = self.curLevelId
  566. self.lastMapId = self.curMapId
  567. self.lastInComeTime = data.last_income_time
  568. self.curMapId = data.map_id
  569. self.curLevelId = data.map_level
  570. if data.map_mode ~=nil then
  571. if self.difficulty == 0 then
  572. self.simpleLvData[1] = data.map_id
  573. self.simpleLvData[2] = data.map_level
  574. elseif self.difficulty == 1 then
  575. self.difficultyLvData[1] = data.map_id
  576. self.difficultyLvData[2] = data.map_level
  577. else
  578. self.difficulty_S_LvData[1] = data.map_id
  579. self.difficulty_S_LvData[2] = data.map_level
  580. end
  581. else
  582. self.simpleLvData[1] = data.map_id
  583. self.simpleLvData[2] = data.map_level
  584. self.difficultyLvData[1] = data.hard_map_id
  585. self.difficultyLvData[2] = data.hard_map_level
  586. self.difficulty_S_LvData[1] = data.hard_s_map_id
  587. self.difficulty_S_LvData[2] = data.hard_s_map_level
  588. end
  589. if first then
  590. CompetitionRefreshLevelLimit = GlobalConfig.Instance:GetConfigIntValue(248)
  591. ManagerContainer.UIFuncUnlockMgr:SetLoggedinLevelId(self:GetCurLevelUniqueId())
  592. end
  593. self.lastMapRewardCount = self.mapRewardCount
  594. self.mapRewardCount = data.reward_map_count
  595. local rewardIntervalTime = GlobalConfig.Instance:GetConfigIntValue(47)
  596. local passedTime = ManagerContainer.LuaGameMgr:CalcPassedTime(self.lastInComeTime) / 1000
  597. if passedTime >= self.maxInComeTime then
  598. passedTime = self.maxInComeTime
  599. end
  600. self.maxRewardNum = self.maxInComeTime / rewardIntervalTime
  601. self.rewardNum = CommonUtil.GetPreciseDecimal(math.floor(passedTime / rewardIntervalTime),0)
  602. self.leftRewardTime = rewardIntervalTime - (passedTime - self.rewardNum*rewardIntervalTime)
  603. if self.leftRewardTime <= 0 or self.leftRewardTime > rewardIntervalTime then
  604. self.leftRewardTime = rewardIntervalTime
  605. end
  606. if data.quick_battle ~= nil then
  607. if data.quick_battle.max_times ~= nil then
  608. self.maxQuickBattleTimes = data.quick_battle.max_times
  609. end
  610. if data.quick_battle.day_times ~= nil then
  611. self.usedQuickBattleTimes = data.quick_battle.day_times
  612. end
  613. end
  614. self:SetCurDifAttr()
  615. ManagerContainer.LuaGameMgr:SetMapLevelId(self.curMapId,self.curLevelId);
  616. if IsShowEnterNextMap or (preMapId > 0 and preMapId~= self.curMapId ) then
  617. if self.nextMapState == NextMapState.WaitServer then
  618. --LogError("==========nextMapState========")
  619. self:ShowEnterNextMap()
  620. return
  621. elseif IsShowEnterNextMap then
  622. --LogError("==========IsShowEnterNextMap========")
  623. self:EnterToTargetMap()
  624. return
  625. end
  626. --LogError("==========nextMapState==WaitShow======")
  627. self.nextMapState = NextMapState.WaitShow
  628. end
  629. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_LEVEL_CHANGED)
  630. end
  631. function LuaBattleMgr:IsNewMap()
  632. return self.curMapId > self.lastMapId
  633. end
  634. function LuaBattleMgr:StartSyncServerTimeTimer()
  635. if self.timerId ~= nil then
  636. return
  637. end
  638. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_GET_SERVER_TIME_ACK,self.OnUpdateServerTimeAck,self)
  639. self.timerId = ManagerContainer.LuaTimerMgr:AddTimer(60000, -1, self, self.SendGetServerTimeReq, nil)
  640. end
  641. function LuaBattleMgr:SendGetServerTimeReq()
  642. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_GET_SERVER_TIME_REQ, {})
  643. end
  644. function LuaBattleMgr:SetReconnected(result)
  645. reconnected = result
  646. end
  647. function LuaBattleMgr:OnUpdateServerTimeAck(timeAck)
  648. ManagerContainer.LuaTimerMgr:SyncServerTime(timeAck.server_time)
  649. --每分钟判断
  650. ManagerContainer.DataMgr.RankActivitiesMgr:CheckRancActivityOpenTime()
  651. ManagerContainer.DataMgr.RuneShopDataMgr:CheckAirShipActivityOpenTime()
  652. ManagerContainer.DataMgr.CompetitionData:UpdateCompetitionTime()
  653. ManagerContainer.DataMgr.ActsDataMgr:UpdateActsEndTime()
  654. if reconnected then
  655. reconnected = false
  656. self:RefreshRewardNum()
  657. end
  658. end
  659. function LuaBattleMgr:StopSyncServerTimeTimer()
  660. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_GET_SERVER_TIME_ACK)
  661. if self.timerId~= nil then
  662. ManagerContainer.LuaTimerMgr:RemoveTimer(self.timerId)
  663. self.timerId = nil
  664. end
  665. end
  666. --收益累积时长
  667. function LuaBattleMgr:AccumIncomeTime()
  668. local passedTime = ManagerContainer.LuaGameMgr:CalcPassedTime(self.lastInComeTime);
  669. return passedTime;
  670. end
  671. function LuaBattleMgr:MaxInComeTime()
  672. return self.maxInComeTime
  673. end
  674. function LuaBattleMgr:GetIncomeInfo()
  675. return self.leftRewardTime, self.rewardNum
  676. end
  677. function LuaBattleMgr:RefreshRewardNum()
  678. local rewardIntervalTime = GlobalConfig.Instance:GetConfigIntValue(47)
  679. local passedTime = ManagerContainer.LuaGameMgr:CalcPassedTime(self.lastInComeTime) / 1000
  680. if passedTime >= self.maxInComeTime then
  681. passedTime = self.maxInComeTime
  682. end
  683. self.rewardNum = CommonUtil.GetPreciseDecimal(math.floor(passedTime / rewardIntervalTime),0)
  684. self.leftRewardTime = rewardIntervalTime - (passedTime - self.rewardNum*rewardIntervalTime)
  685. if self.leftRewardTime <= 0 or self.leftRewardTime > rewardIntervalTime then
  686. self.leftRewardTime = rewardIntervalTime
  687. end
  688. end
  689. function LuaBattleMgr:OnRefreshRewardTime()
  690. self:RefreshRewardNum()
  691. --self.leftRewardTime = self.leftRewardTime - 1
  692. if self.leftRewardTime <= 0 then
  693. self.leftRewardTime = GlobalConfig.Instance:GetConfigIntValue(47)
  694. self.rewardNum = self.rewardNum + 1
  695. if self.rewardNum > self.maxRewardNum then
  696. self.rewardNum = self.maxRewardNum
  697. end
  698. end
  699. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_REFRESH_REWARD_TIME);
  700. end
  701. function LuaBattleMgr:StartAutoChallenge()
  702. if not self.isAutochallenge then
  703. return
  704. end
  705. local sec = GlobalConfig.Instance:GetConfigIntValue(311)
  706. if sec < 0 then
  707. sec = 0
  708. end
  709. if not self.autoChallengeTimer then
  710. self.autoChallengeTimer = Timer.New(function()
  711. self:AutoChallenge()
  712. end, sec, 1)
  713. else
  714. self.autoChallengeTimer:Reset(function()
  715. self:AutoChallenge()
  716. end, sec, 1)
  717. end
  718. if not self.autoChallengeTimer.running then
  719. self.autoChallengeTimer:Start()
  720. end
  721. end
  722. function LuaBattleMgr:AutoChallenge()
  723. if ManagerContainer.LuaUIMgr:HasOpenPage(Enum.UIPageName.UIBattle) then
  724. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_CHALLENGE_AUTO)
  725. end
  726. end
  727. function LuaBattleMgr:StopAutoChallenge(force)
  728. if self.autoChallengeTimer then
  729. self.autoChallengeTimer:Stop()
  730. self.autoChallengeTimer = nil
  731. end
  732. if self.isAutochallenge then
  733. self.isAutochallenge = false
  734. if force then
  735. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("stopautobattle")
  736. end
  737. end
  738. end
  739. function LuaBattleMgr:GetAutoChallengeState()
  740. return self.isAutochallenge
  741. end
  742. function LuaBattleMgr:SetAutoChallengeState(value)
  743. self.isAutochallenge = value
  744. end
  745. --boss出生
  746. function LuaBattleMgr:OnBossSpawned(bossActor,bossName,life,maxLife,skillParam,isPlayRecord)
  747. self.bKillBoss = true
  748. --boos 展示等级设置为当前关卡Turn
  749. if self.difficulty == Enum.MapModeType.Difficulty or self.difficulty == 2 then
  750. self:AddBuffToActor(bossActor,true)
  751. end
  752. local curLevel = ManagerContainer.LuaBattleMgr:GetCurLevelUniqueId()
  753. local levelData = ManagerContainer.CfgMgr:GetLevelDataById(curLevel)
  754. bossActor.ShowLevel = levelData.Turn
  755. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_BOSS_SPAWNED,bossActor,bossName,life,maxLife,skillParam,isPlayRecord)
  756. end
  757. function LuaBattleMgr:OnCloneNewBoss(bossName,life,maxLife,skillParam)
  758. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_CLONE_NEW_BOSS,bossName,life,maxLife,skillParam)
  759. end
  760. -- 开始战斗
  761. function LuaBattleMgr:OnFightingStart(killingBoss)
  762. --LogError("=======OnFightingStart===开始战斗=============")----------困難模式 加入Debug 屬性削減
  763. self.isBattling = true
  764. if killingBoss then
  765. --LogError("=======OnFightingStart===开始战斗=====killingBoss========")----------困難模式 加入Debug 屬性削減
  766. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_FIGHTING_START)
  767. -- if self.difficulty == Enum.MapModeType.Difficulty then
  768. -- self:OnBattleStartBoss()
  769. -- end
  770. end
  771. end
  772. function LuaBattleMgr:OnBattleStartBoss()
  773. ManagerContainer.LuaActorDataMgr:ResetData()
  774. local actorData = ManagerContainer.LuaActorDataMgr:GetActorData(true, ManagerContainer.DataMgr.UserData:GetId())
  775. if actorData then
  776. -- 加入buff
  777. self:AddBuffToActor(actorData)
  778. end
  779. local list = ManagerContainer.DataMgr.PartnerData:GetPartnerDatas()
  780. if list ~= nil then
  781. for _,v in pairs(list) do
  782. if v.owned and v.isBattle then
  783. actorData = ManagerContainer.LuaActorDataMgr:GetActorData(false, v.configId)
  784. if actorData then
  785. -- 加入buff
  786. self:AddBuffToActor(actorData)
  787. end
  788. end
  789. end
  790. end
  791. end
  792. function LuaBattleMgr:AddBuffToActor(actor,isboss)
  793. local buffCfgs = ManagerContainer.CfgMgr:GetLevelDifficultCfg()
  794. local dropBuffs = nil
  795. if isboss ~= nil and isboss then
  796. local buffeffects = nil
  797. if self.difficulty == Enum.MapModeType.Difficulty then
  798. buffeffects = ManagerContainer.CfgMgr:GetHardBossBuffCfgById(self:GetCurDiffLvID())
  799. elseif self.difficulty == 2 then
  800. buffeffects = ManagerContainer.CfgMgr:GetHardBossBuff_S_CfgById(self:GetCurDiff_S_LvID())
  801. end
  802. dropBuffs = self:CreatBuffs(buffCfgs,buffeffects)
  803. else
  804. dropBuffs = self:GetDropBuffs(buffCfgs)
  805. end
  806. if dropBuffs == nil or #dropBuffs == 0 then
  807. return
  808. end
  809. if dropBuffs ~= nil then
  810. local dropBuffParamList = System.Array.CreateInstance(Enum.TypeInfo.BuffParam, #dropBuffs)
  811. for j = 1, #dropBuffs do
  812. local buffParam = dropBuffs[j]
  813. dropBuffParamList[j-1] = BuffParam.New(buffParam.buffId, buffParam.buffRatio, buffParam.buffCd, buffParam.buffType,buffParam.extendPara,buffParam:ConvertFunToStr())
  814. --LogError(j.."======AddBuffToActor========"..Inspect(dropBuffParamList[j-1]))
  815. end
  816. actor:SetDropBuffs(dropBuffParamList)
  817. --actor:SetBuffs(dropBuffParamList)
  818. --LogError("======AddBuffToActor========"..Inspect(actor))
  819. end
  820. if not isboss and actor.HasPet then
  821. local petDropBuffs = self:GetDropBuffs(buffCfgs)
  822. if petDropBuffs ~= nil then
  823. local dropBuffParamList = System.Array.CreateInstance(Enum.TypeInfo.BuffParam, #petDropBuffs)
  824. for j = 1, #petDropBuffs do
  825. local buffParam = petDropBuffs[j]
  826. dropBuffParamList[j-1] = BuffParam.New(buffParam.buffId, buffParam.buffRatio, buffParam.buffCd, buffParam.buffType,buffParam.extendPara,buffParam:ConvertFunToStr())
  827. end
  828. actor.PetData:SetDropBuffs(dropBuffParamList)
  829. end
  830. end
  831. end
  832. function LuaBattleMgr:AddBuffToActor_New(actor,isboss,buffEffects)
  833. local buffCfgs = ManagerContainer.CfgMgr:GetLevelDifficultCfg()
  834. local dropBuffs = self:CreatBuffs(buffCfgs,buffEffects)
  835. if dropBuffs == nil or #dropBuffs == 0 then
  836. return
  837. end
  838. if dropBuffs ~= nil then
  839. local dropBuffParamList = System.Array.CreateInstance(Enum.TypeInfo.BuffParam, #dropBuffs)
  840. for j = 1, #dropBuffs do
  841. local buffParam = dropBuffs[j]
  842. dropBuffParamList[j-1] = BuffParam.New(buffParam.buffId, buffParam.buffRatio, buffParam.buffCd, buffParam.buffType,buffParam.extendPara,buffParam:ConvertFunToStr())
  843. --LogError(j.."======AddBuffToActor========"..Inspect(dropBuffParamList[j-1]))
  844. end
  845. actor:SetDropBuffs(dropBuffParamList)
  846. --LogError("======AddBuffToActor========"..Inspect(actor))
  847. end
  848. if not isboss and actor.HasPet then
  849. local petDropBuffs = self:GetDropBuffs(buffCfgs)
  850. if petDropBuffs ~= nil then
  851. local dropBuffParamList = System.Array.CreateInstance(Enum.TypeInfo.BuffParam, #petDropBuffs)
  852. for j = 1, #petDropBuffs do
  853. local buffParam = petDropBuffs[j]
  854. dropBuffParamList[j-1] = BuffParam.New(buffParam.buffId, buffParam.buffRatio, buffParam.buffCd, buffParam.buffType,buffParam.extendPara,buffParam:ConvertFunToStr())
  855. end
  856. actor.PetData:SetDropBuffs(dropBuffParamList)
  857. end
  858. end
  859. end
  860. function LuaBattleMgr:GetDropBuffs(buffCfgs)
  861. local bufflist ={}
  862. if buffCfgs == nil then
  863. return bufflist
  864. end
  865. local debuffcfg = self:GetCurLeveDebuffCfg()
  866. for i = 1, #buffCfgs, 1 do
  867. local buffCfg = buffCfgs[i]-- 获取buff配置
  868. if buffCfg ~= nil then
  869. local funlist = {{buffCfg.Function[1][1],debuffcfg[buffCfg.Effect][2],buffCfg.Function[1][3]}}
  870. local buff = ExpeditionBuff:new(buffCfg.BuffId,buffCfg.Ratio,buffCfg.CD,buffCfg.ConditionType,buffCfg.ExtendPara,funlist)
  871. bufflist[#bufflist+1] = buff
  872. end
  873. end
  874. return bufflist
  875. end
  876. function LuaBattleMgr:CreatBuffs(buffCfgs,buffEffects)
  877. local bufflist = {}
  878. if buffCfgs == nil or buffEffects == nil then
  879. return bufflist
  880. end
  881. for _, v in pairs(buffEffects.buffEffect) do
  882. local buffCfg = buffCfgs[v[1]]-- 获取buff配置
  883. if buffCfg ~= nil then
  884. local funlist = {}
  885. for _, buffFun in pairs(buffCfg.Function) do
  886. local fun = {buffFun[1],v[2],buffFun[3]}
  887. funlist[#funlist +1] = fun
  888. end
  889. --LogError("FunList = "..Inspect(funlist))
  890. local buff = ExpeditionBuff:new(buffCfg.BuffId,buffCfg.Ratio,buffCfg.CD,buffCfg.ConditionType,buffCfg.ExtendPara,funlist)
  891. bufflist[#bufflist+1] = buff
  892. end
  893. end
  894. return bufflist
  895. end
  896. function LuaBattleMgr:GetCurLeveDebuffCfg()
  897. local id = self:GetCurDiffLvID()
  898. local debuffcfg = ManagerContainer.CfgMgr:GetLevelDebuffCfgById(id)
  899. if debuffcfg == nil then
  900. return {{1,-20},{2,-20},{3,-30}}
  901. end
  902. return debuffcfg.debuffs
  903. end
  904. --清空战斗统计日志
  905. function LuaBattleMgr:ClearBattleLog()
  906. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_CLEAR_New_BattleLog)
  907. end
  908. function LuaBattleMgr:GetFightState()
  909. return self.isBattling
  910. end
  911. function LuaBattleMgr:GetBossFightState()
  912. return self.bKillBoss
  913. end
  914. -- 战斗胜利
  915. function LuaBattleMgr:OnBattleWin(killboss, killBossTime, mapId, levelId, isPlayRecord, recordTimeStamp)
  916. self:CloseBattleStatistics()
  917. self.isBattling = false
  918. if killboss then
  919. self.bKillBoss = false
  920. if not isPlayRecord then -- and self.difficulty == 0
  921. if self.curMapId == mapId and self.curLevelId == levelId then
  922. self:SendBossRewardReq(killBossTime,recordTimeStamp)
  923. else
  924. LogError('[wboy] curMapId : ' .. tostring(self.curMapId) .. ' curMapId : ' .. tostring(self.curLevelId) .. ' mapId : ' .. tostring(mapId) .. ' levelId : ' .. tostring(levelId))
  925. end
  926. battleStateTimer = ManagerContainer.LuaTimerMgr:AddTimer(5000, 1,self,self.BattleStateRefresh,nil);
  927. end
  928. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UI_BATTLE_NORMAL_NTF)
  929. local levelId = self:GetCurLevelUniqueId()
  930. if levelId >= CompetitionRefreshLevelLimit then
  931. ManagerContainer.DataMgr.CompetitionData:SetRefreshSeasonState(true)
  932. ManagerContainer.DataMgr.CompetitionData:QueryCurCompetitionReq(true)
  933. end
  934. ManagerContainer.DataMgr.RankActivitiesMgr:QueryCurRankActivityData(Enum.RankActivitiesType.MapProgress)
  935. end
  936. self:ClearRageTimer()
  937. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_BATTLE_WIN);
  938. end
  939. function LuaBattleMgr:BattleStateRefresh()
  940. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.GOT_ANIM_TYPE_END_NOTIFY, Enum.ItemIEnterType.BattleWin)
  941. end
  942. --战斗失败
  943. function LuaBattleMgr:OnBattleFailed(killboss,isPlayRecord)
  944. self:CloseBattleStatistics()
  945. self.isBattling = false
  946. self.bKillBoss = false
  947. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UI_BATTLE_NORMAL_NTF)
  948. self:ClearRageTimer()
  949. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_BATTLE_FAILED,killboss,isPlayRecord);
  950. self:StopAutoChallenge(true)
  951. end
  952. --强制巡游战斗失败
  953. function LuaBattleMgr:OnForceBattleFailed(killboss,isPlayRecord)
  954. self:CloseBattleStatistics()
  955. self.isBattling = false
  956. self.bKillBoss = false
  957. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UI_BATTLE_NORMAL_NTF)
  958. self:ClearRageTimer()
  959. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_FORCEBATTLE_FAILED,killboss,isPlayRecord);
  960. end
  961. function LuaBattleMgr:CloseBattleStatistics()
  962. if self.bKillBoss then
  963. ManagerContainer.LuaUIMgr:ClosePage(Enum.UIPageName.UIBattleStatistics)
  964. ManagerContainer.LuaUIMgr:ClosePage(Enum.UIPageName.UIBattleBossTips)
  965. end
  966. end
  967. function LuaBattleMgr:ShowErrorQuitBattleMsgBox()
  968. ManagerContainer.LuaUIMgr:ShowOkMessageBox("ErrorQuitBattleTip",self.QuitBattleMsgOk)
  969. end
  970. function LuaBattleMgr:QuitBattleMsgOk()
  971. LuaBattleBridge.SkipReplay()
  972. end
  973. function LuaBattleMgr:CloseErrorQuitBattleMsgBox()
  974. ManagerContainer.LuaUIMgr:CloseOkMessageBox("ErrorQuitBattleTip")
  975. end
  976. function LuaBattleMgr:ShowAntiCheatMsgBox(nType)
  977. --上报使用外挂
  978. self:SendAntiCheat(nType)
  979. ManagerContainer.LuaUIMgr:ShowOkMessageBox("AntiCheatMsg",self.AntiCheatQuitGameMsgOk)
  980. end
  981. function LuaBattleMgr:SendAntiCheat(nType)
  982. --上报使用外挂
  983. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_ANTI_CHEAT_REQ, { cheat_type = nType})
  984. end
  985. function LuaBattleMgr:AntiCheatQuitGameMsgOk()
  986. ManagerContainer.NetManager:ResetNetMgr()
  987. ManagerContainer.LuaGameMgr:QuitGame()
  988. end
  989. function LuaBattleMgr:CloseAntiCheatMsgBox()
  990. ManagerContainer.LuaUIMgr:CloseOkMessageBox("AntiCheatMsg")
  991. end
  992. function LuaBattleMgr:GetCurSimpleLvID()
  993. return self.simpleLvData[1]*10000 + self.simpleLvData[2]
  994. end
  995. function LuaBattleMgr:GetCurDiffLvID()
  996. return self.difficultyLvData[1]*10000 + self.difficultyLvData[2]
  997. end
  998. function LuaBattleMgr:GetCurDiff_S_LvID()
  999. return self.difficulty_S_LvData[1]*10000 + self.difficulty_S_LvData[2]
  1000. end
  1001. function LuaBattleMgr:GetCurLevelUniqueId()
  1002. return self.curMapId*10000 + self.curLevelId
  1003. end
  1004. function LuaBattleMgr:GetLastLevelUniqueId()
  1005. return self.lastMapId*10000 + self.lastLevelId
  1006. end
  1007. function LuaBattleMgr:GetLastMapIdAndLvId()
  1008. return self.lastMapId,self.lastLevelId
  1009. end
  1010. --下一关卡
  1011. function LuaBattleMgr:OnBattleNewWave(levelName)
  1012. self.nextMapState = NextMapState.None
  1013. -- if ManagerContainer.UIFuncUnlockMgr:NeedOpenFuncCurLevelStart(self:GetCurLevelUniqueId()) then
  1014. -- --功能解锁
  1015. -- ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UI_FUNCLOCK_OPEN_NTF)
  1016. -- ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UI_BATTLE_FUNC_OPEN_NTF);
  1017. -- else
  1018. -- self.closeLevelNameTimer = ManagerContainer.LuaTimerMgr:AddTimer(GlobalConfig.Instance:GetConfigFloatValue(79)*1000, 1,self,self.OnCloseLevelName,nil);
  1019. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_NEXT_BATTLE,levelName);
  1020. -- end
  1021. end
  1022. function LuaBattleMgr:OnCloseLevelName()
  1023. self.closeLevelNameTimer = nil;
  1024. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_HIDE_LEVEL_NAME);
  1025. end
  1026. --继续同一关战斗
  1027. function LuaBattleMgr:OnContinueBattle()
  1028. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_CONTINUE_BATTLE);
  1029. ----如果还是处于第一关 且 强制引导战斗没成功 则继续强制引导战斗
  1030. --local curLevelId = self:GetCurLevelUniqueId()
  1031. --if curLevelId == 10001 then
  1032. -- ManagerContainer.ForceGuideMgr:GuideBossBattle()
  1033. --end
  1034. end
  1035. function LuaBattleMgr:OnShowBossRage(vis)
  1036. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_SHOW_BOSS_RAGE)
  1037. end
  1038. --狂暴剩余时间
  1039. function LuaBattleMgr:OnShowBossRageLeftTime(leftTime)
  1040. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_SHOW_BOSS_RAGE_LEFTTIME,leftTime);
  1041. end
  1042. --boss进入狂暴
  1043. function LuaBattleMgr:OnBossInRage()
  1044. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_BOSS_IN_RAGE);
  1045. end
  1046. function LuaBattleMgr:OnBattleStartStory(levelId, storyId)
  1047. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UISTORY_CONDITION_TRIGGER, Enum.UIStoryCondType.FirstSceneEnter, levelId, storyId)
  1048. end
  1049. --战斗结束
  1050. function LuaBattleMgr:OnBattleEnd(killBoss,killBossTime,win,isPlayRecord)
  1051. self.lastLevelZeny = self:CurLevelZeny()
  1052. self.lastLevelExp = self:CurLevelExp()
  1053. self.lastLevelPartnerExp = self:CurLevelParnterExp()
  1054. self.lastLevelCruise = self:CurLevelCruise()
  1055. if killBoss then
  1056. --self.bKillBoss = false
  1057. if not isPlayRecord then
  1058. --ManagerContainer.DataMgr.BigMapData:SendGetData()
  1059. end
  1060. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_BOSS_Battle_End,isPlayRecord)
  1061. self:OnBattleUIVis(true)
  1062. end
  1063. end
  1064. ------------------战斗录像相关----------------------------------------
  1065. function LuaBattleMgr:SendBattleDetailReq(battleRecordUid,battleTime,fightPower)
  1066. self.curReqBattleRecordId = battleRecordUid
  1067. self.cacheRecordBattleTime = battleTime
  1068. self.cacheRecordFightPower = fightPower
  1069. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_PLAYER_BATTLE_RECORD_DETAIL_REQ, {battle_record_uid = battleRecordUid})
  1070. end
  1071. function LuaBattleMgr:OnBattleRecordDetailAck(pkg)
  1072. -- LogError(Inspect(pkg))
  1073. if pkg.error == 0 then
  1074. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Fetch_BattleRecord_Success,pkg.battle_record_uid,pkg.battle_record)
  1075. ManagerContainer.LuaGameMgr:SetGameSpeed(ManagerContainer.LuaGameMgr.GameSpeed)
  1076. self:StopAutoChallenge(true)
  1077. end
  1078. end
  1079. function LuaBattleMgr:GetCacheRecordInfo()
  1080. return self.cacheRecordBattleTime, self.cacheRecordFightPower
  1081. end
  1082. function LuaBattleMgr:OnBattleRecordDetalSaveNtf(pkg)
  1083. --LogError("OnBattleRecordDetalSaveNtf Save")
  1084. local battleRecordUid = pkg.battle_record_uid
  1085. local battleTimeStamp = pkg.record_time_stamp
  1086. local battleRecordStr = LuaBattleBridge.GetBattleRecord(battleTimeStamp)
  1087. if battleRecordStr ~= nil and battleRecordStr~="" then
  1088. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_PLAYER_BATTLE_RECORD_DETAIL_SAVE_REQ, {battle_record_uid = battleRecordUid, battle_record = battleRecordStr})
  1089. end
  1090. end
  1091. function LuaBattleMgr:OnBattleRecordAck(pkg)
  1092. if pkg.error == 0 then
  1093. if #pkg.record_list > 0 then
  1094. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIBattleReplay,pkg.record_list)
  1095. else
  1096. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("NullBattleReport")
  1097. end
  1098. end
  1099. end
  1100. -------------------------------------------------------------------------
  1101. function LuaBattleMgr:OnReplayEnd()
  1102. self:CloseBattleStatistics()
  1103. self.isBattling = false
  1104. self.bKillBoss = false
  1105. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UI_BATTLE_NORMAL_NTF)
  1106. self:ClearRageTimer()
  1107. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_BATTLE_WIN);
  1108. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIDojoExit,true)
  1109. end
  1110. function LuaBattleMgr:GetBossFightStatus()
  1111. return self.bKillBoss
  1112. end
  1113. function LuaBattleMgr:ClearRageTimer()
  1114. if self.rageLeftTimeTimer ~= nil then
  1115. ManagerContainer.LuaTimerMgr:RemoveTimer(self.rageLeftTimeTimer);
  1116. self.rageLeftTimeTimer = nil;
  1117. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_BOSS_IN_RAGE);
  1118. end
  1119. end
  1120. --bIsForce 强制结束战斗 设置属性
  1121. function LuaBattleMgr:SetTeamData(ignore,bIsForce)
  1122. local teamData = ManagerContainer.DataMgr.UserData:GetTeamData(ignore);
  1123. if teamData == nil then return end
  1124. ManagerContainer.LuaGameMgr:SetTeamData(teamData,{bIsForce})
  1125. ManagerContainer.LuaActorAttributeMgr:SyncServerActorDataToLocal()
  1126. end
  1127. --更新技能数据
  1128. function LuaBattleMgr:UpdateTeamSkills()
  1129. local usersSkills = {}
  1130. local heroId = ManagerContainer.DataMgr.UserData:GetId()
  1131. local skillData = ManagerContainer.DataMgr.UserData:GetSkillData(heroId)
  1132. local skills = skillData and skillData:GetUsedSkills() or {}
  1133. local heroData = CommonUtil.GetHeroLogicDataByUid(1)
  1134. CommonUtil.ReplaceBattleSkillBySkillEquip(heroData, skills)
  1135. usersSkills[#usersSkills+1] = {
  1136. uid = heroId,
  1137. skills = skills,
  1138. }
  1139. local list = ManagerContainer.DataMgr.PartnerData:GetBattlePartnerDatas(true)
  1140. if list ~= nil then
  1141. for _,v in pairs(list) do
  1142. skillData = ManagerContainer.DataMgr.UserData:GetSkillData(v.uid)
  1143. local skills = skillData and skillData:GetUsedSkills() or {}
  1144. CommonUtil.ReplaceBattleSkillBySkillEquip(v, skills)
  1145. usersSkills[#usersSkills + 1] = {uid = v.uid, skills = skills }
  1146. end
  1147. end
  1148. ManagerContainer.LuaGameMgr:UpdateTeamSkills(usersSkills);
  1149. end
  1150. function LuaBattleMgr:NotifyEnterNextMapStart()
  1151. if self.nextMapState == NextMapState.WaitShow then
  1152. LogError("========nextMapState=WaitShow=======")
  1153. self:ShowEnterNextMap()
  1154. return
  1155. end
  1156. self.nextMapState = NextMapState.WaitServer
  1157. end
  1158. function LuaBattleMgr:NotifyEnterNextMapEnd()
  1159. if ManagerContainer.FSMMgr:IsBattleState() then
  1160. -- 在战斗场景中,才走大地图过图效果
  1161. self:OnEnterNextMap()
  1162. end
  1163. end
  1164. function LuaBattleMgr:NotifyVipLvChanged()
  1165. self.maxInComeTime = GlobalConfig.Instance:GetConfigIntValue(48)
  1166. self.maxQuickBattleTimes = GlobalConfig.Instance:GetConfigIntValue(240)
  1167. local vipLv = ManagerContainer.DataMgr.UserData:GetVipLv()
  1168. local vipCfg = ManagerContainer.CfgMgr:GetVipCfgById(vipLv)
  1169. if vipCfg then
  1170. self.maxInComeTime = self.maxInComeTime + tonumber(vipCfg.HangupDuration)
  1171. self.maxQuickBattleTimes = self.maxQuickBattleTimes + tonumber(vipCfg.HangupTimes)
  1172. end
  1173. end
  1174. function LuaBattleMgr:ShowEnterNextMap()
  1175. if ManagerContainer.FSMMgr:IsBattleState() then
  1176. -- 在战斗场景中,才走大地图过图效果
  1177. --LogError("========ShowEnterNextMap========")
  1178. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIWorldMap, true)
  1179. end
  1180. end
  1181. function LuaBattleMgr:EnterToTargetMap()
  1182. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIWorldMap, true)
  1183. end
  1184. function LuaBattleMgr:OnLoadingClose()
  1185. self.IsShowDiffTxt = false
  1186. --LogError("-----------OnLoadingClose--------------")
  1187. if self.difficulty == Enum.MapModeType.Difficulty or self.difficulty == 2 then
  1188. self.IsShowDiffTxt = true
  1189. ManagerContainer.LuaTimerMgr:AddTimer(500, 1,self,function ()
  1190. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("DifNtfTxt")
  1191. end,nil);
  1192. --elseif self.difficulty == 2 then
  1193. else
  1194. local cfg = ManagerContainer.CfgMgr:GetPrivilegeCardCfgByLv(2)
  1195. local curmaplvID = self:GetCurLevelUniqueId()
  1196. if cfg and cfg.UnlockCond and cfg.UnlockCond[2] == curmaplvID then
  1197. ManagerContainer.LuaTimerMgr:AddTimer(500, 1,self,function ()
  1198. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopBT)
  1199. --Notice_TeQuanKa
  1200. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("Notice_TeQuanKa")
  1201. end,nil);
  1202. end
  1203. end
  1204. --if
  1205. end
  1206. function LuaBattleMgr:IsShowDifficultyTxt()
  1207. return (self.difficulty == Enum.MapModeType.Difficulty or self.difficulty == 2) and self.IsShowDiffTxt
  1208. end
  1209. -- 创建主角形象
  1210. function LuaBattleMgr:CreateRoleView()
  1211. if self.roleViewSystem then
  1212. local userData = ManagerContainer.DataMgr.UserData
  1213. local heroData = userData:GetMainRoleData()
  1214. self.roleViewSystem:RefreshView(Enum.RoleInEnvType.Battle, userData:GetUserRoleId(), userData:GetViewData(), nil, self, self.CreateRoleViewComplete)
  1215. end
  1216. end
  1217. -- 完成主角创建
  1218. function LuaBattleMgr:CreateRoleViewComplete(gameObject)
  1219. ManagerContainer.LuaGameMgr:CreateRoleViewComplete(gameObject)
  1220. end
  1221. -- 通知战斗需要更新主角新形象
  1222. function LuaBattleMgr:NotifyRefreshRoleView()
  1223. self.waitingRefreshRole = true
  1224. ManagerContainer.LuaGameMgr:NotifyRefreshRoleView()
  1225. end
  1226. function LuaBattleMgr:GetWaitingRefreshRoleState()
  1227. return self.waitingRefreshRole == true
  1228. end
  1229. -- 刷新主角形象
  1230. function LuaBattleMgr:RefreshRoleView()
  1231. if self.roleViewSystem then
  1232. local userData = ManagerContainer.DataMgr.UserData
  1233. local heroData = userData:GetMainRoleData()
  1234. self.roleViewSystem:RefreshView(Enum.RoleInEnvType.Battle, userData:GetUserRoleId(), userData:GetViewData(), nil, self, self.RefreshRoleViewComplete)
  1235. end
  1236. end
  1237. -- 完成主角形象更新
  1238. function LuaBattleMgr:RefreshRoleViewComplete(gameObject, isNewModel)
  1239. self.waitingRefreshRole = false
  1240. ManagerContainer.LuaGameMgr:RefreshRoleViewComplete(gameObject, isNewModel)
  1241. self:NotifyLoadingStatusEnd(Enum.BattleBtnState.RoleModel)
  1242. end
  1243. function LuaBattleMgr:RecycleRoleView()
  1244. if self.roleViewSystem then
  1245. self.roleViewSystem:Recycle()
  1246. end
  1247. end
  1248. -- function LuaBattleMgr:NotifyRefreshUpRoleLvEffect()
  1249. -- self:NotifyRefreshUpLvEffect('Common/FX_Scene_LV_UP')
  1250. -- end
  1251. -- function LuaBattleMgr:NotifyRefreshUpJobLvEffect()
  1252. -- self:NotifyRefreshUpLvEffect('Common/FX_Scene_LV_UP')
  1253. -- end
  1254. -- function LuaBattleMgr:NotifyRefreshUpLvEffect(effectName)
  1255. -- if not self.roleViewSystem then return end
  1256. -- local roleGo = self.roleViewSystem:GetGameObject()
  1257. -- if tolua.isnull(roleGo) then return end
  1258. -- local timeStamp = Time.GetTimestamp()
  1259. -- if not self.upLvEffectCDs then
  1260. -- self.upLvEffectCDs = {}
  1261. -- end
  1262. -- local upLvEffectCD = self.upLvEffectCDs[effectName] or (timeStamp - 2)
  1263. -- -- 1秒内不出现两次升级特效
  1264. -- if timeStamp - upLvEffectCD <= 1 then
  1265. -- return
  1266. -- end
  1267. -- self.upLvEffectCDs[effectName] = timeStamp
  1268. -- ManagerContainer.ResMgr:GetGOFromPool(Constants.EffectPath, effectName, function(go)
  1269. -- if ManagerContainer.FSMMgr:IsBattleState() then
  1270. -- self:UpLvEffectShow(go, effectName)
  1271. -- end
  1272. -- end)
  1273. -- end
  1274. -- --- 显示升级特效
  1275. -- function LuaBattleMgr:UpLvEffectShow(go, effectName)
  1276. -- if not go then return end
  1277. -- if self.roleViewSystem then
  1278. -- local roleGo = self.roleViewSystem:GetGameObject()
  1279. -- if not tolua.isnull(roleGo) then
  1280. -- local link = roleGo.transform:Find('foot_point')
  1281. -- if not tolua.isnull(link) then
  1282. -- go.transform.parent = link
  1283. -- go.transform.localPosition = Vector3.zero
  1284. -- go.transform.localRotation = Quaternion.identity
  1285. -- go.transform.localScale = Vector3.one
  1286. -- local upLvEffects = self.upLvEffects
  1287. -- if not upLvEffects then
  1288. -- upLvEffects = {}
  1289. -- self.upLvEffects = upLvEffects
  1290. -- end
  1291. -- local info = {}
  1292. -- info.effectName = effectName
  1293. -- info.timerId = ManagerContainer.LuaTimerMgr:AddTimer(2000, 1, self, self.UpLvEffectHide, {go = go})
  1294. -- upLvEffects[go] = info
  1295. -- return
  1296. -- end
  1297. -- LogError('Link Point : foot_point is not Find')
  1298. -- end
  1299. -- end
  1300. -- -- 出现问题,直接回收掉效果,直接回收掉升级特效
  1301. -- ManagerContainer.ResMgr:RecycleGO(Constants.EffectPath, effectCfg.Effect, go)
  1302. -- end
  1303. -- --- 升级特效播放完成,需要回收掉
  1304. -- function LuaBattleMgr:UpLvEffectHide(timerId, params)
  1305. -- local go = params.go
  1306. -- if not go then return end
  1307. -- local upLvEffects = self.upLvEffects
  1308. -- if not upLvEffects then return end
  1309. -- local info = upLvEffects[go]
  1310. -- local timeId = info.timerId
  1311. -- local effectName = info.effectName
  1312. -- if timeId ~= timerId then
  1313. -- LogError('timeId is error, cur : ' .. tostring(timeId) .. ' cbTimerId : ' .. tostring(timerId))
  1314. -- end
  1315. -- if timeId then
  1316. -- ManagerContainer.LuaTimerMgr:RemoveTimer(timeId)
  1317. -- timeId = nil
  1318. -- end
  1319. -- upLvEffects[go] = nil
  1320. -- ManagerContainer.ResMgr:RecycleGO(Constants.EffectPath, effectName, go)
  1321. -- end
  1322. -- --- 回收所有显示的升级特效
  1323. -- function LuaBattleMgr:RecycleUpLvEffect()
  1324. -- local upLvEffects = self.upLvEffects
  1325. -- if not upLvEffects then return end
  1326. -- for go, info in pairs(upLvEffects) do
  1327. -- local timeId = info.timerId
  1328. -- local effectName = info.effectName
  1329. -- if timeId then
  1330. -- ManagerContainer.LuaTimerMgr:RemoveTimer(timeId)
  1331. -- timeId = nil
  1332. -- end
  1333. -- ManagerContainer.ResMgr:RecycleGO(Constants.EffectPath, effectName, go)
  1334. -- end
  1335. -- self.upLvEffects = nil
  1336. -- self.upLvEffectCDs = nil
  1337. -- end
  1338. function LuaBattleMgr:OnShowBossWarning()
  1339. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_SHOW_BOSS_WARNING,true);
  1340. ManagerContainer.LuaTimerMgr:AddTimer(3000, 1,self,self.OnHideBossWarningTimer,nil);
  1341. end
  1342. function LuaBattleMgr:OnHideBossWarningTimer()
  1343. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_SHOW_BOSS_WARNING,false);
  1344. end
  1345. function LuaBattleMgr:OnEnterNextMap()
  1346. self.bKillBoss = false
  1347. self.nextMapState = NextMapState.None
  1348. ManagerContainer.LuaGameMgr:OpenLoading(Enum.UIPageName.UILoading)
  1349. ManagerContainer.FSMMgr:ChangeState(Enum.StateEnum.LoadingState.stateId, SceneType.NormalBattleScene)
  1350. end
  1351. function LuaBattleMgr:CurLevelExp()
  1352. return LuaBattleBridge.GetCurLevelExp();
  1353. end
  1354. function LuaBattleMgr:CurLevelParnterExp()
  1355. return LuaBattleBridge.GetCurLevelParnterExp();
  1356. end
  1357. function LuaBattleMgr:CurLevelGold()
  1358. return LuaBattleBridge.GetCurLevelGold();
  1359. end
  1360. function LuaBattleMgr:CurLevelCruise()
  1361. return LuaBattleBridge.GetCurLevelCruise();
  1362. end
  1363. function LuaBattleMgr:CurLevelEvil()
  1364. return LuaBattleBridge.GetCurLevelEvil()
  1365. end
  1366. function LuaBattleMgr:CurLevelZeny()
  1367. return LuaBattleBridge.GetCurLevelZeny()
  1368. end
  1369. function LuaBattleMgr:CurLevelName()
  1370. --local lvname = LuaBattleBridge.GetCurLevelName() --DifLvName
  1371. local mapcfg = ManagerContainer.CfgMgr:GetMapData(self.curMapId)
  1372. local lvname = mapcfg.Name .. self.curLevelId
  1373. if self.IsShowDiffTxt then
  1374. local key = self:CurLevelQianZhuiKey()
  1375. if key ~= "" then
  1376. lvname = I18N.T(key)..lvname
  1377. end
  1378. end
  1379. return lvname
  1380. end
  1381. function LuaBattleMgr:CurLevelQianZhuiKey()
  1382. if self.difficulty == 1 then
  1383. return "DifLvName"
  1384. elseif self.difficulty == 2 then
  1385. return "Dif_S_LvName"
  1386. else
  1387. return ""
  1388. end
  1389. end
  1390. ----- 配置
  1391. function LuaBattleMgr:GetCurSimpleLvCfg ()
  1392. local lvID = self:GetCurSimpleLvID()
  1393. if self.curSimpleLvCgf == nil or self.curSimpleLvCgf.Id ~= lvID then
  1394. self.curSimpleLvCgf = ManagerContainer.CfgMgr:GetLevelDataById(lvID)
  1395. end
  1396. return self.curSimpleLvCgf
  1397. end
  1398. function LuaBattleMgr:CurSimpleLevelExp()
  1399. local lvDataCfg = self:GetCurSimpleLvCfg()
  1400. return lvDataCfg.BaseExpOl / 4
  1401. end
  1402. function LuaBattleMgr:CurSimpleLevelParnterExp()
  1403. local lvDataCfg = self:GetCurSimpleLvCfg()
  1404. return lvDataCfg.ParterOl / 4
  1405. end
  1406. function LuaBattleMgr:CurSimpleLevelGold()
  1407. local lvDataCfg = self:GetCurSimpleLvCfg()
  1408. return lvDataCfg.GoldOl / 4
  1409. end
  1410. function LuaBattleMgr:CurSimpleLevelCruise()
  1411. local lvDataCfg = self:GetCurSimpleLvCfg()
  1412. return lvDataCfg.CruiseOl / 4
  1413. end
  1414. function LuaBattleMgr:CurSimpleLevelEvil()
  1415. local lvDataCfg = self:GetCurSimpleLvCfg()
  1416. return lvDataCfg.EvilOl / 4
  1417. end
  1418. function LuaBattleMgr:CurSimpleLevelZeny()
  1419. local lvDataCfg = self:GetCurSimpleLvCfg()
  1420. return lvDataCfg.ZenyOl / 4
  1421. end
  1422. function LuaBattleMgr:CurSimpleLevelName()
  1423. local lvDataCfg = self:GetCurSimpleLvCfg()
  1424. return lvDataCfg.Name
  1425. end
  1426. -- 配置 end
  1427. function LuaBattleMgr:SetRewardDropPos(dropPos)
  1428. LuaBattleBridge.SetRewardDropPos(dropPos)
  1429. end
  1430. function LuaBattleMgr:Enter()
  1431. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.ROLE_JOB_CHANGE_SUCCESS, self, self.NotifyRefreshRoleView)
  1432. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.FASHION_WEAR_CHANGE, self, self.NotifyRefreshRoleView)
  1433. -- ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.ROLE_LV_CHANGED, self, self.NotifyRefreshUpRoleLvEffect)
  1434. -- ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.JOB_LV_CHANGED, self, self.NotifyRefreshUpJobLvEffect)
  1435. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.BIGMAP_ENTER_NEXTMAP_START, self, self.NotifyEnterNextMapStart)
  1436. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.BIGMAP_ENTER_NEXTMAP_END, self, self.NotifyEnterNextMapEnd)
  1437. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.VIP_LV_CHANGED, self, self.NotifyVipLvChanged)
  1438. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.EID_Loading_Close, self, self.OnLoadingClose)
  1439. self:NotifyVipLvChanged()
  1440. self.bKillBoss = false
  1441. --ManagerContainer.DataMgr.BigMapData:SendGetData()
  1442. self:StartSyncServerTimeTimer()
  1443. if self.rewardTimeTimerId == nil then
  1444. self.rewardTimeTimerId = ManagerContainer.LuaTimerMgr:AddTimer(1000, -1, self, self.OnRefreshRewardTime, nil)
  1445. end
  1446. local mainActor = ManagerContainer.LuaActorDataMgr:GetHeroActorData(1)
  1447. if mainActor ~= nil then
  1448. mainActor.Name = ManagerContainer.DataMgr.UserData:GetUserNickname()
  1449. end
  1450. self.isAutochallenge = false
  1451. end
  1452. function LuaBattleMgr:Exit()
  1453. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.ROLE_JOB_CHANGE_SUCCESS, self, self.NotifyRefreshRoleView)
  1454. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.FASHION_WEAR_CHANGE, self, self.NotifyRefreshRoleView)
  1455. -- ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.ROLE_LV_CHANGED, self, self.NotifyRefreshUpRoleLvEffect)
  1456. -- ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.JOB_LV_CHANGED, self, self.NotifyRefreshUpJobLvEffect)
  1457. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.BIGMAP_ENTER_NEXTMAP_START, self, self.NotifyEnterNextMapStart)
  1458. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.BIGMAP_ENTER_NEXTMAP_END, self, self.NotifyEnterNextMapEnd)
  1459. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.VIP_LV_CHANGED, self, self.NotifyVipLvChanged)
  1460. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.EID_Loading_Close, self, self.OnLoadingClose)
  1461. -- ManagerContainer.LuaBattleMgr:RecycleUpLvEffect()
  1462. ManagerContainer.LuaBattleMgr:RecycleRoleView()
  1463. if self.rewardTimeTimerId~= nil then
  1464. ManagerContainer.LuaTimerMgr:RemoveTimer(self.rewardTimeTimerId)
  1465. self.rewardTimeTimerId = nil
  1466. end
  1467. self.isAutochallenge = false
  1468. end
  1469. function LuaBattleMgr:SendBattleRecordReq()
  1470. ManagerContainer.LuaGameMgr:SendBattleRecordReq(100,{self.curMapId,self.curLevelId})
  1471. end
  1472. function LuaBattleMgr:GetFightersPos()
  1473. return LuaBattleBridge.GetFightersPos();
  1474. end
  1475. function LuaBattleMgr:GetCurMapId()
  1476. return self.curMapId
  1477. end
  1478. function LuaBattleMgr:GetCurMapAndLevel()
  1479. return self.curMapId, self.curLevelId
  1480. end
  1481. function LuaBattleMgr:MaxQuickBattleTimes()
  1482. return self.maxQuickBattleTimes
  1483. end
  1484. function LuaBattleMgr:UsedQuickBattleTimes()
  1485. return self.usedQuickBattleTimes
  1486. end
  1487. function LuaBattleMgr:GetCurrentLevelData()
  1488. return ManagerContainer.CfgMgr:GetLevelDataById(self:GetCurLevelUniqueId())
  1489. end
  1490. function LuaBattleMgr:OnLoadBegin()
  1491. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Loading_Begin);
  1492. -- LogError("LuaBattleMgr:OnLoadBegin")
  1493. end
  1494. function LuaBattleMgr:OnLoadProgress(progress)
  1495. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Loading_Progress,progress);
  1496. -- LogError("LuaBattleMgr:OnLoadProgress:" .. progress)
  1497. end
  1498. function LuaBattleMgr:OnLoadComplete()
  1499. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Loading_Complete);
  1500. -- LogError("LuaBattleMgr:OnLoadComplete")
  1501. end
  1502. function LuaBattleMgr:OnFighterCastSkill(skillParam)
  1503. if skillParam.isBoss then
  1504. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Boss_Skill,skillParam)
  1505. else
  1506. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Cast_Skill,skillParam)
  1507. end
  1508. end
  1509. function LuaBattleMgr:OnShowBossBuff(actorId,isBoss,buffIcon,num,isPlayeRecord)
  1510. if isBoss then
  1511. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Boss_Buff,buffIcon,num)
  1512. else
  1513. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Player_Buff,actorId, buffIcon,num)
  1514. end
  1515. end
  1516. function LuaBattleMgr:OnRemoveBossBuff(actorId,isBoss,buffIcon)
  1517. if isBoss then
  1518. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Boss_Remove_Buff,buffIcon)
  1519. else
  1520. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Remove_Player_Buff, actorId, buffIcon)
  1521. end
  1522. end
  1523. function LuaBattleMgr:OnFighterLifeChanged(isBoss,actorId,life,maxLife)
  1524. if isBoss then
  1525. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Boss_Life,life,maxLife)
  1526. else
  1527. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Fighter_Life,actorId,life,maxLife)
  1528. end
  1529. end
  1530. function LuaBattleMgr:OnFighterEnergyChanged(actorId,sp,maxSp)
  1531. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Fighter_Sp,actorId,sp,maxSp)
  1532. end
  1533. function LuaBattleMgr:OnRefreshSkillCD(isBoss,actorId,leftTime,totalTime)
  1534. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Skill_CD,isBoss,actorId,leftTime,totalTime)
  1535. -- LogError("--------------------------------------------isBoss = " .. tostring(isBoss) .. " actorId = " .. actorId .. " leftTime = " .. leftTime .. " totalTime = " .. totalTime)
  1536. end
  1537. function LuaBattleMgr:OnBattleUIVis(vis)
  1538. if vis then
  1539. --ManagerContainer.LuaUIMgr:Show(Enum.UIPageName.UIBattle)
  1540. --ManagerContainer.LuaUIMgr:Show(Enum.UIPageName.UIMain)
  1541. else
  1542. --ManagerContainer.LuaUIMgr:Hide(Enum.UIPageName.UIBattle)
  1543. --ManagerContainer.LuaUIMgr:Hide(Enum.UIPageName.UIMain)
  1544. end
  1545. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Battle_UI_VISIBLE,vis)
  1546. end
  1547. function LuaBattleMgr:OnRefreshBattleOutput()
  1548. -- if self.logList == nil or #self.logList == 0 then
  1549. -- return
  1550. -- end
  1551. -- self.logList[#self.logList+1] = logStr
  1552. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Add_New_BattleLog)
  1553. end
  1554. -- function LuaBattleMgr:InitBattleOutputList()
  1555. -- self.logList = {}
  1556. -- local battleLogList = LuaBattleBridge.GetBattleLog()
  1557. -- if battleLogList ~= nil then
  1558. -- for i = 1, battleLogList.Count do
  1559. -- self.logList[#self.logList+1] = battleLogList[i-1]
  1560. -- end
  1561. -- end
  1562. -- return self.logList
  1563. -- end
  1564. -- function LuaBattleMgr:GetBattleLogList()
  1565. -- return self.logList
  1566. -- end
  1567. function LuaBattleMgr:NotifyLoadingStatus(status)
  1568. self.battleLoadingState = status
  1569. end
  1570. function LuaBattleMgr:NotifyLoadingStatusEnd(status)
  1571. self.battleLoadingState = nil
  1572. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.BATTLE_LOADING_COMPELETED)
  1573. end
  1574. function LuaBattleMgr:GetBattleLoadingState()
  1575. local statusIdx
  1576. local state, text = self:GetWaitingRefreshRoleState()
  1577. if not state then
  1578. statusIdx = self.battleLoadingState
  1579. else
  1580. statusIdx = Enum.BattleBtnState.RoleModel
  1581. end
  1582. if statusIdx == Enum.BattleBtnState.Skill then
  1583. text = "Challenging4"
  1584. elseif statusIdx == Enum.BattleBtnState.Fellow then
  1585. text = "Challenging3"
  1586. elseif statusIdx == Enum.BattleBtnState.Pet then
  1587. text = "Challenging3"
  1588. elseif statusIdx == Enum.BattleBtnState.RoleModel then
  1589. text = "Challenging2"
  1590. end
  1591. return statusIdx, text
  1592. end
  1593. --判断当前时间如果领取挂机奖励的话,魔魂值是否会溢出,返回值第一个是是否溢出,第二个是领取之前的值
  1594. function LuaBattleMgr:JudgeEvilExpOverFlow()
  1595. local _leftTime, _num = ManagerContainer.LuaBattleMgr:GetIncomeInfo()
  1596. local _curLvEvilExp = ManagerContainer.LuaBattleMgr:CurLevelEvil(); --每分钟挂机获得的魔魂值
  1597. local _evilExp = ManagerContainer.DataMgr.UserData:GetEvilExp();
  1598. local _rewardIntervalTimeM = GlobalConfig.Instance:GetConfigIntValue(47) / 60;
  1599. local _nexEvilExp = _evilExp + _curLvEvilExp * _rewardIntervalTimeM * _num;
  1600. if self.maxEvilExp == 0 then
  1601. self.maxEvilExp = GlobalConfig.Instance:GetConfigIntValue(158);
  1602. end
  1603. local _isOverFlow = _nexEvilExp > self.maxEvilExp;
  1604. return _isOverFlow, _evilExp;
  1605. end
  1606. function LuaBattleMgr:CSPlayerIncomeReq()
  1607. self.accumIncomeTime = ManagerContainer.LuaBattleMgr:AccumIncomeTime();
  1608. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_PLAYER_INCOME_REQ, {})
  1609. self:ReportIncomeRecord(true)
  1610. end
  1611. function LuaBattleMgr:ReportIncomeRecord(success)
  1612. if not SDKMgr.Instance:IsReportAction() then
  1613. return
  1614. end
  1615. local datas = System.Collections.Generic.Dictionary_object_object()
  1616. datas:Add('event', 'mj_online_rewards')
  1617. datas:Add('is_achieve', 1)
  1618. SDKMgr.Instance:ReportAction(datas)
  1619. end
  1620. function LuaBattleMgr:RefreshStatistics()
  1621. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_BattleStatistics)
  1622. end
  1623. function LuaBattleMgr:HeroChangeProfessionSuccess()
  1624. ManagerContainer.DataMgr.UserData:RoleChangeJobAttrSuccess()
  1625. end
  1626. return LuaBattleMgr;