| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195 |
- local ExpeditionDataMgr = class("ExpeditionDataMgr",require("DataBase"))
- local ExpeditionMapData = require("Expedition/ExpeditionMapData")
- local ExpeditionBuff = require("Expedition/ExpeditionBuff")
- local FriendData = require("Friend/FriendData")
- local BitUtil = require("BitUtil")
- function ExpeditionDataMgr:ctor()
- self.allMaps = {}
- self.bInited = false
- self.battleHeros = {}
- self.leftChanllengeNum = 0
- self.curChanllengeMapId = 0 --当前挑战的地图类型id
- self.curChanllengeLevelId = 0 --当前挑战的关卡id
- self.curChanllengeSlotIdx = 0 --当前挑战的位置
- self.curChallengeLevelBossList = nil --当前挑战关卡随机出来的boss [id,level,hp,sp]
- self.serverHerosData = nil
- self.buffs = nil
-
- self.maxAssistNum = 0 --最大可使用救援次数
- self.usedAssistNum = 0 --已经使用的救援次数
- self.maxRescuedNum = 0 --最大可被救援次数
- self.usedRescuedNum = 0 --已经使用的被救援次数
- self.inAssisting = false --求助中
- self.guildAssistingEndTime = nil
-
- self.myRescuerIds = nil
- self.myRescuers = nil
- self.curChallengingBossId = 0
- self.curChallengingBossLevel = 0
- self.bossPreLife = 0 --boss上一秒的血量
- self.bossPreSp = 0 --boss上一秒的蓝量
- self.preSycnHPAndSpTime = 0
- self.lastFinishedMap = 0
- self.battleEndCondList = nil
- self.isSingleReward = false
- end
- function ExpeditionDataMgr:RegisterNetEvents()
- ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_EXPEDITION_CHANGE_NTF,self.OnExpeditionDataNtf, self)
- ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_EXPEDITION_CHALLENGE_PRE_ACK,self.OnChallengeMapAck, self)
- ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_EXPEDITION_CHALLENGE_ACK,self.OnChallengeBossEndAck, self)
- ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_EXPEDITION_SELECT_BUFF_ACK,self.OnSelectBuffAck, self)
- ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_EXPEDITION_REWARD_ACK,self.OnGotRewardAck, self)
- ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_EXPEDITION_BATTLE_HERO_ACK,self.OnApplyBattleTeamAck, self)
- ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_EXPEDITION_CALL_FOR_HELP_ACK,self.OnAssistReqAck, self)
- ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_EXPEDITION_CALL_FOR_HELP_NTF,self.OnAssistNtf, self)
- ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_EXPEDITION_HELP_ACK,self.OnRescueFriendAck, self)
- ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_EXPEDITION_SCORE_RANK_LIST_ACK,self.OnScoreRankListAck, self)
- ManagerContainer.NetManager:NetRegister(ProtoMsgId.SC_EXPEDITION_PASS_REWARD_ACK,self.OnPassRewardAck, self)
-
- ManagerContainer.LuaEventMgr:RegisterEvent(UIEventNames.EID_Expedition_GET_OTHER_PLAYER_BRIEF_INFO,self,self.OnGetBriefInfoAck)
- end
- function ExpeditionDataMgr:Clear()
- self.bInited = false
- self.allMaps = {}
- self.battleHeros = {}
- self.curChallengeLevelBossList = nil
- self.serverHerosData = nil
- self.buffs = nil
- self.battleEndCondList = nil
- self.lastFinishedMap = 0
- end
- function ExpeditionDataMgr:Destroy()
- end
- function ExpeditionDataMgr:UnRegisterNetEvents()
- ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_EXPEDITION_CHANGE_NTF)
- ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_EXPEDITION_CHALLENGE_PRE_ACK)
- ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_EXPEDITION_CHALLENGE_ACK)
- ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_EXPEDITION_SELECT_BUFF_ACK)
- ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_EXPEDITION_REWARD_ACK)
- ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_EXPEDITION_BATTLE_HERO_ACK)
- ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_EXPEDITION_CALL_FOR_HELP_ACK)
- ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_EXPEDITION_CALL_FOR_HELP_NTF)
- ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_EXPEDITION_SCORE_RANK_LIST_ACK)
- ManagerContainer.NetManager:UnRegisterPbIdCallback(ProtoMsgId.SC_EXPEDITION_PASS_REWARD_ACK)
- ManagerContainer.LuaEventMgr:UnregisterEvent(UIEventNames.EID_Expedition_GET_OTHER_PLAYER_BRIEF_INFO,self,self.OnGetBriefInfoAck)
- end
- function ExpeditionDataMgr:InitData()
- if self.bInited then
- return
- end
-
- self.allMaps = {}
- for typeId=1, 100 do
- local cfg = ManagerContainer.CfgMgr:GetExpeditionCfgByTypeAndLevelId(typeId,1)
- if cfg == nil then
- break
- end
- local mapData = ExpeditionMapData:new(typeId,cfg)
- self.allMaps[#self.allMaps + 1] = mapData
- end
- end
- function ExpeditionDataMgr:GetAllMaps()
- return self.allMaps
- end
- function ExpeditionDataMgr:FindMapByTypeId(typeId)
- if self.allMaps == nil then
- return nil
- end
- for i = 1, #self.allMaps do
- if self.allMaps[i].mapId == typeId then
- return self.allMaps[i]
- end
- end
- return nil
- end
- function ExpeditionDataMgr:Reset()
- if self.allMaps == nil then
- return
- end
- for i = 1, #self.allMaps do
- self.allMaps[i]:Reset()
- end
- end
- --
- function ExpeditionDataMgr:ResetSvrIdx()
- self.StartSvrIdx = 1
- end
- --获取服务器数据排行榜 起始IDX
- function ExpeditionDataMgr:GetListSvrStartIdx()
- if nil == self.StartSvrIdx then
- self.StartSvrIdx = 1
- end
- return self.StartSvrIdx
- end
- function ExpeditionDataMgr:GetSelfRank()
- return self.SelfScoreRank
- end
- function ExpeditionDataMgr:GetListfRank()
- return self.ScoreRankList
- end
- function ExpeditionDataMgr:GetRankDataByIdx(Idx)
- if #self.ScoreRankList >= Idx then
- return self.ScoreRankList[Idx]
- end
- end
- function ExpeditionDataMgr:GetNextRankListNum()
- if nil == self.StartSvrIdx then
- self.StartSvrIdx = 1
- end
- local step = 20
- local Max = 100
- local IsOver = false
- self.StartSvrIdx = self.StartSvrIdx + step
-
- if self.StartSvrIdx >= Max then
- self.StartSvrIdx = Max
- IsOver = true
- end
- -- if self.StartSvrIdx > #self.ScoreRankList then
- -- self.StartSvrIdx = #self.ScoreRankList
- -- end
- return self.StartSvrIdx,IsOver
- end
- function ExpeditionDataMgr:CreateRankListSvrData(svrdata)
- if nil == self.SelfScoreRank then
- self.SelfScoreRank = {}
- end
- if nil == self.ScoreRankList then
- self.ScoreRankList = {}
- end
- if svrdata.error == 0 then
- for i = 1, #svrdata.rank_list do
- self.ScoreRankList[svrdata.rank_list[i].rank] = svrdata.rank_list[i]
- end
- self.SelfScoreRank = svrdata.self_rank_info
- --self.StartSvrIdx = svrdata.start_idx
- end
- end
- --收到勇士积分排行榜
- function ExpeditionDataMgr:OnScoreRankListAck(data)
- --LogError(Inspect(data))
- if data.error == Enum.NetErrorCode.ERROR_OK then
- self:CreateRankListSvrData(data)
-
- ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Refresh_Expedition_RankData)
- end
- end
- --请求通过奖励
- function ExpeditionDataMgr:SendPassRewardReq(mapId)
- --LogError("Send..."..tostring(mapId))
- ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_EXPEDITION_PASS_REWARD_REQ, {expedition_type = mapId})
- end
- --收到通过奖励
- function ExpeditionDataMgr:OnPassRewardAck(data)
- -- LogError("OnPassRewardAck")
- if ManagerContainer.NetManager:IsErrorData(data) then
- return
- end
- if data.reward_item_list ~= nil then
- local rewardList = {}
- for i = 1, #data.reward_item_list do
- local _itemData = data.reward_item_list[i]
- rewardList[#rewardList+1] = {cfgId = _itemData.key, num = _itemData.value}
- end
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPOPGot,{rewards = rewardList})
- end
- end
- function ExpeditionDataMgr:IsGetPassReward(mapId)
- --LogError("mapId"..tostring(mapId))
- --LogError("expedition_type_reward"..tostring(self.expedition_type_reward))
- local isGet = BitUtil.RshiftNumBandOne(self.expedition_type_reward,mapId) == 1
- return isGet
- end
- function ExpeditionDataMgr:SendScoreRankListReq(Idx)
- --LogError("Sending"..tostring(Idx))
- ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_EXPEDITION_SCORE_RANK_LIST_REQ, {start_idx = Idx})
- end
- function ExpeditionDataMgr:OnExpeditionDataNtf(data)
- LogError("=========OnExpeditionDataNtf========"..Inspect(data.expedition_info))
- self:SetData(data.expedition_info)
- if data.day_reset then
- if self.curChallengingBossId > 0 then
- ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_SHUT_TIMEBATTLE,Enum.UIPageName.UIExpedition,false)
- self.curChallengingBossId = 0
- end
- ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Expedition_ResetData)
- ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("ExpeReset")
- end
- ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Expedition_RefreshData, self.isSingleReward)
- self.isSingleReward = false
- end
- function ExpeditionDataMgr:SaveUnlockMap(expedition_type)
- local uid = ManagerContainer.DataMgr.UserData:GetUserId()
- UnityEngine.PlayerPrefs.SetString(tostring(uid).."_ExpeditionUnlockMap",tostring(expedition_type))
- end
- function ExpeditionDataMgr:LoadUnlockMap()
- local uid = ManagerContainer.DataMgr.UserData:GetUserId()
- local expedition_type = UnityEngine.PlayerPrefs.GetString(tostring(uid).."_ExpeditionUnlockMap")
- if expedition_type ~= nil and expedition_type ~= "" then
- local temp = tonumber(expedition_type)
- for i = 1, temp do
- local map = self:FindMapByTypeId(i)
- if map ~= nil then
- map:SetNewState(false)
- end
- end
- end
- end
- function ExpeditionDataMgr:SetData(expeditionInfo)
- --LogError("ExpeditionDataMgr:SetData:" .. Inspect(expeditionInfo))
- self:InitData()
- self:Reset()
-
- self.expedition_type_reward = expeditionInfo.expedition_type_reward
- if expeditionInfo == nil then
- return
- end
- --设置解锁的地图
- if expeditionInfo.expedition_type ~= nil then
- for i = 1, expeditionInfo.expedition_type do
- local map = self:FindMapByTypeId(i)
- if map ~= nil then
- map:SetUnlockState(true)
- map:SetNewState(true)
- end
- end
- end
- self:LoadUnlockMap()
- self:SaveUnlockMap(expeditionInfo.expedition_type)
- --老的当天 会清空
- --设置通关地图信息
- -- if expeditionInfo.finish_expedition_list ~= nil then
- -- for i =1, #expeditionInfo.finish_expedition_list do
- -- local map = self:FindMapByTypeId(expeditionInfo.finish_expedition_list[i])
- -- if map ~= nil then
- -- map:SetMapPassed(true)
- -- end
- -- end
- -- self.lastFinishedMap = expeditionInfo.finish_expedition_list[#expeditionInfo.finish_expedition_list]
- -- end
- --小于通过地图信息 重置
- for i =1, expeditionInfo.expedition_type - 1 do
- local map = self:FindMapByTypeId(i)
- if map ~= nil then
- map:SetMapPassed(true)
- self.lastFinishedMap = i
- end
- end
- self.buffs = {}
- if expeditionInfo.battle_buff_list ~= nil then
- for i = 1, #expeditionInfo.battle_buff_list do
- local buff = ManagerContainer.CfgMgr:GetExpeditionBuffCfgById(expeditionInfo.battle_buff_list[i])
- if buff ~= nil then
- self.buffs[#self.buffs+1] = buff
- end
- end
- end
- CommonUtil.ArraySortSelections(self.buffs, Enum.TableSortRule.Down, "Quality", "Id")
- --设置上阵玩家ID
- self.battleHeros = expeditionInfo.battle_hero_list
- self.curChallengeLevelBossList = expeditionInfo.boss_list
- self.serverHerosData = expeditionInfo.battle_hero_hp_list
- self.maxAssistNum = expeditionInfo.assist_num.key
- self.usedAssistNum = expeditionInfo.assist_num.value
- self.maxRescuedNum = expeditionInfo.be_assist_num.key
- self.usedRescuedNum = expeditionInfo.be_assist_num.value
- self.inAssisting = expeditionInfo.assist_state
- self.guildAssistingEndTime = tonumber(tostring(expeditionInfo.assist_guild_end_time/1000))
-
- if expeditionInfo.be_assist_uid_list ~= nil then
- self.myRescuers = {}
- self.myRescuerIds = {}
- for i = 1, #expeditionInfo.be_assist_uid_list do
- local assist = expeditionInfo.be_assist_uid_list[i]
- self.myRescuerIds[#self.myRescuerIds+1] = {uid = assist.key, time = assist.value}
- end
- else
- self.myRescuerIds = nil
- self.myRescuers = nil
- end
- --设置当前挑战地图关卡信息
- local lastChanllengeMapId = self.curChanllengeMapId
- self.leftChanllengeNum = expeditionInfo.challenge_num
- self.curChanllengeMapId = expeditionInfo.cur_expedition_type
- self.curChanllengeLevelId = expeditionInfo.cur_battle_level
- self.curChanllengeSlotIdx = expeditionInfo.battle_idx
-
- self.curexpeditionscore = expeditionInfo.cur_expedition_score--当前关卡积分
- self.curexpeditionscoremax = expeditionInfo.cur_expedition_score_max--当前总积分
- local map = self:FindMapByTypeId(self.curChanllengeMapId)
- if map ~= nil then
- map:SetChallengeState(true)
- map:SetPassedLevels(self.curChanllengeLevelId)
- end
-
- --当为挑战过界面,默认预览最新开启的界面
- if self.curChanllengeMapId == 0 then
- for i = #self.allMaps, 1, -1 do
- if self.allMaps[i].unlocked then
- self.allMaps[i]:SetUnfold(true)
- break
- end
- end
- end
-
- --设置地图关卡奖励领取信息
- if expeditionInfo.reward_state_list ~= nil then
- for i =1, #expeditionInfo.reward_state_list do
- local map = self:FindMapByTypeId(expeditionInfo.reward_state_list[i].expedition_type)
- if map ~= nil then
- map:SetGotRewardLevels(expeditionInfo.reward_state_list[i].reward_state)
- end
- end
- end
- --设置奖励以领取
- for i = #self.allMaps, 1, -1 do
- if self.allMaps[i].isPassed then
- self.allMaps[i]:SetMapGotReward()
- end
- end
- ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Expedition_RefreshScroe)
- ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.RED_POINT_MGR_NOTICE, Enum.RPNotifyType.Expedition, self:HasRedPoint())
- end
- --获取怪物积分
- function ExpeditionDataMgr:GetCurBossScore(bossId)
- local BossInfo = ManagerContainer.CfgMgr:GetExpeditionBossCfg(bossId)
- if BossInfo then
- return BossInfo.WarriorScore
- end
- return 0
- end
- --buff 积分系数
- function ExpeditionDataMgr:GetScoreRatio(Scroe)
- --系数获取
- local mapData = self:FindMapByTypeId(self.curChanllengeMapId)
- if mapData then
- local levelData = mapData:FindLevelByLevelId(1)
- if levelData then
- local LevelCoefficient = levelData:GetLevelCoefficient()
- if LevelCoefficient then
- return math.ceil(LevelCoefficient * 0.01 * Scroe) --向上取整
- end
- end
- end
- return Scroe
- end
- --根据BUFFid 获取积分
- function ExpeditionDataMgr:GetScoreByBuffId(BuffID)
- --LogError(tostring(BuffID))
- local buff = ManagerContainer.CfgMgr:GetExpeditionBuffCfgById(BuffID)
- if buff then
- return self:GetScoreRatio(buff.WarriorScore)
- end
- return 0
- end
- --当前关卡总积分
- function ExpeditionDataMgr:GetCurScore()
- return self.curexpeditionscore
- end
- --历史最高总积分
- function ExpeditionDataMgr:GetMaxScore()
- return self.curexpeditionscoremax
- end
- --是否新纪录
- function ExpeditionDataMgr:IsNewRecord()
- return self:GetMaxScore() <= self:GetCurScore()
- end
- function ExpeditionDataMgr:SaveLastMonster(BossName,Score)
- self.LastBossName = BossName
- self.LastBossScore = Score
- end
- function ExpeditionDataMgr:GetLastMonsterNameScore()
- return self.LastBossName,self.LastBossScore
- end
- function ExpeditionDataMgr:SaveLastBuffScore(BuffID)
- self.LastBuffScore = self:GetScoreByBuffId(BuffID)
- end
- function ExpeditionDataMgr:GetLastBuffScore()
- return self.LastBuffScore
- end
- function ExpeditionDataMgr:GetLastFinishedMapState()
- if self.lastFinishedMap == 0 then return false end
- local map = self:FindMapByTypeId(self.lastFinishedMap)
- if not map then
- return
- end
- return map:HasRedPoint() and map.isPassed
- end
- function ExpeditionDataMgr:CheckUnlockMaps()
- for i = 1, #self.allMaps do
- self.allMaps[i]:CheckUnlock()
- end
- end
- function ExpeditionDataMgr:RefreshUnfold()
- -- self:CheckUnlockMaps()
- for i = 1, #self.allMaps do
- self.allMaps[i]:SetUnfold(false)
- end
-
- if self.curChanllengeMapId > 0 then
- local map = self:FindMapByTypeId(self.curChanllengeMapId)
- map:SetUnfold(true)
- else
- for i = #self.allMaps, 1, -1 do
- if self.allMaps[i].unlocked then
- self.allMaps[i]:SetUnfold(true)
- break
- end
- end
- end
- end
- function ExpeditionDataMgr:CurChallengingMap()
- if self.curChanllengeMapId == 0 then
- return nil
- end
- return self:FindMapByTypeId(self.curChanllengeMapId)
- end
- function ExpeditionDataMgr:IsChallenging()
- return self.curChanllengeMapId > 0
- end
- function ExpeditionDataMgr:HasRedPoint()
- if self.allMaps == nil then
- return false
- end
- for i = 1, #self.allMaps do
- if self.allMaps[i]:HasRedPoint() then
- return true
- end
- end
- --LogError("=======self.lastFinishedMap======="..self.lastFinishedMap)
- for i = 1, self.lastFinishedMap do
- if self.allMaps[i].isPassed then
- local IsShowReward = not self:IsGetPassReward(self.allMaps[i].mapId)--是否领取
- if IsShowReward then
- return IsShowReward
- end
- end
- end
- return false
- end
- function ExpeditionDataMgr:GetCurLevelId()
- return self.curChanllengeLevelId
- end
- function ExpeditionDataMgr:GetBossList()
- return self.curChallengeLevelBossList
- end
- function ExpeditionDataMgr:GetBuffs()
- return self.buffs
- end
- function ExpeditionDataMgr:ChanllengeSlotIdx()
- return self.curChanllengeSlotIdx
- end
- function ExpeditionDataMgr:GetCurrBattleTeamMembers()
- if #self.battleHeros == 0 then
- local teamData = ManagerContainer.DataMgr.UserData:GetTeamData(true)
- for i = 1, #teamData do
- self.battleHeros[#self.battleHeros+1] = teamData[i].uid
- end
- self:SendApplyBattleTeamReq(self.battleHeros)
- end
- return self.battleHeros
- end
- function ExpeditionDataMgr:CurMemberCnt()
- return #self.battleHeros
- end
- function ExpeditionDataMgr:IsInBattleTeam(uid)
- for i = 1, #self.battleHeros do
- if self.battleHeros[i] == uid then
- return true
- end
- end
- return false
- end
- function ExpeditionDataMgr:OnBattle(actorId)
- if self:CurMemberCnt() >= 4 then
- return
- end
- if self:IsInBattleTeam(actorId) then
- return
- end
- self.battleHeros[#self.battleHeros + 1] = actorId
- self:SendApplyBattleTeamReq(self.battleHeros)
- end
- function ExpeditionDataMgr:ReplaceBattleActorId(orgUid,newUid)
- for i=1, #self.battleHeros do
- if self.battleHeros[i] == orgUid then
- self.battleHeros[i] = newUid
- self:SendApplyBattleTeamReq(self.battleHeros)
- break;
- end
- end
- end
- function ExpeditionDataMgr:GetTeamTotalFightPower()
- local TotalPower = 0
- for i = 1, #self.battleHeros do
- local Power = ManagerContainer.DataMgr.UserData:GetAsideFighterSvrPower(self.battleHeros[i],false)
- if nil ~= Power and -1 ~= Power then
- TotalPower = TotalPower + Power
- local PetPower = ManagerContainer.DataMgr.UserData:GetAsideFighterSvrPower(self.battleHeros[i],true)
- if nil ~= PetPower and -1 ~= PetPower then
- TotalPower = TotalPower + PetPower
- end
- else
- --local power
- Power = ManagerContainer.DataMgr.UserData:GetSlotFightPower(self.battleHeros[i])
- TotalPower = TotalPower + Power
- end
- end
- return TotalPower
- end
- function ExpeditionDataMgr:GetHeroHPAndSP(uid)
- if self.serverHerosData == nil then
- return 100,100
- end
- for i = 1, #self.serverHerosData do
- if tostring(self.serverHerosData[i].id) == tostring(uid) then
- return self.serverHerosData[i].hp, self.serverHerosData[i].sp
- end
- end
- return 100, 100
- end
- function ExpeditionDataMgr:SetHeroHPAndSp(uid, hpPercent,spPercent)
- if self.serverHerosData == nil then
- return
- end
- for i = 1, #self.serverHerosData do
- if self.serverHerosData[i].id == uid then
- self.serverHerosData[i].hp = hpPercent
- self.serverHerosData[i].sp = spPercent
- return
- end
- end
- end
- function ExpeditionDataMgr:ResetAllHeroHp()
- if self.serverHerosData == nil then
- return
- end
- for i = 1, #self.serverHerosData do
- self.serverHerosData[i].hp = 100
- end
- end
- function ExpeditionDataMgr:EnterBattle()
- local map = self:FindMapByTypeId(self.curChanllengeMapId)
- if map ~= nil then
- local levelInfo = map:FindLevelByLevelId(self.curChanllengeLevelId)
- self.curMaxFightingTime = levelInfo.maxFightingTime
- ManagerContainer.LuaGameMgr:RefreshTeamData()
- local maxHP = 0
- local maxHPActorId = 0
- local heroIds = {}
- for i = 1, #self.battleHeros do
- local hpPercent,spPercent = self:GetHeroHPAndSP(self.battleHeros[i])
- local actor = ManagerContainer.LuaActorDataMgr:GetActorsById(self.battleHeros[i])
- if hpPercent > 0 then
- local MaxHp = SDataUtil.InvConvert(actor.Life) * hpPercent * 0.01
- heroIds[#heroIds + 1] = self.battleHeros[i]
- if MaxHp > maxHP then
- maxHP = MaxHp
- maxHPActorId = self.battleHeros[i]
- end
- end
- end
- if #heroIds == 0 then
- ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("队伍全部阵亡")
- return
- end
- --清空現有dropbuff 戰鬥結束清理 有bug
- ManagerContainer.LuaActorDataMgr:ResetData()
-
- local ourActors = System.Array.CreateInstance(Enum.TypeInfo.ActorData, #heroIds)
- for i = 1 , #heroIds do
- local actor = ManagerContainer.LuaActorDataMgr:GetActorsById(heroIds[i])
- ourActors[i-1] = actor
- --增加对应压制mark
- ManagerContainer.DataMgr.UserData:SetActorPveMark(heroIds[i],actor)
- --设置掉落buff
- local dropBuffs = self:GetDropBuffs(actor,maxHPActorId)
- if dropBuffs ~= nil then
- local dropBuffParamList = System.Array.CreateInstance(Enum.TypeInfo.BuffParam, #dropBuffs)
- for j = 1, #dropBuffs do
- local buffParam = dropBuffs[j]
- dropBuffParamList[j-1] = BuffParam.New(buffParam.buffId, buffParam.buffRatio, buffParam.buffCd, buffParam.buffType,buffParam.extendPara,buffParam:ConvertFunToStr())
- end
- actor:SetDropBuffs(dropBuffParamList)
- end
- if actor.HasPet then
- local petDropBuffs = self:GetDropBuffs(actor.PetData,maxHPActorId)
- if petDropBuffs ~= nil then
- local dropBuffParamList = System.Array.CreateInstance(Enum.TypeInfo.BuffParam, #petDropBuffs)
- for j = 1, #petDropBuffs do
- local buffParam = petDropBuffs[j]
- dropBuffParamList[j-1] = BuffParam.New(buffParam.buffId, buffParam.buffRatio, buffParam.buffCd, buffParam.buffType,buffParam.extendPara,buffParam:ConvertFunToStr())
- end
- actor.PetData:SetDropBuffs(dropBuffParamList)
- end
- end
- end
- local bossInfo = self.curChallengeLevelBossList[self.curChanllengeSlotIdx]
- local enemyActors = System.Array.CreateInstance(Enum.TypeInfo.ActorData, 1)
- local bossActor = ManagerContainer.LuaActorDataMgr:CreateNpc(bossInfo.id,bossInfo.id,2,bossInfo.level)
- bossActor.IsBoss = true
- enemyActors[0] = bossActor
- local srvActorData = System.Array.CreateInstance(Enum.TypeInfo.ServerFighterParam, #heroIds + 1)
- for i = 1 , #heroIds do
- local hpPercent,spPercent = self:GetHeroHPAndSP(heroIds[i])
- local param = ServerFighterParam.New(heroIds[i],0,0,hpPercent * 0.01,spPercent * 0.01)
- srvActorData[i-1] = param
- end
- self:InitEndBattleCondition()
- local bossParam = ServerFighterParam.New(bossInfo.id,bossInfo.hp,bossInfo.sp,0,0)
- srvActorData[#heroIds] = bossParam
- self.bossPreLife = bossInfo.hp
- self.bossPreSp = bossInfo.sp
- self.curChallengingBossId = bossInfo.id
- self.curChallengingBossLevel = bossInfo.level
- self.preSycnHPAndSpTime = Time.realtimeSinceStartup
-
- --保存最后一次 BOSS信息
- local bossid = bossInfo.id
- local bossCfg = ManagerContainer.CfgMgr:GetNpcCfgById(bossid)
- if bossCfg ~= nil then
- local CurBossScore = self:GetCurBossScore(bossid)
- self:SaveLastMonster(bossCfg.Name,CurBossScore)
- end
- ManagerContainer.LuaGameMgr:EnterExpeditionBattle(map.sceneName,map.bgm,self.curMaxFightingTime,ourActors,enemyActors,map.loadingId,srvActorData,self.battleEndCondList,levelInfo.RestoreSp)
- end
- end
- function ExpeditionDataMgr:InitEndBattleCondition()
- if self.battleEndCondList ~= nil then
- return
- end
- self.battleEndCondList = System.Array.CreateInstance(Enum.TypeInfo.BattleEndCondition, 2)
- self.battleEndCondList[0] = BattleEndCondition.New(Constants.EndBattle_By_UndeadCount,Constants.ResultType_Normal)
- self.battleEndCondList[1] = BattleEndCondition.New(Constants.EndBattle_By_BattleTime,Constants.ResultType_Normal)
- end
- function ExpeditionDataMgr:SyncBossLife(curLife)
- local deltaTime = Time.realtimeSinceStartup - self.preSycnHPAndSpTime
- if deltaTime >= 0.3 then
- local deltaHP = curLife - self.bossPreLife
- local bossList = {{id=self.curChallengingBossId,level=self.curChallengingBossLevel,hp=deltaHP}}
- self:SendRefreshBattleData(bossList)
- self.bossPreLife = curLife
- self.preSycnHPAndSpTime = Time.realtimeSinceStartup
- end
- end
- function ExpeditionDataMgr:SyncBossSP(curSp)
- local deltaTime = Time.realtimeSinceStartup - self.preSycnHPAndSpTime
- if deltaTime >= 0.3 then
- local deltaSp = curSp - self.bossPreSp
- local bossList = {{id=self.curChallengingBossId,level=self.curChallengingBossLevel,sp=deltaSp}}
- self:SendRefreshBattleData(bossList)
- self.bossPreSp = curSp
- self.preSycnHPAndSpTime = Time.realtimeSinceStartup
- end
- end
- function ExpeditionDataMgr:BattleEnd(battleTime,fighterParams,bossLife,bossSp)
- local heroInfos = {}
- if fighterParams ~= nil then
- for i =1, fighterParams.Count do
- local param = fighterParams[i-1]
- heroInfos[#heroInfos+1] = { id = param.uid,
- hp = param.hpPercent * 100,
- sp = param.spPercent * 100}
- end
- end
- local deltaSp = bossSp - self.bossPreSp
- local deltaHP = bossLife - self.bossPreLife
- local bossList = {{id=self.curChallengingBossId,level=self.curChallengingBossLevel,hp=deltaHP,sp=deltaSp}}
- self:SendChallengeBossEnd(battleTime,heroInfos,bossList)
- self.curChallengingBossId = 0
- self.curChallengingBossLevel = 0
- end
- function ExpeditionDataMgr:SendChallengeMapReq(mapId)
- self.reqEnterMapId = mapId
- ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_EXPEDITION_CHALLENGE_PRE_REQ, {expedition_type = mapId})
- end
- function ExpeditionDataMgr:OnChallengeMapAck(data)
- if data.error == 0 then
- ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Expedition_EnterMap_Success)
- if self.reqEnterMapId ~= nil then
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIExpeditionDungeonInfo, self.reqEnterMapId)
- self.reqEnterMapId = nil
- end
- end
- end
- function ExpeditionDataMgr:SendChallengeBossStart(slotIdx)
- self.curChanllengeSlotIdx = slotIdx
- local heroInfos = {}
- local battleTeamIds = self:GetCurrBattleTeamMembers()
- for i = 1, #battleTeamIds do
- local hpPercent,spPercent = self:GetHeroHPAndSP(battleTeamIds[i])
- if hpPercent > 0 then
- heroInfos[#heroInfos+1] = {id = battleTeamIds[i],hp = hpPercent, sp = spPercent}
- end
- end
- local data = {expedition_type = self.curChanllengeMapId,
- battle_level = self.curChanllengeLevelId,
- battle_idx = self.curChanllengeSlotIdx,
- hero_info_list = heroInfos,
- flag = 1}
- -- LogError("SendChallengeBossStart: " .. Inspect(data))
- ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_EXPEDITION_CHALLENGE_REQ, data)
- end
- function ExpeditionDataMgr:SendRefreshBattleData(bossInfo)
- if self.curChanllengeMapId == 0 then
- return
- end
- local data = {expedition_type = self.curChanllengeMapId,
- battle_level = self.curChanllengeLevelId,
- battle_idx = self.curChanllengeSlotIdx,
- boss_change_hp_list = bossInfo,
- flag = 2}
- ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_EXPEDITION_CHALLENGE_REQ, data)
- end
- function ExpeditionDataMgr:SyncHeroLifeAndSp(actorId,life,maxLife,sp,maxSp)
- if self.curChanllengeMapId == 0 then
- return
- end
- local hpPercent = life * 100 / maxLife
- local spPercent = sp * 100 / maxSp
- self:SetHeroHPAndSp(actorId,hpPercent,spPercent)
- local heroInfos = {}
- heroInfos[#heroInfos+1] = { id = actorId,hp = hpPercent, sp = spPercent}
- local data = { expedition_type = self.curChanllengeMapId,
- battle_level = self.curChanllengeLevelId,
- battle_idx = self.curChanllengeSlotIdx,
- hero_info_list = heroInfos,
- flag = 2}
- ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_EXPEDITION_CHALLENGE_REQ, data)
- end
- function ExpeditionDataMgr:SendChallengeBossEnd(battleTime,heroInfo,bossInfo)
- if self.curChanllengeMapId == 0 then
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIBattleFailed,true)
- return
- end
- local data = {expedition_type = self.curChanllengeMapId,
- battle_level = self.curChanllengeLevelId,
- battle_idx = self.curChanllengeSlotIdx,
- hero_info_list = heroInfo,
- boss_change_hp_list = bossInfo,
- battle_time = battleTime,
- flag = 3}
- ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_EXPEDITION_CHALLENGE_REQ, data)
- end
- function ExpeditionDataMgr:OnChallengeBossEndAck(data)
- --LogError("OnChallengeBossEndAck: " .. Inspect(data))
- if data.error == 0 then
- if data.flag == 1 then
- if data.buff_list ~= nil and #data.buff_list > 0 then
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIExpeditionWin,{data.buff_list,false})
- else
- self:EnterBattle()
- end
- elseif data.flag == 3 then
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIBattleFailed,true)
- elseif data.flag == 4 then
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIExpeditionWin,{data.buff_list,true})
- end
- else
- --LogError("OnChallengeBossEndAck Error ="..tostring(data.error))
- -- 超过最大挑战时间
- if data.error == 27 then
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIBattleFailed,true)
- end
- end
- end
- function ExpeditionDataMgr:SendSelectBuffReq(buffId)
- ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_EXPEDITION_SELECT_BUFF_REQ, {select_buff_id = buffId})
- self:SaveLastBuffScore(buffId)
- end
- function ExpeditionDataMgr:OnSelectBuffAck(data)
- if data.error == 0 then
- self:RemoveTimer()
- self.TimeShowTipsId = ManagerContainer.LuaTimerMgr:AddTimer(800, 1, self, self.ShowTips,nil)
- end
- end
- function ExpeditionDataMgr:ShowTips(Score)
- local score = self:GetLastBuffScore()
- if not ManagerContainer.LuaUIMgr:GetPage(Enum.UIPageName.UIErrorTips) then
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIErrorTips, {errorId="ExpeditionArtifact", params ={ tostring(score)}}, nil, nil, nil, Enum.UISibling[Enum.UIType.Top + 1] + 11)
- else
- ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.ERROR_DESC_DISPLAY, {errorId="ExpeditionArtifact",params = { tostring(score)}})
- end
- end
- function ExpeditionDataMgr:RemoveTimer()
- if self.TimeShowTipsId then
- ManagerContainer.LuaTimerMgr:RemoveTimer(self.TimeShowTipsId);
- self.TimeShowTipsId = nil;
- end
- end
- --levelId: 0 表示一键领取
- function ExpeditionDataMgr:SendGotRewardReq(mapId,levelId)
- -- LogError("mapId = " .. mapId .. " levelId = " .. levelId)
- self.isSingleReward = levelId > 0
- ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_EXPEDITION_REWARD_REQ, {expedition_type = mapId, boss_idx = levelId})
- end
- function ExpeditionDataMgr:OnGotRewardAck(data)
- if data.error == 0 then
- local rewardList = {}
- for i = 1, #data.reward_item_list do
- local itemData = data.reward_item_list[i];
- rewardList[#rewardList+1] = {cfgId = itemData.key, num = itemData.value}
- end
- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPOPGot,{rewards = rewardList})
- end
- end
- function ExpeditionDataMgr:SendApplyBattleTeamReq(teamIds)
- -- LogError(Inspect(teamIds))
- ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_EXPEDITION_BATTLE_HERO_REQ, {battle_hero_list = teamIds})
- end
- function ExpeditionDataMgr:OnApplyBattleTeamAck(data)
- -- LogError(data.error)
- end
- function ExpeditionDataMgr:SendAssistReq(uid)
- -- LogError("SendAssistReq = " .. tostring(uid))
- ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_EXPEDITION_CALL_FOR_HELP_REQ, {assist_help_uid = uid})
- end
- function ExpeditionDataMgr:OnAssistReqAck(data)
- -- LogError(data.error)
- end
- function ExpeditionDataMgr:OnAssistNtf(data)
- if data.assist_state == 1 then
- ManagerContainer.LuaUIMgr:ErrorNoticeDisplay("ExpeditionHelp")
- self:ResetAllHeroHp()
- end
- end
- function ExpeditionDataMgr:SendRescueFriendReq(uid,msgType, time)
- self.targetUid = uid
- self.msgType = msgType
- ManagerContainer.NetManager:SendMessage(ProtoMsgId.CS_EXPEDITION_HELP_REQ, {be_helped_uid = uid, msg_type = msgType, help_msg_send_time = time})
- end
- function ExpeditionDataMgr:OnRescueFriendAck(data)
- if data.error == Enum.NetErrorCode.ERROR_OK then
- local uid = tostring(self.targetUid)
- ManagerContainer.DataMgr.ChatData:ExpeditionHelpAck(uid, self.msgType)
- self.targetUid = nil
- self.msgType = nil
- --策划需求 不用显示 奖励界面
- --if data.reward_item_list ~= nil and #data.reward_item_list > 0 then
- -- local rewardList = {}
- -- for i = 1, #data.reward_item_list do
- -- local itemData = data.reward_item_list[i];
- -- rewardList[#rewardList+1] = {cfgId = itemData.key, num = itemData.value}
- -- end
- -- ManagerContainer.LuaUIMgr:Open(Enum.UIPageName.UIPOPGot,{rewards = rewardList})
- --end
- end
- end
- function ExpeditionDataMgr:GetRescuerCnt()
- if self.myRescuerIds ~= nil then
- return #self.myRescuerIds
- end
- return 0
- end
- function ExpeditionDataMgr:GetRescuers()
- return self.myRescuers
- end
- function ExpeditionDataMgr:ReqestRescuerBriefData()
- if self.myRescuerIds == nil or #self.myRescuerIds == 0 then
- return
- end
- local cnt = 10
- local uid_list = {}
- if cnt > #self.myRescuerIds then
- cnt = #self.myRescuerIds
- end
- for i = 1, cnt do
- uid_list[#uid_list+1] = self.myRescuerIds[i].uid
- end
-
- ManagerContainer.DataMgr.FriendDataMgr:ReqFriendBriefData(Enum.FriendTogglePageType.ExpedtionHelpLog,uid_list)
- end
- function ExpeditionDataMgr:OnGetBriefInfoAck(data)
- if data.type == Enum.FriendTogglePageType.ExpedtionHelpLog then
- if data.brief_info ~= nil then
- for i = 1,#data.brief_info do
- local info = data.brief_info[i]
- self:AddRescuer(info)
- self:RemoveRescuerId(info.uid)
- end
- end
- ManagerContainer.LuaEventMgr:Dispatch(UIEventNames.EID_Expedition_REFRESH_HELP_LOG)
- end
- end
- function ExpeditionDataMgr:GetRescuerTime(uid)
- if self.myRescuerIds == nil then
- return 0
- end
- for i = 1, #self.myRescuerIds do
- if self.myRescuerIds[i].uid == uid then
- return self.myRescuerIds[i].time
- end
- end
- return 0
- end
- function ExpeditionDataMgr:RemoveRescuerId(uid)
- for i = 1, #self.myRescuerIds do
- if self.myRescuerIds[i].uid == uid then
- table.remove(self.myRescuerIds,i)
- return
- end
- end
- end
- function ExpeditionDataMgr:FindRescuerById(uid)
- if self.myRescuers == nil then
- return nil
- end
- for i = 1, #self.myRescuers do
- if self.myRescuers[i].uid == uid then
- return self.myRescuers[i]
- end
- end
- return nil
- end
- function ExpeditionDataMgr:AddRescuer(briefInfo)
- if briefInfo == nil then
- return
- end
-
- local obj = self:FindRescuerById(briefInfo.uid)
- if obj ~= nil then
- obj:SetData(briefInfo)
- else
- obj = FriendData:new(briefInfo.uid)
- obj:SetData(briefInfo)
- self.myRescuers[#self.myRescuers+1] = obj
- end
- local time = self:GetRescuerTime(briefInfo.uid)
- obj.param = time
- end
- function ExpeditionDataMgr:GetDropBuffs(actorData,maxHPActorId)
- if self.buffs == nil or #self.buffs == 0 then
- return nil
- end
- local buffList = {}
- for i = 1, #self.buffs do
- --local buffCfg = self.buffs[i]
- local buffCfg = self.buffs[i]
- local filterActorType,filterParamType,filterParamVal = self:ParseFilterParam(buffCfg.FilterParam)
- local matchAType = (filterActorType == -1) or (filterActorType == actorData.IActorType) or (filterActorType == 5 and (actorData.IsHero or actorData.IsFellow))
- local bMatch = false
- if filterParamType == nil then
- if matchAType then
- bMatch = true
- end
- else
- if filterParamType == 1 then --职业
- if matchAType and (filterParamVal == -1 or filterParamVal == actorData.JobType) then
- if buffCfg.FilterExtendParam ~= nil then
- local jobStage = buffCfg.FilterExtendParam[1]
- local jobBranch = buffCfg.FilterExtendParam[2]
- if jobStage == actorData.JobStage and jobBranch == actorData.JobBranch then
- bMatch = true
- end
- else
- bMatch = true
- end
- end
- elseif filterParamType == 2 then --属性
- if matchAType and (filterParamVal == -1 or filterParamVal == actorData.NatureId) then
- bMatch = true
- end
- elseif filterParamType == 3 then --宠物ID
- if matchAType and (filterParamVal == actorData.BaseId) then
- bMatch = true
- end
- elseif filterParamType == 4 then --血量最高的人
- if matchAType and (tostring(actorData.ID) == tostring(maxHPActorId)) then
- bMatch = true
- end
- end
- end
- if bMatch then
- local buff = self:FindBuff(buffList,buffCfg.BuffId)
- if buff == nil then
- local buff = ExpeditionBuff:new(buffCfg.BuffId,buffCfg.Ratio,buffCfg.CD,buffCfg.ConditionType,buffCfg.ExtendPara,buffCfg.Function)
- buffList[#buffList+1] = buff
- else
- buff:AddFun(buffCfg.Function)
- end
- end
- end
- return buffList
- end
- function ExpeditionDataMgr:FindBuff(buffList,buffId)
- if buffList == nil then return nil end
- for i = 1, #buffList do
- if buffList[i].buffId == buffId then
- return buffList[i]
- end
- end
- return nil
- end
- --返回过滤参数类型:paramType:参数类型[1:职业; 2:属性; 3: 宠物ID]
- function ExpeditionDataMgr:ParseFilterParam(params)
- local filterActorType = params[1]
- local filterParamType = nil
- local filterParamVal = nil
- if #params > 1 then
- filterParamType = params[2]
- end
- if #params > 2 then
- filterParamVal = params[3]
- end
- return filterActorType,filterParamType,filterParamVal
- end
- return ExpeditionDataMgr
|