2020-08-22 22:29:20 +02:00
|
|
|
|
#nullable enable
|
2020-12-07 14:52:55 +01:00
|
|
|
|
using Content.Server.AI.Utility.AiLogic;
|
2020-08-22 22:29:20 +02:00
|
|
|
|
using Content.Server.GameObjects.EntitySystems.AI;
|
2020-08-25 04:11:32 +10:00
|
|
|
|
using Content.Server.Interfaces.GameTicking;
|
2020-08-18 23:14:55 +10:00
|
|
|
|
using Content.Shared.GameObjects.Components.Movement;
|
2020-08-25 04:11:32 +10:00
|
|
|
|
using Content.Shared.Roles;
|
2019-04-15 21:11:38 -06:00
|
|
|
|
using Robust.Shared.GameObjects;
|
2020-08-25 04:11:32 +10:00
|
|
|
|
using Robust.Shared.IoC;
|
2019-08-10 05:19:52 -07:00
|
|
|
|
using Robust.Shared.Map;
|
|
|
|
|
|
using Robust.Shared.Maths;
|
2020-08-25 04:11:32 +10:00
|
|
|
|
using Robust.Shared.Prototypes;
|
2019-04-15 21:11:38 -06:00
|
|
|
|
using Robust.Shared.Serialization;
|
2019-08-10 05:19:52 -07:00
|
|
|
|
using Robust.Shared.ViewVariables;
|
2019-04-04 16:18:43 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Content.Server.GameObjects.Components.Movement
|
|
|
|
|
|
{
|
2019-08-10 05:19:52 -07:00
|
|
|
|
[RegisterComponent, ComponentReference(typeof(IMoverComponent))]
|
2019-04-04 16:18:43 +02:00
|
|
|
|
public class AiControllerComponent : Component, IMoverComponent
|
|
|
|
|
|
{
|
|
|
|
|
|
private float _visionRadius;
|
|
|
|
|
|
|
|
|
|
|
|
public override string Name => "AiController";
|
|
|
|
|
|
|
2020-08-25 04:11:32 +10:00
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
|
|
|
|
public string? StartingGearPrototype { get; set; }
|
2019-04-04 16:18:43 +02:00
|
|
|
|
|
2019-08-10 05:19:52 -07:00
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2019-04-04 16:18:43 +02:00
|
|
|
|
public float VisionRadius
|
|
|
|
|
|
{
|
|
|
|
|
|
get => _visionRadius;
|
|
|
|
|
|
set => _visionRadius = value;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-10 05:19:52 -07:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public override void Initialize()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Initialize();
|
|
|
|
|
|
|
2020-10-11 16:36:58 +02:00
|
|
|
|
// This component requires a physics component.
|
|
|
|
|
|
Owner.EnsureComponent<PhysicsComponent>();
|
2019-08-10 05:19:52 -07:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-25 04:11:32 +10:00
|
|
|
|
protected override void Startup()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.Startup();
|
2020-09-02 01:30:03 +02:00
|
|
|
|
|
2020-08-25 04:11:32 +10:00
|
|
|
|
if (StartingGearPrototype != null)
|
|
|
|
|
|
{
|
2021-02-20 17:37:17 +11:00
|
|
|
|
var gameTicker = IoCManager.Resolve<IGameTicker>();
|
|
|
|
|
|
var protoManager = IoCManager.Resolve<IPrototypeManager>();
|
2020-09-02 01:30:03 +02:00
|
|
|
|
|
2021-02-20 17:37:17 +11:00
|
|
|
|
var startingGear = protoManager.Index<StartingGearPrototype>(StartingGearPrototype);
|
|
|
|
|
|
gameTicker.EquipStartingGear(Owner, startingGear, null);
|
|
|
|
|
|
}
|
2020-08-25 04:11:32 +10:00
|
|
|
|
}
|
|
|
|
|
|
|
2019-08-10 05:19:52 -07:00
|
|
|
|
/// <inheritdoc />
|
2019-04-04 16:18:43 +02:00
|
|
|
|
public override void ExposeData(ObjectSerializer serializer)
|
|
|
|
|
|
{
|
|
|
|
|
|
base.ExposeData(serializer);
|
|
|
|
|
|
|
2020-08-25 04:11:32 +10:00
|
|
|
|
serializer.DataReadWriteFunction(
|
2020-09-02 01:30:03 +02:00
|
|
|
|
"startingGear",
|
2020-08-25 04:11:32 +10:00
|
|
|
|
null,
|
|
|
|
|
|
startingGear => StartingGearPrototype = startingGear,
|
|
|
|
|
|
() => StartingGearPrototype);
|
2019-04-04 16:18:43 +02:00
|
|
|
|
serializer.DataField(ref _visionRadius, "vision", 8.0f);
|
|
|
|
|
|
}
|
2019-08-10 05:19:52 -07:00
|
|
|
|
|
2020-02-22 23:37:56 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Movement speed (m/s) that the entity walks, after modifiers
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[ViewVariables]
|
|
|
|
|
|
public float CurrentWalkSpeed
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2020-08-22 22:29:20 +02:00
|
|
|
|
if (Owner.TryGetComponent(out MovementSpeedModifierComponent? component))
|
2020-02-22 23:37:56 +00:00
|
|
|
|
{
|
2020-04-18 13:46:35 +02:00
|
|
|
|
return component.CurrentWalkSpeed;
|
2020-02-22 23:37:56 +00:00
|
|
|
|
}
|
2020-04-18 13:46:35 +02:00
|
|
|
|
|
|
|
|
|
|
return MovementSpeedModifierComponent.DefaultBaseWalkSpeed;
|
2020-02-22 23:37:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2020-04-18 13:46:35 +02:00
|
|
|
|
|
2020-02-22 23:37:56 +00:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Movement speed (m/s) that the entity walks, after modifiers
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[ViewVariables]
|
|
|
|
|
|
public float CurrentSprintSpeed
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2020-08-22 22:29:20 +02:00
|
|
|
|
if (Owner.TryGetComponent(out MovementSpeedModifierComponent? component))
|
2020-02-22 23:37:56 +00:00
|
|
|
|
{
|
2020-04-18 13:46:35 +02:00
|
|
|
|
return component.CurrentSprintSpeed;
|
2020-02-22 23:37:56 +00:00
|
|
|
|
}
|
2020-04-18 13:46:35 +02:00
|
|
|
|
|
|
|
|
|
|
return MovementSpeedModifierComponent.DefaultBaseSprintSpeed;
|
2020-02-22 23:37:56 +00:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2019-08-10 05:19:52 -07:00
|
|
|
|
|
2020-05-02 15:02:52 +01:00
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
[ViewVariables]
|
|
|
|
|
|
public float CurrentPushSpeed => 5.0f;
|
|
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
[ViewVariables]
|
|
|
|
|
|
public float GrabRange => 0.2f;
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-08-10 05:19:52 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Is the entity Sprinting (running)?
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[ViewVariables]
|
2020-06-24 02:21:20 +02:00
|
|
|
|
public bool Sprinting { get; } = true;
|
2019-08-10 05:19:52 -07:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Calculated linear velocity direction of the entity.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[ViewVariables]
|
|
|
|
|
|
public Vector2 VelocityDir { get; set; }
|
|
|
|
|
|
|
2020-06-24 02:21:20 +02:00
|
|
|
|
(Vector2 walking, Vector2 sprinting) IMoverComponent.VelocityDir =>
|
|
|
|
|
|
Sprinting ? (Vector2.Zero, VelocityDir) : (VelocityDir, Vector2.Zero);
|
|
|
|
|
|
|
2020-09-06 16:11:53 +02:00
|
|
|
|
public EntityCoordinates LastPosition { get; set; }
|
2019-08-10 05:19:52 -07:00
|
|
|
|
|
2020-06-24 02:21:20 +02:00
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)] public float StepSoundDistance { get; set; }
|
2020-01-08 15:17:00 -08:00
|
|
|
|
|
2020-06-24 02:21:20 +02:00
|
|
|
|
public void SetVelocityDirection(Direction direction, ushort subTick, bool enabled) { }
|
2020-06-24 04:04:43 +02:00
|
|
|
|
public void SetSprinting(ushort subTick, bool walking) { }
|
2021-02-20 17:37:17 +11:00
|
|
|
|
|
|
|
|
|
|
public virtual void Update(float frameTime) {}
|
2019-04-04 16:18:43 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|