feat: SCP站立回血机制

This commit is contained in:
3cxc
2026-02-12 15:45:00 +08:00
parent 71743ba0f8
commit c99ac3b1b5
4 changed files with 99 additions and 0 deletions

78
Utils/ScpReal.cs Normal file
View File

@@ -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<Player, (Vector3 pos, DateTime time)> _lastMove = [];
private static readonly Dictionary<Player, float> _lastHealth = [];
private static readonly Dictionary<Player, DateTime> _lastDamageTime = [];
public static IEnumerator<float> 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);
}
}
}
}