Systems/Player/ScriptPlayer.Choices.cs
using VNScript;

namespace VNBase;

public sealed partial class ScriptPlayer
{
	public void ExecuteChoice( Script.Choice choice )
	{
		if ( ActiveScript is null || ActiveLabel is null )
		{
			Log.Warning( "Unable to execute choice: No active script or label." );
			return;
		}
		
		if ( _activeDialogue is null )
		{
			Log.Error( "Unable to execute choice: No active dialogue." );
			return;
		}
		
		var targetLabel = _activeDialogue.Labels[choice.TargetLabel];
		var environment = ActiveScript.GetEnvironment();
		
		if ( choice.IsAvailable( environment ) )
		{
			SetLabel( targetLabel );
			ActiveScript.OnChoiceSelected?.Invoke( choice );
			OnChoiceSelected?.Invoke( choice );
			State.IsDialogueFinished = false;
		}
		else
		{
			Log.Error( $"Tried executing choice which isn't available: '{targetLabel.Name}'. This shouldn't be possible!" );
		}
	}
}