Stage event that spawns healing zones. When started it plays a UI sound, posts a local chat message, and if running on the host it chooses 2–4 non-overlapping spawn positions with randomized scales and tells the Manager to spawn healing zones, then removes the event.
using System;
using System.Reflection;
using Sandbox;
public class StageEventHealingZones : StageEvent
{
public override void Start( int randSeed )
{
base.Start( randSeed );
Manager.Instance.PlaySfxUIRpc( "healing_zones_event", pitch: Game.Random.Float( 0.975f, 1.025f ), volume: 0.65f );
Manager.Instance.Chat.AddLocalChatMessage( "Healing zones have spawned!", from: "" );
if ( Networking.IsHost )
{
int numHealingZones = Game.Random.Int( 2, 4 );
List<(Vector2, float)> healingZoneSpawns = new();
for ( int i = 0; i < numHealingZones; i++ )
{
var scale = Game.Random.Float( 0.33f, 1.4f );
var currRadius = 96f * scale;
bool overlap = true;
Vector2 pos = Vector2.Zero;
while ( overlap )
{
pos = Manager.Instance.GetRandomSpawnPos( buffer: 150f );
overlap = false;
foreach ( var pair in healingZoneSpawns )
{
var otherRadius = 96f * pair.Item2;
if ( (pair.Item1 - pos).LengthSquared < Math.Pow( otherRadius + currRadius, 2f ) )
{
overlap = true;
break;
}
}
}
healingZoneSpawns.Add( (pos, scale) );
}
foreach ( var pair in healingZoneSpawns )
{
Manager.Instance.SpawnHealingZone( pos: pair.Item1, scale: pair.Item2 );
}
}
Manager.Instance.RemoveEvent( EventType );
}
}