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.worldLeve = 0 -- 每次重置的时间 this.startTime = 0 -- 已经计时的时间 this.durationTime = 0 -- 设置计时状态 this.isStart = false --图鉴 this.heroHandBook = {} this.equipHandBook = {} this.talismanHandBook={} this.heroHandBookListData={} --移动速度 和 视野范围 this.MapSpeed = 0 this.MapView = 0 this.IsGetFiveStarHero = false this.headBookListTag = 1 this.now_index = 0 this.isCross = 0--是否已跨服 0 未 1 已跨服 --头像框数据 this.headFrameList = {} this.MainPanelRoleMonveState = true --是否为从六星玉帝入口跳转进入 this.isSixStarJump=false --激活的称号 时装 坐骑 this.isRefreshMainPanelNpc = true this.userSkinList = {}--[id] = {skinId , overTime} this.userTitleList = {}--[id] = {titleId , overTime} this.userMountList = {}--[id] = {mountId , overTime} --每日福利红包抢夺次数 this.dailyRedPack = 0 this.startWeek = 0 this.RewardItemSingleShowPopupIsRoleUpStarLayout = false this.RewardItemSingleShowPopupIsRoleUpStarLayout2 = false local update = function() local dt = Time.unscaledDeltaTime this.serverTime = this.serverTime + dt this.UpdateEnergyData() end function this.Initialize() -- 重置数据 this.ServerOpenTime = 0 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.SetServerOpenTime(time) if time then LogRed("服务器开启时间为:"..time) this.ServerOpenTime = time end end -- 获取服务器开启时间 function this.GetServerOpenTime() return this.ServerOpenTime end --获取公会福利红包抢夺次数 function this.GetDailyRedPackageTime() return this.dailyRedPack end --获取公会福利红包抢夺次数 function this.SettDailyRedPackageTime(time) this.dailyRedPack=time LogError("time=="..this.dailyRedPack) end function this.ResetLocalData(var)--初始化所有本地的每日一刷--1是五点推送、2是登陆检测 PlayerPrefs.SetInt(PlayerManager.uid.."MainRightBarSetting",1) local func1 = function () PlayerPrefs.SetInt(PlayerManager.uid.."GeneralPopup_RecruitConfirm"..RecruitType.Ten,0) PlayerPrefs.SetInt(PlayerManager.uid.."GeneralPopup_RecruitConfirm"..RecruitType.TimeLimitTen,0) PlayerPrefs.SetInt(PlayerManager.uid.."GeneralPopup_RecruitConfirm"..RecruitType.PrayerTen,0) PlayerPrefs.SetInt(PlayerManager.uid.."GeneralPopup_RecruitConfirm"..RecruitType.QianKunBoxTen,0) PlayerPrefs.SetInt(PlayerManager.uid.."GeneralPopup_RecruitConfirm"..RecruitType.LingShowTen,0) PlayerPrefs.SetInt(PlayerManager.uid.."GeneralPopup_RecruitConfirm"..RecruitType.XiangYaoTen,0) PlayerPrefs.SetInt(PlayerManager.uid.."GeneralPopup_RecruitConfirm"..RecruitType.BaoGeTen,0) PlayerPrefs.SetInt(PlayerManager.uid.."GeneralPopup_ChangeHeroProConfirm",0) PlayerPrefs.SetInt("IsCheckWeekCard_"..PlayerManager.uid, 0) PlayerPrefs.SetInt(PlayerManager.uid.."monthCard", 0) PlayerPrefs.SetInt(PlayerManager.uid.."piaomiaozhilv", 0) PlayerPrefs.SetInt(PlayerManager.uid.."CommonActPage"..ActivityTypeDef.YunYouShangRen,0) PlayerPrefs.SetInt(PlayerManager.uid.."kaifuchongbang",0) PlayerPrefs.SetInt(PlayerManager.uid.."lingShouBaoGe",0) PlayerPrefs.SetInt(PlayerManager.uid.."tuijianzhenrong",0) PlayerPrefs.SetInt(PlayerManager.uid.."hotRank",0) PlayerPrefs.SetInt(PlayerManager.uid.."chaozhijijin128",0) PlayerPrefs.SetInt(PlayerManager.uid.."chaozhijijin328",0) end if var == 1 then func1() MapTrialManager.TrialRedCheck() elseif var == 2 then local text1 =PlayerManager.uid.."fiveTime" local curTime = GetTimeStamp() if not PlayerPrefs.HasKey(text1) then func1() PlayerPrefs.SetInt(text1,Today_N_OClockTimeStamp(5)) end if PlayerPrefs.GetInt(text1) < curTime then func1() PlayerPrefs.SetInt(text1,Today_N_OClockTimeStamp(5)+86400) end end 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 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 function this.RefreshItemNumById(itemId) if not BagManager.bagDatas[itemId] then return end local 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.Mapping then if #MapManager.stepList > 0 then MapManager.MapUpdateEvent(-1000, function () NetManager.RefreshEnergyRequest({itemId},function() isAddItem[itemId] = true EndLessMapManager.isUpdateOnClose = true Log("地图,同步,刷新") end) end) else NetManager.RefreshEnergyRequest({itemId},function() isAddItem[itemId] = true EndLessMapManager.isUpdateOnClose = true Log("地图,刷新") end) end else Log("请求刷新 "..itemId.." "..this.serverTime.." "..nextRefreshTime) NetManager.RefreshEnergyRequest({itemId},function() isAddItem[itemId] = true end) end end end end end this.curLevelAndExp = {} --无尽请求行动力刷新 function this.RequestEnergy() NetManager.RefreshEnergyRequest({1},function() -- LogWarn("无尽请求行动力刷新") end) end function this.BcakUpdateUserExp(_msg) if not UIManager.IsOpen(UIName.FightMopUpEndPanel) then Log("后端更新玩家等级 和 经验 ".._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 }) -- 打点数据 TapDBManager.SetLevel(this.level) --发送埋点数据 for l = oldLevel+1, this.level do CustomEventManager.SendCustomEvents(FBSDKCustomEventType.RoleLv,l) end CheckRedPointStatus(RedPointType.OrdinaryExplore) CheckRedPointStatus(RedPointType.HeroExplore) CheckRedPointStatus(RedPointType.LegendExplore) CheckRedPointStatus(RedPointType.People_Mirror) if this.level==56 then NetManager.AllEquipTreasureRequest(0) end 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 }) CheckRedPointStatus(RedPointType.OrdinaryExplore) CheckRedPointStatus(RedPointType.HeroExplore) CheckRedPointStatus(RedPointType.LegendExplore) CheckRedPointStatus(RedPointType.People_Mirror) end this.maxEnergy = this.userLevelData[this.level].MaxEnergy -- 看看这个玩家是否升级了 --if PlayerManager.level > FightManager.oldLevel then -- Log("玩家升级成功!") -- Game.GlobalEvent:DispatchEvent(GameEvent.Player.OnLevelChange) --end -- 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("图鉴数:"..#talismanHandBook) if talismanHandBook and #talismanHandBook > 0 then for i = 1, #talismanHandBook do PlayerManager.talismanHandBook[talismanHandBook[i]] = talismanHandBook[i] end end TianShuMiJuanManger.CheckFetterStatus(1) end function this.SetHeroHandBookListData(heroSId,heroStar) local isCheck = false if this.heroHandBook[heroSId] == nil then isCheck = true this.heroHandBook[heroSId]={maxStar=0} this.heroHandBook[heroSId].maxStar=heroStar else if this.heroHandBook[heroSId].maxStar GetTimeStamp() or curTitleData.overTime == 0 then return PlayerManager.designation end end if PlayerManager.designation ~= 0 then NetManager.RequestChangeModifyDecoration(2,0) this.SetPlayerDesignation(0) end PlayerManager.SetisRefreshMainPanelNpc(true) return PlayerManager.designation end --设置玩家皮肤 function this.GetPlayerSkin() --刷新所有时装 坐骑 称号 集合 检查是否有限时到时间的并删除 this.RefreshAllSkinRideTitle() --加判断是否到时间 卸掉 local curSkinData = this.userSkinList[PlayerManager.skin] if curSkinData then if curSkinData.overTime > GetTimeStamp() or curSkinData.overTime == 0 then return PlayerManager.skin end end if PlayerManager.skin ~= 0 then NetManager.RequestChangeModifyDecoration(4,0) this.SetPlayerSkin(0) end PlayerManager.SetisRefreshMainPanelNpc(true) return PlayerManager.skin end --设置玩家坐骑 function this.GetPlayerRide() --加判断是否到时间 卸掉 local currideData = this.userMountList[PlayerManager.ride] if currideData then if currideData.overTime > GetTimeStamp() or currideData.overTime == 0 then return PlayerManager.ride end end if PlayerManager.ride ~= 0 then NetManager.RequestChangeModifyDecoration(3,0) this.SetPlayerRide(0) end PlayerManager.SetisRefreshMainPanelNpc(true) return PlayerManager.ride end function this.SetisRefreshMainPanelNpc(state) --LogBlue("isRefreshMainPanelNpc "..tostring(this.isRefreshMainPanelNpc)) this.isRefreshMainPanelNpc = state end function this.GetisRefreshMainPanelNpc() return this.isRefreshMainPanelNpc end --初始化所以激活的称号 时装 坐骑 function this.InitSkinTitleMountData(userSkinList,userTitleList,userMountList) this.userSkinList = {}--[id] = {skinId , overTime} --LogBlue("#userSkinList "..#userSkinList.." #userTitleList "..#userTitleList.." #userMountList "..#userMountList) for i = 1, #userSkinList do local singData = {} singData.skinId = userSkinList[i].skinId singData.overTime = userSkinList[i].overTime this.userSkinList[singData.skinId] = singData end this.userTitleList = {}--[id] = {titleId , overTime} for i = 1, #userTitleList do local singData = {} singData.titleId = userTitleList[i].titleId singData.overTime = userTitleList[i].overTime LogRed(" titleid== "..singData.titleId.." time=="..singData.overTime.." "..GetTimeStamp()) if singData.overTime==0 or singData.overTime>GetTimeStamp() then this.userTitleList[singData.titleId] = singData end end this.userMountList = {}--[id] = {mountId , overTime} for i = 1, #userMountList do local singData = {} singData.mountId = userMountList[i].mountId singData.overTime = userMountList[i].overTime this.userMountList[singData.mountId] = singData end end --设置称号 时装 坐骑 的限时时间 function this.SetPlayerSkinTime(id,validTime) if this.userSkinList then if validTime then--不为空时是设置时间 没有会新加数据 if this.userSkinList[id] then this.userSkinList[id].overTime = validTime else local singData = {} singData.skinId = id singData.overTime = validTime this.userSkinList[singData.skinId] = singData end else--为空时是删除数据 倒计时结束时 if this.userSkinList[id] then this.userSkinList[id] = nil end end end end function this.SetPlayerTitleTime(id,validTime) if this.userTitleList then if validTime then--不为空时是设置时间 没有会新加数据 if this.userTitleList[id] then if validTime==-1 then this.userTitleList[id] = nil else this.userTitleList[id].overTime = validTime end else local singData = {} singData.titleId = id singData.overTime = validTime this.userTitleList[singData.titleId] = singData this.SetPlayerTitleRedPoint(PlayerTitleRideSkinRedPointTypeStr.Title,1) end else--为空时是删除数据 倒计时结束时 LogRed("time==nil") if this.userTitleList[id] then this.userTitleList[id] = nil end end end end function this.SetPlayerMountTime(id,validTime) if this.userMountList then if validTime then--不为空时是设置时间 没有会新加数据 if this.userMountList[id] then this.userMountList[id].overTime = validTime else local singData = {} singData.mountId = id singData.overTime = validTime this.userMountList[singData.mountId] = singData this.SetPlayerRideRedPoint(PlayerTitleRideSkinRedPointTypeStr.Ride,1) -- FormationManager.UserPowerChanged() NetManager.RequestUserForceChange(FormationTypeDef.FORMATION_NORMAL) end else--为空时是删除数据 倒计时结束时 if this.userMountList[id] then this.userMountList[id] = nil end end end end function this.RefreshAllSkinRideTitle() for key, value in pairs(this.userMountList) do if value and value.overTime > 0 and value.overTime < GetTimeStamp() then --过期 table.remove(this.userMountList,key) end end for key, value in pairs(this.userTitleList) do if value and value.overTime > 0 and value.overTime < GetTimeStamp() then --过期 table.remove(this.userTitleList,key) end end for key, value in pairs(this.userSkinList) do if value and value.overTime > 0 and value.overTime < GetTimeStamp() then --过期 table.remove(this.userSkinList,key) end end 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 = {} --称号 皮肤 坐骑 当前玩家正穿戴的加成 local allPlayerUpConfig = {} if PlayerManager.designation and PlayerManager.designation > 0 then local PlayerHeadIcon = ConfigManager.GetConfigData(ConfigName.PlayerHeadIcon,PlayerManager.designation) if PlayerHeadIcon and PlayerHeadIcon.WearProperty and #PlayerHeadIcon.WearProperty > 0 then table.insert(allPlayerUpConfig,PlayerHeadIcon) end end if PlayerManager.skin and PlayerManager.skin > 0 then local PlayerHeadIcon = ConfigManager.GetConfigData(ConfigName.PlayerHeadIcon,PlayerManager.skin) if PlayerHeadIcon and PlayerHeadIcon.WearProperty and #PlayerHeadIcon.WearProperty > 0 then table.insert(allPlayerUpConfig,PlayerHeadIcon) end end if PlayerManager.ride and PlayerManager.ride > 0 then local PlayerHeadIcon = ConfigManager.GetConfigData(ConfigName.PlayerHeadIcon,PlayerManager.ride) if PlayerHeadIcon and PlayerHeadIcon.WearProperty and #PlayerHeadIcon.WearProperty > 0 then table.insert(allPlayerUpConfig,PlayerHeadIcon) end end for i = 1, #allPlayerUpConfig do for j = 1, #allPlayerUpConfig[i].WearProperty do local curAddProInfo = allPlayerUpConfig[i].WearProperty[j] if addAllProVal[curAddProInfo[1]] then addAllProVal[curAddProInfo[1]] = addAllProVal[curAddProInfo[1]] + curAddProInfo[2] else addAllProVal[curAddProInfo[1]] = curAddProInfo[2] end end end --称号 皮肤 坐骑 当前玩家解锁的加成 local allActiveConfig = {} for key, value in pairs(this.userSkinList) do local PlayerHeadIcon = ConfigManager.GetConfigData(ConfigName.PlayerHeadIcon,value.skinId) if PlayerHeadIcon and PlayerHeadIcon.UnlockProperty and #PlayerHeadIcon.UnlockProperty > 0 then table.insert(allActiveConfig,PlayerHeadIcon) end end for key, value in pairs(this.userTitleList) do local PlayerHeadIcon = ConfigManager.GetConfigData(ConfigName.PlayerHeadIcon,value.titleId) if PlayerHeadIcon and PlayerHeadIcon.UnlockProperty and #PlayerHeadIcon.UnlockProperty > 0 then table.insert(allActiveConfig,PlayerHeadIcon) end end for key, value in pairs(this.userMountList) do local PlayerHeadIcon = ConfigManager.GetConfigData(ConfigName.PlayerHeadIcon,value.mountId) if PlayerHeadIcon and PlayerHeadIcon.UnlockProperty and #PlayerHeadIcon.UnlockProperty > 0 then table.insert(allActiveConfig,PlayerHeadIcon) end end for i = 1, #allActiveConfig do if allActiveConfig[i].UnlockProperty then for j = 1, #allActiveConfig[i].UnlockProperty do local curAddProInfo = allActiveConfig[i].UnlockProperty[j] if addAllProVal[curAddProInfo[1]] then addAllProVal[curAddProInfo[1]] = addAllProVal[curAddProInfo[1]] + curAddProInfo[2] else addAllProVal[curAddProInfo[1]] = curAddProInfo[2] end end end end return addAllProVal end function this.SetPlayerRideRedPoint(str,val) PlayerPrefs.SetInt(PlayerManager.uid..PlayerManager.serverInfo.server_id..PlayerTitleRideSkinRedPointTypeStr.Ride, val) CheckRedPointStatus(RedPointType.Setting_Ride) end function this.SetPlayerTitleRedPoint(str,val) PlayerPrefs.SetInt(PlayerManager.uid..PlayerManager.serverInfo.server_id..PlayerTitleRideSkinRedPointTypeStr.Title, val) CheckRedPointStatus(RedPointType.Setting_Title) end function this.GetPlayerTitleRedPoint(str) local redPointState = PlayerPrefs.GetInt(PlayerManager.uid..PlayerManager.serverInfo.server_id..PlayerTitleRideSkinRedPointTypeStr.Title) return redPointState == 1 end function this.GetPlayerRideRedPoint(str) local redPointState = PlayerPrefs.GetInt(PlayerManager.uid..PlayerManager.serverInfo.server_id..PlayerTitleRideSkinRedPointTypeStr.Ride) return redPointState == 1 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 --主城停留弹气泡 local level_bubble_config = string.split(ConfigManager.GetConfigData(ConfigName.SpecialConfig,88).Value,"|") local battleUpLvTipTime = Timer.New() local curMianPanleLoginShowTipNum = 0 local curLevelPanleLoginShowTipNum = 0 local noShowBattleUpLvTipMaxLv = tonumber(level_bubble_config[3]) local noShowBattleUpLvTipMaxNum = tonumber(level_bubble_config[2]) local showBattleUpLvTipMaxTime = tonumber(level_bubble_config[1]) function this.StarBattleUpLvTipTime(type) local curSecound = 0 if PlayerManager.level >= noShowBattleUpLvTipMaxLv then return end if not FightPointPassManager.IsShowFightRP() then return end if GuideManager.IsInMainGuide() then return end if battleUpLvTipTime then battleUpLvTipTime:Stop() battleUpLvTipTime = nil end if type == 1 and curMianPanleLoginShowTipNum < noShowBattleUpLvTipMaxNum then--主界面 battleUpLvTipTime = Timer.New(function() curSecound = curSecound + 1 -- ----LogGreen("主界面停留 "..curSecound) if curSecound >= showBattleUpLvTipMaxTime then if battleUpLvTipTime then battleUpLvTipTime:Stop() battleUpLvTipTime = nil end Game.GlobalEvent:DispatchEvent(GameEvent.Player.OnShowBattleUpLvTip) curMianPanleLoginShowTipNum = curMianPanleLoginShowTipNum + 1 end end, 1, -1, true) battleUpLvTipTime:Start() elseif type == 2 and curLevelPanleLoginShowTipNum < noShowBattleUpLvTipMaxNum then--关卡界面 battleUpLvTipTime = Timer.New(function() curSecound = curSecound + 1 -- ----LogGreen("关卡界面停留 "..curSecound) if curSecound >= showBattleUpLvTipMaxTime then if battleUpLvTipTime then battleUpLvTipTime:Stop() battleUpLvTipTime = nil end Game.GlobalEvent:DispatchEvent(GameEvent.Player.OnShowBattleUpLvTip) curLevelPanleLoginShowTipNum = curLevelPanleLoginShowTipNum + 1 end end, 1, -1, true) battleUpLvTipTime:Start() end end function this.RefreshWorldLeveData(worldLeve) this.worldLeve = worldLeve Game.GlobalEvent:DispatchEvent(GameEvent.JumpServerHeightLadder.UpdateWordLv) end function this.StopBattleUpLvTipTime() if battleUpLvTipTime then battleUpLvTipTime:Stop() battleUpLvTipTime = nil end end ------- 主城NPC 选择star ---------- ---先去好友里 或 公会成员 去取needNum 个 再去排行榜里去取needAllNum - 去取needNum 个 最后不足自己造NPC 信息 local needNum = 5--7 local needAllNum = 10--14 local rankNPCList = {} local friendNPCList = {} function this.GetMainPlayerNPCData(fun) rankNPCList = {} friendNPCList = {} local friendRandomNum = math.random(1, 2) if friendRandomNum == 2 and PlayerManager.familyId == 0 then friendRandomNum = 1 end -- ----LogGreen("friendRandomNum "..friendRandomNum) local curfriendAllList = {} if friendRandomNum == 1 then NetManager.RequestGetFriendInfo(1,function(msg) for i = 1, #msg.Friends do if msg.Friends[i].id ~= PlayerManager.uid then --LogBlue("msg.Friends[i] "..msg.Friends[i].userSkin.." "..msg.Friends[i].userTitle.." "..msg.Friends[i].userMount.." "..msg.Friends[i].sex) msg.Friends[i].name = PracticeManager.SetNameColor(msg.Friends[i].name,msg.Friends[i].practiceLevel) table.insert(curfriendAllList,msg.Friends[i]) end end if #curfriendAllList > needNum then for i = 1, needNum do this.RandomFirendNPC(curfriendAllList) end else for i = 1, #curfriendAllList do friendNPCList[i] = curfriendAllList[i] -- ----LogGreen("friend "..msg.Friends[i].name) end end -- ----LogGreen("#friendNPCList "..#friendNPCList) this.GetMainPlayerNPCData2(fun) end) else MyGuildManager.RequestMyGuildMembers(function() local MyGuildMemList = MyGuildManager.GetMyGuildMemList() for i = 1, #MyGuildMemList do if MyGuildMemList[i].roleUid ~= PlayerManager.uid then --LogBlue("MyGuildMemList[i] "..MyGuildMemList[i].userSkin.." "..MyGuildMemList[i].userTitle.." "..MyGuildMemList[i].userMount.." "..MyGuildMemList[i].sex) table.insert(curfriendAllList,MyGuildMemList[i]) end end if #curfriendAllList > needNum then for i = 1, needNum do this.RandomFirendNPC(curfriendAllList) end else for i = 1, #curfriendAllList do friendNPCList[i] = curfriendAllList[i] -- ----LogGreen("MyGuildMemList "..MyGuildMemList[i].userName) end end -- ----LogGreen("#MyGuildMemList "..#friendNPCList) this.GetMainPlayerNPCData2(fun) end) end end function this.GetPlayerViewDataByType(index,randomList,needNum,func) local x = function(index,needNum,randomList) --LogGreen("后 needNum:"..needNum.." randomList:".. LengthOfTable(randomList).." index:"..index) needNum = needNum - LengthOfTable(randomList) if needNum > 0 then this.GetPlayerViewDataByType(index,randomList,needNum,func) else if func then func(randomList) end end end if index == 1 then local friendNPCList1 = {} NetManager.RequestGetFriendInfo(1,function(msg) --LogGreen("发送好友信息") for i = 1, #msg.Friends do if msg.Friends[i].id ~= PlayerManager.uid then --LogBlue("msg.Friends[i] "..msg.Friends[i].userSkin.." "..msg.Friends[i].userTitle.." "..msg.Friends[i].userMount.." "..msg.Friends[i].sex.." "..msg.Friends[i].userName) msg.Friends[i].name = PracticeManager.SetNameColor(msg.Friends[i].name,msg.Friends[i].practiceLevel) table.insert(friendNPCList1,msg.Friends[i]) end end --LogGreen("前 needNum:"..needNum.." randomList:"..LengthOfTable(randomList)) randomList = this.AddPlayer(friendNPCList1,randomList,needNum) x(2,needNum,randomList) end) elseif index == 2 then local GuildNPCList1 = {} if ActTimeCtrlManager.SingleFuncState(FUNCTION_OPEN_TYPE.GUILD) and PlayerManager.familyId ~= 0 then MyGuildManager.RequestMyGuildMembers(function() --LogGreen("发送工会成员信息") local MyGuildMemList = MyGuildManager.GetMyGuildMemList() for i = 1, #MyGuildMemList do if MyGuildMemList[i].roleUid ~= PlayerManager.uid then --LogBlue("MyGuildMemList[i] "..MyGuildMemList[i].userSkin.." "..MyGuildMemList[i].userTitle.." "..MyGuildMemList[i].userMount.." "..MyGuildMemList[i].sex.." "..MyGuildMemList[i].userName) table.insert(GuildNPCList1,MyGuildMemList[i]) end end --LogGreen("前 needNum:"..needNum.." randomList:"..LengthOfTable(randomList)) randomList = this.AddPlayer(GuildNPCList1,randomList,needNum) x(3,needNum,randomList) end) else x(3,needNum,randomList) end elseif index == 3 then local rankNPCList1 = {} RankingManager.InitData(rankKingList[1].rankType, function() --LogGreen("发送排行榜信息") local rankAllList = RankingManager.GetRankingInfo() for i = 1, math.max(20,#rankAllList) do if rankAllList[i] and rankAllList[i].uid ~= PlayerManager.uid then --LogBlue("rankAllList[i] "..rankAllList[i].userSkin.." "..rankAllList[i].userTitle.." "..rankAllList[i].userMount.." "..rankAllList[i].sex.." "..rankAllList[i].userName) table.insert(rankNPCList1,rankAllList[i]) end end --LogGreen("前 needNum:"..needNum.." randomList:"..LengthOfTable(randomList)) randomList = this.AddPlayer(rankNPCList1,randomList,needNum) x(4,needNum,randomList) end) else --LogGreen("机器人 前 needNum:"..needNum.." randomList:"..LengthOfTable(randomList)) for i = 1, needNum do local singleUserData = {} singleUserData.userName = NameManager.GetLocalRandomName() singleUserData.sex = math.random(0,1) singleUserData.uid = 1000 + i singleUserData.userSkin = PlayerManager.GetPlayerSkin() singleUserData.userTitle = 0 singleUserData.userMount = 0 singleUserData.precticelevel = 1 singleUserData.lv = 0 table.insert(randomList,singleUserData) end --LogGreen("机器人 后 needNum:"..needNum.." randomList:"..LengthOfTable(randomList)) if func then func(randomList) end end end function this.AddPlayer(list1,randomList,needNum) if #list1 > needNum then for i = 1, needNum do this.RandomNPC(list1,randomList) end else for i = 1, #list1 do local uid = 0 if list1[i].id then uid = list1[i].id elseif list1[i].roleUid then uid = list1[i].roleUid elseif list1[i].uid then uid = list1[i].uid end if not randomList[uid] and uid > 0 then randomList[uid] = list1[i] end end end return randomList end --获取战斗地图随机人 function this.GetFightMapPlayerNPCData(needNum,func) local randomList = {} --LogGreen("初始化数据") --LogGreen("needNum:"..needNum) needNum = needNum - LengthOfTable(randomList) if needNum > 0 then this.GetPlayerViewDataByType(1,randomList,needNum,func) end end function this.GetMainPlayerNPCData2(fun) local rankRandomNum = math.random(1, 4) if rankRandomNum == 3 then rankRandomNum = 2 end--如果是公会排行 改成战力排行 (公会排行展示的是公会名字) local curAddNum = needNum - LengthOfTable(friendNPCList) curAddNum = needNum + curAddNum -- ----LogGreen("rankRandomNum "..rankRandomNum) RankingManager.InitData(rankKingList[rankRandomNum].rankType, function() local rankAllList = RankingManager.GetRankingInfo() local currankAllList = {} for i = 1, 25 do if rankAllList[i] and rankAllList[i].uid ~= PlayerManager.uid then -- --LogBlue("rankAllList[i] "..rankAllList[i].userSkin.." "..rankAllList[i].userTitle.." "..rankAllList[i].userMount.." "..rankAllList[i].sex) table.insert(currankAllList,rankAllList[i]) end end if #currankAllList > curAddNum then for i = 1, curAddNum do this.RandomRankNPC(currankAllList) end else for i = 1, #currankAllList do rankNPCList[i] = currankAllList[i] -- ----LogGreen("rank "..currankAllList[i].userName) end end -- ----LogGreen("#rankNPCList "..#rankNPCList) this.GetMainPlayerNPCData3(fun) end) end function this.GetMainPlayerNPCData3(fun) local upList = {} for key,val in pairs(friendNPCList) do table.insert(upList,val) end for key,val in pairs(rankNPCList) do -- 去重 local isRepetition = false for ke2y,val2 in pairs(upList) do local curUid = val2.roleUid or val2.id if val.uid == curUid then isRepetition = true end end if not isRepetition then table.insert(upList,val) end end if #upList < needAllNum then for i = 1, needAllNum - #upList do local singleUserData = {} singleUserData.userName = NameManager.GetLocalRandomName() singleUserData.sex = math.random(0,1) singleUserData.uid = 1000 + i singleUserData.userSkin = PlayerManager.GetPlayerSkin() singleUserData.userTitle = 0 singleUserData.userMount = 0 singleUserData.practiceLevel = 1 singleUserData.lv = 0 table.insert(upList,singleUserData) end end -- ----LogGreen("#upList "..#upList) if fun then fun(upList) end end function this.RandomRankNPC(currankAllList) local playerRandomNum = math.random(1, #currankAllList) if rankNPCList[playerRandomNum] then this.RandomRankNPC(currankAllList) else rankNPCList[playerRandomNum] = currankAllList[playerRandomNum] -- ----LogGreen("rank "..currankAllList[playerRandomNum].userName) end end function this.RandomFirendNPC(currankAllList) local playerRandomNum = math.random(1, #currankAllList) if friendNPCList[playerRandomNum] then this.RandomFirendNPC(currankAllList) else friendNPCList[playerRandomNum] = currankAllList[playerRandomNum] -- ----LogGreen("friend "..currankAllList[playerRandomNum].userName) end end local currankAllList = {} function this.RandomNPC(_currankAllList,curlist) if _currankAllList then currankAllList = {} for i = 1,#_currankAllList do table.insert(currankAllList,_currankAllList[i]) end end if not currankAllList or #currankAllList < 1 then return end local playerRandomNum = math.random(1, #currankAllList) local uid = 0 if currankAllList[playerRandomNum].id then uid = currankAllList[playerRandomNum].id elseif currankAllList[playerRandomNum].roleUid then uid = currankAllList[playerRandomNum].roleUid elseif currankAllList[playerRandomNum].uid then uid = currankAllList[playerRandomNum].uid end if curlist[uid] or uid < 1 then table.remove(currankAllList,playerRandomNum) this.RandomNPC(nil,curlist) else curlist[uid] = {} curlist[uid] = currankAllList[playerRandomNum] end end ---------- 主城NPC 选择 end---------- return this