349 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			Lua
		
	
			
		
		
	
	
			349 lines
		
	
	
		
			13 KiB
		
	
	
	
		
			Lua
		
	
PlayerManager = {}
 | 
						|
local this = PlayerManager
 | 
						|
local gameSetting = ConfigManager.GetConfig(ConfigName.GameSetting)
 | 
						|
this.userLevelData = ConfigManager.GetConfig(ConfigName.PlayerLevelConfig)
 | 
						|
this.globalSystemConfig = ConfigManager.GetConfig(ConfigName.GlobalSystemConfig)
 | 
						|
this.serverTime = 0
 | 
						|
this.maxEnergy = 0
 | 
						|
this.singleAddEnergy = gameSetting[1].EnergyRecoverSpeed[1]
 | 
						|
this.singleAddTimeGap = gameSetting[1].EnergyRecoverSpeed[2]
 | 
						|
this.exp = 0
 | 
						|
this.level = 0
 | 
						|
this.maxForce = 0
 | 
						|
-- 每次重置的时间
 | 
						|
this.startTime = 0
 | 
						|
-- 已经计时的时间
 | 
						|
this.durationTime = 0
 | 
						|
-- 设置计时状态
 | 
						|
this.isStart = false
 | 
						|
--图鉴
 | 
						|
this.heroHandBook = {}
 | 
						|
this.equipHandBook = {}
 | 
						|
this.talismanHandBook={}
 | 
						|
this.heroHandBookListData={}
 | 
						|
--移动速度 和  视野范围
 | 
						|
this.MapSpeed = 0
 | 
						|
this.MapView = 0
 | 
						|
 | 
						|
local update = function()
 | 
						|
    local dt = Time.unscaledDeltaTime
 | 
						|
    this.serverTime = this.serverTime + dt
 | 
						|
    this.UpdateEnergyData()
 | 
						|
end
 | 
						|
function this.Initialize()
 | 
						|
    Game.GlobalEvent:AddEvent(GameEvent.Network.OnReceiveHeartBeat, function(network, time)
 | 
						|
        if network.type == SocketType.LOGIN then
 | 
						|
            --Log("刷新心跳时间--------------"..time)
 | 
						|
            this.serverTime = time
 | 
						|
        end
 | 
						|
    end)
 | 
						|
    Game.GlobalEvent:AddEvent(GameEvent.Player.OnGoldChange, this.OnGoldChange)
 | 
						|
end
 | 
						|
 | 
						|
function this.InitServerTime()
 | 
						|
    UpdateBeat:Add(update, this)
 | 
						|
end
 | 
						|
 | 
						|
function this.OnGoldChange()
 | 
						|
 | 
						|
end
 | 
						|
 | 
						|
--每间隔一段时间恢复精力
 | 
						|
function this.UpdateEnergyData()
 | 
						|
    -- 一个计时器
 | 
						|
 | 
						|
    if MapManager.isOpen then
 | 
						|
        local dt = this.serverTime - this.startTime
 | 
						|
        dt = math.floor(dt)
 | 
						|
        if dt ~= this.durationTime then
 | 
						|
            -- 数值更新
 | 
						|
            this.durationTime = dt
 | 
						|
            Game.GlobalEvent:DispatchEvent(GameEvent.Mission.OnTimeChange, this.durationTime)
 | 
						|
        end
 | 
						|
    end
 | 
						|
 | 
						|
    -- 截取服务器时间
 | 
						|
    ActTimeCtrlManager.Updata()
 | 
						|
    ActTimeCtrlManager.serTime = math.floor(this.serverTime)
 | 
						|
    -- 刷新需要刷新的道具
 | 
						|
    -- this.RefreshItemNumBySerTime()
 | 
						|
end
 | 
						|
local needRefreshItemTabs = {1,44, 53,54}
 | 
						|
local isAddItem = {
 | 
						|
    [1] = true,
 | 
						|
    --[2] = true,
 | 
						|
    [44] = true,
 | 
						|
    [53] = true,
 | 
						|
    [54]=true,
 | 
						|
}
 | 
						|
-- 刷新需要刷新的道具
 | 
						|
function this.RefreshItemNumBySerTime()
 | 
						|
    for i, itemId in pairs(needRefreshItemTabs) do
 | 
						|
        --一些类型的特殊判断
 | 
						|
        if itemId == 1 then--行动力
 | 
						|
            if not EndLessMapManager.isTrigger and not EndLessMapManager.EnergyEnough() then-- 已经是行动力的上限不再刷新-- 正在正在触发事件不刷新
 | 
						|
                this.RefreshItemNumById(itemId)
 | 
						|
            end
 | 
						|
        elseif  itemId == 44 then--外敌挑战券
 | 
						|
            if BagManager.GetItemCountById(itemId) then
 | 
						|
                this.RefreshItemNumById(itemId)
 | 
						|
            end
 | 
						|
        elseif  itemId == 53 then--兽潮入场券
 | 
						|
            this.RefreshItemNumById(itemId)
 | 
						|
        elseif  itemId == 54 then-- 召唤外敌次数
 | 
						|
            this.RefreshItemNumById(itemId)
 | 
						|
 | 
						|
        end
 | 
						|
    end
 | 
						|
end
 | 
						|
local nextRefreshTime = 0
 | 
						|
function this.RefreshItemNumById(itemId)
 | 
						|
    if not BagManager.bagDatas[itemId] then return end
 | 
						|
    nextRefreshTime = BagManager.bagDatas[itemId].nextFlushTime
 | 
						|
    if(nextRefreshTime) then
 | 
						|
        if this.serverTime >= nextRefreshTime and nextRefreshTime ~= 0 then
 | 
						|
            if isAddItem[itemId] then
 | 
						|
                isAddItem[itemId] = false
 | 
						|
                --地图里需要特殊处理  其他正常
 | 
						|
                if itemId == 1 and CarbonManager.difficulty == CARBON_TYPE.ENDLESS and MapManager.isInMap then
 | 
						|
                    if #MapManager.stepList > 0 then
 | 
						|
                        MapManager.MapUpdateEvent(-1000, function ()
 | 
						|
                            NetManager.RefreshEnergyRequest({itemId},function()
 | 
						|
                                isAddItem[itemId] = true
 | 
						|
                                EndLessMapManager.isUpdateOnClose = true
 | 
						|
                                Log(Language[11504])
 | 
						|
                            end)
 | 
						|
                        end)
 | 
						|
                    else
 | 
						|
                        NetManager.RefreshEnergyRequest({itemId},function()
 | 
						|
                            isAddItem[itemId] = true
 | 
						|
                            EndLessMapManager.isUpdateOnClose = true
 | 
						|
                            Log(Language[11505])
 | 
						|
                        end)
 | 
						|
                    end
 | 
						|
                else
 | 
						|
                    Log(Language[11506]..itemId.."      "..this.serverTime.."        "..nextRefreshTime)
 | 
						|
                    NetManager.RefreshEnergyRequest({itemId},function()
 | 
						|
                        isAddItem[itemId] = true
 | 
						|
                    end)
 | 
						|
                end
 | 
						|
            end
 | 
						|
        end
 | 
						|
 | 
						|
    end
 | 
						|
end
 | 
						|
this.curLevelAndExp = {}
 | 
						|
function this.BcakUpdateUserExp(_msg)
 | 
						|
    if not UIManager.IsOpen(UIName.FightMopUpEndPanel) then
 | 
						|
        Log(Language[11507].._msg.level.."        ".._msg.exp)
 | 
						|
 | 
						|
        this.exp = _msg.exp
 | 
						|
        local oldLevel = this.level
 | 
						|
        this.level = _msg.level
 | 
						|
 | 
						|
        if this.level > oldLevel then
 | 
						|
            CheckRedPointStatus(RedPointType.HeroExplore_OpenMap)
 | 
						|
            CheckRedPointStatus(RedPointType.EpicExplore_OpenCarbon)
 | 
						|
            --FightManager.SetAndGetSingleFightState3(this.level)
 | 
						|
            RedPointManager.SetExploreRedPoint({ level = this.level })
 | 
						|
        end
 | 
						|
        Game.GlobalEvent:DispatchEvent(GameEvent.Player.OnPlayerLvChange)
 | 
						|
        if this.userLevelData and this.userLevelData[this.level] then
 | 
						|
            this.maxEnergy = this.userLevelData[this.level].MaxEnergy
 | 
						|
        else
 | 
						|
            this.maxEnergy = 0
 | 
						|
        end
 | 
						|
    else
 | 
						|
        this.curLevelAndExp = _msg
 | 
						|
    end
 | 
						|
end
 | 
						|
--跟具经验进行升级
 | 
						|
function this.PromoteLevel(exp)
 | 
						|
    --Log("增加经验值     " .. exp)
 | 
						|
    local maxPlayerLv = GameDataBase.SheetBase.GetKeys(this.userLevelData)
 | 
						|
    this.exp = this.exp + exp
 | 
						|
    while this.exp >= this.userLevelData[this.level].Exp and this.level < #maxPlayerLv do
 | 
						|
        this.exp = this.exp - this.userLevelData[this.level].Exp
 | 
						|
        this.level = this.level + 1
 | 
						|
        this.level = this.level >= #maxPlayerLv and #maxPlayerLv or this.level
 | 
						|
        CheckRedPointStatus(RedPointType.HeroExplore_OpenMap)
 | 
						|
        CheckRedPointStatus(RedPointType.EpicExplore_OpenCarbon)
 | 
						|
        CheckRedPointStatus(RedPointType.SecretTer_NewHourseOpen)
 | 
						|
        --Log("¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥¥   玩家升级增加经验"..this.userLevelData[this.level].AddEnergy.."      "..BagManager.GetItemCountById(2))
 | 
						|
        --FightManager.SetAndGetSingleFightState3(this.level)
 | 
						|
        RedPointManager.SetExploreRedPoint({ level = this.level })
 | 
						|
    end
 | 
						|
    this.maxEnergy = this.userLevelData[this.level].MaxEnergy
 | 
						|
 | 
						|
    -- 看看这个玩家是否升级了
 | 
						|
    --if PlayerManager.level > FightManager.oldLevel then
 | 
						|
    --    Log("玩家升级成功!")
 | 
						|
    --    Game.GlobalEvent:DispatchEvent(GameEvent.Player.OnLevelChange)
 | 
						|
    --end
 | 
						|
    -- 打点数据
 | 
						|
    TapDBManager.SetLevel(this.level)
 | 
						|
    -- ThinkingAnalyticsManager.SetSuperProperties({
 | 
						|
 | 
						|
    -- })
 | 
						|
end
 | 
						|
function this.SetMaxEnergy()
 | 
						|
    this.maxEnergy = this.userLevelData[this.level].MaxEnergy
 | 
						|
end
 | 
						|
--获取单个英雄装备被动技能累计评分
 | 
						|
function this.GetSingHeroAllEquipSkillListScore(_curHeroData)
 | 
						|
    local Score = 0
 | 
						|
    local curHeroData = _curHeroData
 | 
						|
    if curHeroData and curHeroData.equipIdList then
 | 
						|
        for i = 1, #curHeroData.equipIdList do
 | 
						|
            local curEquip = EquipManager.GetSingleEquipData(curHeroData.equipIdList[i])
 | 
						|
            if curEquip then
 | 
						|
                --if curEquip.skillId and curEquip.skillId > 0 then
 | 
						|
                    Score = Score + curEquip.equipConfig.Score
 | 
						|
                --end
 | 
						|
            end
 | 
						|
        end
 | 
						|
    end
 | 
						|
    return Score
 | 
						|
end
 | 
						|
 | 
						|
--图鉴更新
 | 
						|
function this.InitHandBookData(heroHandBook,talismanHandBook)
 | 
						|
    --根据后端传的有过的所有英雄的数据更新本地英雄图鉴数据
 | 
						|
    if heroHandBook and #heroHandBook > 0 then
 | 
						|
        for n,m in ipairs(heroHandBook) do
 | 
						|
            if not PlayerManager.heroHandBook then
 | 
						|
                PlayerManager.heroHandBook={}
 | 
						|
            end
 | 
						|
            if not PlayerManager.heroHandBook[m.heroId] then
 | 
						|
                PlayerManager.heroHandBook[m.heroId]={maxStar=0}
 | 
						|
            end
 | 
						|
            PlayerManager.heroHandBook[m.heroId].maxStar = m.maxStar
 | 
						|
        end
 | 
						|
    end
 | 
						|
    --根据后端传的有过的所有装备的数据更新本地装备图鉴数据
 | 
						|
    Log(Language[11508]..#talismanHandBook)
 | 
						|
    if talismanHandBook and #talismanHandBook > 0 then
 | 
						|
        for i = 1, #talismanHandBook do
 | 
						|
            PlayerManager.talismanHandBook[talismanHandBook[i]] = talismanHandBook[i]
 | 
						|
        end
 | 
						|
    end
 | 
						|
end
 | 
						|
 | 
						|
function this.SetHeroHandBookListData(heroSId,heroStar)
 | 
						|
    if this.heroHandBook[heroSId] == nil then
 | 
						|
        this.heroHandBook[heroSId]={maxStar=0}
 | 
						|
        this.heroHandBook[heroSId].maxStar=heroStar
 | 
						|
    else
 | 
						|
        if this.heroHandBook[heroSId].maxStar<heroStar then
 | 
						|
            this.heroHandBook[heroSId].maxStar=heroStar
 | 
						|
        end
 | 
						|
    end
 | 
						|
    
 | 
						|
end
 | 
						|
function this.SetEquipHandBookListData(equipSId)
 | 
						|
    if this.equipHandBook[equipSId] == nil then
 | 
						|
        this.equipHandBook[equipSId] = equipSId
 | 
						|
    end
 | 
						|
end
 | 
						|
--------------------------------------------
 | 
						|
 | 
						|
-- 切磋
 | 
						|
function this.RequestPlayWithSomeOne(uid, teamId, tname, func)
 | 
						|
    if uid == PlayerManager.uid then
 | 
						|
        PopupTipPanel.ShowTip(Language[11509])
 | 
						|
        return
 | 
						|
    end
 | 
						|
    NetManager.RequestPlayWithSomeOne(uid, teamId, function(msg)
 | 
						|
        local fightData = BattleManager.GetBattleServerData({fightData = msg.fightData}, 1)
 | 
						|
        if tname then
 | 
						|
            tname = PlayerManager.nickName .."|" .. tname
 | 
						|
        end
 | 
						|
        BattleRecordManager.SetBattleRecord(fightData)
 | 
						|
        BattleRecordManager.SetBattleBothNameStr(tname)
 | 
						|
 | 
						|
        BattleRecordManager.GetBattleRecord()
 | 
						|
        local battlePanel = UIManager.OpenPanel(UIName.BattlePanel, fightData, BATTLE_TYPE.BACK, func)
 | 
						|
        battlePanel:SetResult(BattleLogic.Result)
 | 
						|
 | 
						|
    end)
 | 
						|
end
 | 
						|
-----------------------------------玩家坐骑 皮肤 称号
 | 
						|
--设置玩家称号
 | 
						|
function this.SetPlayerDesignation(value)
 | 
						|
    PlayerManager.designation = value
 | 
						|
end
 | 
						|
--设置玩家皮肤
 | 
						|
function this.SetPlayerSkin(value)
 | 
						|
    PlayerManager.skin = value
 | 
						|
end
 | 
						|
--设置玩家坐骑
 | 
						|
function this.SetPlayerRide(value)
 | 
						|
    PlayerManager.ride = value
 | 
						|
end
 | 
						|
--设置玩家坐骑等级
 | 
						|
function this.SetPlayerRideLv(value)
 | 
						|
    PlayerManager.rideLevel = value
 | 
						|
end
 | 
						|
--设置当前玩家 视野范围 和 移动速度
 | 
						|
function this.SetMoveSpeedAndMapView()
 | 
						|
    if PlayerManager.ride > 0 then
 | 
						|
        local playerMountLevelUpConFig = ConfigManager.GetConfigData(ConfigName.PlayerMountLevelUp,PlayerManager.rideLevel)
 | 
						|
        if playerMountLevelUpConFig then
 | 
						|
            this.MapSpeed = playerMountLevelUpConFig.MapSpeed
 | 
						|
            this.MapView = playerMountLevelUpConFig.MapView
 | 
						|
        end
 | 
						|
    end
 | 
						|
end
 | 
						|
--计算 称号 皮肤 坐骑战力加成
 | 
						|
function this.CalculatePlayerDcorateProAddVal()
 | 
						|
    local addAllProVal = {}
 | 
						|
    --称号
 | 
						|
    if PlayerManager.designation and PlayerManager.designation > 0 then
 | 
						|
        local playerAppearance = ConfigManager.GetConfigData(ConfigName.PlayerAppearance,PlayerManager.designation)
 | 
						|
        if playerAppearance then
 | 
						|
            for j = 1, #playerAppearance.Property do
 | 
						|
                if addAllProVal[playerAppearance.Property[j][1]] then
 | 
						|
                    addAllProVal[playerAppearance.Property[j][1]] = addAllProVal[playerAppearance.Property[j][1]] + playerAppearance.Property[j][2]
 | 
						|
                else
 | 
						|
                    addAllProVal[playerAppearance.Property[j][1]] = playerAppearance.Property[j][2]
 | 
						|
                end
 | 
						|
            end
 | 
						|
        end
 | 
						|
    end
 | 
						|
    --皮肤
 | 
						|
    if PlayerManager.skin and PlayerManager.skin > 0 then
 | 
						|
        local playerAppearance = ConfigManager.GetConfigData(ConfigName.PlayerAppearance,PlayerManager.skin)
 | 
						|
        if playerAppearance then
 | 
						|
            for j = 1, #playerAppearance.Property do
 | 
						|
                if addAllProVal[playerAppearance.Property[j][1]] then
 | 
						|
                    addAllProVal[playerAppearance.Property[j][1]] = addAllProVal[playerAppearance.Property[j][1]] + playerAppearance.Property[j][2]
 | 
						|
                else
 | 
						|
                    addAllProVal[playerAppearance.Property[j][1]] = playerAppearance.Property[j][2]
 | 
						|
                end
 | 
						|
            end
 | 
						|
        end
 | 
						|
    end
 | 
						|
    --坐骑
 | 
						|
    if PlayerManager.ride and PlayerManager.ride > 0 then
 | 
						|
        local playerMountLevelUpConFig = ConfigManager.GetConfigData(ConfigName.PlayerMountLevelUp,PlayerManager.rideLevel)
 | 
						|
        if playerMountLevelUpConFig then
 | 
						|
            for j = 1, #playerMountLevelUpConFig.Property do
 | 
						|
                if addAllProVal[playerMountLevelUpConFig.Property[j][1]] then
 | 
						|
                    addAllProVal[playerMountLevelUpConFig.Property[j][1]] = addAllProVal[playerMountLevelUpConFig.Property[j][1]] + playerMountLevelUpConFig.Property[j][2]
 | 
						|
                else
 | 
						|
                    addAllProVal[playerMountLevelUpConFig.Property[j][1]] = playerMountLevelUpConFig.Property[j][2]
 | 
						|
                end
 | 
						|
            end
 | 
						|
        end
 | 
						|
    end
 | 
						|
    return addAllProVal
 | 
						|
end
 | 
						|
 | 
						|
function this.GetHeroDataByStar(star,staticid)
 | 
						|
    if PlayerManager.heroHandBook and PlayerManager.heroHandBook[staticid] and PlayerManager.heroHandBook[staticid].maxStar >= star then 
 | 
						|
        return true
 | 
						|
    end
 | 
						|
    return false
 | 
						|
end
 | 
						|
 | 
						|
return this |