using Content.Server.AI.EntitySystems;
using Content.Server.Station.Systems;
using Content.Shared.Movement.Components;
using Content.Shared.Roles;
using Robust.Shared.Map;
using Robust.Shared.Prototypes;
namespace Content.Server.AI.Components
{
[RegisterComponent]
[ComponentReference(typeof(IMobMoverComponent))]
[Virtual]
public class AiControllerComponent : Component, IMobMoverComponent, IMoverComponent
{
[DataField("logic")] private float _visionRadius = 8.0f;
public bool CanMove { get; set; } = true;
// TODO: Need to ECS a lot more of the AI first before we can ECS this
///
/// Whether the AI is actively iterated.
///
public bool Awake
{
get => _awake;
set
{
if (_awake == value) return;
_awake = value;
if (_awake)
EntitySystem.Get().WakeNPC(this);
else
EntitySystem.Get().SleepNPC(this);
}
}
[DataField("awake")]
private bool _awake = true;
[ViewVariables(VVAccess.ReadWrite)]
[DataField("startingGear")]
public string? StartingGearPrototype { get; set; }
[ViewVariables(VVAccess.ReadWrite)]
public float VisionRadius
{
get => _visionRadius;
set => _visionRadius = value;
}
///
protected override void Initialize()
{
base.Initialize();
// This component requires a physics component.
Owner.EnsureComponent();
}
protected override void Startup()
{
base.Startup();
if (StartingGearPrototype != null)
{
var stationSpawning = EntitySystem.Get();
var protoManager = IoCManager.Resolve();
var startingGear = protoManager.Index(StartingGearPrototype);
stationSpawning.EquipStartingGear(Owner, startingGear, null);
}
}
///
/// Movement speed (m/s) that the entity walks, after modifiers
///
[ViewVariables]
public float CurrentWalkSpeed
{
get
{
if (IoCManager.Resolve().TryGetComponent(Owner, out MovementSpeedModifierComponent? component))
{
return component.CurrentWalkSpeed;
}
return MovementSpeedModifierComponent.DefaultBaseWalkSpeed;
}
}
///
/// Movement speed (m/s) that the entity walks, after modifiers
///
[ViewVariables]
public float CurrentSprintSpeed
{
get
{
if (IoCManager.Resolve().TryGetComponent(Owner, out MovementSpeedModifierComponent? component))
{
return component.CurrentSprintSpeed;
}
return MovementSpeedModifierComponent.DefaultBaseSprintSpeed;
}
}
public Angle LastGridAngle { get => Angle.Zero; set {} }
///
[ViewVariables(VVAccess.ReadWrite)]
public float PushStrength { get; set; } = IMobMoverComponent.PushStrengthDefault;
[ViewVariables(VVAccess.ReadWrite)]
public float WeightlessStrength { get; set; } = IMobMoverComponent.WeightlessStrengthDefault;
///
[ViewVariables(VVAccess.ReadWrite)]
public float GrabRange { get; set; } = IMobMoverComponent.GrabRangeDefault;
///
/// Is the entity Sprinting (running)?
///
[ViewVariables]
public bool Sprinting { get; } = true;
///
/// Calculated linear velocity direction of the entity.
///
[ViewVariables]
public Vector2 VelocityDir { get; set; }
(Vector2 walking, Vector2 sprinting) IMoverComponent.VelocityDir =>
Sprinting ? (Vector2.Zero, VelocityDir) : (VelocityDir, Vector2.Zero);
public EntityCoordinates LastPosition { get; set; }
[ViewVariables(VVAccess.ReadWrite)]
public float StepSoundDistance { get; set; }
public void SetVelocityDirection(Direction direction, ushort subTick, bool enabled) { }
public void SetSprinting(ushort subTick, bool walking) { }
public virtual void Update(float frameTime) {}
}
}