Files
tbd-station-14/Content.Server/GameObjects/Components/Movement/AiControllerComponent.cs
DrSmugleaf b9196d0a10 Add a test that puts all components on an entity and checks for no exceptions (#1815)
* Add test that puts all components on an entity and checks for no exceptions

Also fix all the exceptions that happened because of this

* Add comments to the test

* Fix nullable errors

* Fix more nullable errors

* More nullable error fixes

* Unignore basic actor component

* Fix more nullable errors

* NULLABLE ERROR

* Add string interpolation

* Merge if checks

* Remove redundant pragma warning disable 649

* Address reviews

* Remove null wrappers around TryGetComponent

* Merge conflict fixes

* APC battery component error fix

* Fix power test

* Fix atmos mapgrid usages
2020-08-22 22:29:20 +02:00

135 lines
3.9 KiB
C#

#nullable enable
using Content.Server.GameObjects.EntitySystems.AI;
using Content.Shared.GameObjects.Components.Movement;
using Robust.Server.AI;
using Robust.Shared.GameObjects;
using Robust.Shared.GameObjects.Components;
using Robust.Shared.GameObjects.Systems;
using Robust.Shared.Map;
using Robust.Shared.Maths;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Movement
{
[RegisterComponent, ComponentReference(typeof(IMoverComponent))]
public class AiControllerComponent : Component, IMoverComponent
{
private string? _logicName;
private float _visionRadius;
public override string Name => "AiController";
[ViewVariables(VVAccess.ReadWrite)]
public string? LogicName
{
get => _logicName;
set
{
_logicName = value;
Processor = null!;
}
}
public AiLogicProcessor? Processor { get; set; }
[ViewVariables(VVAccess.ReadWrite)]
public float VisionRadius
{
get => _visionRadius;
set => _visionRadius = value;
}
/// <inheritdoc />
public override void Initialize()
{
base.Initialize();
// This component requires a collidable component.
Owner.EnsureComponent<CollidableComponent>();
EntitySystem.Get<AiSystem>().ProcessorInitialize(this);
}
/// <inheritdoc />
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref _logicName, "logic", null);
serializer.DataField(ref _visionRadius, "vision", 8.0f);
}
protected override void Shutdown()
{
base.Shutdown();
Processor?.Shutdown();
}
/// <summary>
/// Movement speed (m/s) that the entity walks, after modifiers
/// </summary>
[ViewVariables]
public float CurrentWalkSpeed
{
get
{
if (Owner.TryGetComponent(out MovementSpeedModifierComponent? component))
{
return component.CurrentWalkSpeed;
}
return MovementSpeedModifierComponent.DefaultBaseWalkSpeed;
}
}
/// <summary>
/// Movement speed (m/s) that the entity walks, after modifiers
/// </summary>
[ViewVariables]
public float CurrentSprintSpeed
{
get
{
if (Owner.TryGetComponent(out MovementSpeedModifierComponent? component))
{
return component.CurrentSprintSpeed;
}
return MovementSpeedModifierComponent.DefaultBaseSprintSpeed;
}
}
/// <inheritdoc />
[ViewVariables]
public float CurrentPushSpeed => 5.0f;
/// <inheritdoc />
[ViewVariables]
public float GrabRange => 0.2f;
/// <summary>
/// Is the entity Sprinting (running)?
/// </summary>
[ViewVariables]
public bool Sprinting { get; } = true;
/// <summary>
/// Calculated linear velocity direction of the entity.
/// </summary>
[ViewVariables]
public Vector2 VelocityDir { get; set; }
(Vector2 walking, Vector2 sprinting) IMoverComponent.VelocityDir =>
Sprinting ? (Vector2.Zero, VelocityDir) : (VelocityDir, Vector2.Zero);
public GridCoordinates 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) { }
}
}