using System; using System.Collections.Generic; using Thousandto.Code.Center; using Thousandto.Core.Asset; using FLogger = UnityEngine.Gonbest.MagicCube.FLogger; namespace Thousandto.Code.Logic { //游戏限制系统,可以限制角色数量和特效数量,根据游戏设置进行限制,用以限制角色数量,优化客户端效率 class GameObjectLimit { //更新玩家屏蔽的timer private static float _playerCountTimer = 0.0f; //初始化 public static void Initialize() { //GameCenter.UnRegFixEventHandle(CoreEventDefine.EID_CORE_FPS_LEVEL_CHANGED, OnFPSLevelChanged); //GameCenter.RegFixEventHandle(CoreEventDefine.EID_CORE_FPS_LEVEL_CHANGED, OnFPSLevelChanged); } //反初始化 public static void UnInitialize() { } private static int GetSettingPlayerCount() { return Math.Min(GameCenter.GameSetting.GetSetting(GameSettingKeyCode.MaxShowPlayerCount), GameSetting.MaxPlayerCount); } //在仇恨列表中的玩家,队友,杀气值大于200,同骑的玩家始终会显示 private static bool IsMustShow(LocalPlayer lp, RemotePlayer p) { if (lp.IsStrikeBack(p.ID)) return true; if (GameCenter.LuaSystem.Adaptor.IsTeamMember(p.ID)) return true; return false; } //是否可以显示 public static bool IsCanShow(RemotePlayer p) { var showRemotePlayer = GameCenter.GameSetting.GetSetting(GameSettingKeyCode.ShowOtherPlayer) > 0; if (showRemotePlayer) { int settingCount = GetSettingPlayerCount(); GameScene scene = GameCenter.GameSceneSystem.ActivedScene; LocalPlayer lp = scene.GetLocalPlayer(); if (IsMustShow(lp, p)) { return true; } int count = scene.GetCount((entity) => { if (entity is RemotePlayer) { var player = entity as RemotePlayer; if (player.IsShowModel) return true; } return false; }); if (count >= settingCount) { return false; } return true; } return false; } //是否可以显示 public static bool IsCanShow(Pet p) { if (GameCenter.GameSceneSystem.ActivedScene != null) { if (p.PropMoudle.MasterID == GameCenter.GameSceneSystem.GetLocalPlayerID()) { //主角宠物永远显示 return true; } if(GameCenter.GameSetting.GetSetting(GameSettingKeyCode.ShowOtherPet) <= 0) { return false; } var rp = GameCenter.GameSceneSystem.ActivedScene.Find(p.PropMoudle.MasterID); if (rp != null) { return rp.IsShowModel; } } return false; } //是否可以显示助战宠物 public static bool IsCanShow(AssistPet p) { if (GameCenter.GameSceneSystem.ActivedScene != null) { return true; } return false; } //是否可以显示飞剑 public static bool IsCanShow(FlySword flySword) { if (GameCenter.GameSceneSystem.ActivedScene != null) { if (flySword.PropMoudle.MasterID == GameCenter.GameSceneSystem.GetLocalPlayerID()) { //主角飞剑永远显示 return true; } if (GameCenter.GameSetting.GetSetting(GameSettingKeyCode.ShowOtherFlySword) <= 0) { return false; } var rp = GameCenter.GameSceneSystem.ActivedScene.Find(flySword.PropMoudle.MasterID); if (rp != null) { return rp.IsShowModel; } } return false; } //是否可以显示仙娃 public static bool IsCanShow(MarryChild marryChild) { if (GameCenter.GameSceneSystem.ActivedScene != null) { if (marryChild.PropMoudle.MasterID == GameCenter.GameSceneSystem.GetLocalPlayerID()) { //主角飞剑永远显示 return true; } if (GameCenter.GameSetting.GetSetting(GameSettingKeyCode.ShowOtherMarryChild) <= 0) { return false; } var rp = GameCenter.GameSceneSystem.ActivedScene.Find(marryChild.PropMoudle.MasterID); if (rp != null) { return rp.IsShowModel; } } return false; } //是否可以显示 public static bool IsCanShow(Monster p) { return GameCenter.GameSetting.GetSetting(GameSettingKeyCode.ShowMonster) > 0; } //是否可以显示翅膀 public static bool IsCanShowWing() { return !(GameCenter.GameSetting.GetSetting(GameSettingKeyCode.EnableShowWing) > 0); } public static void RefreshShowMonster() { if (!GameCenter.GameSceneSystem.CheckActivedScene()) return; LocalPlayer lp = GameCenter.GameSceneSystem.GetLocalPlayer(); if (lp == null) { return; } List monsterList = GameCenter.GameSceneSystem.FindEntityAll(); var isShow = GameCenter.GameSetting.GetSetting(GameSettingKeyCode.ShowMonster) > 0; //全部展示 for (int i = 0; i < monsterList.Count; ++i) { monsterList[i].IsShowModel = isShow; } } //刷新玩家的显示 public static void RefreshShowPlayer() { try { _playerCountTimer = 0.0f; if (!GameCenter.GameSceneSystem.CheckActivedScene()) return; LocalPlayer lp = GameCenter.GameSceneSystem.GetLocalPlayer(); if (lp == null) { return; } int settingCount = 0; if (GameCenter.GameSetting.GetSetting(GameSettingKeyCode.ShowOtherPlayer) <= 0) { settingCount = 0; } else { settingCount = GetSettingPlayerCount(); } List playerList = GameCenter.GameSceneSystem.FindEntityAll(); if (playerList.Count <= settingCount) { //全部展示 for (int i = 0; i < playerList.Count; ++i) { playerList[i].IsShowModel = true; } } else { //需要进行数量限制 int showCount = 0; //先排除掉必须显示的玩家 for (int i = playerList.Count - 1; i >= 0; --i) { if (IsMustShow(lp, playerList[i])) { playerList[i].IsShowModel = true; ++showCount; playerList.RemoveAt(i); } } if (playerList.Count > 0) { if (showCount > settingCount) { //其他的全部不展示 for (int i = playerList.Count - 1; i >= 0; --i) { playerList[i].IsShowModel = false; } } else { var tmpDic = new Dictionary(); for(int i = playerList.Count - 1; i >= 0 ; --i) { var player = playerList[i]; if(tmpDic.ContainsKey(player)) { //有重复,删除掉 playerList.RemoveAt(i); continue; } tmpDic.Add(player, true); } int canShowCount = settingCount - showCount; playerList.Sort((left, right) => { //1.判断对象是否有效,是否相等 if (left == null || right == null || left == right) return 0; if (left.ID == 0 || right.ID == 0) return 0; //2.好友判断 bool lf = lp.IsFriend(left); bool rf = lp.IsFriend(left); if (lf != rf) { if (lf) { return -1; } else if (rf) { return 1; } } //3.距离判断 var lDis = lp.GetSqrDistance2d(left.Position2d); var rDis = lp.GetSqrDistance2d(right.Position2d); if(float.IsInfinity(lDis)||float.IsInfinity(rDis) || float.IsNaN(lDis) || float.IsNaN(rDis)) { //无效值 return 0; } return lDis.CompareTo(rDis); }); for (int i = 0; i < playerList.Count; ++i) { playerList[i].IsShowModel = i < canShowCount; } } } } var showOtherPet = GameCenter.GameSetting.GetSetting(GameSettingKeyCode.ShowOtherPet) > 0; List petList = GameCenter.GameSceneSystem.ActivedScene.FindAll(); for (int i = 0; i < petList.Count; ++i) { if (petList[i].IsLocalPet()) { petList[i].IsShowModel = true; } else { RemotePlayer master = GameCenter.GameSceneSystem.ActivedScene.Find(petList[i].PropMoudle.MasterID); if (showOtherPet && master != null && master.IsShowModel) { petList[i].IsShowModel = true; } else { petList[i].IsShowModel = false; } } } var showOtherFlySword = GameCenter.GameSetting.GetSetting(GameSettingKeyCode.ShowOtherFlySword) > 0; List flySwordList = GameCenter.GameSceneSystem.ActivedScene.FindAll(); for (int i = 0; i < flySwordList.Count; ++i) { if (flySwordList[i].IsLocalFlySword()) { flySwordList[i].IsShowModel = true; } else { RemotePlayer master = GameCenter.GameSceneSystem.ActivedScene.Find(flySwordList[i].PropMoudle.MasterID); if (showOtherFlySword && master != null && master.IsShowModel) { flySwordList[i].IsShowModel = true; } else { flySwordList[i].IsShowModel = false; } } } var showOtherMarryChild = GameCenter.GameSetting.GetSetting(GameSettingKeyCode.ShowOtherMarryChild) > 0; List marryChildList = GameCenter.GameSceneSystem.ActivedScene.FindAll(); for (int i = 0; i < marryChildList.Count; ++i) { if (marryChildList[i].IsLocalMarryChild()) { marryChildList[i].IsShowModel = true; } else { RemotePlayer master = GameCenter.GameSceneSystem.ActivedScene.Find(marryChildList[i].PropMoudle.MasterID); if (showOtherMarryChild && master != null && master.IsShowModel) { marryChildList[i].IsShowModel = true; } else { marryChildList[i].IsShowModel = false; } } } } catch (System.Exception ex) { FLogger.LogException(ex); } } //是否可以播放特效 public static bool CanPlayVfx(Character host, ModelTypeCode vfxType) { if (host == null) return false; //if (GameCenter.GameSetting.IsEnabled(GameSettingKeyCode.TPVFXSkill)) // return false; var vfxLevel = GameCenter.GameSetting.GetSetting(GameSettingKeyCode.SkillVfxLevel); if (vfxLevel == 0) { return (host.IsLocalPlayer() && host.IsShowModel) || (host.IsLocalFlySword() && host.IsShowModel); } if (vfxLevel == 1) { return (host.IsLocalPlayer() || host.IsLocalFlySword() || host.IsLocalPet()) && host.IsShowModel; } if (vfxLevel == 2) { if (!host.IsShowModel) { return false; } if(host.IsLocalPlayer() || host.IsLocalFlySword() || host.IsLocalPet()) { return true; } //获取当前技能特效的数量 int nonceCount = FGameObjectModel.GetModelTypeFGOCount(vfxType); return nonceCount < GameCenter.MapLogicSwitch.MaxSkillVfxCount; } return host.IsLocalPlayer() && host.IsShowModel; } public static void Tick(float dt) { if (GameCenter.GameSceneSystem.GetLocalPlayer() == null) return; _playerCountTimer += dt; if (_playerCountTimer > 10.0f) { RefreshShowPlayer(); } } } }