Put base movement in control of MovementSpeedModifierComponent.

PlayerInputMoverComponent was unsuitable because it gets added/removed dynamically and is specific to players (AIs don't use it).
This commit is contained in:
Pieter-Jan Briers
2020-04-18 13:46:35 +02:00
parent 028ca7a732
commit 1578a32fa1
3 changed files with 42 additions and 58 deletions

View File

@@ -56,18 +56,6 @@ namespace Content.Server.GameObjects.Components.Movement
serializer.DataField(ref _visionRadius, "vision", 8.0f);
}
/// <summary>
/// Movement speed (m/s) that the entity walks, before modifiers
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public float BaseWalkSpeed { get; set; } = PlayerInputMoverComponent.DefaultBaseWalkSpeed;
/// <summary>
/// Movement speed (m/s) that the entity sprints, before modifiers
/// </summary>
[ViewVariables(VVAccess.ReadWrite)]
public float BaseSprintSpeed { get; set; } = PlayerInputMoverComponent.DefaultBaseSprintSpeed;
/// <summary>
/// Movement speed (m/s) that the entity walks, after modifiers
/// </summary>
@@ -76,14 +64,15 @@ namespace Content.Server.GameObjects.Components.Movement
{
get
{
float speed = BaseWalkSpeed;
if (Owner.TryGetComponent<MovementSpeedModifierComponent>(out MovementSpeedModifierComponent component))
if (Owner.TryGetComponent(out MovementSpeedModifierComponent component))
{
speed *= component.WalkSpeedModifier;
return component.CurrentWalkSpeed;
}
return speed;
return MovementSpeedModifierComponent.DefaultBaseWalkSpeed;
}
}
/// <summary>
/// Movement speed (m/s) that the entity walks, after modifiers
/// </summary>
@@ -92,12 +81,12 @@ namespace Content.Server.GameObjects.Components.Movement
{
get
{
float speed = BaseSprintSpeed;
if (Owner.TryGetComponent<MovementSpeedModifierComponent>(out MovementSpeedModifierComponent component))
if (Owner.TryGetComponent(out MovementSpeedModifierComponent component))
{
speed *= component.SprintSpeedModifier;
return component.CurrentSprintSpeed;
}
return speed;
return MovementSpeedModifierComponent.DefaultBaseSprintSpeed;
}
}