LuaBattleMgr.lua 67 KB

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