LuaBattleMgr.lua 64 KB

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