swb_base/Weapon.Scoping.cs

Partial Weapon class methods for scoping behavior. OnScopeStart waits ScopeInDelay, checks validity and state, sets IsScoping, hides the viewmodel and plays scope-in sound. OnScopeEnd resets lens center, clears IsScoping, shows the viewmodel and plays scope-out sound.

Process Execution
namespace SWB.Base;

public partial class Weapon
{
	public async virtual void OnScopeStart()
	{
		SetScopeLensCenter( DefaultScopeLensCenter );

		await GameTask.DelaySeconds( ScopeInfo.ScopeInDelay );
		if ( !this.IsValid() || !IsAiming || IsScoping || IsReloading ) return;

		IsScoping = true;
		ViewModelHandler.ShouldDraw = false;

		if ( ScopeInfo.ScopeInSound is not null )
			PlaySound( ScopeInfo.ScopeInSound );
	}

	public virtual void OnScopeEnd()
	{
		SetScopeLensCenter( DefaultScopeLensCenter );

		if ( !IsScoping ) return;

		IsScoping = false;
		ViewModelHandler.ShouldDraw = true;

		if ( ScopeInfo.ScopeOutSound is not null )
			PlaySound( ScopeInfo.ScopeOutSound );
	}
}