2021-12-05 14:08:35 +11:00
|
|
|
|
using Content.Server.AI.EntitySystems;
|
|
|
|
|
|
using Content.Server.GameTicking;
|
2021-06-09 22:19:39 +02:00
|
|
|
|
using Content.Shared.Movement.Components;
|
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;
|
2021-03-05 01:08:38 +01:00
|
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
2019-08-10 05:19:52 -07:00
|
|
|
|
using Robust.Shared.ViewVariables;
|
2019-04-04 16:18:43 +02:00
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
|
namespace Content.Server.AI.Components
|
2019-04-04 16:18:43 +02:00
|
|
|
|
{
|
2021-03-08 04:09:59 +11:00
|
|
|
|
[RegisterComponent]
|
|
|
|
|
|
[ComponentReference(typeof(IMobMoverComponent))]
|
2022-02-16 00:23:23 -07:00
|
|
|
|
[Virtual]
|
2021-03-08 04:09:59 +11:00
|
|
|
|
public class AiControllerComponent : Component, IMobMoverComponent, IMoverComponent
|
2019-04-04 16:18:43 +02:00
|
|
|
|
{
|
2021-03-05 01:08:38 +01:00
|
|
|
|
[DataField("logic")] private float _visionRadius = 8.0f;
|
2019-04-04 16:18:43 +02:00
|
|
|
|
|
2021-12-05 14:08:35 +11:00
|
|
|
|
// TODO: Need to ECS a lot more of the AI first before we can ECS this
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Whether the AI is actively iterated.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public bool Awake
|
|
|
|
|
|
{
|
|
|
|
|
|
get => _awake;
|
|
|
|
|
|
set
|
|
|
|
|
|
{
|
|
|
|
|
|
if (_awake == value) return;
|
|
|
|
|
|
|
|
|
|
|
|
_awake = value;
|
|
|
|
|
|
|
|
|
|
|
|
if (_awake)
|
|
|
|
|
|
EntitySystem.Get<NPCSystem>().WakeNPC(this);
|
|
|
|
|
|
else
|
|
|
|
|
|
EntitySystem.Get<NPCSystem>().SleepNPC(this);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[DataField("awake")]
|
|
|
|
|
|
private bool _awake = true;
|
|
|
|
|
|
|
2020-08-25 04:11:32 +10:00
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2021-03-05 01:08:38 +01:00
|
|
|
|
[DataField("startingGear")]
|
2020-08-25 04:11:32 +10:00
|
|
|
|
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 />
|
2021-06-19 19:41:26 -07:00
|
|
|
|
protected override void Initialize()
|
2019-08-10 05:19:52 -07:00
|
|
|
|
{
|
|
|
|
|
|
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-06-20 10:09:24 +02:00
|
|
|
|
var gameTicker = EntitySystem.Get<GameTicker>();
|
2021-02-20 17:37:17 +11:00
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
|
|
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
|
|
|
|
|
|
{
|
2021-12-03 15:53:09 +01:00
|
|
|
|
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, 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
|
|
|
|
|
|
{
|
2021-12-03 15:53:09 +01:00
|
|
|
|
if (IoCManager.Resolve<IEntityManager>().TryGetComponent(Owner, 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
|
|
|
|
|
2021-11-02 20:35:02 +07:00
|
|
|
|
public Angle LastGridAngle { get => Angle.Zero; set {} }
|
|
|
|
|
|
|
2020-05-02 15:02:52 +01:00
|
|
|
|
/// <inheritdoc />
|
2021-03-08 04:09:59 +11:00
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2021-03-08 12:48:15 +11:00
|
|
|
|
public float PushStrength { get; set; } = IMobMoverComponent.PushStrengthDefault;
|
|
|
|
|
|
|
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
|
|
|
|
public float WeightlessStrength { get; set; } = IMobMoverComponent.WeightlessStrengthDefault;
|
2020-05-02 15:02:52 +01:00
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
2021-03-08 04:09:59 +11:00
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2021-03-08 12:48:15 +11:00
|
|
|
|
public float GrabRange { get; set; } = IMobMoverComponent.GrabRangeDefault;
|
2020-05-02 15:02:52 +01:00
|
|
|
|
|
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
|
|
|
|
|
2021-03-08 04:09:59 +11: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
|
|
|
|
}
|
|
|
|
|
|
}
|