RiotRoofHatch.cs
using Sandbox;
using System;
namespace PaintballBaddies;
// Slide the existing glass clear of its opening during co-op; restore it for Paint Rush.
// This is local presentation on each peer. Neither authored scene nor workshop map is modified.
public sealed class RiotRoofHatch : Component
{
private readonly List<(ModelRenderer pane,Vector3 position)> panes=new();
private bool ready;
private float openness;
public float Openness=>openness;
protected override void OnUpdate()
{
if(!ready)
{
foreach(var r in Scene.GetAllComponents<ModelRenderer>().Where(r=>r.GameObject.Name is "Foundry skylight glazing" or "Service annex skylight"))
panes.Add((r,r.LocalPosition));
ready=true;
}
var session=MultiplayerSession.Find(Scene);
float goal=session?.IsPopRiot==true && session.InRound ? 1 : 0;
openness=MathX.Lerp(openness,goal,1-MathF.Exp(-2.5f*Time.Delta));
foreach(var (pane,position) in panes)
if(pane.IsValid())pane.LocalPosition=position+new Vector3(0,230*openness,3*openness);
}
protected override void OnDestroy()
{
foreach(var (pane,position) in panes)if(pane.IsValid())pane.LocalPosition=position;
}
}