2021-03-08 04:09:59 +11:00
|
|
|
using System;
|
|
|
|
|
using Robust.Shared.GameObjects;
|
2021-07-12 01:32:10 -07:00
|
|
|
using Robust.Shared.GameStates;
|
2021-12-03 12:23:18 +01:00
|
|
|
using Robust.Shared.IoC;
|
2021-03-08 04:09:59 +11:00
|
|
|
using Robust.Shared.Map;
|
|
|
|
|
using Robust.Shared.Maths;
|
|
|
|
|
using Robust.Shared.Players;
|
|
|
|
|
using Robust.Shared.Serialization;
|
|
|
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
|
|
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
|
|
2021-06-09 22:19:39 +02:00
|
|
|
namespace Content.Shared.Movement.Components
|
2021-03-08 04:09:59 +11:00
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The basic player mover with footsteps and grabbing
|
|
|
|
|
/// </summary>
|
|
|
|
|
[RegisterComponent]
|
|
|
|
|
[ComponentReference(typeof(IMobMoverComponent))]
|
2021-07-12 01:32:10 -07:00
|
|
|
[NetworkedComponent()]
|
2022-02-16 00:23:23 -07:00
|
|
|
public sealed class SharedPlayerMobMoverComponent : Component, IMobMoverComponent
|
2021-03-08 04:09:59 +11:00
|
|
|
{
|
|
|
|
|
private float _stepSoundDistance;
|
|
|
|
|
[DataField("grabRange")]
|
2021-03-08 12:48:15 +11:00
|
|
|
private float _grabRange = IMobMoverComponent.GrabRangeDefault;
|
2021-03-08 04:09:59 +11:00
|
|
|
[DataField("pushStrength")]
|
2021-03-08 12:48:15 +11:00
|
|
|
private float _pushStrength = IMobMoverComponent.PushStrengthDefault;
|
|
|
|
|
|
|
|
|
|
[DataField("weightlessStrength")]
|
|
|
|
|
private float _weightlessStrength = IMobMoverComponent.WeightlessStrengthDefault;
|
2021-03-08 04:09:59 +11:00
|
|
|
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
|
|
|
public EntityCoordinates LastPosition { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Used to keep track of how far we have moved before playing a step sound
|
|
|
|
|
/// </summary>
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
|
|
|
public float StepSoundDistance
|
|
|
|
|
{
|
|
|
|
|
get => _stepSoundDistance;
|
|
|
|
|
set
|
|
|
|
|
{
|
2021-09-29 20:07:01 +10:00
|
|
|
if (MathHelper.CloseToPercent(_stepSoundDistance, value)) return;
|
2021-03-08 04:09:59 +11:00
|
|
|
_stepSoundDistance = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
|
|
|
public float GrabRange
|
|
|
|
|
{
|
|
|
|
|
get => _grabRange;
|
|
|
|
|
set
|
|
|
|
|
{
|
2021-09-29 20:07:01 +10:00
|
|
|
if (MathHelper.CloseToPercent(_grabRange, value)) return;
|
2021-03-08 04:09:59 +11:00
|
|
|
_grabRange = value;
|
|
|
|
|
Dirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
|
|
|
public float PushStrength
|
|
|
|
|
{
|
|
|
|
|
get => _pushStrength;
|
|
|
|
|
set
|
|
|
|
|
{
|
2021-09-29 20:07:01 +10:00
|
|
|
if (MathHelper.CloseToPercent(_pushStrength, value)) return;
|
2021-03-08 04:09:59 +11:00
|
|
|
_pushStrength = value;
|
|
|
|
|
Dirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-03-08 12:48:15 +11:00
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
|
|
|
public float WeightlessStrength
|
|
|
|
|
{
|
|
|
|
|
get => _weightlessStrength;
|
|
|
|
|
set
|
|
|
|
|
{
|
2021-09-29 20:07:01 +10:00
|
|
|
if (MathHelper.CloseToPercent(_weightlessStrength, value)) return;
|
2021-03-08 12:48:15 +11:00
|
|
|
_weightlessStrength = value;
|
|
|
|
|
Dirty();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-19 19:41:26 -07:00
|
|
|
protected override void Initialize()
|
2021-03-08 04:09:59 +11:00
|
|
|
{
|
|
|
|
|
base.Initialize();
|
2021-12-03 15:53:09 +01:00
|
|
|
if (!IoCManager.Resolve<IEntityManager>().HasComponent<IMoverComponent>(Owner))
|
2021-03-08 04:09:59 +11:00
|
|
|
{
|
|
|
|
|
Owner.EnsureComponentWarn<SharedPlayerInputMoverComponent>();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-30 15:20:38 +01:00
|
|
|
public override ComponentState GetComponentState()
|
2021-03-08 04:09:59 +11:00
|
|
|
{
|
2021-03-08 12:48:15 +11:00
|
|
|
return new PlayerMobMoverComponentState(_grabRange, _pushStrength, _weightlessStrength);
|
2021-03-08 04:09:59 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
|
|
|
|
{
|
|
|
|
|
base.HandleComponentState(curState, nextState);
|
|
|
|
|
if (curState is not PlayerMobMoverComponentState playerMoverState) return;
|
|
|
|
|
GrabRange = playerMoverState.GrabRange;
|
|
|
|
|
PushStrength = playerMoverState.PushStrength;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Serializable, NetSerializable]
|
|
|
|
|
private sealed class PlayerMobMoverComponentState : ComponentState
|
|
|
|
|
{
|
|
|
|
|
public float GrabRange;
|
|
|
|
|
public float PushStrength;
|
2021-03-08 12:48:15 +11:00
|
|
|
public float WeightlessStrength;
|
2021-03-08 04:09:59 +11:00
|
|
|
|
2021-07-12 01:32:10 -07:00
|
|
|
public PlayerMobMoverComponentState(float grabRange, float pushStrength, float weightlessStrength)
|
2021-03-08 04:09:59 +11:00
|
|
|
{
|
|
|
|
|
GrabRange = grabRange;
|
|
|
|
|
PushStrength = pushStrength;
|
2021-03-08 12:48:15 +11:00
|
|
|
WeightlessStrength = weightlessStrength;
|
2021-03-08 04:09:59 +11:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|