relics/RelicSlotMachine.cs

A relic that reacts to the Match event: it plays slot machine and coin sounds, spawns a floating money gain text at the point under the screen centre, then grants money scaled by relic level plus the EarnExtraMoney stat. It also pushes and later pops an event message on the manager.

using Sandbox;
using System.Reflection.PortableExecutable;
using System.Runtime.Versioning;
using System.Threading.Tasks;

public class RelicSlotMachine : Relic
{
	public override bool ShouldHandleEvent( EventType eventType )
	{
		return eventType == EventType.Match && Manager.IsAdjacent( Manager.Instance.ChosenCards[0].GridPos, Manager.Instance.ChosenCards[1].GridPos );
	}

	public override async Task HandleEventAsync( EventType eventType )
	{
		Manager.Instance.PushEventMessage( this, eventType );

		await Task.DelayRealtime( 100 );

		Manager.Instance.PlaySfxCenter( "slot_machine", volume: 0.8f, pitch: Game.Random.Float( 0.95f, 1.05f ) );

		await Task.DelayRealtime( 400 );

		Manager.Instance.PlaySfxCenter( "coin", volume: 1.4f, pitch: Game.Random.Float( 0.9f, 1.1f ) );

		await Task.DelayRealtime( 50 );

		int moneyAmount = Level + (int)Manager.Instance.Stats[StatType.EarnExtraMoney];

		var camera = Scene.Camera;
		var ray = camera.ScreenPixelToRay( new Vector3( Screen.Width / 2, Screen.Height / 2, 0f ) );
		var tr = Scene.Trace.Ray( ray, 10000f ).Run();

		Manager.Instance.SpawnGainMoneyFloater( moneyAmount, tr.EndPosition );

		await Manager.Instance.GainMoney( moneyAmount );

		await Task.DelayRealtime( 900 );

		Manager.Instance.PopEventMessage();
	}
}