LuaBattleMgr.lua 63 KB

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