using Content.Shared.Pointing.Components;
using Robust.Server.GameObjects;
using DrawDepth = Content.Shared.DrawDepth.DrawDepth;
namespace Content.Server.Pointing.Components
{
[RegisterComponent]
[ComponentReference(typeof(SharedPointingArrowComponent))]
public sealed class PointingArrowComponent : SharedPointingArrowComponent
{
[Dependency] private readonly IEntityManager _entMan = default!;
///
/// The current amount of seconds left on this arrow.
///
[ViewVariables(VVAccess.ReadWrite)]
[DataField("duration")]
private float _duration = 4;
///
/// The amount of seconds before the arrow changes movement direction.
///
[ViewVariables(VVAccess.ReadWrite)]
[DataField("step")]
private float _step = 0.5f;
///
/// The amount of units that this arrow will move by when multiplied
/// by the frame time.
///
[ViewVariables(VVAccess.ReadWrite)]
[DataField("speed")]
private float _speed = 1;
///
/// The current amount of seconds left before the arrow changes
/// movement direction.
///
[ViewVariables(VVAccess.ReadWrite)]
private float _currentStep;
///
/// Whether or not this arrow is currently going up.
///
[ViewVariables(VVAccess.ReadWrite)]
private bool _up;
///
/// Whether or not this arrow will convert into a
/// when its duration runs out.
///
[ViewVariables(VVAccess.ReadWrite)]
[DataField("rogue")]
public bool Rogue = false;
public void Update(float frameTime)
{
var movement = _speed * frameTime * (_up ? 1 : -1);
_entMan.GetComponent(Owner).LocalPosition += (0, movement);
_duration -= frameTime;
_currentStep -= frameTime;
if (_duration <= 0)
{
if (Rogue)
{
_entMan.RemoveComponent(Owner);
_entMan.AddComponent(Owner);
return;
}
_entMan.DeleteEntity(Owner);
return;
}
if (_currentStep <= 0)
{
_currentStep = _step;
_up ^= true;
}
}
}
}