LuaBattleMgr.lua 65 KB

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