LuaBattleMgr.lua 63 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751
  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. else
  1091. local cfg = ManagerContainer.CfgMgr:GetPrivilegeCardCfgByLv(2)
  1092. local curmaplvID = self:GetCurLevelUniqueId()
  1093. if cfg and cfg.UnlockCond and cfg.UnlockCond[2] == curmaplvID then
  1094. ManagerContainer.LuaTimerMgr:AddTimer(500, 1,self,function ()
  1095. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIRuneShopBT)
  1096. --Notice_TeQuanKa
  1097. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("Notice_TeQuanKa")
  1098. end,nil);
  1099. end
  1100. end
  1101. --if
  1102. end
  1103. function LuaBattleMgr:IsShowDifficultyTxt()
  1104. return self.difficulty == Enum.MapModeType.Difficulty and self.IsShowDiffTxt
  1105. end
  1106. -- 创建主角形象
  1107. function LuaBattleMgr:CreateRoleView()
  1108. if self.roleViewSystem then
  1109. local userData = ManagerContainer.DataMgr.UserData
  1110. local heroData = userData:GetMainRoleData()
  1111. self.roleViewSystem:RefreshView(Enum.RoleInEnvType.Battle, userData:GetUserRoleId(), userData:GetViewData(), nil, self, self.CreateRoleViewComplete)
  1112. end
  1113. end
  1114. -- 完成主角创建
  1115. function LuaBattleMgr:CreateRoleViewComplete(gameObject)
  1116. ManagerContainer.LuaGameMgr:CreateRoleViewComplete(gameObject)
  1117. end
  1118. -- 通知战斗需要更新主角新形象
  1119. function LuaBattleMgr:NotifyRefreshRoleView()
  1120. self.waitingRefreshRole = true
  1121. ManagerContainer.LuaGameMgr:NotifyRefreshRoleView()
  1122. end
  1123. function LuaBattleMgr:GetWaitingRefreshRoleState()
  1124. return self.waitingRefreshRole == true
  1125. end
  1126. -- 刷新主角形象
  1127. function LuaBattleMgr:RefreshRoleView()
  1128. if self.roleViewSystem then
  1129. local userData = ManagerContainer.DataMgr.UserData
  1130. local heroData = userData:GetMainRoleData()
  1131. self.roleViewSystem:RefreshView(Enum.RoleInEnvType.Battle, userData:GetUserRoleId(), userData:GetViewData(), nil, self, self.RefreshRoleViewComplete)
  1132. end
  1133. end
  1134. -- 完成主角形象更新
  1135. function LuaBattleMgr:RefreshRoleViewComplete(gameObject, isNewModel)
  1136. self.waitingRefreshRole = false
  1137. ManagerContainer.LuaGameMgr:RefreshRoleViewComplete(gameObject, isNewModel)
  1138. self:NotifyLoadingStatusEnd(Enum.BattleBtnState.RoleModel)
  1139. end
  1140. function LuaBattleMgr:RecycleRoleView()
  1141. if self.roleViewSystem then
  1142. self.roleViewSystem:Recycle()
  1143. end
  1144. end
  1145. -- function LuaBattleMgr:NotifyRefreshUpRoleLvEffect()
  1146. -- self:NotifyRefreshUpLvEffect('Common/FX_Scene_LV_UP')
  1147. -- end
  1148. -- function LuaBattleMgr:NotifyRefreshUpJobLvEffect()
  1149. -- self:NotifyRefreshUpLvEffect('Common/FX_Scene_LV_UP')
  1150. -- end
  1151. -- function LuaBattleMgr:NotifyRefreshUpLvEffect(effectName)
  1152. -- if not self.roleViewSystem then return end
  1153. -- local roleGo = self.roleViewSystem:GetGameObject()
  1154. -- if tolua.isnull(roleGo) then return end
  1155. -- local timeStamp = Time.GetTimestamp()
  1156. -- if not self.upLvEffectCDs then
  1157. -- self.upLvEffectCDs = {}
  1158. -- end
  1159. -- local upLvEffectCD = self.upLvEffectCDs[effectName] or (timeStamp - 2)
  1160. -- -- 1秒内不出现两次升级特效
  1161. -- if timeStamp - upLvEffectCD <= 1 then
  1162. -- return
  1163. -- end
  1164. -- self.upLvEffectCDs[effectName] = timeStamp
  1165. -- ManagerContainer.ResMgr:GetGOFromPool(Constants.EffectPath, effectName, function(go)
  1166. -- if ManagerContainer.FSMMgr:IsBattleState() then
  1167. -- self:UpLvEffectShow(go, effectName)
  1168. -- end
  1169. -- end)
  1170. -- end
  1171. -- --- 显示升级特效
  1172. -- function LuaBattleMgr:UpLvEffectShow(go, effectName)
  1173. -- if not go then return end
  1174. -- if self.roleViewSystem then
  1175. -- local roleGo = self.roleViewSystem:GetGameObject()
  1176. -- if not tolua.isnull(roleGo) then
  1177. -- local link = roleGo.transform:Find('foot_point')
  1178. -- if not tolua.isnull(link) then
  1179. -- go.transform.parent = link
  1180. -- go.transform.localPosition = Vector3.zero
  1181. -- go.transform.localRotation = Quaternion.identity
  1182. -- go.transform.localScale = Vector3.one
  1183. -- local upLvEffects = self.upLvEffects
  1184. -- if not upLvEffects then
  1185. -- upLvEffects = {}
  1186. -- self.upLvEffects = upLvEffects
  1187. -- end
  1188. -- local info = {}
  1189. -- info.effectName = effectName
  1190. -- info.timerId = ManagerContainer.LuaTimerMgr:AddTimer(2000, 1, self, self.UpLvEffectHide, {go = go})
  1191. -- upLvEffects[go] = info
  1192. -- return
  1193. -- end
  1194. -- LogError('Link Point : foot_point is not Find')
  1195. -- end
  1196. -- end
  1197. -- -- 出现问题,直接回收掉效果,直接回收掉升级特效
  1198. -- ManagerContainer.ResMgr:RecycleGO(Constants.EffectPath, effectCfg.Effect, go)
  1199. -- end
  1200. -- --- 升级特效播放完成,需要回收掉
  1201. -- function LuaBattleMgr:UpLvEffectHide(timerId, params)
  1202. -- local go = params.go
  1203. -- if not go then return end
  1204. -- local upLvEffects = self.upLvEffects
  1205. -- if not upLvEffects then return end
  1206. -- local info = upLvEffects[go]
  1207. -- local timeId = info.timerId
  1208. -- local effectName = info.effectName
  1209. -- if timeId ~= timerId then
  1210. -- LogError('timeId is error, cur : ' .. tostring(timeId) .. ' cbTimerId : ' .. tostring(timerId))
  1211. -- end
  1212. -- if timeId then
  1213. -- ManagerContainer.LuaTimerMgr:RemoveTimer(timeId)
  1214. -- timeId = nil
  1215. -- end
  1216. -- upLvEffects[go] = nil
  1217. -- ManagerContainer.ResMgr:RecycleGO(Constants.EffectPath, effectName, go)
  1218. -- end
  1219. -- --- 回收所有显示的升级特效
  1220. -- function LuaBattleMgr:RecycleUpLvEffect()
  1221. -- local upLvEffects = self.upLvEffects
  1222. -- if not upLvEffects then return end
  1223. -- for go, info in pairs(upLvEffects) do
  1224. -- local timeId = info.timerId
  1225. -- local effectName = info.effectName
  1226. -- if timeId then
  1227. -- ManagerContainer.LuaTimerMgr:RemoveTimer(timeId)
  1228. -- timeId = nil
  1229. -- end
  1230. -- ManagerContainer.ResMgr:RecycleGO(Constants.EffectPath, effectName, go)
  1231. -- end
  1232. -- self.upLvEffects = nil
  1233. -- self.upLvEffectCDs = nil
  1234. -- end
  1235. function LuaBattleMgr:OnShowBossWarning()
  1236. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_SHOW_BOSS_WARNING,true);
  1237. ManagerContainer.LuaTimerMgr:AddTimer(3000, 1,self,self.OnHideBossWarningTimer,nil);
  1238. end
  1239. function LuaBattleMgr:OnHideBossWarningTimer()
  1240. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_SHOW_BOSS_WARNING,false);
  1241. end
  1242. function LuaBattleMgr:OnEnterNextMap()
  1243. self.bKillBoss = false
  1244. self.nextMapState = NextMapState.None
  1245. ManagerContainer.LuaGameMgr:OpenLoading(Enum.UIPageName.UILoading)
  1246. ManagerContainer.FSMMgr:ChangeState(Enum.StateEnum.LoadingState.stateId, SceneType.NormalBattleScene)
  1247. end
  1248. function LuaBattleMgr:CurLevelExp()
  1249. return LuaBattleBridge.GetCurLevelExp();
  1250. end
  1251. function LuaBattleMgr:CurLevelParnterExp()
  1252. return LuaBattleBridge.GetCurLevelParnterExp();
  1253. end
  1254. function LuaBattleMgr:CurLevelGold()
  1255. return LuaBattleBridge.GetCurLevelGold();
  1256. end
  1257. function LuaBattleMgr:CurLevelCruise()
  1258. return LuaBattleBridge.GetCurLevelCruise();
  1259. end
  1260. function LuaBattleMgr:CurLevelEvil()
  1261. return LuaBattleBridge.GetCurLevelEvil()
  1262. end
  1263. function LuaBattleMgr:CurLevelZeny()
  1264. return LuaBattleBridge.GetCurLevelZeny()
  1265. end
  1266. function LuaBattleMgr:CurLevelName()
  1267. local lvname = LuaBattleBridge.GetCurLevelName() --DifLvName
  1268. if self.IsShowDiffTxt then
  1269. lvname = I18N.T("DifLvName")..lvname
  1270. end
  1271. return lvname
  1272. end
  1273. ----- 配置
  1274. function LuaBattleMgr:GetCurSimpleLvCfg ()
  1275. local lvID = self:GetCurSimpleLvID()
  1276. if self.curSimpleLvCgf == nil or self.curSimpleLvCgf.Id ~= lvID then
  1277. self.curSimpleLvCgf = ManagerContainer.CfgMgr:GetLevelDataById(lvID)
  1278. end
  1279. return self.curSimpleLvCgf
  1280. end
  1281. function LuaBattleMgr:CurSimpleLevelExp()
  1282. local lvDataCfg = self:GetCurSimpleLvCfg()
  1283. return lvDataCfg.BaseExpOl / 4
  1284. end
  1285. function LuaBattleMgr:CurSimpleLevelParnterExp()
  1286. local lvDataCfg = self:GetCurSimpleLvCfg()
  1287. return lvDataCfg.ParterOl / 4
  1288. end
  1289. function LuaBattleMgr:CurSimpleLevelGold()
  1290. local lvDataCfg = self:GetCurSimpleLvCfg()
  1291. return lvDataCfg.GoldOl / 4
  1292. end
  1293. function LuaBattleMgr:CurSimpleLevelCruise()
  1294. local lvDataCfg = self:GetCurSimpleLvCfg()
  1295. return lvDataCfg.CruiseOl / 4
  1296. end
  1297. function LuaBattleMgr:CurSimpleLevelEvil()
  1298. local lvDataCfg = self:GetCurSimpleLvCfg()
  1299. return lvDataCfg.EvilOl / 4
  1300. end
  1301. function LuaBattleMgr:CurSimpleLevelZeny()
  1302. local lvDataCfg = self:GetCurSimpleLvCfg()
  1303. return lvDataCfg.ZenyOl / 4
  1304. end
  1305. function LuaBattleMgr:CurSimpleLevelName()
  1306. local lvDataCfg = self:GetCurSimpleLvCfg()
  1307. return lvDataCfg.Name
  1308. end
  1309. -- 配置 end
  1310. function LuaBattleMgr:SetRewardDropPos(dropPos)
  1311. LuaBattleBridge.SetRewardDropPos(dropPos)
  1312. end
  1313. function LuaBattleMgr:Enter()
  1314. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.ROLE_JOB_CHANGE_SUCCESS, self, self.NotifyRefreshRoleView)
  1315. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.FASHION_WEAR_CHANGE, self, self.NotifyRefreshRoleView)
  1316. -- ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.ROLE_LV_CHANGED, self, self.NotifyRefreshUpRoleLvEffect)
  1317. -- ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.JOB_LV_CHANGED, self, self.NotifyRefreshUpJobLvEffect)
  1318. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.BIGMAP_ENTER_NEXTMAP_START, self, self.NotifyEnterNextMapStart)
  1319. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.BIGMAP_ENTER_NEXTMAP_END, self, self.NotifyEnterNextMapEnd)
  1320. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.VIP_LV_CHANGED, self, self.NotifyVipLvChanged)
  1321. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.EID_Loading_Close, self, self.OnLoadingClose)
  1322. self:NotifyVipLvChanged()
  1323. self.bKillBoss = false
  1324. --ManagerContainer.DataMgr.BigMapData:SendGetData()
  1325. self:StartSyncServerTimeTimer()
  1326. if self.rewardTimeTimerId == nil then
  1327. self.rewardTimeTimerId = ManagerContainer.LuaTimerMgr:AddTimer(1000, -1, self, self.OnRefreshRewardTime, nil)
  1328. end
  1329. local mainActor = ManagerContainer.LuaActorDataMgr:GetHeroActorData(1)
  1330. if mainActor ~= nil then
  1331. mainActor.Name = ManagerContainer.DataMgr.UserData:GetUserNickname()
  1332. end
  1333. self.isAutochallenge = false
  1334. end
  1335. function LuaBattleMgr:Exit()
  1336. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.ROLE_JOB_CHANGE_SUCCESS, self, self.NotifyRefreshRoleView)
  1337. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.FASHION_WEAR_CHANGE, self, self.NotifyRefreshRoleView)
  1338. -- ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.ROLE_LV_CHANGED, self, self.NotifyRefreshUpRoleLvEffect)
  1339. -- ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.JOB_LV_CHANGED, self, self.NotifyRefreshUpJobLvEffect)
  1340. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.BIGMAP_ENTER_NEXTMAP_START, self, self.NotifyEnterNextMapStart)
  1341. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.BIGMAP_ENTER_NEXTMAP_END, self, self.NotifyEnterNextMapEnd)
  1342. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.VIP_LV_CHANGED, self, self.NotifyVipLvChanged)
  1343. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.EID_Loading_Close, self, self.OnLoadingClose)
  1344. -- ManagerContainer.LuaBattleMgr:RecycleUpLvEffect()
  1345. ManagerContainer.LuaBattleMgr:RecycleRoleView()
  1346. if self.rewardTimeTimerId~= nil then
  1347. ManagerContainer.LuaTimerMgr:RemoveTimer(self.rewardTimeTimerId)
  1348. self.rewardTimeTimerId = nil
  1349. end
  1350. self.isAutochallenge = false
  1351. end
  1352. function LuaBattleMgr:SendBattleRecordReq()
  1353. ManagerContainer.LuaGameMgr:SendBattleRecordReq(100,{self.curMapId,self.curLevelId})
  1354. end
  1355. function LuaBattleMgr:GetFightersPos()
  1356. return LuaBattleBridge.GetFightersPos();
  1357. end
  1358. function LuaBattleMgr:GetCurMapId()
  1359. return self.curMapId
  1360. end
  1361. function LuaBattleMgr:GetCurMapAndLevel()
  1362. return self.curMapId, self.curLevelId
  1363. end
  1364. function LuaBattleMgr:MaxQuickBattleTimes()
  1365. return self.maxQuickBattleTimes
  1366. end
  1367. function LuaBattleMgr:UsedQuickBattleTimes()
  1368. return self.usedQuickBattleTimes
  1369. end
  1370. function LuaBattleMgr:GetCurrentLevelData()
  1371. return ManagerContainer.CfgMgr:GetLevelDataById(self:GetCurLevelUniqueId())
  1372. end
  1373. function LuaBattleMgr:OnLoadBegin()
  1374. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Loading_Begin);
  1375. -- LogError("LuaBattleMgr:OnLoadBegin")
  1376. end
  1377. function LuaBattleMgr:OnLoadProgress(progress)
  1378. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Loading_Progress,progress);
  1379. -- LogError("LuaBattleMgr:OnLoadProgress:" .. progress)
  1380. end
  1381. function LuaBattleMgr:OnLoadComplete()
  1382. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Loading_Complete);
  1383. -- LogError("LuaBattleMgr:OnLoadComplete")
  1384. end
  1385. function LuaBattleMgr:OnFighterCastSkill(skillParam)
  1386. if skillParam.isBoss then
  1387. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Boss_Skill,skillParam)
  1388. else
  1389. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Cast_Skill,skillParam)
  1390. end
  1391. end
  1392. function LuaBattleMgr:OnShowBossBuff(actorId,isBoss,buffIcon,num,isPlayeRecord)
  1393. if isBoss then
  1394. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Boss_Buff,buffIcon,num)
  1395. else
  1396. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Player_Buff,actorId, buffIcon,num)
  1397. end
  1398. end
  1399. function LuaBattleMgr:OnRemoveBossBuff(actorId,isBoss,buffIcon)
  1400. if isBoss then
  1401. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Boss_Remove_Buff,buffIcon)
  1402. else
  1403. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Remove_Player_Buff, actorId, buffIcon)
  1404. end
  1405. end
  1406. function LuaBattleMgr:OnFighterLifeChanged(isBoss,actorId,life,maxLife)
  1407. if isBoss then
  1408. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Boss_Life,life,maxLife)
  1409. else
  1410. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Fighter_Life,actorId,life,maxLife)
  1411. end
  1412. end
  1413. function LuaBattleMgr:OnFighterEnergyChanged(actorId,sp,maxSp)
  1414. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Fighter_Sp,actorId,sp,maxSp)
  1415. end
  1416. function LuaBattleMgr:OnRefreshSkillCD(isBoss,actorId,leftTime,totalTime)
  1417. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Skill_CD,isBoss,actorId,leftTime,totalTime)
  1418. -- LogError("--------------------------------------------isBoss = " .. tostring(isBoss) .. " actorId = " .. actorId .. " leftTime = " .. leftTime .. " totalTime = " .. totalTime)
  1419. end
  1420. function LuaBattleMgr:OnBattleUIVis(vis)
  1421. if vis then
  1422. --ManagerContainer.LuaUIMgr:Show(Enum.UIPageName.UIBattle)
  1423. --ManagerContainer.LuaUIMgr:Show(Enum.UIPageName.UIMain)
  1424. else
  1425. --ManagerContainer.LuaUIMgr:Hide(Enum.UIPageName.UIBattle)
  1426. --ManagerContainer.LuaUIMgr:Hide(Enum.UIPageName.UIMain)
  1427. end
  1428. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Battle_UI_VISIBLE,vis)
  1429. end
  1430. function LuaBattleMgr:OnRefreshBattleOutput()
  1431. -- if self.logList == nil or #self.logList == 0 then
  1432. -- return
  1433. -- end
  1434. -- self.logList[#self.logList+1] = logStr
  1435. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Add_New_BattleLog)
  1436. end
  1437. -- function LuaBattleMgr:InitBattleOutputList()
  1438. -- self.logList = {}
  1439. -- local battleLogList = LuaBattleBridge.GetBattleLog()
  1440. -- if battleLogList ~= nil then
  1441. -- for i = 1, battleLogList.Count do
  1442. -- self.logList[#self.logList+1] = battleLogList[i-1]
  1443. -- end
  1444. -- end
  1445. -- return self.logList
  1446. -- end
  1447. -- function LuaBattleMgr:GetBattleLogList()
  1448. -- return self.logList
  1449. -- end
  1450. function LuaBattleMgr:NotifyLoadingStatus(status)
  1451. self.battleLoadingState = status
  1452. end
  1453. function LuaBattleMgr:NotifyLoadingStatusEnd(status)
  1454. self.battleLoadingState = nil
  1455. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.BATTLE_LOADING_COMPELETED)
  1456. end
  1457. function LuaBattleMgr:GetBattleLoadingState()
  1458. local statusIdx
  1459. local state, text = self:GetWaitingRefreshRoleState()
  1460. if not state then
  1461. statusIdx = self.battleLoadingState
  1462. else
  1463. statusIdx = Enum.BattleBtnState.RoleModel
  1464. end
  1465. if statusIdx == Enum.BattleBtnState.Skill then
  1466. text = "Challenging4"
  1467. elseif statusIdx == Enum.BattleBtnState.Fellow then
  1468. text = "Challenging3"
  1469. elseif statusIdx == Enum.BattleBtnState.Pet then
  1470. text = "Challenging3"
  1471. elseif statusIdx == Enum.BattleBtnState.RoleModel then
  1472. text = "Challenging2"
  1473. end
  1474. return statusIdx, text
  1475. end
  1476. --判断当前时间如果领取挂机奖励的话,魔魂值是否会溢出,返回值第一个是是否溢出,第二个是领取之前的值
  1477. function LuaBattleMgr:JudgeEvilExpOverFlow()
  1478. local _leftTime, _num = ManagerContainer.LuaBattleMgr:GetIncomeInfo()
  1479. local _curLvEvilExp = ManagerContainer.LuaBattleMgr:CurLevelEvil(); --每分钟挂机获得的魔魂值
  1480. local _evilExp = ManagerContainer.DataMgr.UserData:GetEvilExp();
  1481. local _rewardIntervalTimeM = GlobalConfig.Instance:GetConfigIntValue(47) / 60;
  1482. local _nexEvilExp = _evilExp + _curLvEvilExp * _rewardIntervalTimeM * _num;
  1483. if self.maxEvilExp == 0 then
  1484. self.maxEvilExp = GlobalConfig.Instance:GetConfigIntValue(158);
  1485. end
  1486. local _isOverFlow = _nexEvilExp > self.maxEvilExp;
  1487. return _isOverFlow, _evilExp;
  1488. end
  1489. function LuaBattleMgr:CSPlayerIncomeReq()
  1490. self.accumIncomeTime = ManagerContainer.LuaBattleMgr:AccumIncomeTime();
  1491. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_PLAYER_INCOME_REQ, {})
  1492. self:ReportIncomeRecord(true)
  1493. end
  1494. function LuaBattleMgr:ReportIncomeRecord(success)
  1495. if not SDKMgr.Instance:IsReportAction() then
  1496. return
  1497. end
  1498. local datas = System.Collections.Generic.Dictionary_object_object()
  1499. datas:Add('event', 'mj_online_rewards')
  1500. datas:Add('is_achieve', 1)
  1501. SDKMgr.Instance:ReportAction(datas)
  1502. end
  1503. function LuaBattleMgr:RefreshStatistics()
  1504. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_BattleStatistics)
  1505. end
  1506. function LuaBattleMgr:HeroChangeProfessionSuccess()
  1507. ManagerContainer.DataMgr.UserData:RoleChangeJobAttrSuccess()
  1508. end
  1509. return LuaBattleMgr;