using System; using System.Collections.Generic; using Sandbox; namespace MurderGame; /// /// Component designed for movement, only 1 per pawn. /// public class BaseControllerComponent : EntityComponent, ISingletonComponent { internal HashSet Events = new(StringComparer.OrdinalIgnoreCase); internal HashSet Tags; public Vector3 WishVelocity { get; set; } public virtual void Simulate( IClient cl ) { } public virtual void FrameSimulate( IClient cl ) { } public virtual void BuildInput() { } /// /// Call OnEvent for each event /// public virtual void RunEvents( BaseControllerComponent additionalController ) { if ( Events == null ) { return; } foreach ( var e in Events ) { OnEvent( e ); additionalController?.OnEvent( e ); } } /// /// An event has been triggered - maybe handle it /// public virtual void OnEvent( string name ) { } /// /// Returns true if we have this event /// public bool HasEvent( string eventName ) { if ( Events == null ) { return false; } return Events.Contains( eventName ); } /// /// public bool HasTag( string tagName ) { if ( Tags == null ) { return false; } return Tags.Contains( tagName ); } /// /// Allows the controller to pass events to other systems /// while staying abstracted. /// For example, it could pass a "jump" event, which could then /// be picked up by the playeranimator to trigger a jump animation, /// and picked up by the player to play a jump sound. /// public void AddEvent( string eventName ) { // TODO - shall we allow passing data with the event? if ( Events == null ) { Events = new HashSet(); } if ( Events.Contains( eventName ) ) { return; } Events.Add( eventName ); } /// /// public void SetTag( string tagName ) { // TODO - shall we allow passing data with the event? Tags ??= new HashSet(); if ( Tags.Contains( tagName ) ) { return; } Tags.Add( tagName ); } }