OverdriveEnemy.Freeze.cs
using Sandbox;
using System;
namespace PaintballBaddies;

public sealed partial class OverdriveEnemy
{
    public const float FreezeDuration=7;
    [Sync(SyncFlags.FromHost)] public float FrozenRemaining {get;private set;}
    [Sync(SyncFlags.FromHost)] public int FreezeSerial {get;private set;}
    [Sync(SyncFlags.FromHost)] public bool IceShattered {get;private set;}
    public bool FrozenSolid=>FrozenRemaining>0 && FreezeDuration-FrozenRemaining>=.45f;
    private int shownFreeze;
    private bool shownShatter;

    internal bool FlashFreeze()
    {
        var s=MultiplayerSession.Find(Scene);
        if(!MultiplayerSession.Authority || Dead || s is not {IsOverdrive:true,InRound:true} || s.RoundId!=Round)return false;
        // Repeated grenades extend the hold without reopening a vulnerable thaw frame.
        FrozenRemaining=FrozenSolid ? FreezeDuration-.46f : FreezeDuration;FreezeSerial++;
        Windup=ThrowRecovery=SlipRemaining=0;RangedWindup=false;Agent?.Stop();if(Agent.IsValid())Agent.UpdatePosition=false;
        return true;
    }
    private bool TickFreeze()
    {
        if(FrozenRemaining<=0)return false;
        Agent?.Stop();FrozenRemaining=MathF.Max(0,FrozenRemaining-Time.Delta);
        if(FrozenRemaining<=0 && Agent.IsValid()){Agent.SetAgentPosition(WorldPosition);Agent.UpdatePosition=true;}
        attackClock=MathF.Max(attackClock,.65f);
        return true;
    }
    private bool ShatterFrozen(Vector3 impulse,PaintballCombatant shooter,bool headshot)
    {
        if(!MultiplayerSession.Authority || Dead)return false;
        var s=MultiplayerSession.Find(Scene);
        if(s is not {IsOverdrive:true,InRound:true} || s.RoundId!=Round)return false;
        LastImpulse=impulse;Health=0;Dead=true;IceShattered=true;CollapseRemaining=0;
        Windup=ThrowRecovery=SlipRemaining=0;RangedWindup=false;
        Components.Get<BoxCollider>().Enabled=false;Agent?.Stop();
        if(shooter.IsValid())shooter.RegisterSausageKill(headshot);
        s.RiotHit(shooter);s.OverdriveKill(shooter,headshot ? 75 : 40,WorldPosition);
        return true;
    }
    private void UpdateCryoPresentation()
    {
        if(shownFreeze!=FreezeSerial)
        {shownFreeze=FreezeSerial;CryoBurst.Spawn(Scene,AimPoint,false,true);}
        if(IceShattered && !shownShatter)
        {shownShatter=true;CryoBurst.Spawn(Scene,AimPoint,true);}
    }
}