Player/Mechanics/TakeoverAnimationMechanic.cs
namespace Opium;
public partial class TakeoverAnimationMechanic : PlayerMechanic
{
[Property] public float Time { get; set; } = 2f;
public bool HasActivated { get; set; }
[Property] public GameObject WeaponPrefab { get; set; }
[Property] public BaseWeapon WeaponInstance { get; set; }
[Property] public CameraEffect OnStartCameraEffect { get; set; }
[Property] public SoundEvent SoundOnEnd { get; set; }
public override IEnumerable<string> GetTags()
{
yield return "takeover";
}
TimeSince TimeSinceActive = 1f;
public override bool ShouldBecomeActive()
{
return TimeSinceActive < Time;
}
protected override void OnStart()
{
IsActive = true;
HasActivated = true;
}
public override bool LockMouseMovement => true;
public override bool LockMovement => true;
protected override void OnActiveChanged( bool before, bool after )
{
base.OnActiveChanged( before, after );
if ( !after )
{
if ( WeaponInstance is not null )
{
Player.Inventory.SetCurrent( null, false );
WeaponInstance?.GameObject?.Destroy();
Log.Info( "Weapon instance destroyed.. Welcome." );
}
HasActivated = false;
Player.ExtraCamOffset = 0;
Player.Components.Get<PlayerObjectivesUI>( FindMode.EnabledInSelfAndDescendants )?.ShowObjectiveUI();
if ( SoundOnEnd is not null )
{
Sound.Play( SoundOnEnd );
}
}
else
{
Log.Info( "takeover started" );
TimeSinceActive = 0;
if ( WeaponPrefab is not null )
{
WeaponInstance = Player.Inventory.CreateWeaponFromPrefab( WeaponPrefab );
Player.Inventory.SetCurrent( WeaponInstance, false );
WeaponInstance.ViewModel.Components.Get<ViewModel>()?.ModelRenderer.Set( "b_falling", true );
}
if ( OnStartCameraEffect is not null )
{
OnStartCameraEffect.Player = Player;
OnStartCameraEffect.Enabled = true;
}
}
}
public override void BuildWishInput( ref Vector3 wish )
{
wish *= 0f;
}
}