LuaBattleMgr.lua 64 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768
  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 -- 普通模式
  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. else
  399. if data.left_cd_time > 0 then
  400. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.BATTLE_CHALLENGE_TIME_REFRESH, data.left_cd_time)
  401. else
  402. LogError("---------OnChallengeBossFightAck---------"..Inspect(data))
  403. self.isBattling = true
  404. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Challenge_Boss_Fight_ACK,data.factor_list)
  405. end
  406. end
  407. end
  408. function LuaBattleMgr:SendChangeMapLevelTypeReq(type)
  409. --LogError("==================="..type)
  410. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_MAP_LEVEL_TYPE_CHANGE_REQ, {type = type})
  411. end
  412. function LuaBattleMgr:OnChangeMapLevelTypeAct(data)
  413. --LogError("========OnChangeMapLevelTypeAct=====模式變化請求回復=="..Inspect(data))
  414. --local mapMode = data.type < 0 and Enum.MapModeType.Simple or Enum.MapModeType.Difficulty
  415. if data.error ~= 0 then
  416. return
  417. end
  418. local mapMode = ManagerContainer.LuaBattleMgr:GetBattleMode() == Enum.MapModeType.Difficulty and Enum.MapModeType.Simple or Enum.MapModeType.Difficulty
  419. self:SetBattleMode(mapMode)
  420. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.MAP_MODE_CHANGE,mapMode)
  421. end
  422. function LuaBattleMgr:SendQuickBattleReq()
  423. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_QUICK_BATTLE_INCOME_REQ, {})
  424. end
  425. function LuaBattleMgr:SendBattleIncomeReq()
  426. local _isOverFlow, _evilExp = self:JudgeEvilExpOverFlow();
  427. if _isOverFlow then
  428. ManagerContainer.LuaUIMgr:ShowMessageBox("EvilOverFlowTips",{_evilExp, self.maxEvilExp},nil,self,self.CSPlayerIncomeReq,nil)
  429. else
  430. self:CSPlayerIncomeReq();
  431. end
  432. end
  433. function LuaBattleMgr:OnBattleIncomeAck(playerIncomeAck)
  434. if playerIncomeAck.error == 0 then
  435. self.rewardItemList = playerIncomeAck.item_list
  436. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_BATTLE_INCOME_ACK,0);
  437. end
  438. end
  439. function LuaBattleMgr:OnQuickBattleIncomeAck(playerIncomeAck)
  440. if playerIncomeAck.error == 0 then
  441. self.rewardItemList = playerIncomeAck.item_list
  442. local itemIcons = {};
  443. for i =1, #self.rewardItemList do
  444. local item = self.rewardItemList[i];
  445. if item.key >= 100 then
  446. local itemCfg = ManagerContainer.CfgMgr:GetItemById(item.key)
  447. if itemCfg~= nil then
  448. itemIcons[#itemIcons+1] = itemCfg.Icon
  449. end
  450. end
  451. end
  452. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIBattleReward,1)
  453. end
  454. end
  455. function LuaBattleMgr:GetRewardCnt(type)
  456. if self.rewardItemList == nil then
  457. return 0
  458. end
  459. for i =1, #self.rewardItemList do
  460. local item = self.rewardItemList[i];
  461. if item.key == type then
  462. return item.value;
  463. end
  464. end
  465. return 0;
  466. end
  467. function LuaBattleMgr:SendBossRewardReq(killedBossTime,recordTimeStamp)
  468. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_PLAYER_BOSS_REWARD_REQ, {challenge_time = killedBossTime,map_id =self.curMapId ,map_level=self.curLevelId,record_time_stamp=recordTimeStamp})
  469. end
  470. function LuaBattleMgr:OnBossRewardAck(playerBossRewardAck)
  471. LogError("OnBossRewardAck -- " .. Inspect(playerBossRewardAck))
  472. if battleStateTimer then
  473. ManagerContainer.LuaTimerMgr:RemoveTimer(battleStateTimer)
  474. battleStateTimer = nil
  475. end
  476. if playerBossRewardAck.error == 0 then
  477. ManagerContainer.LuaUIMgr:ClosePage(Enum.UIPageName.UIChat)
  478. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIBattle)
  479. self.rewardItemList = playerBossRewardAck.item_list
  480. local rewards = clone(self.rewardItemList)
  481. if self:IsNewMap() then
  482. --LogError("========Open==UIBattleBossBox========")
  483. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIBattleBossBox)
  484. else
  485. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIBattleWin,rewards)
  486. end
  487. else
  488. -- LogError("----------------OnBattleIncomeAck---- " .. playerBossRewardAck.error)
  489. self:ClearRageTimer()
  490. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_BATTLE_FAILED);
  491. end
  492. end
  493. function LuaBattleMgr:OnBattleDataChangeNtf(data)
  494. local isshow = self.difficulty ~= self.lastMapMode
  495. if isshow then
  496. LogError("-----------切换模式--------")
  497. self.lastMapMode = self.difficulty
  498. end
  499. self:OnBattleDataChange(data,isshow)
  500. end
  501. function LuaBattleMgr:OnBattleDataChange(data,IsShowEnterNextMap)
  502. self:SetBattleData(data,false,IsShowEnterNextMap)
  503. LogError("OnBattleDataChangeNtf -- " .. Inspect(data))
  504. -- LogError("self.lastInComeTime -- " .. self.lastInComeTime)
  505. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_REFRESH_REWARD_TIME);
  506. end
  507. function LuaBattleMgr:GetRewardMapCount()
  508. return self.lastMapRewardCount
  509. end
  510. -- 模擬數據
  511. function LuaBattleMgr:GetSimulationBattleData(mapId,mapLv)
  512. return {
  513. last_income_time = self.lastInComeTime,
  514. map_id = mapId,
  515. map_level = mapLv,
  516. max_income_time = 216000000,
  517. quick_battle = {
  518. day_times = self.usedQuickBattleTimes,
  519. draw_time = 1728939602,
  520. max_times = self.maxQuickBattleTimes
  521. },
  522. reward_map_count = self.mapRewardCount
  523. }
  524. end
  525. -- 設置苦難模式下配置
  526. function LuaBattleMgr:SetCurDifAttr()
  527. ManagerContainer.LuaGameMgr:ClearDifAttr()
  528. if self.difficulty == 1 or self.difficulty == 2 then
  529. --ManagerContainer.LuaGameMgr:AddDifAttr(7,100)
  530. local enemyAttrAddCfg = nil
  531. if self.difficulty == 1 then
  532. local curDiffID = self:GetCurDiffLvID()
  533. enemyAttrAddCfg = ManagerContainer.CfgMgr:GetLevelEnemyAttributeAdditionCfgById(curDiffID)
  534. else
  535. local curDiffID = self:GetCurDiff_S_LvID()
  536. enemyAttrAddCfg = ManagerContainer.CfgMgr:GetLevelEnemyAttributeAddition_S_CfgById(curDiffID)
  537. end
  538. local CurAttrAdd = enemyAttrAddCfg.AttrAdd
  539. for _, v in pairs(CurAttrAdd) do
  540. ManagerContainer.LuaGameMgr:AddDifAttr(v[1],v[2])
  541. end
  542. if enemyAttrAddCfg.NewLv > 0 then
  543. ManagerContainer.LuaGameMgr:AddDifAttr(-156,enemyAttrAddCfg.NewLv )
  544. end
  545. end
  546. end
  547. function LuaBattleMgr:SetBattleData(data,first,IsShowEnterNextMap)
  548. local preMapId = self.curMapId;
  549. self.lastLevelId = self.curLevelId
  550. self.lastMapId = self.curMapId
  551. self.lastInComeTime = data.last_income_time
  552. self.curMapId = data.map_id
  553. self.curLevelId = data.map_level
  554. if self.difficulty == 0 then
  555. self.simpleLvData[1] = data.map_id
  556. self.simpleLvData[2] = data.map_level
  557. elseif self.difficulty == 1 then
  558. self.difficultyLvData[1] = data.map_id
  559. self.difficultyLvData[2] = data.map_level
  560. else
  561. self.difficulty_S_LvData[1] = data.map_id
  562. self.difficulty_S_LvData[2] = data.map_level
  563. end
  564. if first then
  565. CompetitionRefreshLevelLimit = GlobalConfig.Instance:GetConfigIntValue(248)
  566. ManagerContainer.UIFuncUnlockMgr:SetLoggedinLevelId(self:GetCurLevelUniqueId())
  567. end
  568. self.lastMapRewardCount = self.mapRewardCount
  569. self.mapRewardCount = data.reward_map_count
  570. local rewardIntervalTime = GlobalConfig.Instance:GetConfigIntValue(47)
  571. local passedTime = ManagerContainer.LuaGameMgr:CalcPassedTime(self.lastInComeTime) / 1000
  572. if passedTime >= self.maxInComeTime then
  573. passedTime = self.maxInComeTime
  574. end
  575. self.maxRewardNum = self.maxInComeTime / rewardIntervalTime
  576. self.rewardNum = CommonUtil.GetPreciseDecimal(math.floor(passedTime / rewardIntervalTime),0)
  577. self.leftRewardTime = rewardIntervalTime - (passedTime - self.rewardNum*rewardIntervalTime)
  578. if self.leftRewardTime <= 0 or self.leftRewardTime > rewardIntervalTime then
  579. self.leftRewardTime = rewardIntervalTime
  580. end
  581. if data.quick_battle ~= nil then
  582. if data.quick_battle.max_times ~= nil then
  583. self.maxQuickBattleTimes = data.quick_battle.max_times
  584. end
  585. if data.quick_battle.day_times ~= nil then
  586. self.usedQuickBattleTimes = data.quick_battle.day_times
  587. end
  588. end
  589. self:SetCurDifAttr()
  590. ManagerContainer.LuaGameMgr:SetMapLevelId(self.curMapId,self.curLevelId);
  591. if IsShowEnterNextMap or (preMapId > 0 and preMapId~= self.curMapId ) then
  592. if self.nextMapState == NextMapState.WaitServer then
  593. --LogError("==========nextMapState========")
  594. self:ShowEnterNextMap()
  595. return
  596. elseif IsShowEnterNextMap then
  597. --LogError("==========IsShowEnterNextMap========")
  598. self:EnterToTargetMap()
  599. return
  600. end
  601. --LogError("==========nextMapState==WaitShow======")
  602. self.nextMapState = NextMapState.WaitShow
  603. end
  604. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_LEVEL_CHANGED)
  605. end
  606. function LuaBattleMgr:IsNewMap()
  607. return self.curMapId > self.lastMapId
  608. end
  609. function LuaBattleMgr:StartSyncServerTimeTimer()
  610. if self.timerId ~= nil then
  611. return
  612. end
  613. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_GET_SERVER_TIME_ACK,self.OnUpdateServerTimeAck,self)
  614. self.timerId = ManagerContainer.LuaTimerMgr:AddTimer(60000, -1, self, self.SendGetServerTimeReq, nil)
  615. end
  616. function LuaBattleMgr:SendGetServerTimeReq()
  617. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_GET_SERVER_TIME_REQ, {})
  618. end
  619. function LuaBattleMgr:SetReconnected(result)
  620. reconnected = result
  621. end
  622. function LuaBattleMgr:OnUpdateServerTimeAck(timeAck)
  623. ManagerContainer.LuaTimerMgr:SyncServerTime(timeAck.server_time)
  624. --每分钟判断
  625. ManagerContainer.DataMgr.RankActivitiesMgr:CheckRancActivityOpenTime()
  626. ManagerContainer.DataMgr.RuneShopDataMgr:CheckAirShipActivityOpenTime()
  627. ManagerContainer.DataMgr.CompetitionData:UpdateCompetitionTime()
  628. ManagerContainer.DataMgr.ActsDataMgr:UpdateActsEndTime()
  629. if reconnected then
  630. reconnected = false
  631. self:RefreshRewardNum()
  632. end
  633. end
  634. function LuaBattleMgr:StopSyncServerTimeTimer()
  635. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_GET_SERVER_TIME_ACK)
  636. if self.timerId~= nil then
  637. ManagerContainer.LuaTimerMgr:RemoveTimer(self.timerId)
  638. self.timerId = nil
  639. end
  640. end
  641. --收益累积时长
  642. function LuaBattleMgr:AccumIncomeTime()
  643. local passedTime = ManagerContainer.LuaGameMgr:CalcPassedTime(self.lastInComeTime);
  644. return passedTime;
  645. end
  646. function LuaBattleMgr:MaxInComeTime()
  647. return self.maxInComeTime
  648. end
  649. function LuaBattleMgr:GetIncomeInfo()
  650. return self.leftRewardTime, self.rewardNum
  651. end
  652. function LuaBattleMgr:RefreshRewardNum()
  653. local rewardIntervalTime = GlobalConfig.Instance:GetConfigIntValue(47)
  654. local passedTime = ManagerContainer.LuaGameMgr:CalcPassedTime(self.lastInComeTime) / 1000
  655. if passedTime >= self.maxInComeTime then
  656. passedTime = self.maxInComeTime
  657. end
  658. self.rewardNum = CommonUtil.GetPreciseDecimal(math.floor(passedTime / rewardIntervalTime),0)
  659. self.leftRewardTime = rewardIntervalTime - (passedTime - self.rewardNum*rewardIntervalTime)
  660. if self.leftRewardTime <= 0 or self.leftRewardTime > rewardIntervalTime then
  661. self.leftRewardTime = rewardIntervalTime
  662. end
  663. end
  664. function LuaBattleMgr:OnRefreshRewardTime()
  665. self:RefreshRewardNum()
  666. --self.leftRewardTime = self.leftRewardTime - 1
  667. if self.leftRewardTime <= 0 then
  668. self.leftRewardTime = GlobalConfig.Instance:GetConfigIntValue(47)
  669. self.rewardNum = self.rewardNum + 1
  670. if self.rewardNum > self.maxRewardNum then
  671. self.rewardNum = self.maxRewardNum
  672. end
  673. end
  674. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_REFRESH_REWARD_TIME);
  675. end
  676. function LuaBattleMgr:StartAutoChallenge()
  677. if not self.isAutochallenge then
  678. return
  679. end
  680. local sec = GlobalConfig.Instance:GetConfigIntValue(311)
  681. if sec < 0 then
  682. sec = 0
  683. end
  684. if not self.autoChallengeTimer then
  685. self.autoChallengeTimer = Timer.New(function()
  686. self:AutoChallenge()
  687. end, sec, 1)
  688. else
  689. self.autoChallengeTimer:Reset(function()
  690. self:AutoChallenge()
  691. end, sec, 1)
  692. end
  693. if not self.autoChallengeTimer.running then
  694. self.autoChallengeTimer:Start()
  695. end
  696. end
  697. function LuaBattleMgr:AutoChallenge()
  698. if ManagerContainer.LuaUIMgr:HasOpenPage(Enum.UIPageName.UIBattle) then
  699. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_CHALLENGE_AUTO)
  700. end
  701. end
  702. function LuaBattleMgr:StopAutoChallenge(force)
  703. if self.autoChallengeTimer then
  704. self.autoChallengeTimer:Stop()
  705. self.autoChallengeTimer = nil
  706. end
  707. if self.isAutochallenge then
  708. self.isAutochallenge = false
  709. if force then
  710. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("stopautobattle")
  711. end
  712. end
  713. end
  714. function LuaBattleMgr:GetAutoChallengeState()
  715. return self.isAutochallenge
  716. end
  717. function LuaBattleMgr:SetAutoChallengeState(value)
  718. self.isAutochallenge = value
  719. end
  720. --boss出生
  721. function LuaBattleMgr:OnBossSpawned(bossActor,bossName,life,maxLife,skillParam,isPlayRecord)
  722. self.bKillBoss = true
  723. --boos 展示等级设置为当前关卡Turn
  724. local curLevel = ManagerContainer.LuaBattleMgr:GetCurLevelUniqueId()
  725. local levelData = ManagerContainer.CfgMgr:GetLevelDataById(curLevel)
  726. bossActor.ShowLevel = levelData.Turn
  727. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_BOSS_SPAWNED,bossActor,bossName,life,maxLife,skillParam,isPlayRecord)
  728. end
  729. function LuaBattleMgr:OnCloneNewBoss(bossName,life,maxLife,skillParam)
  730. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_CLONE_NEW_BOSS,bossName,life,maxLife,skillParam)
  731. end
  732. -- 开始战斗
  733. function LuaBattleMgr:OnFightingStart(killingBoss)
  734. --LogError("=======OnFightingStart===开始战斗=============")----------困難模式 加入Debug 屬性削減
  735. self.isBattling = true
  736. if killingBoss then
  737. --LogError("=======OnFightingStart===开始战斗=====killingBoss========")----------困難模式 加入Debug 屬性削減
  738. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_FIGHTING_START)
  739. -- if self.difficulty == Enum.MapModeType.Difficulty then
  740. -- self:OnBattleStartBoss()
  741. -- end
  742. end
  743. end
  744. function LuaBattleMgr:OnBattleStartBoss()
  745. ManagerContainer.LuaActorDataMgr:ResetData()
  746. local actorData = ManagerContainer.LuaActorDataMgr:GetActorData(true, ManagerContainer.DataMgr.UserData:GetId())
  747. if actorData then
  748. -- 加入Debug 屬性削減
  749. self:AddBuffToActor(actorData)
  750. end
  751. local list = ManagerContainer.DataMgr.PartnerData:GetPartnerDatas()
  752. if list ~= nil then
  753. for _,v in pairs(list) do
  754. if v.owned and v.isBattle then
  755. actorData = ManagerContainer.LuaActorDataMgr:GetActorData(false, v.configId)
  756. if actorData then
  757. -- 加入Debug 屬性削減
  758. self:AddBuffToActor(actorData)
  759. end
  760. end
  761. end
  762. end
  763. end
  764. function LuaBattleMgr:AddBuffToActor(actor)
  765. local buffCfgs = ManagerContainer.CfgMgr:GetLevelDifficultCfg()
  766. local dropBuffs = self:GetDropBuffs(buffCfgs)
  767. if dropBuffs ~= nil then
  768. local dropBuffParamList = System.Array.CreateInstance(Enum.TypeInfo.BuffParam, #dropBuffs)
  769. for j = 1, #dropBuffs do
  770. local buffParam = dropBuffs[j]
  771. dropBuffParamList[j-1] = BuffParam.New(buffParam.buffId, buffParam.buffRatio, buffParam.buffCd, buffParam.buffType,buffParam.extendPara,buffParam:ConvertFunToStr())
  772. --LogError(j.."======AddBuffToActor========"..Inspect(dropBuffParamList[j-1]))
  773. end
  774. actor:SetDropBuffs(dropBuffParamList)
  775. --actor:SetBuffs(dropBuffParamList)
  776. --LogError("======AddBuffToActor========"..Inspect(actor))
  777. end
  778. if actor.HasPet then
  779. local petDropBuffs = self:GetDropBuffs(buffCfgs)
  780. if petDropBuffs ~= nil then
  781. local dropBuffParamList = System.Array.CreateInstance(Enum.TypeInfo.BuffParam, #petDropBuffs)
  782. for j = 1, #petDropBuffs do
  783. local buffParam = petDropBuffs[j]
  784. dropBuffParamList[j-1] = BuffParam.New(buffParam.buffId, buffParam.buffRatio, buffParam.buffCd, buffParam.buffType,buffParam.extendPara,buffParam:ConvertFunToStr())
  785. end
  786. actor.PetData:SetDropBuffs(dropBuffParamList)
  787. end
  788. end
  789. end
  790. function LuaBattleMgr:GetDropBuffs(buffCfgs)
  791. local bufflist ={}
  792. if buffCfgs == nil then
  793. return bufflist
  794. end
  795. local debuffcfg = self:GetCurLeveDebuffCfg()
  796. for i = 1, #buffCfgs, 1 do
  797. local buffCfg = buffCfgs[i]-- 获取buff配置
  798. if buffCfg ~= nil then
  799. local funlist = {{buffCfg.Function[1][1],debuffcfg[buffCfg.Effect][2],buffCfg.Function[1][3]}}
  800. local buff = ExpeditionBuff:new(buffCfg.BuffId,buffCfg.Ratio,buffCfg.CD,buffCfg.ConditionType,buffCfg.ExtendPara,funlist)
  801. bufflist[#bufflist+1] = buff
  802. end
  803. end
  804. return bufflist
  805. end
  806. function LuaBattleMgr:GetCurLeveDebuffCfg()
  807. local id = self:GetCurDiffLvID()
  808. local debuffcfg = ManagerContainer.CfgMgr:GetLevelDebuffCfgById(id)
  809. if debuffcfg == nil then
  810. return {{1,-20},{2,-20},{3,-30}}
  811. end
  812. return debuffcfg.debuffs
  813. end
  814. --清空战斗统计日志
  815. function LuaBattleMgr:ClearBattleLog()
  816. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_CLEAR_New_BattleLog)
  817. end
  818. function LuaBattleMgr:GetFightState()
  819. return self.isBattling
  820. end
  821. function LuaBattleMgr:GetBossFightState()
  822. return self.bKillBoss
  823. end
  824. -- 战斗胜利
  825. function LuaBattleMgr:OnBattleWin(killboss, killBossTime, mapId, levelId, isPlayRecord, recordTimeStamp)
  826. self:CloseBattleStatistics()
  827. self.isBattling = false
  828. if killboss then
  829. self.bKillBoss = false
  830. if not isPlayRecord then -- and self.difficulty == 0
  831. if self.curMapId == mapId and self.curLevelId == levelId then
  832. self:SendBossRewardReq(killBossTime,recordTimeStamp)
  833. else
  834. LogError('[wboy] curMapId : ' .. tostring(self.curMapId) .. ' curMapId : ' .. tostring(self.curLevelId) .. ' mapId : ' .. tostring(mapId) .. ' levelId : ' .. tostring(levelId))
  835. end
  836. battleStateTimer = ManagerContainer.LuaTimerMgr:AddTimer(5000, 1,self,self.BattleStateRefresh,nil);
  837. end
  838. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UI_BATTLE_NORMAL_NTF)
  839. local levelId = self:GetCurLevelUniqueId()
  840. if levelId >= CompetitionRefreshLevelLimit then
  841. ManagerContainer.DataMgr.CompetitionData:SetRefreshSeasonState(true)
  842. ManagerContainer.DataMgr.CompetitionData:QueryCurCompetitionReq(true)
  843. end
  844. ManagerContainer.DataMgr.RankActivitiesMgr:QueryCurRankActivityData(Enum.RankActivitiesType.MapProgress)
  845. end
  846. self:ClearRageTimer()
  847. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_BATTLE_WIN);
  848. end
  849. function LuaBattleMgr:BattleStateRefresh()
  850. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.GOT_ANIM_TYPE_END_NOTIFY, Enum.ItemIEnterType.BattleWin)
  851. end
  852. --战斗失败
  853. function LuaBattleMgr:OnBattleFailed(killboss,isPlayRecord)
  854. self:CloseBattleStatistics()
  855. self.isBattling = false
  856. self.bKillBoss = false
  857. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UI_BATTLE_NORMAL_NTF)
  858. self:ClearRageTimer()
  859. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_BATTLE_FAILED,killboss,isPlayRecord);
  860. self:StopAutoChallenge(true)
  861. end
  862. --强制巡游战斗失败
  863. function LuaBattleMgr:OnForceBattleFailed(killboss,isPlayRecord)
  864. self:CloseBattleStatistics()
  865. self.isBattling = false
  866. self.bKillBoss = false
  867. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UI_BATTLE_NORMAL_NTF)
  868. self:ClearRageTimer()
  869. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_FORCEBATTLE_FAILED,killboss,isPlayRecord);
  870. end
  871. function LuaBattleMgr:CloseBattleStatistics()
  872. if self.bKillBoss then
  873. ManagerContainer.LuaUIMgr:ClosePage(Enum.UIPageName.UIBattleStatistics)
  874. ManagerContainer.LuaUIMgr:ClosePage(Enum.UIPageName.UIBattleBossTips)
  875. end
  876. end
  877. function LuaBattleMgr:ShowErrorQuitBattleMsgBox()
  878. ManagerContainer.LuaUIMgr:ShowOkMessageBox("ErrorQuitBattleTip",self.QuitBattleMsgOk)
  879. end
  880. function LuaBattleMgr:QuitBattleMsgOk()
  881. LuaBattleBridge.SkipReplay()
  882. end
  883. function LuaBattleMgr:CloseErrorQuitBattleMsgBox()
  884. ManagerContainer.LuaUIMgr:CloseOkMessageBox("ErrorQuitBattleTip")
  885. end
  886. function LuaBattleMgr:ShowAntiCheatMsgBox(nType)
  887. --上报使用外挂
  888. self:SendAntiCheat(nType)
  889. ManagerContainer.LuaUIMgr:ShowOkMessageBox("AntiCheatMsg",self.AntiCheatQuitGameMsgOk)
  890. end
  891. function LuaBattleMgr:SendAntiCheat(nType)
  892. --上报使用外挂
  893. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_ANTI_CHEAT_REQ, { cheat_type = nType})
  894. end
  895. function LuaBattleMgr:AntiCheatQuitGameMsgOk()
  896. ManagerContainer.NetManager:ResetNetMgr()
  897. ManagerContainer.LuaGameMgr:QuitGame()
  898. end
  899. function LuaBattleMgr:CloseAntiCheatMsgBox()
  900. ManagerContainer.LuaUIMgr:CloseOkMessageBox("AntiCheatMsg")
  901. end
  902. function LuaBattleMgr:GetCurSimpleLvID()
  903. return self.simpleLvData[1]*10000 + self.simpleLvData[2]
  904. end
  905. function LuaBattleMgr:GetCurDiffLvID()
  906. return self.difficultyLvData[1]*10000 + self.difficultyLvData[2]
  907. end
  908. function LuaBattleMgr:GetCurDiff_S_LvID()
  909. return self.difficulty_S_LvData[1]*10000 + self.difficulty_S_LvData[2]
  910. end
  911. function LuaBattleMgr:GetCurLevelUniqueId()
  912. return self.curMapId*10000 + self.curLevelId
  913. end
  914. function LuaBattleMgr:GetLastLevelUniqueId()
  915. return self.lastMapId*10000 + self.lastLevelId
  916. end
  917. function LuaBattleMgr:GetLastMapIdAndLvId()
  918. return self.lastMapId,self.lastLevelId
  919. end
  920. --下一关卡
  921. function LuaBattleMgr:OnBattleNewWave(levelName)
  922. self.nextMapState = NextMapState.None
  923. -- if ManagerContainer.UIFuncUnlockMgr:NeedOpenFuncCurLevelStart(self:GetCurLevelUniqueId()) then
  924. -- --功能解锁
  925. -- ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UI_FUNCLOCK_OPEN_NTF)
  926. -- ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UI_BATTLE_FUNC_OPEN_NTF);
  927. -- else
  928. -- self.closeLevelNameTimer = ManagerContainer.LuaTimerMgr:AddTimer(GlobalConfig.Instance:GetConfigFloatValue(79)*1000, 1,self,self.OnCloseLevelName,nil);
  929. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_NEXT_BATTLE,levelName);
  930. -- end
  931. end
  932. function LuaBattleMgr:OnCloseLevelName()
  933. self.closeLevelNameTimer = nil;
  934. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_HIDE_LEVEL_NAME);
  935. end
  936. --继续同一关战斗
  937. function LuaBattleMgr:OnContinueBattle()
  938. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_CONTINUE_BATTLE);
  939. ----如果还是处于第一关 且 强制引导战斗没成功 则继续强制引导战斗
  940. --local curLevelId = self:GetCurLevelUniqueId()
  941. --if curLevelId == 10001 then
  942. -- ManagerContainer.ForceGuideMgr:GuideBossBattle()
  943. --end
  944. end
  945. function LuaBattleMgr:OnShowBossRage(vis)
  946. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_SHOW_BOSS_RAGE)
  947. end
  948. --狂暴剩余时间
  949. function LuaBattleMgr:OnShowBossRageLeftTime(leftTime)
  950. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_SHOW_BOSS_RAGE_LEFTTIME,leftTime);
  951. end
  952. --boss进入狂暴
  953. function LuaBattleMgr:OnBossInRage()
  954. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_BOSS_IN_RAGE);
  955. end
  956. function LuaBattleMgr:OnBattleStartStory(levelId, storyId)
  957. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UISTORY_CONDITION_TRIGGER, Enum.UIStoryCondType.FirstSceneEnter, levelId, storyId)
  958. end
  959. --战斗结束
  960. function LuaBattleMgr:OnBattleEnd(killBoss,killBossTime,win,isPlayRecord)
  961. self.lastLevelZeny = self:CurLevelZeny()
  962. self.lastLevelExp = self:CurLevelExp()
  963. self.lastLevelPartnerExp = self:CurLevelParnterExp()
  964. self.lastLevelCruise = self:CurLevelCruise()
  965. if killBoss then
  966. --self.bKillBoss = false
  967. if not isPlayRecord then
  968. --ManagerContainer.DataMgr.BigMapData:SendGetData()
  969. end
  970. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_BOSS_Battle_End,isPlayRecord)
  971. self:OnBattleUIVis(true)
  972. end
  973. end
  974. ------------------战斗录像相关----------------------------------------
  975. function LuaBattleMgr:SendBattleDetailReq(battleRecordUid,battleTime,fightPower)
  976. self.curReqBattleRecordId = battleRecordUid
  977. self.cacheRecordBattleTime = battleTime
  978. self.cacheRecordFightPower = fightPower
  979. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_PLAYER_BATTLE_RECORD_DETAIL_REQ, {battle_record_uid = battleRecordUid})
  980. end
  981. function LuaBattleMgr:OnBattleRecordDetailAck(pkg)
  982. -- LogError(Inspect(pkg))
  983. if pkg.error == 0 then
  984. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Fetch_BattleRecord_Success,pkg.battle_record_uid,pkg.battle_record)
  985. ManagerContainer.LuaGameMgr:SetGameSpeed(ManagerContainer.LuaGameMgr.GameSpeed)
  986. self:StopAutoChallenge(true)
  987. end
  988. end
  989. function LuaBattleMgr:GetCacheRecordInfo()
  990. return self.cacheRecordBattleTime, self.cacheRecordFightPower
  991. end
  992. function LuaBattleMgr:OnBattleRecordDetalSaveNtf(pkg)
  993. --LogError("OnBattleRecordDetalSaveNtf Save")
  994. local battleRecordUid = pkg.battle_record_uid
  995. local battleTimeStamp = pkg.record_time_stamp
  996. local battleRecordStr = LuaBattleBridge.GetBattleRecord(battleTimeStamp)
  997. if battleRecordStr ~= nil and battleRecordStr~="" then
  998. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_PLAYER_BATTLE_RECORD_DETAIL_SAVE_REQ, {battle_record_uid = battleRecordUid, battle_record = battleRecordStr})
  999. end
  1000. end
  1001. function LuaBattleMgr:OnBattleRecordAck(pkg)
  1002. if pkg.error == 0 then
  1003. if #pkg.record_list > 0 then
  1004. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIBattleReplay,pkg.record_list)
  1005. else
  1006. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("NullBattleReport")
  1007. end
  1008. end
  1009. end
  1010. -------------------------------------------------------------------------
  1011. function LuaBattleMgr:OnReplayEnd()
  1012. self:CloseBattleStatistics()
  1013. self.isBattling = false
  1014. self.bKillBoss = false
  1015. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.UI_BATTLE_NORMAL_NTF)
  1016. self:ClearRageTimer()
  1017. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_BATTLE_WIN);
  1018. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIDojoExit,true)
  1019. end
  1020. function LuaBattleMgr:GetBossFightStatus()
  1021. return self.bKillBoss
  1022. end
  1023. function LuaBattleMgr:ClearRageTimer()
  1024. if self.rageLeftTimeTimer ~= nil then
  1025. ManagerContainer.LuaTimerMgr:RemoveTimer(self.rageLeftTimeTimer);
  1026. self.rageLeftTimeTimer = nil;
  1027. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_BOSS_IN_RAGE);
  1028. end
  1029. end
  1030. --bIsForce 强制结束战斗 设置属性
  1031. function LuaBattleMgr:SetTeamData(ignore,bIsForce)
  1032. local teamData = ManagerContainer.DataMgr.UserData:GetTeamData(ignore);
  1033. if teamData == nil then return end
  1034. ManagerContainer.LuaGameMgr:SetTeamData(teamData,{bIsForce})
  1035. ManagerContainer.LuaActorAttributeMgr:SyncServerActorDataToLocal()
  1036. end
  1037. --更新技能数据
  1038. function LuaBattleMgr:UpdateTeamSkills()
  1039. local usersSkills = {}
  1040. local heroId = ManagerContainer.DataMgr.UserData:GetId()
  1041. local skillData = ManagerContainer.DataMgr.UserData:GetSkillData(heroId)
  1042. local skills = skillData and skillData:GetUsedSkills() or {}
  1043. local heroData = CommonUtil.GetHeroLogicDataByUid(1)
  1044. CommonUtil.ReplaceBattleSkillBySkillEquip(heroData, skills)
  1045. usersSkills[#usersSkills+1] = {
  1046. uid = heroId,
  1047. skills = skills,
  1048. }
  1049. local list = ManagerContainer.DataMgr.PartnerData:GetBattlePartnerDatas(true)
  1050. if list ~= nil then
  1051. for _,v in pairs(list) do
  1052. skillData = ManagerContainer.DataMgr.UserData:GetSkillData(v.uid)
  1053. local skills = skillData and skillData:GetUsedSkills() or {}
  1054. CommonUtil.ReplaceBattleSkillBySkillEquip(v, skills)
  1055. usersSkills[#usersSkills + 1] = {uid = v.uid, skills = skills }
  1056. end
  1057. end
  1058. ManagerContainer.LuaGameMgr:UpdateTeamSkills(usersSkills);
  1059. end
  1060. function LuaBattleMgr:NotifyEnterNextMapStart()
  1061. if self.nextMapState == NextMapState.WaitShow then
  1062. LogError("========nextMapState=WaitShow=======")
  1063. self:ShowEnterNextMap()
  1064. return
  1065. end
  1066. self.nextMapState = NextMapState.WaitServer
  1067. end
  1068. function LuaBattleMgr:NotifyEnterNextMapEnd()
  1069. if ManagerContainer.FSMMgr:IsBattleState() then
  1070. -- 在战斗场景中,才走大地图过图效果
  1071. self:OnEnterNextMap()
  1072. end
  1073. end
  1074. function LuaBattleMgr:NotifyVipLvChanged()
  1075. self.maxInComeTime = GlobalConfig.Instance:GetConfigIntValue(48)
  1076. self.maxQuickBattleTimes = GlobalConfig.Instance:GetConfigIntValue(240)
  1077. local vipLv = ManagerContainer.DataMgr.UserData:GetVipLv()
  1078. local vipCfg = ManagerContainer.CfgMgr:GetVipCfgById(vipLv)
  1079. if vipCfg then
  1080. self.maxInComeTime = self.maxInComeTime + tonumber(vipCfg.HangupDuration)
  1081. self.maxQuickBattleTimes = self.maxQuickBattleTimes + tonumber(vipCfg.HangupTimes)
  1082. end
  1083. end
  1084. function LuaBattleMgr:ShowEnterNextMap()
  1085. if ManagerContainer.FSMMgr:IsBattleState() then
  1086. -- 在战斗场景中,才走大地图过图效果
  1087. --LogError("========ShowEnterNextMap========")
  1088. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIWorldMap, true)
  1089. end
  1090. end
  1091. function LuaBattleMgr:EnterToTargetMap()
  1092. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIWorldMap, true)
  1093. end
  1094. function LuaBattleMgr:OnLoadingClose()
  1095. self.IsShowDiffTxt = false
  1096. --LogError("-----------OnLoadingClose--------------")
  1097. if self.difficulty == Enum.MapModeType.Difficulty or self.difficulty == 2 then
  1098. self.IsShowDiffTxt = true
  1099. ManagerContainer.LuaTimerMgr:AddTimer(500, 1,self,function ()
  1100. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("DifNtfTxt")
  1101. end,nil);
  1102. --elseif self.difficulty == 2 then
  1103. else
  1104. local cfg = ManagerContainer.CfgMgr:GetPrivilegeCardCfgByLv(2)
  1105. local curmaplvID = self:GetCurLevelUniqueId()
  1106. if cfg and cfg.UnlockCond and cfg.UnlockCond[2] == curmaplvID then
  1107. ManagerContainer.LuaTimerMgr:AddTimer(500, 1,self,function ()
  1108. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopBT)
  1109. --Notice_TeQuanKa
  1110. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("Notice_TeQuanKa")
  1111. end,nil);
  1112. end
  1113. end
  1114. --if
  1115. end
  1116. function LuaBattleMgr:IsShowDifficultyTxt()
  1117. return (self.difficulty == Enum.MapModeType.Difficulty or self.difficulty == 2)and self.IsShowDiffTxt
  1118. end
  1119. -- 创建主角形象
  1120. function LuaBattleMgr:CreateRoleView()
  1121. if self.roleViewSystem then
  1122. local userData = ManagerContainer.DataMgr.UserData
  1123. local heroData = userData:GetMainRoleData()
  1124. self.roleViewSystem:RefreshView(Enum.RoleInEnvType.Battle, userData:GetUserRoleId(), userData:GetViewData(), nil, self, self.CreateRoleViewComplete)
  1125. end
  1126. end
  1127. -- 完成主角创建
  1128. function LuaBattleMgr:CreateRoleViewComplete(gameObject)
  1129. ManagerContainer.LuaGameMgr:CreateRoleViewComplete(gameObject)
  1130. end
  1131. -- 通知战斗需要更新主角新形象
  1132. function LuaBattleMgr:NotifyRefreshRoleView()
  1133. self.waitingRefreshRole = true
  1134. ManagerContainer.LuaGameMgr:NotifyRefreshRoleView()
  1135. end
  1136. function LuaBattleMgr:GetWaitingRefreshRoleState()
  1137. return self.waitingRefreshRole == true
  1138. end
  1139. -- 刷新主角形象
  1140. function LuaBattleMgr:RefreshRoleView()
  1141. if self.roleViewSystem then
  1142. local userData = ManagerContainer.DataMgr.UserData
  1143. local heroData = userData:GetMainRoleData()
  1144. self.roleViewSystem:RefreshView(Enum.RoleInEnvType.Battle, userData:GetUserRoleId(), userData:GetViewData(), nil, self, self.RefreshRoleViewComplete)
  1145. end
  1146. end
  1147. -- 完成主角形象更新
  1148. function LuaBattleMgr:RefreshRoleViewComplete(gameObject, isNewModel)
  1149. self.waitingRefreshRole = false
  1150. ManagerContainer.LuaGameMgr:RefreshRoleViewComplete(gameObject, isNewModel)
  1151. self:NotifyLoadingStatusEnd(Enum.BattleBtnState.RoleModel)
  1152. end
  1153. function LuaBattleMgr:RecycleRoleView()
  1154. if self.roleViewSystem then
  1155. self.roleViewSystem:Recycle()
  1156. end
  1157. end
  1158. -- function LuaBattleMgr:NotifyRefreshUpRoleLvEffect()
  1159. -- self:NotifyRefreshUpLvEffect('Common/FX_Scene_LV_UP')
  1160. -- end
  1161. -- function LuaBattleMgr:NotifyRefreshUpJobLvEffect()
  1162. -- self:NotifyRefreshUpLvEffect('Common/FX_Scene_LV_UP')
  1163. -- end
  1164. -- function LuaBattleMgr:NotifyRefreshUpLvEffect(effectName)
  1165. -- if not self.roleViewSystem then return end
  1166. -- local roleGo = self.roleViewSystem:GetGameObject()
  1167. -- if tolua.isnull(roleGo) then return end
  1168. -- local timeStamp = Time.GetTimestamp()
  1169. -- if not self.upLvEffectCDs then
  1170. -- self.upLvEffectCDs = {}
  1171. -- end
  1172. -- local upLvEffectCD = self.upLvEffectCDs[effectName] or (timeStamp - 2)
  1173. -- -- 1秒内不出现两次升级特效
  1174. -- if timeStamp - upLvEffectCD <= 1 then
  1175. -- return
  1176. -- end
  1177. -- self.upLvEffectCDs[effectName] = timeStamp
  1178. -- ManagerContainer.ResMgr:GetGOFromPool(Constants.EffectPath, effectName, function(go)
  1179. -- if ManagerContainer.FSMMgr:IsBattleState() then
  1180. -- self:UpLvEffectShow(go, effectName)
  1181. -- end
  1182. -- end)
  1183. -- end
  1184. -- --- 显示升级特效
  1185. -- function LuaBattleMgr:UpLvEffectShow(go, effectName)
  1186. -- if not go then return end
  1187. -- if self.roleViewSystem then
  1188. -- local roleGo = self.roleViewSystem:GetGameObject()
  1189. -- if not tolua.isnull(roleGo) then
  1190. -- local link = roleGo.transform:Find('foot_point')
  1191. -- if not tolua.isnull(link) then
  1192. -- go.transform.parent = link
  1193. -- go.transform.localPosition = Vector3.zero
  1194. -- go.transform.localRotation = Quaternion.identity
  1195. -- go.transform.localScale = Vector3.one
  1196. -- local upLvEffects = self.upLvEffects
  1197. -- if not upLvEffects then
  1198. -- upLvEffects = {}
  1199. -- self.upLvEffects = upLvEffects
  1200. -- end
  1201. -- local info = {}
  1202. -- info.effectName = effectName
  1203. -- info.timerId = ManagerContainer.LuaTimerMgr:AddTimer(2000, 1, self, self.UpLvEffectHide, {go = go})
  1204. -- upLvEffects[go] = info
  1205. -- return
  1206. -- end
  1207. -- LogError('Link Point : foot_point is not Find')
  1208. -- end
  1209. -- end
  1210. -- -- 出现问题,直接回收掉效果,直接回收掉升级特效
  1211. -- ManagerContainer.ResMgr:RecycleGO(Constants.EffectPath, effectCfg.Effect, go)
  1212. -- end
  1213. -- --- 升级特效播放完成,需要回收掉
  1214. -- function LuaBattleMgr:UpLvEffectHide(timerId, params)
  1215. -- local go = params.go
  1216. -- if not go then return end
  1217. -- local upLvEffects = self.upLvEffects
  1218. -- if not upLvEffects then return end
  1219. -- local info = upLvEffects[go]
  1220. -- local timeId = info.timerId
  1221. -- local effectName = info.effectName
  1222. -- if timeId ~= timerId then
  1223. -- LogError('timeId is error, cur : ' .. tostring(timeId) .. ' cbTimerId : ' .. tostring(timerId))
  1224. -- end
  1225. -- if timeId then
  1226. -- ManagerContainer.LuaTimerMgr:RemoveTimer(timeId)
  1227. -- timeId = nil
  1228. -- end
  1229. -- upLvEffects[go] = nil
  1230. -- ManagerContainer.ResMgr:RecycleGO(Constants.EffectPath, effectName, go)
  1231. -- end
  1232. -- --- 回收所有显示的升级特效
  1233. -- function LuaBattleMgr:RecycleUpLvEffect()
  1234. -- local upLvEffects = self.upLvEffects
  1235. -- if not upLvEffects then return end
  1236. -- for go, info in pairs(upLvEffects) do
  1237. -- local timeId = info.timerId
  1238. -- local effectName = info.effectName
  1239. -- if timeId then
  1240. -- ManagerContainer.LuaTimerMgr:RemoveTimer(timeId)
  1241. -- timeId = nil
  1242. -- end
  1243. -- ManagerContainer.ResMgr:RecycleGO(Constants.EffectPath, effectName, go)
  1244. -- end
  1245. -- self.upLvEffects = nil
  1246. -- self.upLvEffectCDs = nil
  1247. -- end
  1248. function LuaBattleMgr:OnShowBossWarning()
  1249. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_SHOW_BOSS_WARNING,true);
  1250. ManagerContainer.LuaTimerMgr:AddTimer(3000, 1,self,self.OnHideBossWarningTimer,nil);
  1251. end
  1252. function LuaBattleMgr:OnHideBossWarningTimer()
  1253. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_SHOW_BOSS_WARNING,false);
  1254. end
  1255. function LuaBattleMgr:OnEnterNextMap()
  1256. self.bKillBoss = false
  1257. self.nextMapState = NextMapState.None
  1258. ManagerContainer.LuaGameMgr:OpenLoading(Enum.UIPageName.UILoading)
  1259. ManagerContainer.FSMMgr:ChangeState(Enum.StateEnum.LoadingState.stateId, SceneType.NormalBattleScene)
  1260. end
  1261. function LuaBattleMgr:CurLevelExp()
  1262. return LuaBattleBridge.GetCurLevelExp();
  1263. end
  1264. function LuaBattleMgr:CurLevelParnterExp()
  1265. return LuaBattleBridge.GetCurLevelParnterExp();
  1266. end
  1267. function LuaBattleMgr:CurLevelGold()
  1268. return LuaBattleBridge.GetCurLevelGold();
  1269. end
  1270. function LuaBattleMgr:CurLevelCruise()
  1271. return LuaBattleBridge.GetCurLevelCruise();
  1272. end
  1273. function LuaBattleMgr:CurLevelEvil()
  1274. return LuaBattleBridge.GetCurLevelEvil()
  1275. end
  1276. function LuaBattleMgr:CurLevelZeny()
  1277. return LuaBattleBridge.GetCurLevelZeny()
  1278. end
  1279. function LuaBattleMgr:CurLevelName()
  1280. local lvname = LuaBattleBridge.GetCurLevelName() --DifLvName
  1281. if self.IsShowDiffTxt then
  1282. lvname = I18N.T("DifLvName")..lvname
  1283. end
  1284. return lvname
  1285. end
  1286. ----- 配置
  1287. function LuaBattleMgr:GetCurSimpleLvCfg ()
  1288. local lvID = self:GetCurSimpleLvID()
  1289. if self.curSimpleLvCgf == nil or self.curSimpleLvCgf.Id ~= lvID then
  1290. self.curSimpleLvCgf = ManagerContainer.CfgMgr:GetLevelDataById(lvID)
  1291. end
  1292. return self.curSimpleLvCgf
  1293. end
  1294. function LuaBattleMgr:CurSimpleLevelExp()
  1295. local lvDataCfg = self:GetCurSimpleLvCfg()
  1296. return lvDataCfg.BaseExpOl / 4
  1297. end
  1298. function LuaBattleMgr:CurSimpleLevelParnterExp()
  1299. local lvDataCfg = self:GetCurSimpleLvCfg()
  1300. return lvDataCfg.ParterOl / 4
  1301. end
  1302. function LuaBattleMgr:CurSimpleLevelGold()
  1303. local lvDataCfg = self:GetCurSimpleLvCfg()
  1304. return lvDataCfg.GoldOl / 4
  1305. end
  1306. function LuaBattleMgr:CurSimpleLevelCruise()
  1307. local lvDataCfg = self:GetCurSimpleLvCfg()
  1308. return lvDataCfg.CruiseOl / 4
  1309. end
  1310. function LuaBattleMgr:CurSimpleLevelEvil()
  1311. local lvDataCfg = self:GetCurSimpleLvCfg()
  1312. return lvDataCfg.EvilOl / 4
  1313. end
  1314. function LuaBattleMgr:CurSimpleLevelZeny()
  1315. local lvDataCfg = self:GetCurSimpleLvCfg()
  1316. return lvDataCfg.ZenyOl / 4
  1317. end
  1318. function LuaBattleMgr:CurSimpleLevelName()
  1319. local lvDataCfg = self:GetCurSimpleLvCfg()
  1320. return lvDataCfg.Name
  1321. end
  1322. -- 配置 end
  1323. function LuaBattleMgr:SetRewardDropPos(dropPos)
  1324. LuaBattleBridge.SetRewardDropPos(dropPos)
  1325. end
  1326. function LuaBattleMgr:Enter()
  1327. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.ROLE_JOB_CHANGE_SUCCESS, self, self.NotifyRefreshRoleView)
  1328. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.FASHION_WEAR_CHANGE, self, self.NotifyRefreshRoleView)
  1329. -- ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.ROLE_LV_CHANGED, self, self.NotifyRefreshUpRoleLvEffect)
  1330. -- ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.JOB_LV_CHANGED, self, self.NotifyRefreshUpJobLvEffect)
  1331. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.BIGMAP_ENTER_NEXTMAP_START, self, self.NotifyEnterNextMapStart)
  1332. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.BIGMAP_ENTER_NEXTMAP_END, self, self.NotifyEnterNextMapEnd)
  1333. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.VIP_LV_CHANGED, self, self.NotifyVipLvChanged)
  1334. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.EID_Loading_Close, self, self.OnLoadingClose)
  1335. self:NotifyVipLvChanged()
  1336. self.bKillBoss = false
  1337. --ManagerContainer.DataMgr.BigMapData:SendGetData()
  1338. self:StartSyncServerTimeTimer()
  1339. if self.rewardTimeTimerId == nil then
  1340. self.rewardTimeTimerId = ManagerContainer.LuaTimerMgr:AddTimer(1000, -1, self, self.OnRefreshRewardTime, nil)
  1341. end
  1342. local mainActor = ManagerContainer.LuaActorDataMgr:GetHeroActorData(1)
  1343. if mainActor ~= nil then
  1344. mainActor.Name = ManagerContainer.DataMgr.UserData:GetUserNickname()
  1345. end
  1346. self.isAutochallenge = false
  1347. end
  1348. function LuaBattleMgr:Exit()
  1349. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.ROLE_JOB_CHANGE_SUCCESS, self, self.NotifyRefreshRoleView)
  1350. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.FASHION_WEAR_CHANGE, self, self.NotifyRefreshRoleView)
  1351. -- ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.ROLE_LV_CHANGED, self, self.NotifyRefreshUpRoleLvEffect)
  1352. -- ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.JOB_LV_CHANGED, self, self.NotifyRefreshUpJobLvEffect)
  1353. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.BIGMAP_ENTER_NEXTMAP_START, self, self.NotifyEnterNextMapStart)
  1354. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.BIGMAP_ENTER_NEXTMAP_END, self, self.NotifyEnterNextMapEnd)
  1355. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.VIP_LV_CHANGED, self, self.NotifyVipLvChanged)
  1356. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.EID_Loading_Close, self, self.OnLoadingClose)
  1357. -- ManagerContainer.LuaBattleMgr:RecycleUpLvEffect()
  1358. ManagerContainer.LuaBattleMgr:RecycleRoleView()
  1359. if self.rewardTimeTimerId~= nil then
  1360. ManagerContainer.LuaTimerMgr:RemoveTimer(self.rewardTimeTimerId)
  1361. self.rewardTimeTimerId = nil
  1362. end
  1363. self.isAutochallenge = false
  1364. end
  1365. function LuaBattleMgr:SendBattleRecordReq()
  1366. ManagerContainer.LuaGameMgr:SendBattleRecordReq(100,{self.curMapId,self.curLevelId})
  1367. end
  1368. function LuaBattleMgr:GetFightersPos()
  1369. return LuaBattleBridge.GetFightersPos();
  1370. end
  1371. function LuaBattleMgr:GetCurMapId()
  1372. return self.curMapId
  1373. end
  1374. function LuaBattleMgr:GetCurMapAndLevel()
  1375. return self.curMapId, self.curLevelId
  1376. end
  1377. function LuaBattleMgr:MaxQuickBattleTimes()
  1378. return self.maxQuickBattleTimes
  1379. end
  1380. function LuaBattleMgr:UsedQuickBattleTimes()
  1381. return self.usedQuickBattleTimes
  1382. end
  1383. function LuaBattleMgr:GetCurrentLevelData()
  1384. return ManagerContainer.CfgMgr:GetLevelDataById(self:GetCurLevelUniqueId())
  1385. end
  1386. function LuaBattleMgr:OnLoadBegin()
  1387. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Loading_Begin);
  1388. -- LogError("LuaBattleMgr:OnLoadBegin")
  1389. end
  1390. function LuaBattleMgr:OnLoadProgress(progress)
  1391. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Loading_Progress,progress);
  1392. -- LogError("LuaBattleMgr:OnLoadProgress:" .. progress)
  1393. end
  1394. function LuaBattleMgr:OnLoadComplete()
  1395. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Loading_Complete);
  1396. -- LogError("LuaBattleMgr:OnLoadComplete")
  1397. end
  1398. function LuaBattleMgr:OnFighterCastSkill(skillParam)
  1399. if skillParam.isBoss then
  1400. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Boss_Skill,skillParam)
  1401. else
  1402. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Cast_Skill,skillParam)
  1403. end
  1404. end
  1405. function LuaBattleMgr:OnShowBossBuff(actorId,isBoss,buffIcon,num,isPlayeRecord)
  1406. if isBoss then
  1407. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Boss_Buff,buffIcon,num)
  1408. else
  1409. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Player_Buff,actorId, buffIcon,num)
  1410. end
  1411. end
  1412. function LuaBattleMgr:OnRemoveBossBuff(actorId,isBoss,buffIcon)
  1413. if isBoss then
  1414. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Boss_Remove_Buff,buffIcon)
  1415. else
  1416. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Remove_Player_Buff, actorId, buffIcon)
  1417. end
  1418. end
  1419. function LuaBattleMgr:OnFighterLifeChanged(isBoss,actorId,life,maxLife)
  1420. if isBoss then
  1421. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Boss_Life,life,maxLife)
  1422. else
  1423. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Fighter_Life,actorId,life,maxLife)
  1424. end
  1425. end
  1426. function LuaBattleMgr:OnFighterEnergyChanged(actorId,sp,maxSp)
  1427. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Fighter_Sp,actorId,sp,maxSp)
  1428. end
  1429. function LuaBattleMgr:OnRefreshSkillCD(isBoss,actorId,leftTime,totalTime)
  1430. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Skill_CD,isBoss,actorId,leftTime,totalTime)
  1431. -- LogError("--------------------------------------------isBoss = " .. tostring(isBoss) .. " actorId = " .. actorId .. " leftTime = " .. leftTime .. " totalTime = " .. totalTime)
  1432. end
  1433. function LuaBattleMgr:OnBattleUIVis(vis)
  1434. if vis then
  1435. --ManagerContainer.LuaUIMgr:Show(Enum.UIPageName.UIBattle)
  1436. --ManagerContainer.LuaUIMgr:Show(Enum.UIPageName.UIMain)
  1437. else
  1438. --ManagerContainer.LuaUIMgr:Hide(Enum.UIPageName.UIBattle)
  1439. --ManagerContainer.LuaUIMgr:Hide(Enum.UIPageName.UIMain)
  1440. end
  1441. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Battle_UI_VISIBLE,vis)
  1442. end
  1443. function LuaBattleMgr:OnRefreshBattleOutput()
  1444. -- if self.logList == nil or #self.logList == 0 then
  1445. -- return
  1446. -- end
  1447. -- self.logList[#self.logList+1] = logStr
  1448. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Add_New_BattleLog)
  1449. end
  1450. -- function LuaBattleMgr:InitBattleOutputList()
  1451. -- self.logList = {}
  1452. -- local battleLogList = LuaBattleBridge.GetBattleLog()
  1453. -- if battleLogList ~= nil then
  1454. -- for i = 1, battleLogList.Count do
  1455. -- self.logList[#self.logList+1] = battleLogList[i-1]
  1456. -- end
  1457. -- end
  1458. -- return self.logList
  1459. -- end
  1460. -- function LuaBattleMgr:GetBattleLogList()
  1461. -- return self.logList
  1462. -- end
  1463. function LuaBattleMgr:NotifyLoadingStatus(status)
  1464. self.battleLoadingState = status
  1465. end
  1466. function LuaBattleMgr:NotifyLoadingStatusEnd(status)
  1467. self.battleLoadingState = nil
  1468. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.BATTLE_LOADING_COMPELETED)
  1469. end
  1470. function LuaBattleMgr:GetBattleLoadingState()
  1471. local statusIdx
  1472. local state, text = self:GetWaitingRefreshRoleState()
  1473. if not state then
  1474. statusIdx = self.battleLoadingState
  1475. else
  1476. statusIdx = Enum.BattleBtnState.RoleModel
  1477. end
  1478. if statusIdx == Enum.BattleBtnState.Skill then
  1479. text = "Challenging4"
  1480. elseif statusIdx == Enum.BattleBtnState.Fellow then
  1481. text = "Challenging3"
  1482. elseif statusIdx == Enum.BattleBtnState.Pet then
  1483. text = "Challenging3"
  1484. elseif statusIdx == Enum.BattleBtnState.RoleModel then
  1485. text = "Challenging2"
  1486. end
  1487. return statusIdx, text
  1488. end
  1489. --判断当前时间如果领取挂机奖励的话,魔魂值是否会溢出,返回值第一个是是否溢出,第二个是领取之前的值
  1490. function LuaBattleMgr:JudgeEvilExpOverFlow()
  1491. local _leftTime, _num = ManagerContainer.LuaBattleMgr:GetIncomeInfo()
  1492. local _curLvEvilExp = ManagerContainer.LuaBattleMgr:CurLevelEvil(); --每分钟挂机获得的魔魂值
  1493. local _evilExp = ManagerContainer.DataMgr.UserData:GetEvilExp();
  1494. local _rewardIntervalTimeM = GlobalConfig.Instance:GetConfigIntValue(47) / 60;
  1495. local _nexEvilExp = _evilExp + _curLvEvilExp * _rewardIntervalTimeM * _num;
  1496. if self.maxEvilExp == 0 then
  1497. self.maxEvilExp = GlobalConfig.Instance:GetConfigIntValue(158);
  1498. end
  1499. local _isOverFlow = _nexEvilExp > self.maxEvilExp;
  1500. return _isOverFlow, _evilExp;
  1501. end
  1502. function LuaBattleMgr:CSPlayerIncomeReq()
  1503. self.accumIncomeTime = ManagerContainer.LuaBattleMgr:AccumIncomeTime();
  1504. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_PLAYER_INCOME_REQ, {})
  1505. self:ReportIncomeRecord(true)
  1506. end
  1507. function LuaBattleMgr:ReportIncomeRecord(success)
  1508. if not SDKMgr.Instance:IsReportAction() then
  1509. return
  1510. end
  1511. local datas = System.Collections.Generic.Dictionary_object_object()
  1512. datas:Add('event', 'mj_online_rewards')
  1513. datas:Add('is_achieve', 1)
  1514. SDKMgr.Instance:ReportAction(datas)
  1515. end
  1516. function LuaBattleMgr:RefreshStatistics()
  1517. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_BattleStatistics)
  1518. end
  1519. function LuaBattleMgr:HeroChangeProfessionSuccess()
  1520. ManagerContainer.DataMgr.UserData:RoleChangeJobAttrSuccess()
  1521. end
  1522. return LuaBattleMgr;