LuaBattleMgr.lua 64 KB

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