LuaBattleMgr.lua 66 KB

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