ExpeditionDataMgr.lua 41 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195
  1. local ExpeditionDataMgr = class("ExpeditionDataMgr",require("DataBase"))
  2. local ExpeditionMapData = require("Expedition/ExpeditionMapData")
  3. local ExpeditionBuff = require("Expedition/ExpeditionBuff")
  4. local FriendData = require("Friend/FriendData")
  5. local BitUtil = require("BitUtil")
  6. function ExpeditionDataMgr:ctor()
  7. self.allMaps = {}
  8. self.bInited = false
  9. self.battleHeros = {}
  10. self.leftChanllengeNum = 0
  11. self.curChanllengeMapId = 0 --当前挑战的地图类型id
  12. self.curChanllengeLevelId = 0 --当前挑战的关卡id
  13. self.curChanllengeSlotIdx = 0 --当前挑战的位置
  14. self.curChallengeLevelBossList = nil --当前挑战关卡随机出来的boss [id,level,hp,sp]
  15. self.serverHerosData = nil
  16. self.buffs = nil
  17. self.maxAssistNum = 0 --最大可使用救援次数
  18. self.usedAssistNum = 0 --已经使用的救援次数
  19. self.maxRescuedNum = 0 --最大可被救援次数
  20. self.usedRescuedNum = 0 --已经使用的被救援次数
  21. self.inAssisting = false --求助中
  22. self.guildAssistingEndTime = nil
  23. self.myRescuerIds = nil
  24. self.myRescuers = nil
  25. self.curChallengingBossId = 0
  26. self.curChallengingBossLevel = 0
  27. self.bossPreLife = 0 --boss上一秒的血量
  28. self.bossPreSp = 0 --boss上一秒的蓝量
  29. self.preSycnHPAndSpTime = 0
  30. self.lastFinishedMap = 0
  31. self.battleEndCondList = nil
  32. self.isSingleReward = false
  33. end
  34. function ExpeditionDataMgr:RegisterNetEvents()
  35. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_EXPEDITION_CHANGE_NTF,self.OnExpeditionDataNtf, self)
  36. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_EXPEDITION_CHALLENGE_PRE_ACK,self.OnChallengeMapAck, self)
  37. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_EXPEDITION_CHALLENGE_ACK,self.OnChallengeBossEndAck, self)
  38. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_EXPEDITION_SELECT_BUFF_ACK,self.OnSelectBuffAck, self)
  39. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_EXPEDITION_REWARD_ACK,self.OnGotRewardAck, self)
  40. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_EXPEDITION_BATTLE_HERO_ACK,self.OnApplyBattleTeamAck, self)
  41. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_EXPEDITION_CALL_FOR_HELP_ACK,self.OnAssistReqAck, self)
  42. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_EXPEDITION_CALL_FOR_HELP_NTF,self.OnAssistNtf, self)
  43. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_EXPEDITION_HELP_ACK,self.OnRescueFriendAck, self)
  44. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_EXPEDITION_SCORE_RANK_LIST_ACK,self.OnScoreRankListAck, self)
  45. ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_EXPEDITION_PASS_REWARD_ACK,self.OnPassRewardAck, self)
  46. ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.EID_Expedition_GET_OTHER_PLAYER_BRIEF_INFO,self,self.OnGetBriefInfoAck)
  47. end
  48. function ExpeditionDataMgr:Clear()
  49. self.bInited = false
  50. self.allMaps = {}
  51. self.battleHeros = {}
  52. self.curChallengeLevelBossList = nil
  53. self.serverHerosData = nil
  54. self.buffs = nil
  55. self.battleEndCondList = nil
  56. self.lastFinishedMap = 0
  57. end
  58. function ExpeditionDataMgr:Destroy()
  59. end
  60. function ExpeditionDataMgr:UnRegisterNetEvents()
  61. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_EXPEDITION_CHANGE_NTF)
  62. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_EXPEDITION_CHALLENGE_PRE_ACK)
  63. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_EXPEDITION_CHALLENGE_ACK)
  64. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_EXPEDITION_SELECT_BUFF_ACK)
  65. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_EXPEDITION_REWARD_ACK)
  66. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_EXPEDITION_BATTLE_HERO_ACK)
  67. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_EXPEDITION_CALL_FOR_HELP_ACK)
  68. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_EXPEDITION_CALL_FOR_HELP_NTF)
  69. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_EXPEDITION_SCORE_RANK_LIST_ACK)
  70. ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_EXPEDITION_PASS_REWARD_ACK)
  71. ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.EID_Expedition_GET_OTHER_PLAYER_BRIEF_INFO,self,self.OnGetBriefInfoAck)
  72. end
  73. function ExpeditionDataMgr:InitData()
  74. if self.bInited then
  75. return
  76. end
  77. self.allMaps = {}
  78. for typeId=1, 100 do
  79. local cfg = ManagerContainer.CfgMgr:GetExpeditionCfgByTypeAndLevelId(typeId,1)
  80. if cfg == nil then
  81. break
  82. end
  83. local mapData = ExpeditionMapData:new(typeId,cfg)
  84. self.allMaps[#self.allMaps + 1] = mapData
  85. end
  86. end
  87. function ExpeditionDataMgr:GetAllMaps()
  88. return self.allMaps
  89. end
  90. function ExpeditionDataMgr:FindMapByTypeId(typeId)
  91. if self.allMaps == nil then
  92. return nil
  93. end
  94. for i = 1, #self.allMaps do
  95. if self.allMaps[i].mapId == typeId then
  96. return self.allMaps[i]
  97. end
  98. end
  99. return nil
  100. end
  101. function ExpeditionDataMgr:Reset()
  102. if self.allMaps == nil then
  103. return
  104. end
  105. for i = 1, #self.allMaps do
  106. self.allMaps[i]:Reset()
  107. end
  108. end
  109. --
  110. function ExpeditionDataMgr:ResetSvrIdx()
  111. self.StartSvrIdx = 1
  112. end
  113. --获取服务器数据排行榜 起始IDX
  114. function ExpeditionDataMgr:GetListSvrStartIdx()
  115. if nil == self.StartSvrIdx then
  116. self.StartSvrIdx = 1
  117. end
  118. return self.StartSvrIdx
  119. end
  120. function ExpeditionDataMgr:GetSelfRank()
  121. return self.SelfScoreRank
  122. end
  123. function ExpeditionDataMgr:GetListfRank()
  124. return self.ScoreRankList
  125. end
  126. function ExpeditionDataMgr:GetRankDataByIdx(Idx)
  127. if #self.ScoreRankList >= Idx then
  128. return self.ScoreRankList[Idx]
  129. end
  130. end
  131. function ExpeditionDataMgr:GetNextRankListNum()
  132. if nil == self.StartSvrIdx then
  133. self.StartSvrIdx = 1
  134. end
  135. local step = 20
  136. local Max = 100
  137. local IsOver = false
  138. self.StartSvrIdx = self.StartSvrIdx + step
  139. if self.StartSvrIdx >= Max then
  140. self.StartSvrIdx = Max
  141. IsOver = true
  142. end
  143. -- if self.StartSvrIdx > #self.ScoreRankList then
  144. -- self.StartSvrIdx = #self.ScoreRankList
  145. -- end
  146. return self.StartSvrIdx,IsOver
  147. end
  148. function ExpeditionDataMgr:CreateRankListSvrData(svrdata)
  149. if nil == self.SelfScoreRank then
  150. self.SelfScoreRank = {}
  151. end
  152. if nil == self.ScoreRankList then
  153. self.ScoreRankList = {}
  154. end
  155. if svrdata.error == 0 then
  156. for i = 1, #svrdata.rank_list do
  157. self.ScoreRankList[svrdata.rank_list[i].rank] = svrdata.rank_list[i]
  158. end
  159. self.SelfScoreRank = svrdata.self_rank_info
  160. --self.StartSvrIdx = svrdata.start_idx
  161. end
  162. end
  163. --收到勇士积分排行榜
  164. function ExpeditionDataMgr:OnScoreRankListAck(data)
  165. --LogError(Inspect(data))
  166. if data.error == Enum.NetErrorCode.ERROR_OK then
  167. self:CreateRankListSvrData(data)
  168. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Expedition_RankData)
  169. end
  170. end
  171. --请求通过奖励
  172. function ExpeditionDataMgr:SendPassRewardReq(mapId)
  173. --LogError("Send..."..tostring(mapId))
  174. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_EXPEDITION_PASS_REWARD_REQ, {expedition_type = mapId})
  175. end
  176. --收到通过奖励
  177. function ExpeditionDataMgr:OnPassRewardAck(data)
  178. -- LogError("OnPassRewardAck")
  179. if ManagerContainer.NetManager:IsErrorData(data) then
  180. return
  181. end
  182. if data.reward_item_list ~= nil then
  183. local rewardList = {}
  184. for i = 1, #data.reward_item_list do
  185. local _itemData = data.reward_item_list[i]
  186. rewardList[#rewardList+1] = {cfgId = _itemData.key, num = _itemData.value}
  187. end
  188. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPOPGot,{rewards = rewardList})
  189. end
  190. end
  191. function ExpeditionDataMgr:IsGetPassReward(mapId)
  192. --LogError("mapId"..tostring(mapId))
  193. --LogError("expedition_type_reward"..tostring(self.expedition_type_reward))
  194. local isGet = BitUtil.RshiftNumBandOne(self.expedition_type_reward,mapId) == 1
  195. return isGet
  196. end
  197. function ExpeditionDataMgr:SendScoreRankListReq(Idx)
  198. --LogError("Sending"..tostring(Idx))
  199. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_EXPEDITION_SCORE_RANK_LIST_REQ, {start_idx = Idx})
  200. end
  201. function ExpeditionDataMgr:OnExpeditionDataNtf(data)
  202. LogError("=========OnExpeditionDataNtf========"..Inspect(data.expedition_info))
  203. self:SetData(data.expedition_info)
  204. if data.day_reset then
  205. if self.curChallengingBossId > 0 then
  206. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_SHUT_TIMEBATTLE,Enum.UIPageName.UIExpedition,false)
  207. self.curChallengingBossId = 0
  208. end
  209. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Expedition_ResetData)
  210. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("ExpeReset")
  211. end
  212. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Expedition_RefreshData, self.isSingleReward)
  213. self.isSingleReward = false
  214. end
  215. function ExpeditionDataMgr:SaveUnlockMap(expedition_type)
  216. local uid = ManagerContainer.DataMgr.UserData:GetUserId()
  217. UnityEngine.PlayerPrefs.SetString(tostring(uid).."_ExpeditionUnlockMap",tostring(expedition_type))
  218. end
  219. function ExpeditionDataMgr:LoadUnlockMap()
  220. local uid = ManagerContainer.DataMgr.UserData:GetUserId()
  221. local expedition_type = UnityEngine.PlayerPrefs.GetString(tostring(uid).."_ExpeditionUnlockMap")
  222. if expedition_type ~= nil and expedition_type ~= "" then
  223. local temp = tonumber(expedition_type)
  224. for i = 1, temp do
  225. local map = self:FindMapByTypeId(i)
  226. if map ~= nil then
  227. map:SetNewState(false)
  228. end
  229. end
  230. end
  231. end
  232. function ExpeditionDataMgr:SetData(expeditionInfo)
  233. --LogError("ExpeditionDataMgr:SetData:" .. Inspect(expeditionInfo))
  234. self:InitData()
  235. self:Reset()
  236. self.expedition_type_reward = expeditionInfo.expedition_type_reward
  237. if expeditionInfo == nil then
  238. return
  239. end
  240. --设置解锁的地图
  241. if expeditionInfo.expedition_type ~= nil then
  242. for i = 1, expeditionInfo.expedition_type do
  243. local map = self:FindMapByTypeId(i)
  244. if map ~= nil then
  245. map:SetUnlockState(true)
  246. map:SetNewState(true)
  247. end
  248. end
  249. end
  250. self:LoadUnlockMap()
  251. self:SaveUnlockMap(expeditionInfo.expedition_type)
  252. --老的当天 会清空
  253. --设置通关地图信息
  254. -- if expeditionInfo.finish_expedition_list ~= nil then
  255. -- for i =1, #expeditionInfo.finish_expedition_list do
  256. -- local map = self:FindMapByTypeId(expeditionInfo.finish_expedition_list[i])
  257. -- if map ~= nil then
  258. -- map:SetMapPassed(true)
  259. -- end
  260. -- end
  261. -- self.lastFinishedMap = expeditionInfo.finish_expedition_list[#expeditionInfo.finish_expedition_list]
  262. -- end
  263. --小于通过地图信息 重置
  264. for i =1, expeditionInfo.expedition_type - 1 do
  265. local map = self:FindMapByTypeId(i)
  266. if map ~= nil then
  267. map:SetMapPassed(true)
  268. self.lastFinishedMap = i
  269. end
  270. end
  271. self.buffs = {}
  272. if expeditionInfo.battle_buff_list ~= nil then
  273. for i = 1, #expeditionInfo.battle_buff_list do
  274. local buff = ManagerContainer.CfgMgr:GetExpeditionBuffCfgById(expeditionInfo.battle_buff_list[i])
  275. if buff ~= nil then
  276. self.buffs[#self.buffs+1] = buff
  277. end
  278. end
  279. end
  280. CommonUtil.ArraySortSelections(self.buffs, Enum.TableSortRule.Down, "Quality", "Id")
  281. --设置上阵玩家ID
  282. self.battleHeros = expeditionInfo.battle_hero_list
  283. self.curChallengeLevelBossList = expeditionInfo.boss_list
  284. self.serverHerosData = expeditionInfo.battle_hero_hp_list
  285. self.maxAssistNum = expeditionInfo.assist_num.key
  286. self.usedAssistNum = expeditionInfo.assist_num.value
  287. self.maxRescuedNum = expeditionInfo.be_assist_num.key
  288. self.usedRescuedNum = expeditionInfo.be_assist_num.value
  289. self.inAssisting = expeditionInfo.assist_state
  290. self.guildAssistingEndTime = tonumber(tostring(expeditionInfo.assist_guild_end_time/1000))
  291. if expeditionInfo.be_assist_uid_list ~= nil then
  292. self.myRescuers = {}
  293. self.myRescuerIds = {}
  294. for i = 1, #expeditionInfo.be_assist_uid_list do
  295. local assist = expeditionInfo.be_assist_uid_list[i]
  296. self.myRescuerIds[#self.myRescuerIds+1] = {uid = assist.key, time = assist.value}
  297. end
  298. else
  299. self.myRescuerIds = nil
  300. self.myRescuers = nil
  301. end
  302. --设置当前挑战地图关卡信息
  303. local lastChanllengeMapId = self.curChanllengeMapId
  304. self.leftChanllengeNum = expeditionInfo.challenge_num
  305. self.curChanllengeMapId = expeditionInfo.cur_expedition_type
  306. self.curChanllengeLevelId = expeditionInfo.cur_battle_level
  307. self.curChanllengeSlotIdx = expeditionInfo.battle_idx
  308. self.curexpeditionscore = expeditionInfo.cur_expedition_score--当前关卡积分
  309. self.curexpeditionscoremax = expeditionInfo.cur_expedition_score_max--当前总积分
  310. local map = self:FindMapByTypeId(self.curChanllengeMapId)
  311. if map ~= nil then
  312. map:SetChallengeState(true)
  313. map:SetPassedLevels(self.curChanllengeLevelId)
  314. end
  315. --当为挑战过界面,默认预览最新开启的界面
  316. if self.curChanllengeMapId == 0 then
  317. for i = #self.allMaps, 1, -1 do
  318. if self.allMaps[i].unlocked then
  319. self.allMaps[i]:SetUnfold(true)
  320. break
  321. end
  322. end
  323. end
  324. --设置地图关卡奖励领取信息
  325. if expeditionInfo.reward_state_list ~= nil then
  326. for i =1, #expeditionInfo.reward_state_list do
  327. local map = self:FindMapByTypeId(expeditionInfo.reward_state_list[i].expedition_type)
  328. if map ~= nil then
  329. map:SetGotRewardLevels(expeditionInfo.reward_state_list[i].reward_state)
  330. end
  331. end
  332. end
  333. --设置奖励以领取
  334. for i = #self.allMaps, 1, -1 do
  335. if self.allMaps[i].isPassed then
  336. self.allMaps[i]:SetMapGotReward()
  337. end
  338. end
  339. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Expedition_RefreshScroe)
  340. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.RED_POINT_MGR_NOTICE, Enum.RPNotifyType.Expedition, self:HasRedPoint())
  341. end
  342. --获取怪物积分
  343. function ExpeditionDataMgr:GetCurBossScore(bossId)
  344. local BossInfo = ManagerContainer.CfgMgr:GetExpeditionBossCfg(bossId)
  345. if BossInfo then
  346. return BossInfo.WarriorScore
  347. end
  348. return 0
  349. end
  350. --buff 积分系数
  351. function ExpeditionDataMgr:GetScoreRatio(Scroe)
  352. --系数获取
  353. local mapData = self:FindMapByTypeId(self.curChanllengeMapId)
  354. if mapData then
  355. local levelData = mapData:FindLevelByLevelId(1)
  356. if levelData then
  357. local LevelCoefficient = levelData:GetLevelCoefficient()
  358. if LevelCoefficient then
  359. return math.ceil(LevelCoefficient * 0.01 * Scroe) --向上取整
  360. end
  361. end
  362. end
  363. return Scroe
  364. end
  365. --根据BUFFid 获取积分
  366. function ExpeditionDataMgr:GetScoreByBuffId(BuffID)
  367. --LogError(tostring(BuffID))
  368. local buff = ManagerContainer.CfgMgr:GetExpeditionBuffCfgById(BuffID)
  369. if buff then
  370. return self:GetScoreRatio(buff.WarriorScore)
  371. end
  372. return 0
  373. end
  374. --当前关卡总积分
  375. function ExpeditionDataMgr:GetCurScore()
  376. return self.curexpeditionscore
  377. end
  378. --历史最高总积分
  379. function ExpeditionDataMgr:GetMaxScore()
  380. return self.curexpeditionscoremax
  381. end
  382. --是否新纪录
  383. function ExpeditionDataMgr:IsNewRecord()
  384. return self:GetMaxScore() <= self:GetCurScore()
  385. end
  386. function ExpeditionDataMgr:SaveLastMonster(BossName,Score)
  387. self.LastBossName = BossName
  388. self.LastBossScore = Score
  389. end
  390. function ExpeditionDataMgr:GetLastMonsterNameScore()
  391. return self.LastBossName,self.LastBossScore
  392. end
  393. function ExpeditionDataMgr:SaveLastBuffScore(BuffID)
  394. self.LastBuffScore = self:GetScoreByBuffId(BuffID)
  395. end
  396. function ExpeditionDataMgr:GetLastBuffScore()
  397. return self.LastBuffScore
  398. end
  399. function ExpeditionDataMgr:GetLastFinishedMapState()
  400. if self.lastFinishedMap == 0 then return false end
  401. local map = self:FindMapByTypeId(self.lastFinishedMap)
  402. if not map then
  403. return
  404. end
  405. return map:HasRedPoint() and map.isPassed
  406. end
  407. function ExpeditionDataMgr:CheckUnlockMaps()
  408. for i = 1, #self.allMaps do
  409. self.allMaps[i]:CheckUnlock()
  410. end
  411. end
  412. function ExpeditionDataMgr:RefreshUnfold()
  413. -- self:CheckUnlockMaps()
  414. for i = 1, #self.allMaps do
  415. self.allMaps[i]:SetUnfold(false)
  416. end
  417. if self.curChanllengeMapId > 0 then
  418. local map = self:FindMapByTypeId(self.curChanllengeMapId)
  419. map:SetUnfold(true)
  420. else
  421. for i = #self.allMaps, 1, -1 do
  422. if self.allMaps[i].unlocked then
  423. self.allMaps[i]:SetUnfold(true)
  424. break
  425. end
  426. end
  427. end
  428. end
  429. function ExpeditionDataMgr:CurChallengingMap()
  430. if self.curChanllengeMapId == 0 then
  431. return nil
  432. end
  433. return self:FindMapByTypeId(self.curChanllengeMapId)
  434. end
  435. function ExpeditionDataMgr:IsChallenging()
  436. return self.curChanllengeMapId > 0
  437. end
  438. function ExpeditionDataMgr:HasRedPoint()
  439. if self.allMaps == nil then
  440. return false
  441. end
  442. for i = 1, #self.allMaps do
  443. if self.allMaps[i]:HasRedPoint() then
  444. return true
  445. end
  446. end
  447. --LogError("=======self.lastFinishedMap======="..self.lastFinishedMap)
  448. for i = 1, self.lastFinishedMap do
  449. if self.allMaps[i].isPassed then
  450. local IsShowReward = not self:IsGetPassReward(self.allMaps[i].mapId)--是否领取
  451. if IsShowReward then
  452. return IsShowReward
  453. end
  454. end
  455. end
  456. return false
  457. end
  458. function ExpeditionDataMgr:GetCurLevelId()
  459. return self.curChanllengeLevelId
  460. end
  461. function ExpeditionDataMgr:GetBossList()
  462. return self.curChallengeLevelBossList
  463. end
  464. function ExpeditionDataMgr:GetBuffs()
  465. return self.buffs
  466. end
  467. function ExpeditionDataMgr:ChanllengeSlotIdx()
  468. return self.curChanllengeSlotIdx
  469. end
  470. function ExpeditionDataMgr:GetCurrBattleTeamMembers()
  471. if #self.battleHeros == 0 then
  472. local teamData = ManagerContainer.DataMgr.UserData:GetTeamData(true)
  473. for i = 1, #teamData do
  474. self.battleHeros[#self.battleHeros+1] = teamData[i].uid
  475. end
  476. self:SendApplyBattleTeamReq(self.battleHeros)
  477. end
  478. return self.battleHeros
  479. end
  480. function ExpeditionDataMgr:CurMemberCnt()
  481. return #self.battleHeros
  482. end
  483. function ExpeditionDataMgr:IsInBattleTeam(uid)
  484. for i = 1, #self.battleHeros do
  485. if self.battleHeros[i] == uid then
  486. return true
  487. end
  488. end
  489. return false
  490. end
  491. function ExpeditionDataMgr:OnBattle(actorId)
  492. if self:CurMemberCnt() >= 4 then
  493. return
  494. end
  495. if self:IsInBattleTeam(actorId) then
  496. return
  497. end
  498. self.battleHeros[#self.battleHeros + 1] = actorId
  499. self:SendApplyBattleTeamReq(self.battleHeros)
  500. end
  501. function ExpeditionDataMgr:ReplaceBattleActorId(orgUid,newUid)
  502. for i=1, #self.battleHeros do
  503. if self.battleHeros[i] == orgUid then
  504. self.battleHeros[i] = newUid
  505. self:SendApplyBattleTeamReq(self.battleHeros)
  506. break;
  507. end
  508. end
  509. end
  510. function ExpeditionDataMgr:GetTeamTotalFightPower()
  511. local TotalPower = 0
  512. for i = 1, #self.battleHeros do
  513. local Power = ManagerContainer.DataMgr.UserData:GetAsideFighterSvrPower(self.battleHeros[i],false)
  514. if nil ~= Power and -1 ~= Power then
  515. TotalPower = TotalPower + Power
  516. local PetPower = ManagerContainer.DataMgr.UserData:GetAsideFighterSvrPower(self.battleHeros[i],true)
  517. if nil ~= PetPower and -1 ~= PetPower then
  518. TotalPower = TotalPower + PetPower
  519. end
  520. else
  521. --local power
  522. Power = ManagerContainer.DataMgr.UserData:GetSlotFightPower(self.battleHeros[i])
  523. TotalPower = TotalPower + Power
  524. end
  525. end
  526. return TotalPower
  527. end
  528. function ExpeditionDataMgr:GetHeroHPAndSP(uid)
  529. if self.serverHerosData == nil then
  530. return 100,100
  531. end
  532. for i = 1, #self.serverHerosData do
  533. if tostring(self.serverHerosData[i].id) == tostring(uid) then
  534. return self.serverHerosData[i].hp, self.serverHerosData[i].sp
  535. end
  536. end
  537. return 100, 100
  538. end
  539. function ExpeditionDataMgr:SetHeroHPAndSp(uid, hpPercent,spPercent)
  540. if self.serverHerosData == nil then
  541. return
  542. end
  543. for i = 1, #self.serverHerosData do
  544. if self.serverHerosData[i].id == uid then
  545. self.serverHerosData[i].hp = hpPercent
  546. self.serverHerosData[i].sp = spPercent
  547. return
  548. end
  549. end
  550. end
  551. function ExpeditionDataMgr:ResetAllHeroHp()
  552. if self.serverHerosData == nil then
  553. return
  554. end
  555. for i = 1, #self.serverHerosData do
  556. self.serverHerosData[i].hp = 100
  557. end
  558. end
  559. function ExpeditionDataMgr:EnterBattle()
  560. local map = self:FindMapByTypeId(self.curChanllengeMapId)
  561. if map ~= nil then
  562. local levelInfo = map:FindLevelByLevelId(self.curChanllengeLevelId)
  563. self.curMaxFightingTime = levelInfo.maxFightingTime
  564. ManagerContainer.LuaGameMgr:RefreshTeamData()
  565. local maxHP = 0
  566. local maxHPActorId = 0
  567. local heroIds = {}
  568. for i = 1, #self.battleHeros do
  569. local hpPercent,spPercent = self:GetHeroHPAndSP(self.battleHeros[i])
  570. local actor = ManagerContainer.LuaActorDataMgr:GetActorsById(self.battleHeros[i])
  571. if hpPercent > 0 then
  572. local MaxHp = SDataUtil.InvConvert(actor.Life) * hpPercent * 0.01
  573. heroIds[#heroIds + 1] = self.battleHeros[i]
  574. if MaxHp > maxHP then
  575. maxHP = MaxHp
  576. maxHPActorId = self.battleHeros[i]
  577. end
  578. end
  579. end
  580. if #heroIds == 0 then
  581. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("队伍全部阵亡")
  582. return
  583. end
  584. --清空現有dropbuff 戰鬥結束清理 有bug
  585. ManagerContainer.LuaActorDataMgr:ResetData()
  586. local ourActors = System.Array.CreateInstance(Enum.TypeInfo.ActorData, #heroIds)
  587. for i = 1 , #heroIds do
  588. local actor = ManagerContainer.LuaActorDataMgr:GetActorsById(heroIds[i])
  589. ourActors[i-1] = actor
  590. --增加对应压制mark
  591. ManagerContainer.DataMgr.UserData:SetActorPveMark(heroIds[i],actor)
  592. --设置掉落buff
  593. local dropBuffs = self:GetDropBuffs(actor,maxHPActorId)
  594. if dropBuffs ~= nil then
  595. local dropBuffParamList = System.Array.CreateInstance(Enum.TypeInfo.BuffParam, #dropBuffs)
  596. for j = 1, #dropBuffs do
  597. local buffParam = dropBuffs[j]
  598. dropBuffParamList[j-1] = BuffParam.New(buffParam.buffId, buffParam.buffRatio, buffParam.buffCd, buffParam.buffType,buffParam.extendPara,buffParam:ConvertFunToStr())
  599. end
  600. actor:SetDropBuffs(dropBuffParamList)
  601. end
  602. if actor.HasPet then
  603. local petDropBuffs = self:GetDropBuffs(actor.PetData,maxHPActorId)
  604. if petDropBuffs ~= nil then
  605. local dropBuffParamList = System.Array.CreateInstance(Enum.TypeInfo.BuffParam, #petDropBuffs)
  606. for j = 1, #petDropBuffs do
  607. local buffParam = petDropBuffs[j]
  608. dropBuffParamList[j-1] = BuffParam.New(buffParam.buffId, buffParam.buffRatio, buffParam.buffCd, buffParam.buffType,buffParam.extendPara,buffParam:ConvertFunToStr())
  609. end
  610. actor.PetData:SetDropBuffs(dropBuffParamList)
  611. end
  612. end
  613. end
  614. local bossInfo = self.curChallengeLevelBossList[self.curChanllengeSlotIdx]
  615. local enemyActors = System.Array.CreateInstance(Enum.TypeInfo.ActorData, 1)
  616. local bossActor = ManagerContainer.LuaActorDataMgr:CreateNpc(bossInfo.id,bossInfo.id,2,bossInfo.level)
  617. bossActor.IsBoss = true
  618. enemyActors[0] = bossActor
  619. local srvActorData = System.Array.CreateInstance(Enum.TypeInfo.ServerFighterParam, #heroIds + 1)
  620. for i = 1 , #heroIds do
  621. local hpPercent,spPercent = self:GetHeroHPAndSP(heroIds[i])
  622. local param = ServerFighterParam.New(heroIds[i],0,0,hpPercent * 0.01,spPercent * 0.01)
  623. srvActorData[i-1] = param
  624. end
  625. self:InitEndBattleCondition()
  626. local bossParam = ServerFighterParam.New(bossInfo.id,bossInfo.hp,bossInfo.sp,0,0)
  627. srvActorData[#heroIds] = bossParam
  628. self.bossPreLife = bossInfo.hp
  629. self.bossPreSp = bossInfo.sp
  630. self.curChallengingBossId = bossInfo.id
  631. self.curChallengingBossLevel = bossInfo.level
  632. self.preSycnHPAndSpTime = Time.realtimeSinceStartup
  633. --保存最后一次 BOSS信息
  634. local bossid = bossInfo.id
  635. local bossCfg = ManagerContainer.CfgMgr:GetNpcCfgById(bossid)
  636. if bossCfg ~= nil then
  637. local CurBossScore = self:GetCurBossScore(bossid)
  638. self:SaveLastMonster(bossCfg.Name,CurBossScore)
  639. end
  640. ManagerContainer.LuaGameMgr:EnterExpeditionBattle(map.sceneName,map.bgm,self.curMaxFightingTime,ourActors,enemyActors,map.loadingId,srvActorData,self.battleEndCondList,levelInfo.RestoreSp)
  641. end
  642. end
  643. function ExpeditionDataMgr:InitEndBattleCondition()
  644. if self.battleEndCondList ~= nil then
  645. return
  646. end
  647. self.battleEndCondList = System.Array.CreateInstance(Enum.TypeInfo.BattleEndCondition, 2)
  648. self.battleEndCondList[0] = BattleEndCondition.New(Constants.EndBattle_By_UndeadCount,Constants.ResultType_Normal)
  649. self.battleEndCondList[1] = BattleEndCondition.New(Constants.EndBattle_By_BattleTime,Constants.ResultType_Normal)
  650. end
  651. function ExpeditionDataMgr:SyncBossLife(curLife)
  652. local deltaTime = Time.realtimeSinceStartup - self.preSycnHPAndSpTime
  653. if deltaTime >= 0.3 then
  654. local deltaHP = curLife - self.bossPreLife
  655. local bossList = {{id=self.curChallengingBossId,level=self.curChallengingBossLevel,hp=deltaHP}}
  656. self:SendRefreshBattleData(bossList)
  657. self.bossPreLife = curLife
  658. self.preSycnHPAndSpTime = Time.realtimeSinceStartup
  659. end
  660. end
  661. function ExpeditionDataMgr:SyncBossSP(curSp)
  662. local deltaTime = Time.realtimeSinceStartup - self.preSycnHPAndSpTime
  663. if deltaTime >= 0.3 then
  664. local deltaSp = curSp - self.bossPreSp
  665. local bossList = {{id=self.curChallengingBossId,level=self.curChallengingBossLevel,sp=deltaSp}}
  666. self:SendRefreshBattleData(bossList)
  667. self.bossPreSp = curSp
  668. self.preSycnHPAndSpTime = Time.realtimeSinceStartup
  669. end
  670. end
  671. function ExpeditionDataMgr:BattleEnd(battleTime,fighterParams,bossLife,bossSp)
  672. local heroInfos = {}
  673. if fighterParams ~= nil then
  674. for i =1, fighterParams.Count do
  675. local param = fighterParams[i-1]
  676. heroInfos[#heroInfos+1] = { id = param.uid,
  677. hp = param.hpPercent * 100,
  678. sp = param.spPercent * 100}
  679. end
  680. end
  681. local deltaSp = bossSp - self.bossPreSp
  682. local deltaHP = bossLife - self.bossPreLife
  683. local bossList = {{id=self.curChallengingBossId,level=self.curChallengingBossLevel,hp=deltaHP,sp=deltaSp}}
  684. self:SendChallengeBossEnd(battleTime,heroInfos,bossList)
  685. self.curChallengingBossId = 0
  686. self.curChallengingBossLevel = 0
  687. end
  688. function ExpeditionDataMgr:SendChallengeMapReq(mapId)
  689. self.reqEnterMapId = mapId
  690. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_EXPEDITION_CHALLENGE_PRE_REQ, {expedition_type = mapId})
  691. end
  692. function ExpeditionDataMgr:OnChallengeMapAck(data)
  693. if data.error == 0 then
  694. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Expedition_EnterMap_Success)
  695. if self.reqEnterMapId ~= nil then
  696. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIExpeditionDungeonInfo, self.reqEnterMapId)
  697. self.reqEnterMapId = nil
  698. end
  699. end
  700. end
  701. function ExpeditionDataMgr:SendChallengeBossStart(slotIdx)
  702. self.curChanllengeSlotIdx = slotIdx
  703. local heroInfos = {}
  704. local battleTeamIds = self:GetCurrBattleTeamMembers()
  705. for i = 1, #battleTeamIds do
  706. local hpPercent,spPercent = self:GetHeroHPAndSP(battleTeamIds[i])
  707. if hpPercent > 0 then
  708. heroInfos[#heroInfos+1] = {id = battleTeamIds[i],hp = hpPercent, sp = spPercent}
  709. end
  710. end
  711. local data = {expedition_type = self.curChanllengeMapId,
  712. battle_level = self.curChanllengeLevelId,
  713. battle_idx = self.curChanllengeSlotIdx,
  714. hero_info_list = heroInfos,
  715. flag = 1}
  716. -- LogError("SendChallengeBossStart: " .. Inspect(data))
  717. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_EXPEDITION_CHALLENGE_REQ, data)
  718. end
  719. function ExpeditionDataMgr:SendRefreshBattleData(bossInfo)
  720. if self.curChanllengeMapId == 0 then
  721. return
  722. end
  723. local data = {expedition_type = self.curChanllengeMapId,
  724. battle_level = self.curChanllengeLevelId,
  725. battle_idx = self.curChanllengeSlotIdx,
  726. boss_change_hp_list = bossInfo,
  727. flag = 2}
  728. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_EXPEDITION_CHALLENGE_REQ, data)
  729. end
  730. function ExpeditionDataMgr:SyncHeroLifeAndSp(actorId,life,maxLife,sp,maxSp)
  731. if self.curChanllengeMapId == 0 then
  732. return
  733. end
  734. local hpPercent = life * 100 / maxLife
  735. local spPercent = sp * 100 / maxSp
  736. self:SetHeroHPAndSp(actorId,hpPercent,spPercent)
  737. local heroInfos = {}
  738. heroInfos[#heroInfos+1] = { id = actorId,hp = hpPercent, sp = spPercent}
  739. local data = { expedition_type = self.curChanllengeMapId,
  740. battle_level = self.curChanllengeLevelId,
  741. battle_idx = self.curChanllengeSlotIdx,
  742. hero_info_list = heroInfos,
  743. flag = 2}
  744. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_EXPEDITION_CHALLENGE_REQ, data)
  745. end
  746. function ExpeditionDataMgr:SendChallengeBossEnd(battleTime,heroInfo,bossInfo)
  747. if self.curChanllengeMapId == 0 then
  748. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIBattleFailed,true)
  749. return
  750. end
  751. local data = {expedition_type = self.curChanllengeMapId,
  752. battle_level = self.curChanllengeLevelId,
  753. battle_idx = self.curChanllengeSlotIdx,
  754. hero_info_list = heroInfo,
  755. boss_change_hp_list = bossInfo,
  756. battle_time = battleTime,
  757. flag = 3}
  758. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_EXPEDITION_CHALLENGE_REQ, data)
  759. end
  760. function ExpeditionDataMgr:OnChallengeBossEndAck(data)
  761. --LogError("OnChallengeBossEndAck: " .. Inspect(data))
  762. if data.error == 0 then
  763. if data.flag == 1 then
  764. if data.buff_list ~= nil and #data.buff_list > 0 then
  765. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIExpeditionWin,{data.buff_list,false})
  766. else
  767. self:EnterBattle()
  768. end
  769. elseif data.flag == 3 then
  770. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIBattleFailed,true)
  771. elseif data.flag == 4 then
  772. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIExpeditionWin,{data.buff_list,true})
  773. end
  774. else
  775. --LogError("OnChallengeBossEndAck Error ="..tostring(data.error))
  776. -- 超过最大挑战时间
  777. if data.error == 27 then
  778. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIBattleFailed,true)
  779. end
  780. end
  781. end
  782. function ExpeditionDataMgr:SendSelectBuffReq(buffId)
  783. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_EXPEDITION_SELECT_BUFF_REQ, {select_buff_id = buffId})
  784. self:SaveLastBuffScore(buffId)
  785. end
  786. function ExpeditionDataMgr:OnSelectBuffAck(data)
  787. if data.error == 0 then
  788. self:RemoveTimer()
  789. self.TimeShowTipsId = ManagerContainer.LuaTimerMgr:AddTimer(800, 1, self, self.ShowTips,nil)
  790. end
  791. end
  792. function ExpeditionDataMgr:ShowTips(Score)
  793. local score = self:GetLastBuffScore()
  794. if not ManagerContainer.LuaUIMgr:GetPage(Enum.UIPageName.UIErrorTips) then
  795. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIErrorTips, {errorId="ExpeditionArtifact", params ={ tostring(score)}}, nil, nil, nil, Enum.UISibling[Enum.UIType.Top + 1] + 11)
  796. else
  797. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.ERROR_DESC_DISPLAY, {errorId="ExpeditionArtifact",params = { tostring(score)}})
  798. end
  799. end
  800. function ExpeditionDataMgr:RemoveTimer()
  801. if self.TimeShowTipsId then
  802. ManagerContainer.LuaTimerMgr:RemoveTimer(self.TimeShowTipsId);
  803. self.TimeShowTipsId = nil;
  804. end
  805. end
  806. --levelId: 0 表示一键领取
  807. function ExpeditionDataMgr:SendGotRewardReq(mapId,levelId)
  808. -- LogError("mapId = " .. mapId .. " levelId = " .. levelId)
  809. self.isSingleReward = levelId > 0
  810. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_EXPEDITION_REWARD_REQ, {expedition_type = mapId, boss_idx = levelId})
  811. end
  812. function ExpeditionDataMgr:OnGotRewardAck(data)
  813. if data.error == 0 then
  814. local rewardList = {}
  815. for i = 1, #data.reward_item_list do
  816. local itemData = data.reward_item_list[i];
  817. rewardList[#rewardList+1] = {cfgId = itemData.key, num = itemData.value}
  818. end
  819. ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPOPGot,{rewards = rewardList})
  820. end
  821. end
  822. function ExpeditionDataMgr:SendApplyBattleTeamReq(teamIds)
  823. -- LogError(Inspect(teamIds))
  824. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_EXPEDITION_BATTLE_HERO_REQ, {battle_hero_list = teamIds})
  825. end
  826. function ExpeditionDataMgr:OnApplyBattleTeamAck(data)
  827. -- LogError(data.error)
  828. end
  829. function ExpeditionDataMgr:SendAssistReq(uid)
  830. -- LogError("SendAssistReq = " .. tostring(uid))
  831. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_EXPEDITION_CALL_FOR_HELP_REQ, {assist_help_uid = uid})
  832. end
  833. function ExpeditionDataMgr:OnAssistReqAck(data)
  834. -- LogError(data.error)
  835. end
  836. function ExpeditionDataMgr:OnAssistNtf(data)
  837. if data.assist_state == 1 then
  838. ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("ExpeditionHelp")
  839. self:ResetAllHeroHp()
  840. end
  841. end
  842. function ExpeditionDataMgr:SendRescueFriendReq(uid,msgType, time)
  843. self.targetUid = uid
  844. self.msgType = msgType
  845. ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_EXPEDITION_HELP_REQ, {be_helped_uid = uid, msg_type = msgType, help_msg_send_time = time})
  846. end
  847. function ExpeditionDataMgr:OnRescueFriendAck(data)
  848. if data.error == Enum.NetErrorCode.ERROR_OK then
  849. local uid = tostring(self.targetUid)
  850. ManagerContainer.DataMgr.ChatData:ExpeditionHelpAck(uid, self.msgType)
  851. self.targetUid = nil
  852. self.msgType = nil
  853. --策划需求 不用显示 奖励界面
  854. --if data.reward_item_list ~= nil and #data.reward_item_list > 0 then
  855. -- local rewardList = {}
  856. -- for i = 1, #data.reward_item_list do
  857. -- local itemData = data.reward_item_list[i];
  858. -- rewardList[#rewardList+1] = {cfgId = itemData.key, num = itemData.value}
  859. -- end
  860. -- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPOPGot,{rewards = rewardList})
  861. --end
  862. end
  863. end
  864. function ExpeditionDataMgr:GetRescuerCnt()
  865. if self.myRescuerIds ~= nil then
  866. return #self.myRescuerIds
  867. end
  868. return 0
  869. end
  870. function ExpeditionDataMgr:GetRescuers()
  871. return self.myRescuers
  872. end
  873. function ExpeditionDataMgr:ReqestRescuerBriefData()
  874. if self.myRescuerIds == nil or #self.myRescuerIds == 0 then
  875. return
  876. end
  877. local cnt = 10
  878. local uid_list = {}
  879. if cnt > #self.myRescuerIds then
  880. cnt = #self.myRescuerIds
  881. end
  882. for i = 1, cnt do
  883. uid_list[#uid_list+1] = self.myRescuerIds[i].uid
  884. end
  885. ManagerContainer.DataMgr.FriendDataMgr:ReqFriendBriefData(Enum.FriendTogglePageType.ExpedtionHelpLog,uid_list)
  886. end
  887. function ExpeditionDataMgr:OnGetBriefInfoAck(data)
  888. if data.type == Enum.FriendTogglePageType.ExpedtionHelpLog then
  889. if data.brief_info ~= nil then
  890. for i = 1,#data.brief_info do
  891. local info = data.brief_info[i]
  892. self:AddRescuer(info)
  893. self:RemoveRescuerId(info.uid)
  894. end
  895. end
  896. ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Expedition_REFRESH_HELP_LOG)
  897. end
  898. end
  899. function ExpeditionDataMgr:GetRescuerTime(uid)
  900. if self.myRescuerIds == nil then
  901. return 0
  902. end
  903. for i = 1, #self.myRescuerIds do
  904. if self.myRescuerIds[i].uid == uid then
  905. return self.myRescuerIds[i].time
  906. end
  907. end
  908. return 0
  909. end
  910. function ExpeditionDataMgr:RemoveRescuerId(uid)
  911. for i = 1, #self.myRescuerIds do
  912. if self.myRescuerIds[i].uid == uid then
  913. table.remove(self.myRescuerIds,i)
  914. return
  915. end
  916. end
  917. end
  918. function ExpeditionDataMgr:FindRescuerById(uid)
  919. if self.myRescuers == nil then
  920. return nil
  921. end
  922. for i = 1, #self.myRescuers do
  923. if self.myRescuers[i].uid == uid then
  924. return self.myRescuers[i]
  925. end
  926. end
  927. return nil
  928. end
  929. function ExpeditionDataMgr:AddRescuer(briefInfo)
  930. if briefInfo == nil then
  931. return
  932. end
  933. local obj = self:FindRescuerById(briefInfo.uid)
  934. if obj ~= nil then
  935. obj:SetData(briefInfo)
  936. else
  937. obj = FriendData:new(briefInfo.uid)
  938. obj:SetData(briefInfo)
  939. self.myRescuers[#self.myRescuers+1] = obj
  940. end
  941. local time = self:GetRescuerTime(briefInfo.uid)
  942. obj.param = time
  943. end
  944. function ExpeditionDataMgr:GetDropBuffs(actorData,maxHPActorId)
  945. if self.buffs == nil or #self.buffs == 0 then
  946. return nil
  947. end
  948. local buffList = {}
  949. for i = 1, #self.buffs do
  950. --local buffCfg = self.buffs[i]
  951. local buffCfg = self.buffs[i]
  952. local filterActorType,filterParamType,filterParamVal = self:ParseFilterParam(buffCfg.FilterParam)
  953. local matchAType = (filterActorType == -1) or (filterActorType == actorData.IActorType) or (filterActorType == 5 and (actorData.IsHero or actorData.IsFellow))
  954. local bMatch = false
  955. if filterParamType == nil then
  956. if matchAType then
  957. bMatch = true
  958. end
  959. else
  960. if filterParamType == 1 then --职业
  961. if matchAType and (filterParamVal == -1 or filterParamVal == actorData.JobType) then
  962. if buffCfg.FilterExtendParam ~= nil then
  963. local jobStage = buffCfg.FilterExtendParam[1]
  964. local jobBranch = buffCfg.FilterExtendParam[2]
  965. if jobStage == actorData.JobStage and jobBranch == actorData.JobBranch then
  966. bMatch = true
  967. end
  968. else
  969. bMatch = true
  970. end
  971. end
  972. elseif filterParamType == 2 then --属性
  973. if matchAType and (filterParamVal == -1 or filterParamVal == actorData.NatureId) then
  974. bMatch = true
  975. end
  976. elseif filterParamType == 3 then --宠物ID
  977. if matchAType and (filterParamVal == actorData.BaseId) then
  978. bMatch = true
  979. end
  980. elseif filterParamType == 4 then --血量最高的人
  981. if matchAType and (tostring(actorData.ID) == tostring(maxHPActorId)) then
  982. bMatch = true
  983. end
  984. end
  985. end
  986. if bMatch then
  987. local buff = self:FindBuff(buffList,buffCfg.BuffId)
  988. if buff == nil then
  989. local buff = ExpeditionBuff:new(buffCfg.BuffId,buffCfg.Ratio,buffCfg.CD,buffCfg.ConditionType,buffCfg.ExtendPara,buffCfg.Function)
  990. buffList[#buffList+1] = buff
  991. else
  992. buff:AddFun(buffCfg.Function)
  993. end
  994. end
  995. end
  996. return buffList
  997. end
  998. function ExpeditionDataMgr:FindBuff(buffList,buffId)
  999. if buffList == nil then return nil end
  1000. for i = 1, #buffList do
  1001. if buffList[i].buffId == buffId then
  1002. return buffList[i]
  1003. end
  1004. end
  1005. return nil
  1006. end
  1007. --返回过滤参数类型:paramType:参数类型[1:职业; 2:属性; 3: 宠物ID]
  1008. function ExpeditionDataMgr:ParseFilterParam(params)
  1009. local filterActorType = params[1]
  1010. local filterParamType = nil
  1011. local filterParamVal = nil
  1012. if #params > 1 then
  1013. filterParamType = params[2]
  1014. end
  1015. if #params > 2 then
  1016. filterParamVal = params[3]
  1017. end
  1018. return filterActorType,filterParamType,filterParamVal
  1019. end
  1020. return ExpeditionDataMgr