LuaBattleMgr.lua 67 KB

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