WiP movement prediction.
This commit is contained in:
@@ -8,6 +8,7 @@ using Content.Server.Interfaces.GameObjects;
|
||||
using Content.Server.Utility;
|
||||
using Content.Shared.Chemistry;
|
||||
using Content.Shared.GameObjects.Components.Chemistry;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Robust.Server.GameObjects.Components.Container;
|
||||
using Robust.Server.GameObjects.Components.UserInterface;
|
||||
using Robust.Server.Interfaces.GameObjects;
|
||||
|
||||
@@ -5,6 +5,7 @@ using System.Threading.Tasks.Dataflow;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.Interfaces;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Robust.Server.GameObjects.Components.Container;
|
||||
using Robust.Server.Interfaces.Player;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
@@ -3,11 +3,9 @@ using System.Linq;
|
||||
using Content.Server.GameObjects.Components.Mobs;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.Interfaces;
|
||||
using Content.Server.Interfaces.GameObjects;
|
||||
using Content.Server.Mobs;
|
||||
using Content.Server.Utility;
|
||||
using Content.Shared.GameObjects.Components.Instruments;
|
||||
using NFluidsynth;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.Components.UserInterface;
|
||||
using Robust.Server.Interfaces.GameObjects;
|
||||
@@ -15,16 +13,12 @@ using Robust.Server.Interfaces.Player;
|
||||
using Robust.Server.Player;
|
||||
using Robust.Shared.Enums;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Log;
|
||||
using Robust.Shared.Interfaces.Network;
|
||||
using Robust.Shared.Interfaces.Timing;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using Logger = Robust.Shared.Log.Logger;
|
||||
using MidiEvent = Robust.Shared.Audio.Midi.MidiEvent;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Instruments
|
||||
{
|
||||
|
||||
@@ -12,6 +12,7 @@ using Content.Shared.Chemistry;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.GameObjects.Components;
|
||||
using Content.Shared.GameObjects.Components.Interactable;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.Maps;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
|
||||
@@ -7,6 +7,7 @@ using Content.Server.Throw;
|
||||
using Content.Server.Utility;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.GameObjects.Components.Items;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.Physics;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Interfaces.GameObjects;
|
||||
|
||||
@@ -3,6 +3,7 @@ using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.Mobs;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.GameObjects.Components.Mobs;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
|
||||
@@ -3,16 +3,18 @@ using System.Collections.Generic;
|
||||
using Content.Server.GameObjects.Components.Mobs;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.Interfaces;
|
||||
using Content.Server.Interfaces.GameObjects.Components.Movement;
|
||||
using Content.Server.Observer;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.GameObjects.Components.Mobs;
|
||||
using Content.Shared.GameObjects.Components.Movement;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.Interfaces.Player;
|
||||
using Robust.Shared.ContentPack;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Network;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Server.GameObjects
|
||||
@@ -218,11 +220,11 @@ namespace Content.Server.GameObjects
|
||||
Owner.GetComponent<DamageableComponent>().TakeDamage(DamageType.Heat, burnDamage, null);
|
||||
}
|
||||
|
||||
void IRelayMoveInput.MoveInputPressed(IPlayerSession session)
|
||||
void IRelayMoveInput.MoveInputPressed(ICommonSession session)
|
||||
{
|
||||
if (CurrentDamageState is DeadState)
|
||||
{
|
||||
new Ghost().Execute(null, session, null);
|
||||
new Ghost().Execute(null, (IPlayerSession) session, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,50 +1,40 @@
|
||||
using System;
|
||||
using System.Threading;
|
||||
using Content.Server.GameObjects.Components.Movement;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.Interfaces.GameObjects;
|
||||
using Content.Server.Mobs;
|
||||
using Content.Shared.Audio;
|
||||
using Content.Shared.GameObjects.Components.Mobs;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.EntitySystems;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Systems;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Timers;
|
||||
using Robust.Shared.Interfaces.Timing;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using Timer = Robust.Shared.Timers.Timer;
|
||||
using CannyFastMath;
|
||||
using Content.Shared.GameObjects.Components.Movement;
|
||||
using Math = CannyFastMath.Math;
|
||||
using MathF = CannyFastMath.MathF;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Mobs
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class StunnableComponent : Component, IActionBlocker, IInteractHand, IMoveSpeedModifier
|
||||
[ComponentReference(typeof(SharedStunnableComponent))]
|
||||
public class StunnableComponent : SharedStunnableComponent, IInteractHand
|
||||
{
|
||||
public override string Name => "Stunnable";
|
||||
|
||||
#pragma warning disable 649
|
||||
[Dependency] private IGameTiming _gameTiming;
|
||||
#pragma warning restore 649
|
||||
|
||||
private TimeSpan? _lastStun;
|
||||
|
||||
[ViewVariables]
|
||||
public TimeSpan? StunStart => _lastStun;
|
||||
[ViewVariables] public TimeSpan? StunStart => _lastStun;
|
||||
|
||||
[ViewVariables]
|
||||
public TimeSpan? StunEnd => _lastStun == null
|
||||
? (TimeSpan?) null
|
||||
: _gameTiming.CurTime + (TimeSpan.FromSeconds(Math.Max(_stunnedTimer, Math.Max(_knockdownTimer, _slowdownTimer))));
|
||||
: _gameTiming.CurTime +
|
||||
(TimeSpan.FromSeconds(Math.Max(_stunnedTimer, Math.Max(_knockdownTimer, _slowdownTimer))));
|
||||
|
||||
private const int StunLevels = 8;
|
||||
|
||||
@@ -59,14 +49,12 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
private float _knockdownTimer = 0f;
|
||||
private float _slowdownTimer = 0f;
|
||||
|
||||
private float _walkModifierOverride = 0f;
|
||||
private float _runModifierOverride = 0f;
|
||||
private string _stunTexture;
|
||||
private CancellationTokenSource _statusRemoveCancellation = new CancellationTokenSource();
|
||||
|
||||
[ViewVariables] public bool Stunned => _stunnedTimer > 0f;
|
||||
[ViewVariables] public bool KnockedDown => _knockdownTimer > 0f;
|
||||
[ViewVariables] public bool SlowedDown => _slowdownTimer > 0f;
|
||||
[ViewVariables] public override bool Stunned => _stunnedTimer > 0f;
|
||||
[ViewVariables] public override bool KnockedDown => _knockdownTimer > 0f;
|
||||
[ViewVariables] public override bool SlowedDown => _slowdownTimer > 0f;
|
||||
[ViewVariables] public float StunCap => _stunCap;
|
||||
[ViewVariables] public float KnockdownCap => _knockdownCap;
|
||||
[ViewVariables] public float SlowdownCap => _slowdownCap;
|
||||
@@ -79,7 +67,8 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
serializer.DataField(ref _slowdownCap, "slowdownCap", 20f);
|
||||
serializer.DataField(ref _helpInterval, "helpInterval", 1f);
|
||||
serializer.DataField(ref _helpKnockdownRemove, "helpKnockdownRemove", 1f);
|
||||
serializer.DataField(ref _stunTexture, "stunTexture", "/Textures/Objects/Melee/stunbaton.rsi/stunbaton_off.png");
|
||||
serializer.DataField(ref _stunTexture, "stunTexture",
|
||||
"/Textures/Objects/Melee/stunbaton.rsi/stunbaton_off.png");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -99,6 +88,7 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
_lastStun = _gameTiming.CurTime;
|
||||
|
||||
SetStatusEffect();
|
||||
Dirty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -118,6 +108,7 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
_lastStun = _gameTiming.CurTime;
|
||||
|
||||
SetStatusEffect();
|
||||
Dirty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -143,16 +134,17 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
if (seconds <= 0f)
|
||||
return;
|
||||
|
||||
_walkModifierOverride = walkModifierOverride;
|
||||
_runModifierOverride = runModifierOverride;
|
||||
WalkModifierOverride = walkModifierOverride;
|
||||
RunModifierOverride = runModifierOverride;
|
||||
|
||||
_slowdownTimer = seconds;
|
||||
_lastStun = _gameTiming.CurTime;
|
||||
|
||||
if(Owner.TryGetComponent(out MovementSpeedModifierComponent movement))
|
||||
if (Owner.TryGetComponent(out MovementSpeedModifierComponent movement))
|
||||
movement.RefreshMovementSpeedModifiers();
|
||||
|
||||
SetStatusEffect();
|
||||
Dirty();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -162,6 +154,7 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
{
|
||||
_knockdownTimer = 0f;
|
||||
_stunnedTimer = 0f;
|
||||
Dirty();
|
||||
}
|
||||
|
||||
public bool InteractHand(InteractHandEventArgs eventArgs)
|
||||
@@ -170,7 +163,7 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
return false;
|
||||
|
||||
_canHelp = false;
|
||||
Timer.Spawn(((int)_helpInterval*1000), () => _canHelp = true);
|
||||
Timer.Spawn(((int) _helpInterval * 1000), () => _canHelp = true);
|
||||
|
||||
EntitySystem.Get<AudioSystem>()
|
||||
.PlayFromEntity("/Audio/effects/thudswoosh.ogg", Owner, AudioHelpers.WithVariation(0.25f));
|
||||
@@ -179,6 +172,7 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
|
||||
SetStatusEffect();
|
||||
|
||||
Dirty();
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -187,7 +181,8 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
if (!Owner.TryGetComponent(out ServerStatusEffectsComponent status))
|
||||
return;
|
||||
|
||||
status.ChangeStatusEffect(StatusEffect.Stun, _stunTexture, (StunStart == null || StunEnd == null) ? default : (StunStart.Value, StunEnd.Value));
|
||||
status.ChangeStatusEffect(StatusEffect.Stun, _stunTexture,
|
||||
(StunStart == null || StunEnd == null) ? default : (StunStart.Value, StunEnd.Value));
|
||||
_statusRemoveCancellation.Cancel();
|
||||
_statusRemoveCancellation = new CancellationTokenSource();
|
||||
}
|
||||
@@ -201,6 +196,7 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
if (_stunnedTimer <= 0)
|
||||
{
|
||||
_stunnedTimer = 0f;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -213,6 +209,7 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
StandingStateHelper.Standing(Owner);
|
||||
|
||||
_knockdownTimer = 0f;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,12 +221,14 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
{
|
||||
_slowdownTimer = 0f;
|
||||
|
||||
if(Owner.TryGetComponent(out MovementSpeedModifierComponent movement))
|
||||
if (Owner.TryGetComponent(out MovementSpeedModifierComponent movement))
|
||||
movement.RefreshMovementSpeedModifiers();
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
if (!StunStart.HasValue || !StunEnd.HasValue || !Owner.TryGetComponent(out ServerStatusEffectsComponent status))
|
||||
if (!StunStart.HasValue || !StunEnd.HasValue ||
|
||||
!Owner.TryGetComponent(out ServerStatusEffectsComponent status))
|
||||
return;
|
||||
|
||||
var start = StunStart.Value;
|
||||
@@ -245,31 +244,6 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
}
|
||||
}
|
||||
|
||||
#region ActionBlockers
|
||||
public bool CanMove() => (!Stunned);
|
||||
|
||||
public bool CanInteract() => (!Stunned);
|
||||
|
||||
public bool CanUse() => (!Stunned);
|
||||
|
||||
public bool CanThrow() => (!Stunned);
|
||||
|
||||
public bool CanSpeak() => true;
|
||||
|
||||
public bool CanDrop() => (!Stunned);
|
||||
|
||||
public bool CanPickup() => (!Stunned);
|
||||
|
||||
public bool CanEmote() => true;
|
||||
|
||||
public bool CanAttack() => (!Stunned);
|
||||
|
||||
public bool CanEquip() => (!Stunned);
|
||||
|
||||
public bool CanUnequip() => (!Stunned);
|
||||
public bool CanChangeDirection() => true;
|
||||
#endregion
|
||||
|
||||
public float StunTimeModifier
|
||||
{
|
||||
get
|
||||
@@ -318,8 +292,11 @@ namespace Content.Server.GameObjects.Components.Mobs
|
||||
}
|
||||
}
|
||||
|
||||
public float WalkSpeedModifier => (SlowedDown ? (_walkModifierOverride <= 0f ? 0.5f : _walkModifierOverride) : 1f);
|
||||
public float SprintSpeedModifier => (SlowedDown ? (_runModifierOverride <= 0f ? 0.5f : _runModifierOverride) : 1f);
|
||||
public override ComponentState GetComponentState()
|
||||
{
|
||||
return new StunnableComponentState(Stunned, KnockedDown, SlowedDown, WalkModifierOverride,
|
||||
RunModifierOverride);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using Content.Server.AI.Utility;
|
||||
using Content.Server.AI.Utility.AiLogic;
|
||||
using Content.Server.Interfaces.GameObjects.Components.Movement;
|
||||
using Content.Shared.GameObjects.Components.Movement;
|
||||
using Robust.Server.AI;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -111,7 +109,7 @@ namespace Content.Server.GameObjects.Components.Movement
|
||||
/// Is the entity Sprinting (running)?
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public bool Sprinting { get; set; } = true;
|
||||
public bool Sprinting { get; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Calculated linear velocity direction of the entity.
|
||||
@@ -119,11 +117,14 @@ namespace Content.Server.GameObjects.Components.Movement
|
||||
[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; }
|
||||
[ViewVariables(VVAccess.ReadWrite)] public float StepSoundDistance { get; set; }
|
||||
|
||||
public void SetVelocityDirection(Direction direction, bool enabled) { }
|
||||
public void SetVelocityDirection(Direction direction, ushort subTick, bool enabled) { }
|
||||
public void SetSprinting(ushort subTick, bool enabled) { }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,93 +0,0 @@
|
||||
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Movement
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class MovementSpeedModifierComponent : Component
|
||||
{
|
||||
public const float DefaultBaseWalkSpeed = 4.0f;
|
||||
public const float DefaultBaseSprintSpeed = 7.0f;
|
||||
|
||||
public override string Name => "MovementSpeedModifier";
|
||||
|
||||
private float _cachedWalkSpeedModifier = 1.0f;
|
||||
[ViewVariables]
|
||||
public float WalkSpeedModifier
|
||||
{
|
||||
get
|
||||
{
|
||||
RecalculateMovementSpeedModifiers();
|
||||
return _cachedWalkSpeedModifier;
|
||||
}
|
||||
}
|
||||
private float _cachedSprintSpeedModifier;
|
||||
[ViewVariables]
|
||||
public float SprintSpeedModifier
|
||||
{
|
||||
get
|
||||
{
|
||||
RecalculateMovementSpeedModifiers();
|
||||
return _cachedSprintSpeedModifier;
|
||||
}
|
||||
}
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float BaseWalkSpeed { get; set; }
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public float BaseSprintSpeed { get; set; }
|
||||
|
||||
[ViewVariables]
|
||||
public float CurrentWalkSpeed => WalkSpeedModifier * BaseWalkSpeed;
|
||||
[ViewVariables]
|
||||
public float CurrentSprintSpeed => SprintSpeedModifier * BaseSprintSpeed;
|
||||
|
||||
/// <summary>
|
||||
/// set to warn us that a component's movespeed modifier has changed
|
||||
/// </summary>
|
||||
private bool _movespeedModifiersNeedRefresh = true;
|
||||
|
||||
public void RefreshMovementSpeedModifiers()
|
||||
{
|
||||
_movespeedModifiersNeedRefresh = true;
|
||||
}
|
||||
|
||||
public override void ExposeData(ObjectSerializer serializer)
|
||||
{
|
||||
base.ExposeData(serializer);
|
||||
|
||||
serializer.DataField(this, p => p.BaseWalkSpeed, "baseWalkSpeed", 4);
|
||||
serializer.DataField(this, p => p.BaseSprintSpeed, "baseSprintSpeed", 7);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Recalculate movement speed with current modifiers, or return early if no change
|
||||
/// </summary>
|
||||
private void RecalculateMovementSpeedModifiers()
|
||||
{
|
||||
{
|
||||
if (!_movespeedModifiersNeedRefresh)
|
||||
return;
|
||||
var movespeedModifiers = Owner.GetAllComponents<IMoveSpeedModifier>();
|
||||
float walkSpeedModifier = 1.0f;
|
||||
float sprintSpeedModifier = 1.0f;
|
||||
foreach (var component in movespeedModifiers)
|
||||
{
|
||||
walkSpeedModifier *= component.WalkSpeedModifier;
|
||||
sprintSpeedModifier *= component.SprintSpeedModifier;
|
||||
}
|
||||
_cachedWalkSpeedModifier = walkSpeedModifier;
|
||||
_cachedSprintSpeedModifier = sprintSpeedModifier;
|
||||
}
|
||||
_movespeedModifiersNeedRefresh = false;
|
||||
}
|
||||
}
|
||||
|
||||
interface IMoveSpeedModifier
|
||||
{
|
||||
float WalkSpeedModifier { get; }
|
||||
float SprintSpeedModifier { get; }
|
||||
}
|
||||
}
|
||||
@@ -1,17 +1,11 @@
|
||||
|
||||
using Content.Server.Interfaces.GameObjects.Components.Movement;
|
||||
using Robust.Server.GameObjects;
|
||||
using Content.Shared.GameObjects.Components.Movement;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameObjects.Components;
|
||||
using Robust.Shared.Log;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Interfaces.Configuration;
|
||||
using Robust.Shared.Configuration;
|
||||
|
||||
#nullable enable
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Movement
|
||||
{
|
||||
@@ -20,138 +14,11 @@ namespace Content.Server.GameObjects.Components.Movement
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IMoverComponent))]
|
||||
public class PlayerInputMoverComponent : Component, IMoverComponent, ICollideSpecial
|
||||
public class PlayerInputMoverComponent : SharedPlayerInputMoverComponent, IMoverComponent, ICollideSpecial
|
||||
{
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IConfigurationManager _configurationManager;
|
||||
#pragma warning restore 649
|
||||
public override GridCoordinates LastPosition { get; set; }
|
||||
|
||||
private bool _movingUp;
|
||||
private bool _movingDown;
|
||||
private bool _movingLeft;
|
||||
private bool _movingRight;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Name => "PlayerInputMover";
|
||||
|
||||
/// <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; set; } = true;
|
||||
|
||||
/// <summary>
|
||||
/// Calculated linear velocity direction of the entity.
|
||||
/// </summary>
|
||||
[ViewVariables]
|
||||
public Vector2 VelocityDir { get; private set; }
|
||||
|
||||
public GridCoordinates LastPosition { get; set; }
|
||||
|
||||
public float StepSoundDistance { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether or not the player can move diagonally.
|
||||
/// </summary>
|
||||
[ViewVariables] public bool DiagonalMovementEnabled => _configurationManager.GetCVar<bool>("game.diagonalmovement");
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnAdd()
|
||||
{
|
||||
// This component requires that the entity has a PhysicsComponent.
|
||||
if (!Owner.HasComponent<PhysicsComponent>())
|
||||
Logger.Error($"[ECS] {Owner.Prototype.Name} - {nameof(PlayerInputMoverComponent)} requires {nameof(PhysicsComponent)}. ");
|
||||
|
||||
base.OnAdd();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Toggles one of the four cardinal directions. Each of the four directions are
|
||||
/// composed into a single direction vector, <see cref="VelocityDir"/>. Enabling
|
||||
/// opposite directions will cancel each other out, resulting in no direction.
|
||||
/// </summary>
|
||||
/// <param name="direction">Direction to toggle.</param>
|
||||
/// <param name="enabled">If the direction is active.</param>
|
||||
public void SetVelocityDirection(Direction direction, bool enabled)
|
||||
{
|
||||
switch (direction)
|
||||
{
|
||||
case Direction.East:
|
||||
_movingRight = enabled;
|
||||
break;
|
||||
case Direction.North:
|
||||
_movingUp = enabled;
|
||||
break;
|
||||
case Direction.West:
|
||||
_movingLeft = enabled;
|
||||
break;
|
||||
case Direction.South:
|
||||
_movingDown = enabled;
|
||||
break;
|
||||
}
|
||||
|
||||
// key directions are in screen coordinates
|
||||
// _moveDir is in world coordinates
|
||||
// if the camera is moved, this needs to be changed
|
||||
|
||||
var x = 0;
|
||||
x -= _movingLeft ? 1 : 0;
|
||||
x += _movingRight ? 1 : 0;
|
||||
|
||||
var y = 0;
|
||||
if (DiagonalMovementEnabled || x == 0)
|
||||
{
|
||||
y -= _movingDown ? 1 : 0;
|
||||
y += _movingUp ? 1 : 0;
|
||||
}
|
||||
|
||||
VelocityDir = new Vector2(x, y);
|
||||
|
||||
// can't normalize zero length vector
|
||||
if (VelocityDir.LengthSquared > 1.0e-6)
|
||||
VelocityDir = VelocityDir.Normalized;
|
||||
}
|
||||
public override float StepSoundDistance { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Special collision override, can be used to give custom behaviors deciding when to collide
|
||||
@@ -167,6 +34,5 @@ namespace Content.Server.GameObjects.Components.Movement
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using Content.Server.GameObjects.Components.Mobs;
|
||||
using Content.Server.Interfaces.GameObjects.Components.Movement;
|
||||
using Content.Shared.GameObjects.Components.Movement;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.Components.Container;
|
||||
using Robust.Shared.GameObjects;
|
||||
@@ -44,11 +44,11 @@ namespace Content.Server.GameObjects.Components.Movement
|
||||
public float GrabRange => 0.0f;
|
||||
|
||||
public bool Sprinting { get; set; }
|
||||
public Vector2 VelocityDir { get; } = Vector2.Zero;
|
||||
public (Vector2 walking, Vector2 sprinting) VelocityDir { get; } = (Vector2.Zero, Vector2.Zero);
|
||||
public GridCoordinates LastPosition { get; set; }
|
||||
public float StepSoundDistance { get; set; }
|
||||
|
||||
public void SetVelocityDirection(Direction direction, bool enabled)
|
||||
public void SetVelocityDirection(Direction direction, ushort subTick, bool enabled)
|
||||
{
|
||||
var gridId = Owner.Transform.GridID;
|
||||
|
||||
@@ -74,6 +74,11 @@ namespace Content.Server.GameObjects.Components.Movement
|
||||
}
|
||||
}
|
||||
|
||||
public void SetSprinting(ushort subTick, bool enabled)
|
||||
{
|
||||
// Shuttles can't sprint.
|
||||
}
|
||||
|
||||
private Vector2 CalcNewVelocity(Direction direction, bool enabled)
|
||||
{
|
||||
switch (direction)
|
||||
|
||||
@@ -4,6 +4,8 @@ using Content.Server.GameObjects.Components.Mobs;
|
||||
using Content.Server.GameObjects.Components.Movement;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.GameObjects.Components.Mobs;
|
||||
using Content.Shared.GameObjects.Components.Movement;
|
||||
using Content.Shared.GameObjects.Components.Nutrition;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.Random;
|
||||
@@ -15,14 +17,12 @@ using Robust.Shared.ViewVariables;
|
||||
namespace Content.Server.GameObjects.Components.Nutrition
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed class HungerComponent : Component, IMoveSpeedModifier
|
||||
public sealed class HungerComponent : SharedHungerComponent
|
||||
{
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IRobustRandom _random;
|
||||
#pragma warning restore 649
|
||||
|
||||
public override string Name => "Hunger";
|
||||
|
||||
// Base stuff
|
||||
public float BaseDecayRate => _baseDecayRate;
|
||||
[ViewVariables] private float _baseDecayRate;
|
||||
@@ -30,7 +30,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
[ViewVariables] private float _actualDecayRate;
|
||||
|
||||
// Hunger
|
||||
public HungerThreshold CurrentHungerThreshold => _currentHungerThreshold;
|
||||
public override HungerThreshold CurrentHungerThreshold => _currentHungerThreshold;
|
||||
private HungerThreshold _currentHungerThreshold;
|
||||
private HungerThreshold _lastHungerThreshold;
|
||||
public float CurrentHunger => _currentHunger;
|
||||
@@ -127,6 +127,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
_currentHungerThreshold = GetHungerThreshold(_currentHunger);
|
||||
_lastHungerThreshold = HungerThreshold.Okay; // TODO: Potentially change this -> Used Okay because no effects.
|
||||
HungerThresholdEffect(true);
|
||||
Dirty();
|
||||
}
|
||||
|
||||
public HungerThreshold GetHungerThreshold(float food)
|
||||
@@ -161,6 +162,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
{
|
||||
_currentHungerThreshold = calculatedHungerThreshold;
|
||||
HungerThresholdEffect();
|
||||
Dirty();
|
||||
}
|
||||
if (_currentHungerThreshold == HungerThreshold.Dead)
|
||||
{
|
||||
@@ -179,36 +181,11 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
_currentHunger = HungerThresholds[HungerThreshold.Okay];
|
||||
}
|
||||
|
||||
float IMoveSpeedModifier.WalkSpeedModifier
|
||||
public override ComponentState GetComponentState()
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_currentHungerThreshold == HungerThreshold.Starving)
|
||||
{
|
||||
return 0.5f;
|
||||
}
|
||||
return 1.0f;
|
||||
}
|
||||
}
|
||||
float IMoveSpeedModifier.SprintSpeedModifier
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_currentHungerThreshold == HungerThreshold.Starving)
|
||||
{
|
||||
return 0.5f;
|
||||
}
|
||||
return 1.0f;
|
||||
}
|
||||
return new HungerComponentState(_currentHungerThreshold);
|
||||
}
|
||||
}
|
||||
|
||||
public enum HungerThreshold
|
||||
{
|
||||
Overfed,
|
||||
Okay,
|
||||
Peckish,
|
||||
Starving,
|
||||
Dead,
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ using Content.Server.GameObjects.Components.Mobs;
|
||||
using Content.Server.GameObjects.Components.Movement;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.GameObjects.Components.Mobs;
|
||||
using Content.Shared.GameObjects.Components.Movement;
|
||||
using Content.Shared.GameObjects.Components.Nutrition;
|
||||
using JetBrains.Annotations;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.Random;
|
||||
@@ -15,14 +17,12 @@ using Robust.Shared.ViewVariables;
|
||||
namespace Content.Server.GameObjects.Components.Nutrition
|
||||
{
|
||||
[RegisterComponent]
|
||||
public sealed class ThirstComponent : Component, IMoveSpeedModifier
|
||||
public sealed class ThirstComponent : SharedThirstComponent, IMoveSpeedModifier
|
||||
{
|
||||
#pragma warning disable 649
|
||||
[Dependency] private readonly IRobustRandom _random;
|
||||
#pragma warning restore 649
|
||||
|
||||
public override string Name => "Thirst";
|
||||
|
||||
// Base stuff
|
||||
public float BaseDecayRate => _baseDecayRate;
|
||||
[ViewVariables] private float _baseDecayRate;
|
||||
@@ -30,7 +30,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
[ViewVariables] private float _actualDecayRate;
|
||||
|
||||
// Thirst
|
||||
public ThirstThreshold CurrentThirstThreshold => _currentThirstThreshold;
|
||||
public override ThirstThreshold CurrentThirstThreshold => _currentThirstThreshold;
|
||||
private ThirstThreshold _currentThirstThreshold;
|
||||
private ThirstThreshold _lastThirstThreshold;
|
||||
public float CurrentThirst => _currentThirst;
|
||||
@@ -126,6 +126,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
_lastThirstThreshold = ThirstThreshold.Okay; // TODO: Potentially change this -> Used Okay because no effects.
|
||||
// TODO: Check all thresholds make sense and throw if they don't.
|
||||
ThirstThresholdEffect(true);
|
||||
Dirty();
|
||||
}
|
||||
|
||||
public ThirstThreshold GetThirstThreshold(float drink)
|
||||
@@ -160,6 +161,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
{
|
||||
_currentThirstThreshold = calculatedThirstThreshold;
|
||||
ThirstThresholdEffect();
|
||||
Dirty();
|
||||
}
|
||||
|
||||
if (_currentThirstThreshold == ThirstThreshold.Dead)
|
||||
@@ -174,42 +176,16 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
||||
}
|
||||
}
|
||||
|
||||
float IMoveSpeedModifier.SprintSpeedModifier
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_currentThirstThreshold == ThirstThreshold.Parched)
|
||||
{
|
||||
return 0.25f;
|
||||
}
|
||||
return 1.0f;
|
||||
}
|
||||
}
|
||||
float IMoveSpeedModifier.WalkSpeedModifier
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_currentThirstThreshold == ThirstThreshold.Parched)
|
||||
{
|
||||
return 0.5f;
|
||||
}
|
||||
return 1.0f;
|
||||
}
|
||||
}
|
||||
|
||||
public void ResetThirst()
|
||||
{
|
||||
_currentThirst = ThirstThresholds[ThirstThreshold.Okay];
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState()
|
||||
{
|
||||
return new ThirstComponentState(_currentThirstThreshold);
|
||||
}
|
||||
}
|
||||
|
||||
public enum ThirstThreshold
|
||||
{
|
||||
// Hydrohomies
|
||||
OverHydrated,
|
||||
Okay,
|
||||
Thirsty,
|
||||
Parched,
|
||||
Dead,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.Players;
|
||||
using Content.Shared.GameObjects.Components.Observer;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Server.GameObjects.Components;
|
||||
using Robust.Server.Interfaces.GameObjects;
|
||||
@@ -15,7 +16,7 @@ using Timer = Robust.Shared.Timers.Timer;
|
||||
namespace Content.Server.GameObjects.Components.Observer
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class GhostComponent : SharedGhostComponent, IActionBlocker
|
||||
public class GhostComponent : SharedGhostComponent
|
||||
{
|
||||
private bool _canReturnToBody = true;
|
||||
|
||||
@@ -75,13 +76,5 @@ namespace Content.Server.GameObjects.Components.Observer
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanInteract() => false;
|
||||
public bool CanUse() => false;
|
||||
public bool CanThrow() => false;
|
||||
public bool CanDrop() => false;
|
||||
public bool CanPickup() => false;
|
||||
public bool CanEmote() => false;
|
||||
public bool CanAttack() => false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
using System;
|
||||
using Content.Server.GameObjects.Components.Mobs;
|
||||
using Content.Server.GameObjects.EntitySystems;
|
||||
using Content.Server.GameObjects.Components.Movement;
|
||||
using Content.Shared.GameObjects.Components.Weapons.Ranged;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Interfaces.GameObjects;
|
||||
using Robust.Shared.Interfaces.Network;
|
||||
@@ -88,7 +88,7 @@ namespace Content.Server.GameObjects.Components.Weapon.Ranged
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
var curTime = IoCManager.Resolve<IGameTiming>().CurTime;
|
||||
var span = curTime - _lastFireTime;
|
||||
if (span.TotalSeconds < 1 / FireRate)
|
||||
|
||||
Reference in New Issue
Block a user