diff --git a/Configs/Config.cs b/Configs/Config.cs index 10667a3..2435c08 100644 --- a/Configs/Config.cs +++ b/Configs/Config.cs @@ -85,5 +85,20 @@ namespace EasyTools.Configs [Description("Is 1853 harmless? / 是否开启1853(洗手液)无害?")] public bool harmless_1853 { get; set; } = true; + + + /// ///////////////////////////////////////////////// + [Description("SCP静止回血?")] + public bool heal_scp { get; set; } = true; + + + [Description("等待多少秒后持续回血")] + public float heal_scp_secend { get; set; } = 6; + + [Description("受伤检测")] + public float heal_atk_secend { get; set; } = 2; + + [Description("回血量")] + public int heal_scp_x { get; set; } = 2; } } diff --git a/EasyTools.csproj b/EasyTools.csproj index 16be4a6..c2056ee 100644 --- a/EasyTools.csproj +++ b/EasyTools.csproj @@ -130,6 +130,7 @@ + diff --git a/Events/CustomEventHandler.cs b/Events/CustomEventHandler.cs index 26eb35f..ababd9d 100644 --- a/Events/CustomEventHandler.cs +++ b/Events/CustomEventHandler.cs @@ -58,6 +58,11 @@ namespace EasyTools.Events { Timing.RunCoroutine(Util.AutoServerBroadcast()); } + + if (Config.heal_scp) + { + Timing.RunCoroutine(ScpReal.AutoReal()); + } }); } diff --git a/Utils/ScpReal.cs b/Utils/ScpReal.cs new file mode 100644 index 0000000..70ee75c --- /dev/null +++ b/Utils/ScpReal.cs @@ -0,0 +1,78 @@ +using CustomPlayerEffects; +using EasyTools.Events; +using LabApi.Features.Wrappers; +using MEC; +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using UnityEngine; + +namespace EasyTools.Utils +{ + public class ScpReal + { + + private static readonly Dictionary _lastMove = []; + + private static readonly Dictionary _lastHealth = []; + private static readonly Dictionary _lastDamageTime = []; + + public static IEnumerator AutoReal() + { + while (true) + { + if (Round.IsRoundEnded || !Round.IsRoundStarted) + { + yield break; + } + + foreach (Player p in Player.ReadyList) + { + if (p.IsSCP) + { + + // 先检测玩家是否正在受到伤害 + if (_lastHealth.TryGetValue(p, out var lastHealth)) + { + if (p.Health < lastHealth) + { + _lastDamageTime[p] = DateTime.UtcNow; + } + } + + _lastHealth[p] = lastHealth; + + Vector3 pos = p.Position; + if(_lastMove.TryGetValue(p,out var last)) + { + if (Vector3.Distance(pos,last.pos) < 0.1f) + { + + bool canceled = false; + // 检测是否正在受伤 + if (_lastDamageTime.TryGetValue(p,out var lastDamageTime)) + { + if (DateTime.UtcNow - lastDamageTime < TimeSpan.FromSeconds(CustomEventHandler.Config.heal_atk_secend)) { canceled = true; } + } + + if (!canceled && DateTime.UtcNow - last.time > TimeSpan.FromSeconds(CustomEventHandler.Config.heal_scp_secend)) + { + float old_health = p.Health; + float new_health = old_health + CustomEventHandler.Config.heal_scp_x; + if (new_health <= p.MaxHealth) + { + p.Health = new_health; + } + } + } + else { _lastMove[p] = (pos, DateTime.UtcNow); } + }else { _lastMove[p] = (pos, DateTime.UtcNow); } + }else if (_lastMove.ContainsKey(p)) { _lastMove.Remove(p); } + } + yield return Timing.WaitForSeconds(1f); + } + } + } +}