From d8d869b6ae49c54d077c272507c8ffbdb4b01fd8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=B0=B8=E5=AE=89404?= <101850798+YongAn404@users.noreply.github.com> Date: Mon, 7 Oct 2024 10:38:33 +0800 Subject: [PATCH] 1.0.0-alpha.8 (#8) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 音频系统的小改,部分注释补充 * 注释补充 * 问题的修复 (#6) * add BDNT(Bypass Do Not Track) * add GetAllProperties * 修复功能 * 修复错版 (#10) --- Commands/PlayerCommand.cs | 45 +++++++++++++++++++++++++++ Components/CapacityList.cs | 59 +++++++++-------------------------- Players/FramePlayer.cs | 25 +++++++++++++-- Players/HintManager.cs | 63 ++++++++++++++++++++++++-------------- Roles/CustomRolePlus.cs | 43 ++++++++++++++------------ YongAnFrame.csproj | 2 ++ YongAnFrameConfig.cs | 1 + 7 files changed, 147 insertions(+), 91 deletions(-) create mode 100644 Commands/PlayerCommand.cs diff --git a/Commands/PlayerCommand.cs b/Commands/PlayerCommand.cs new file mode 100644 index 0000000..e8f1b96 --- /dev/null +++ b/Commands/PlayerCommand.cs @@ -0,0 +1,45 @@ +using CommandSystem; +using Exiled.API.Features; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using YongAnFrame.Players; + +namespace YongAnFrame.Commands +{ + [CommandHandler(typeof(ClientCommandHandler))] + public class PlayerCommand : ICommand + { + public string Command => "player"; + + public string[] Aliases => ["play", "pl", "pr"]; + + public string Description => "用于管理自己的用户"; + + public bool Execute(ArraySegment arguments, ICommandSender sender, out string response) + { + response = "NULL"; + if (arguments.Count < 2) + { + switch (arguments.Array[1]) + { + case "BDNT": + if (Player.TryGet(sender, out Player player)) + { + FramePlayer fPlayer = FramePlayer.Get(player); + fPlayer.HintManager.Clean(); + string[] text = new string[36]; + + fPlayer.ExPlayer.ShowHint($"{string.Join("\n", text)}\n\n\n\n\n\n\n\n\n\n\n\n\n\n", 10000f); + } + + return true; + } + + } + return false; + } + } +} diff --git a/Components/CapacityList.cs b/Components/CapacityList.cs index 0398685..e6bd390 100644 --- a/Components/CapacityList.cs +++ b/Components/CapacityList.cs @@ -8,39 +8,33 @@ namespace YongAnFrame.Components { - public class CapacityList(int capacity) : IList, ICollection, IEnumerable, IEnumerable + public class CapacityList(int capacity) { private readonly List list = new(capacity); + public int Capacity { get; set; } = capacity; public int Count => list.Count; - public bool IsReadOnly => ((ICollection)list).IsReadOnly; - public T this[int index] { - get => list[index]; - set => list[index] = value; - } - - public int IndexOf(T item) - { - return list.IndexOf(item); - } - - public void Insert(int index, T item) - { - list.Insert(index, item); - } + get + { + if (Count > index) + { + return list[index]; + } + return default; + } + set + { - public void RemoveAt(int index) - { - list.RemoveAt(index); + } } public void Add(T item) { - if (Capacity <= list.Count) + if (Capacity > list.Count) { list.Add(item); } @@ -51,34 +45,9 @@ public void Add(T item) } } - public void Clear() - { - list.Clear(); - } - - public bool Contains(T item) - { - return list.Contains(item); - } - - public void CopyTo(T[] array, int arrayIndex) - { - list.CopyTo(array, arrayIndex); - } - public bool Remove(T item) { return list.Remove(item); } - - IEnumerator IEnumerable.GetEnumerator() - { - return list.GetEnumerator(); - } - - IEnumerator IEnumerable.GetEnumerator() - { - return ((IEnumerable)list).GetEnumerator(); - } } } diff --git a/Players/FramePlayer.cs b/Players/FramePlayer.cs index e7c8ff2..ba2d81f 100644 --- a/Players/FramePlayer.cs +++ b/Players/FramePlayer.cs @@ -1,4 +1,5 @@ using Exiled.API.Features; +using Exiled.CustomRoles.API; using Exiled.Events.EventArgs.Player; using Exiled.Events.Features; using MEC; @@ -30,7 +31,16 @@ public sealed class FramePlayer /// /// 实例拥有的自定义角色 /// - public CustomRolePlus CustomRolePlus { get; internal set; } + public CustomRolePlus CustomRolePlus { + get + { + if (ExPlayer.GetCustomRoles().Count != 0) + { + return (CustomRolePlus)ExPlayer.GetCustomRoles()[0]; + } + return null; + } + } /// /// 提示系统管理器 /// @@ -39,7 +49,10 @@ public sealed class FramePlayer /// 玩家等级 /// public ulong Level { get; set; } - + /// + /// 玩家批准绕过DNT + /// + public bool IsBDNT { get; set; } /// /// 正在使用的名称称号 /// @@ -72,7 +85,8 @@ private static void OnStaticVerified(VerifiedEventArgs args) } private static void OnStaticDestroying(DestroyingEventArgs args) { - args.Player.ToFPlayer().Invalid(); + FramePlayer fPlayer = args.Player.ToFPlayer(); + fPlayer.Invalid(); } //private static void OnStaticWaitingForPlayers() //{ @@ -175,6 +189,11 @@ internal void UpdateShowInfoList() ExPlayer.RankName = CustomRolePlus.Name; ExPlayer.RankColor = CustomRolePlus.NameColor; } + else + { + ExPlayer.RankName = string.Empty; + ExPlayer.RankColor = string.Empty; + } } if (usingTitles == null) ExPlayer.CustomName = $"[LV:{Level}]{ExPlayer.Nickname}"; diff --git a/Players/HintManager.cs b/Players/HintManager.cs index d6b5cee..2fd367b 100644 --- a/Players/HintManager.cs +++ b/Players/HintManager.cs @@ -1,4 +1,5 @@ -using MEC; +using Exiled.API.Features; +using MEC; using System.Collections.Generic; using System.Reflection; using YongAnFrame.Components; @@ -17,7 +18,6 @@ public sealed class HintManager private readonly CoroutineHandle coroutine; - public Text[] CustomText = new Text[20]; public CapacityList MessageTexts { get; } = new(7); public CapacityList ChatTexts { get; } = new(6); @@ -33,25 +33,36 @@ public IEnumerator Update() { string[] text = new string[36]; - int usedMex = text.Length - 1; int used = 0; text[used] = $"YongAnFrame 1.0.0-alpha7"; + + if (fPlayer.ExPlayer.DoNotTrack && !fPlayer.IsBDNT) + { + text[used] = "[注意]已开启DoNotTrack(DNT),游戏数据不会被保存,想保存数据请控制台输入pl BDNT查看详情"; + } + used = 1; text[used] = ""; - for (int i = 0; i < ChatTexts.Count; i++) + for (int i = 0; i < ChatTexts.Capacity; i++) { - Text textData = ChatTexts[i]; - - text[used] += textData; - used++; - - textData.Duration--; - if (textData.Duration <= 0) + Text chatText = ChatTexts[i]; + if(chatText != null) + { + text[used] += chatText; + chatText.Duration--; + + if (chatText.Duration <= 0) + { + ChatTexts.Remove(chatText); + i--; + } + } + else { - ChatTexts.Remove(textData); - i--; + text[used] = string.Empty; } + used++; } foreach (Text data in CustomText) @@ -60,20 +71,26 @@ public IEnumerator Update() used++; } - - for (int i = 0; i < MessageTexts.Count; i++) + for (int i = 0; i < MessageTexts.Capacity; i++) { Text messageText = MessageTexts[i]; - text[used] = $"[{messageText.Duration}]{messageText}"; - - messageText.Duration--; - if (messageText.Duration <= 0) + if (messageText != null) + { + text[used] = $"[{messageText.Duration}]{messageText}"; + + messageText.Duration--; + if (messageText.Duration <= 0) + { + MessageTexts.Remove(messageText); + i--; + } + } + else { - MessageTexts.Remove(messageText); - i--; + text[used] = string.Empty; } + used++; } - text[used] += ""; if (fPlayer.CustomRolePlus != null) @@ -81,7 +98,7 @@ public IEnumerator Update() text[34] = fPlayer.CustomRolePlus.Name; text[35] = fPlayer.CustomRolePlus.Description; } - + fPlayer.ExPlayer.ShowHint($"{string.Join("\n", text)}\n\n\n\n\n\n\n\n\n\n\n\n\n\n", 2f); yield return Timing.WaitForSeconds(1f); } diff --git a/Roles/CustomRolePlus.cs b/Roles/CustomRolePlus.cs index f171fdb..98692bb 100644 --- a/Roles/CustomRolePlus.cs +++ b/Roles/CustomRolePlus.cs @@ -52,32 +52,21 @@ public abstract class CustomRolePlus : CustomRole public virtual RoleTypeId OldRole { get; set; } = RoleTypeId.None; #region Static - public static int SpawnChanceNum { get; private set; } = Loader.Random.StrictNext(1, 101); + public static int RespawnWave { get; private set; } = 0; public static void SubscribeStaticEvents() { Exiled.Events.Handlers.Server.RoundStarted += new CustomEventHandler(OnStaticRoundStarted); Exiled.Events.Handlers.Server.RespawningTeam += new CustomEventHandler(OnStaticRespawningTeam); - Exiled.Events.Handlers.Server.RestartingRound -= new CustomEventHandler(OnStaticRestartingRound); } public static void UnsubscribeStaticEvents() { Exiled.Events.Handlers.Server.RoundStarted -= new CustomEventHandler(OnStaticRoundStarted); Exiled.Events.Handlers.Server.RespawningTeam -= new CustomEventHandler(OnStaticRespawningTeam); - Exiled.Events.Handlers.Server.RestartingRound -= new CustomEventHandler(OnStaticRestartingRound); - } - - private static void OnStaticRestartingRound() - { - SpawnChanceNum = Loader.Random.StrictNext(1, 101); } private static void OnStaticRoundStarted() { - foreach (var item in Player.List) - { - Log.Debug(item); - } RespawnWave = 0; } private static void OnStaticRespawningTeam(RespawningTeamEventArgs args) @@ -86,6 +75,15 @@ private static void OnStaticRespawningTeam(RespawningTeamEventArgs args) } #endregion + /// + /// 获取这个角色所有自定义角色的属性 + /// + /// 获取的值 + public virtual CustomRolePlusProperties[] GetAllProperties() + { + return [.. BaseData.Values]; + } + /// /// 检查玩家是否拥有该角色 /// @@ -118,13 +116,11 @@ public override void AddRole(Player player) /// 框架玩家 public virtual void AddRole(FramePlayer fPlayer) { - if (Check(fPlayer.ExPlayer)) return; + if (Check(fPlayer)) return; Log.Debug($"已添加{fPlayer.ExPlayer.Nickname}的{Name}({Id})角色"); base.AddRole(fPlayer.ExPlayer); - fPlayer.CustomRolePlus?.RemoveRole(fPlayer); - fPlayer.CustomRolePlus = this; AddRoleData(fPlayer); if (MoreProperties.BaseMovementSpeedMultiplier < 1f) @@ -173,7 +169,7 @@ public override void RemoveRole(Player player) /// 框架玩家 public virtual void RemoveRole(FramePlayer fPlayer) { - if (!Check(fPlayer)) return; + if (!Check(fPlayer) || fPlayer == null) return; Log.Debug($"已删除{fPlayer.ExPlayer.Nickname}的{Name}({Id})角色"); if (Check(fPlayer, out CustomRolePlusProperties data) && !data.IsDeathHandling) { @@ -182,7 +178,6 @@ public virtual void RemoveRole(FramePlayer fPlayer) base.RemoveRole(fPlayer.ExPlayer); BaseData.Remove(fPlayer); fPlayer.ExPlayer.ShowHint($"", 0.1f); - fPlayer.CustomRolePlus = null; fPlayer.UpdateShowInfoList(); } @@ -202,7 +197,7 @@ public virtual bool TrySpawn(FramePlayer fPlayer, bool chanceRef = false) { limitCount = 0; } - if (spawnCount < SpawnProperties.MaxCount && Server.PlayerCount >= SpawnProperties.MinPlayer && SpawnChanceNum <= SpawnProperties.Chance && SpawnProperties.Limit > limitCount) + if (fPlayer.CustomRolePlus == null && spawnCount < SpawnProperties.MaxCount && Server.PlayerCount >= SpawnProperties.MinPlayer && SpawnChanceNum <= SpawnProperties.Chance && SpawnProperties.Limit > limitCount) { limitCount++; spawnCount++; @@ -234,12 +229,18 @@ private void OnRestartingRound() // TrySpawn(NoCustomRole.FindAll((p) => OldRole == RoleTypeId.None && Role == p.ExPlayer.Role.Type || p.ExPlayer.Role.Type == OldRole)); // } //} + public int SpawnChanceNum { get; private set; } = Loader.Random.StrictNext(1, 101); + + private void OnStaticRestartingRound() + { + SpawnChanceNum = Loader.Random.StrictNext(1, 101); + } private void OnSpawning(SpawningEventArgs args) { FramePlayer fPlayer = args.Player.ToFPlayer(); - if (fPlayer.CustomRolePlus == null && IsStaetSpawn && (OldRole != RoleTypeId.None && args.Player.Role.Type == OldRole) || (OldRole == RoleTypeId.None && args.Player.Role.Type == Role)) + if (IsStaetSpawn && (OldRole != RoleTypeId.None && args.Player.Role.Type == OldRole) || (OldRole == RoleTypeId.None && args.Player.Role.Type == Role)) { switch (SpawnProperties.RefreshTeam) { @@ -366,6 +367,7 @@ protected override void SubscribeEvents() Exiled.Events.Handlers.Server.RestartingRound += new CustomEventHandler(OnRestartingRound); Exiled.Events.Handlers.Player.DroppingItem += new CustomEventHandler(OnDroppingItem); Exiled.Events.Handlers.Player.Dying += new CustomEventHandler(OnDying); + Exiled.Events.Handlers.Server.RestartingRound += new CustomEventHandler(OnStaticRestartingRound); base.SubscribeEvents(); if (this is ISkill skill) @@ -380,8 +382,9 @@ protected override void UnsubscribeEvents() Exiled.Events.Handlers.Player.Hurting -= new CustomEventHandler(OnHurting); Exiled.Events.Handlers.Server.RestartingRound -= new CustomEventHandler(OnRestartingRound); Exiled.Events.Handlers.Player.DroppingItem -= new CustomEventHandler(OnDroppingItem); - Exiled.Events.Handlers.Player.Spawning += new CustomEventHandler(OnSpawning); + Exiled.Events.Handlers.Player.Spawning -= new CustomEventHandler(OnSpawning); Exiled.Events.Handlers.Player.Dying -= new CustomEventHandler(OnDying); + Exiled.Events.Handlers.Server.RestartingRound -= new CustomEventHandler(OnStaticRestartingRound); base.UnsubscribeEvents(); if (this is ISkill skill) diff --git a/YongAnFrame.csproj b/YongAnFrame.csproj index d4c8b68..7a9d60d 100644 --- a/YongAnFrame.csproj +++ b/YongAnFrame.csproj @@ -41,6 +41,7 @@ packages\EXILEDOFFICIAL.8.11.0\lib\net48\Assembly-CSharp-Publicized.dll False + False packages\EXILEDOFFICIAL.8.11.0\lib\net48\CommandSystem.Core.dll @@ -98,6 +99,7 @@ + diff --git a/YongAnFrameConfig.cs b/YongAnFrameConfig.cs index a5c7f51..086f6a5 100644 --- a/YongAnFrameConfig.cs +++ b/YongAnFrameConfig.cs @@ -6,5 +6,6 @@ public sealed class YongAnFrameConfig : IConfig { public bool IsEnabled { get; set; } = true; public bool Debug { get; set; } + public string BypassDoNotTrackText { get; set; } = "BDNT(Bypass Do Not Track)协议\r\n根据VSR(Verified Server Rules) 8.11,开启DNT(Do Not Track)的玩家不会进行非服务器安全性的游戏数据收集或保存。\r\n根据VSR 8.11.5,只有签署BDNT的玩家才会对DNT相关的规则不适用。\r\n根据VSR 8.11.5.3,欲签署BDNT的玩家有知晓收集或保存数据内容的权利。\r\n|||如果你看不懂BDNT协议的条例请不要签署|||\r\n1.你将会被收集SteamID用来保存等级和称号数据,这个条例收集的数据是公开展示的,任何人都可以访问!\r\n2.签署玩家依然有请求删除收集或保存数据的权利,请求之后你依然有24小时可以撤销请求(注意!删除数据是不可逆的)!"; } }