WiP movement prediction.
This commit is contained in:
@@ -107,7 +107,6 @@ namespace Content.Client
|
|||||||
"WeaponCapacitorCharger",
|
"WeaponCapacitorCharger",
|
||||||
"PowerCellCharger",
|
"PowerCellCharger",
|
||||||
"AiController",
|
"AiController",
|
||||||
"PlayerInputMover",
|
|
||||||
"Computer",
|
"Computer",
|
||||||
"AsteroidRock",
|
"AsteroidRock",
|
||||||
"ResearchServer",
|
"ResearchServer",
|
||||||
@@ -125,8 +124,6 @@ namespace Content.Client
|
|||||||
"Food",
|
"Food",
|
||||||
"FoodContainer",
|
"FoodContainer",
|
||||||
"Stomach",
|
"Stomach",
|
||||||
"Hunger",
|
|
||||||
"Thirst",
|
|
||||||
"Rotatable",
|
"Rotatable",
|
||||||
"MagicMirror",
|
"MagicMirror",
|
||||||
"MedkitFill",
|
"MedkitFill",
|
||||||
@@ -142,7 +139,6 @@ namespace Content.Client
|
|||||||
"Bloodstream",
|
"Bloodstream",
|
||||||
"TransformableContainer",
|
"TransformableContainer",
|
||||||
"Mind",
|
"Mind",
|
||||||
"MovementSpeedModifier",
|
|
||||||
"StorageFill",
|
"StorageFill",
|
||||||
"Mop",
|
"Mop",
|
||||||
"Bucket",
|
"Bucket",
|
||||||
@@ -154,7 +150,6 @@ namespace Content.Client
|
|||||||
"DroppedBodyPart",
|
"DroppedBodyPart",
|
||||||
"DroppedMechanism",
|
"DroppedMechanism",
|
||||||
"BodyManager",
|
"BodyManager",
|
||||||
"Stunnable",
|
|
||||||
"SolarPanel",
|
"SolarPanel",
|
||||||
"BodyScanner",
|
"BodyScanner",
|
||||||
"Stunbaton",
|
"Stunbaton",
|
||||||
|
|||||||
@@ -0,0 +1,43 @@
|
|||||||
|
using Content.Shared.GameObjects.Components.Mobs;
|
||||||
|
using Content.Shared.GameObjects.Components.Movement;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
|
namespace Content.Client.GameObjects.Components.Mobs
|
||||||
|
{
|
||||||
|
[RegisterComponent]
|
||||||
|
[ComponentReference(typeof(SharedStunnableComponent))]
|
||||||
|
public class StunnableComponent : SharedStunnableComponent
|
||||||
|
{
|
||||||
|
private bool _stunned;
|
||||||
|
private bool _knockedDown;
|
||||||
|
private bool _slowedDown;
|
||||||
|
|
||||||
|
public override bool Stunned => _stunned;
|
||||||
|
public override bool KnockedDown => _knockedDown;
|
||||||
|
public override bool SlowedDown => _slowedDown;
|
||||||
|
|
||||||
|
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||||
|
{
|
||||||
|
base.HandleComponentState(curState, nextState);
|
||||||
|
|
||||||
|
if (!(curState is StunnableComponentState state))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_stunned = state.Stunned;
|
||||||
|
_knockedDown = state.KnockedDown;
|
||||||
|
_slowedDown = state.SlowedDown;
|
||||||
|
|
||||||
|
WalkModifierOverride = state.WalkModifierOverride;
|
||||||
|
RunModifierOverride = state.RunModifierOverride;
|
||||||
|
|
||||||
|
if (Owner.TryGetComponent(out MovementSpeedModifierComponent movement))
|
||||||
|
{
|
||||||
|
movement.RefreshMovementSpeedModifiers();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
using Content.Shared.GameObjects.Components.Movement;
|
||||||
|
using Robust.Client.Player;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.IoC;
|
||||||
|
using Robust.Shared.Map;
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
|
namespace Content.Client.GameObjects.Components.Movement
|
||||||
|
{
|
||||||
|
[RegisterComponent]
|
||||||
|
[ComponentReference(typeof(IMoverComponent))]
|
||||||
|
public class PlayerInputMoverComponent : SharedPlayerInputMoverComponent, IMoverComponent
|
||||||
|
{
|
||||||
|
public override GridCoordinates LastPosition { get; set; }
|
||||||
|
public override float StepSoundDistance { get; set; }
|
||||||
|
|
||||||
|
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||||
|
{
|
||||||
|
if (IoCManager.Resolve<IPlayerManager>().LocalPlayer!.ControlledEntity == Owner)
|
||||||
|
{
|
||||||
|
base.HandleComponentState(curState, nextState);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
using Content.Shared.GameObjects.Components.Movement;
|
||||||
|
using Content.Shared.GameObjects.Components.Nutrition;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
|
namespace Content.Client.GameObjects.Components.Nutrition
|
||||||
|
{
|
||||||
|
[RegisterComponent]
|
||||||
|
public class HungerComponent : SharedHungerComponent
|
||||||
|
{
|
||||||
|
private HungerThreshold _currentHungerThreshold;
|
||||||
|
public override HungerThreshold CurrentHungerThreshold => _currentHungerThreshold;
|
||||||
|
|
||||||
|
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||||
|
{
|
||||||
|
if (!(curState is HungerComponentState hunger))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_currentHungerThreshold = hunger.CurrentThreshold;
|
||||||
|
|
||||||
|
if (Owner.TryGetComponent(out MovementSpeedModifierComponent movement))
|
||||||
|
{
|
||||||
|
movement.RefreshMovementSpeedModifiers();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,30 @@
|
|||||||
|
using Content.Shared.GameObjects.Components.Movement;
|
||||||
|
using Content.Shared.GameObjects.Components.Nutrition;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
|
namespace Content.Client.GameObjects.Components.Nutrition
|
||||||
|
{
|
||||||
|
[RegisterComponent]
|
||||||
|
public class ThirstComponent : SharedThirstComponent
|
||||||
|
{
|
||||||
|
private ThirstThreshold _currentThirstThreshold;
|
||||||
|
public override ThirstThreshold CurrentThirstThreshold => _currentThirstThreshold;
|
||||||
|
|
||||||
|
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||||
|
{
|
||||||
|
if (!(curState is ThirstComponentState thirst))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_currentThirstThreshold = thirst.CurrentThreshold;
|
||||||
|
|
||||||
|
if (Owner.TryGetComponent(out MovementSpeedModifierComponent movement))
|
||||||
|
{
|
||||||
|
movement.RefreshMovementSpeedModifiers();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
53
Content.Client/GameObjects/EntitySystems/MoverSystem.cs
Normal file
53
Content.Client/GameObjects/EntitySystems/MoverSystem.cs
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
using Content.Shared.GameObjects.Components.Movement;
|
||||||
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
|
using Content.Shared.Physics;
|
||||||
|
using JetBrains.Annotations;
|
||||||
|
using Robust.Client.GameObjects;
|
||||||
|
using Robust.Client.Physics;
|
||||||
|
using Robust.Client.Player;
|
||||||
|
using Robust.Shared.GameObjects.Components;
|
||||||
|
using Robust.Shared.IoC;
|
||||||
|
using Robust.Shared.Physics;
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
|
namespace Content.Client.GameObjects.EntitySystems
|
||||||
|
{
|
||||||
|
[UsedImplicitly]
|
||||||
|
public class MoverSystem : SharedMoverSystem
|
||||||
|
{
|
||||||
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
|
||||||
|
UpdatesBefore.Add(typeof(PhysicsSystem));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void FrameUpdate(float frameTime)
|
||||||
|
{
|
||||||
|
var playerEnt = _playerManager.LocalPlayer?.ControlledEntity;
|
||||||
|
|
||||||
|
if (playerEnt == null || !playerEnt.TryGetComponent(out IMoverComponent mover))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var physics = playerEnt.GetComponent<PhysicsComponent>();
|
||||||
|
playerEnt.TryGetComponent(out CollidableComponent? collidable);
|
||||||
|
|
||||||
|
UpdateKinematics(playerEnt.Transform, mover, physics, collidable);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update(float frameTime)
|
||||||
|
{
|
||||||
|
FrameUpdate(frameTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void SetController(SharedPhysicsComponent physics)
|
||||||
|
{
|
||||||
|
((PhysicsComponent)physics).SetController<MoverController>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -444,7 +444,7 @@ namespace Content.Client.GameObjects.EntitySystems
|
|||||||
var func = args.Function;
|
var func = args.Function;
|
||||||
var funcId = _master._inputManager.NetworkBindMap.KeyFunctionID(args.Function);
|
var funcId = _master._inputManager.NetworkBindMap.KeyFunctionID(args.Function);
|
||||||
|
|
||||||
var message = new FullInputCmdMessage(_master._gameTiming.CurTick, funcId, BoundKeyState.Down,
|
var message = new FullInputCmdMessage(_master._gameTiming.CurTick, _master._gameTiming.TickFraction, funcId, BoundKeyState.Down,
|
||||||
_entity.Transform.GridPosition,
|
_entity.Transform.GridPosition,
|
||||||
args.PointerLocation, _entity.Uid);
|
args.PointerLocation, _entity.Uid);
|
||||||
|
|
||||||
|
|||||||
@@ -183,7 +183,7 @@ namespace Content.Client.State
|
|||||||
if (!_mapManager.TryFindGridAt(mousePosWorld, out var grid))
|
if (!_mapManager.TryFindGridAt(mousePosWorld, out var grid))
|
||||||
grid = _mapManager.GetDefaultGrid(mousePosWorld.MapId);
|
grid = _mapManager.GetDefaultGrid(mousePosWorld.MapId);
|
||||||
|
|
||||||
var message = new FullInputCmdMessage(_timing.CurTick, funcId, args.State,
|
var message = new FullInputCmdMessage(_timing.CurTick, _timing.TickFraction, funcId, args.State,
|
||||||
grid.MapToGrid(mousePosWorld), args.PointerLocation,
|
grid.MapToGrid(mousePosWorld), args.PointerLocation,
|
||||||
entityToClick?.Uid ?? EntityUid.Invalid);
|
entityToClick?.Uid ?? EntityUid.Invalid);
|
||||||
|
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ namespace Content.Client.UserInterface
|
|||||||
if (!_mapManager.TryFindGridAt(mousePosWorld, out var grid))
|
if (!_mapManager.TryFindGridAt(mousePosWorld, out var grid))
|
||||||
grid = _mapManager.GetDefaultGrid(mousePosWorld.MapId);
|
grid = _mapManager.GetDefaultGrid(mousePosWorld.MapId);
|
||||||
|
|
||||||
var message = new FullInputCmdMessage(_gameTiming.CurTick, funcId, BoundKeyState.Down,
|
var message = new FullInputCmdMessage(_gameTiming.CurTick, _gameTiming.TickFraction, funcId, BoundKeyState.Down,
|
||||||
grid.MapToGrid(mousePosWorld), args.PointerLocation, item.Uid);
|
grid.MapToGrid(mousePosWorld), args.PointerLocation, item.Uid);
|
||||||
|
|
||||||
// client side command handlers will always be sent the local player session.
|
// client side command handlers will always be sent the local player session.
|
||||||
|
|||||||
@@ -2,10 +2,10 @@ using System;
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Content.Server.GameObjects.Components.Movement;
|
using Content.Server.GameObjects.Components.Movement;
|
||||||
using Content.Server.GameObjects.EntitySystems;
|
|
||||||
using Content.Server.GameObjects.EntitySystems.AI.Pathfinding;
|
using Content.Server.GameObjects.EntitySystems.AI.Pathfinding;
|
||||||
using Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Pathfinders;
|
using Content.Server.GameObjects.EntitySystems.AI.Pathfinding.Pathfinders;
|
||||||
using Content.Server.GameObjects.EntitySystems.JobQueues;
|
using Content.Server.GameObjects.EntitySystems.JobQueues;
|
||||||
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
using Robust.Shared.GameObjects.Components;
|
using Robust.Shared.GameObjects.Components;
|
||||||
using Robust.Shared.Interfaces.GameObjects;
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
using Robust.Shared.Interfaces.Map;
|
using Robust.Shared.Interfaces.Map;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Content.Server.AI.Utility.Curves;
|
using Content.Server.AI.Utility.Curves;
|
||||||
using Content.Server.AI.WorldState;
|
using Content.Server.AI.WorldState;
|
||||||
using Content.Server.AI.WorldState.States;
|
using Content.Server.AI.WorldState.States;
|
||||||
using Content.Server.GameObjects.EntitySystems;
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
|
|
||||||
namespace Content.Server.AI.Utility.Considerations.ActionBlocker
|
namespace Content.Server.AI.Utility.Considerations.ActionBlocker
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using Content.Server.AI.Utility.Curves;
|
|||||||
using Content.Server.AI.WorldState;
|
using Content.Server.AI.WorldState;
|
||||||
using Content.Server.AI.WorldState.States;
|
using Content.Server.AI.WorldState.States;
|
||||||
using Content.Server.GameObjects.Components.Nutrition;
|
using Content.Server.GameObjects.Components.Nutrition;
|
||||||
|
using Content.Shared.GameObjects.Components.Nutrition;
|
||||||
|
|
||||||
namespace Content.Server.AI.Utility.Considerations.Nutrition.Drink
|
namespace Content.Server.AI.Utility.Considerations.Nutrition.Drink
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ using Content.Server.AI.Utility.Curves;
|
|||||||
using Content.Server.AI.WorldState;
|
using Content.Server.AI.WorldState;
|
||||||
using Content.Server.AI.WorldState.States;
|
using Content.Server.AI.WorldState.States;
|
||||||
using Content.Server.GameObjects.Components.Nutrition;
|
using Content.Server.GameObjects.Components.Nutrition;
|
||||||
|
using Content.Shared.GameObjects.Components.Nutrition;
|
||||||
|
|
||||||
namespace Content.Server.AI.Utility.Considerations.Nutrition
|
namespace Content.Server.AI.Utility.Considerations.Nutrition
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using Content.Server.GameObjects.Components.Nutrition;
|
using Content.Server.GameObjects.Components.Nutrition;
|
||||||
|
using Content.Shared.GameObjects.Components.Nutrition;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
|
|
||||||
namespace Content.Server.AI.WorldState.States.Nutrition
|
namespace Content.Server.AI.WorldState.States.Nutrition
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using Content.Server.GameObjects.Components.Nutrition;
|
using Content.Server.GameObjects.Components.Nutrition;
|
||||||
|
using Content.Shared.GameObjects.Components.Nutrition;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using ThirstComponent = Content.Server.GameObjects.Components.Nutrition.ThirstComponent;
|
using ThirstComponent = Content.Server.GameObjects.Components.Nutrition.ThirstComponent;
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ using Content.Server.Interfaces.Chat;
|
|||||||
using Content.Server.Observer;
|
using Content.Server.Observer;
|
||||||
using Content.Server.Players;
|
using Content.Server.Players;
|
||||||
using Content.Shared.Chat;
|
using Content.Shared.Chat;
|
||||||
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
using Robust.Server.Interfaces.Player;
|
using Robust.Server.Interfaces.Player;
|
||||||
using Robust.Shared.Interfaces.GameObjects;
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
using Robust.Shared.Interfaces.Network;
|
using Robust.Shared.Interfaces.Network;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ using Content.Server.Interfaces.GameObjects;
|
|||||||
using Content.Server.Utility;
|
using Content.Server.Utility;
|
||||||
using Content.Shared.Chemistry;
|
using Content.Shared.Chemistry;
|
||||||
using Content.Shared.GameObjects.Components.Chemistry;
|
using Content.Shared.GameObjects.Components.Chemistry;
|
||||||
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
using Robust.Server.GameObjects.Components.Container;
|
using Robust.Server.GameObjects.Components.Container;
|
||||||
using Robust.Server.GameObjects.Components.UserInterface;
|
using Robust.Server.GameObjects.Components.UserInterface;
|
||||||
using Robust.Server.Interfaces.GameObjects;
|
using Robust.Server.Interfaces.GameObjects;
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using System.Threading.Tasks.Dataflow;
|
|||||||
using Content.Server.GameObjects.EntitySystems;
|
using Content.Server.GameObjects.EntitySystems;
|
||||||
using Content.Server.Interfaces;
|
using Content.Server.Interfaces;
|
||||||
using Content.Shared.GameObjects;
|
using Content.Shared.GameObjects;
|
||||||
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
using Robust.Server.GameObjects.Components.Container;
|
using Robust.Server.GameObjects.Components.Container;
|
||||||
using Robust.Server.Interfaces.Player;
|
using Robust.Server.Interfaces.Player;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
|
|||||||
@@ -3,11 +3,9 @@ using System.Linq;
|
|||||||
using Content.Server.GameObjects.Components.Mobs;
|
using Content.Server.GameObjects.Components.Mobs;
|
||||||
using Content.Server.GameObjects.EntitySystems;
|
using Content.Server.GameObjects.EntitySystems;
|
||||||
using Content.Server.Interfaces;
|
using Content.Server.Interfaces;
|
||||||
using Content.Server.Interfaces.GameObjects;
|
|
||||||
using Content.Server.Mobs;
|
using Content.Server.Mobs;
|
||||||
using Content.Server.Utility;
|
|
||||||
using Content.Shared.GameObjects.Components.Instruments;
|
using Content.Shared.GameObjects.Components.Instruments;
|
||||||
using NFluidsynth;
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Server.GameObjects.Components.UserInterface;
|
using Robust.Server.GameObjects.Components.UserInterface;
|
||||||
using Robust.Server.Interfaces.GameObjects;
|
using Robust.Server.Interfaces.GameObjects;
|
||||||
@@ -15,16 +13,12 @@ using Robust.Server.Interfaces.Player;
|
|||||||
using Robust.Server.Player;
|
using Robust.Server.Player;
|
||||||
using Robust.Shared.Enums;
|
using Robust.Shared.Enums;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.Interfaces.GameObjects;
|
|
||||||
using Robust.Shared.Interfaces.Log;
|
|
||||||
using Robust.Shared.Interfaces.Network;
|
using Robust.Shared.Interfaces.Network;
|
||||||
using Robust.Shared.Interfaces.Timing;
|
using Robust.Shared.Interfaces.Timing;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Players;
|
using Robust.Shared.Players;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
using Robust.Shared.ViewVariables;
|
using Robust.Shared.ViewVariables;
|
||||||
using Logger = Robust.Shared.Log.Logger;
|
|
||||||
using MidiEvent = Robust.Shared.Audio.Midi.MidiEvent;
|
|
||||||
|
|
||||||
namespace Content.Server.GameObjects.Components.Instruments
|
namespace Content.Server.GameObjects.Components.Instruments
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ using Content.Shared.Chemistry;
|
|||||||
using Content.Shared.GameObjects;
|
using Content.Shared.GameObjects;
|
||||||
using Content.Shared.GameObjects.Components;
|
using Content.Shared.GameObjects.Components;
|
||||||
using Content.Shared.GameObjects.Components.Interactable;
|
using Content.Shared.GameObjects.Components.Interactable;
|
||||||
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
using Content.Shared.Maps;
|
using Content.Shared.Maps;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Server.GameObjects.EntitySystems;
|
using Robust.Server.GameObjects.EntitySystems;
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ using Content.Server.Throw;
|
|||||||
using Content.Server.Utility;
|
using Content.Server.Utility;
|
||||||
using Content.Shared.GameObjects;
|
using Content.Shared.GameObjects;
|
||||||
using Content.Shared.GameObjects.Components.Items;
|
using Content.Shared.GameObjects.Components.Items;
|
||||||
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
using Content.Shared.Physics;
|
using Content.Shared.Physics;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Server.Interfaces.GameObjects;
|
using Robust.Server.Interfaces.GameObjects;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using Content.Server.GameObjects.EntitySystems;
|
|||||||
using Content.Server.Mobs;
|
using Content.Server.Mobs;
|
||||||
using Content.Shared.Audio;
|
using Content.Shared.Audio;
|
||||||
using Content.Shared.GameObjects.Components.Mobs;
|
using Content.Shared.GameObjects.Components.Mobs;
|
||||||
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Server.GameObjects.EntitySystems;
|
using Robust.Server.GameObjects.EntitySystems;
|
||||||
|
|||||||
@@ -3,16 +3,18 @@ using System.Collections.Generic;
|
|||||||
using Content.Server.GameObjects.Components.Mobs;
|
using Content.Server.GameObjects.Components.Mobs;
|
||||||
using Content.Server.GameObjects.EntitySystems;
|
using Content.Server.GameObjects.EntitySystems;
|
||||||
using Content.Server.Interfaces;
|
using Content.Server.Interfaces;
|
||||||
using Content.Server.Interfaces.GameObjects.Components.Movement;
|
|
||||||
using Content.Server.Observer;
|
using Content.Server.Observer;
|
||||||
using Content.Shared.GameObjects;
|
using Content.Shared.GameObjects;
|
||||||
using Content.Shared.GameObjects.Components.Mobs;
|
using Content.Shared.GameObjects.Components.Mobs;
|
||||||
|
using Content.Shared.GameObjects.Components.Movement;
|
||||||
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Server.Interfaces.Player;
|
using Robust.Server.Interfaces.Player;
|
||||||
using Robust.Shared.ContentPack;
|
using Robust.Shared.ContentPack;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.Interfaces.GameObjects;
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
using Robust.Shared.Interfaces.Network;
|
using Robust.Shared.Interfaces.Network;
|
||||||
|
using Robust.Shared.Players;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
namespace Content.Server.GameObjects
|
namespace Content.Server.GameObjects
|
||||||
@@ -218,11 +220,11 @@ namespace Content.Server.GameObjects
|
|||||||
Owner.GetComponent<DamageableComponent>().TakeDamage(DamageType.Heat, burnDamage, null);
|
Owner.GetComponent<DamageableComponent>().TakeDamage(DamageType.Heat, burnDamage, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
void IRelayMoveInput.MoveInputPressed(IPlayerSession session)
|
void IRelayMoveInput.MoveInputPressed(ICommonSession session)
|
||||||
{
|
{
|
||||||
if (CurrentDamageState is DeadState)
|
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;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using Content.Server.GameObjects.Components.Movement;
|
|
||||||
using Content.Server.GameObjects.EntitySystems;
|
using Content.Server.GameObjects.EntitySystems;
|
||||||
using Content.Server.Interfaces.GameObjects;
|
|
||||||
using Content.Server.Mobs;
|
using Content.Server.Mobs;
|
||||||
using Content.Shared.Audio;
|
using Content.Shared.Audio;
|
||||||
using Content.Shared.GameObjects.Components.Mobs;
|
using Content.Shared.GameObjects.Components.Mobs;
|
||||||
using Microsoft.Extensions.Logging;
|
|
||||||
using Robust.Server.GameObjects;
|
|
||||||
using Robust.Server.GameObjects.EntitySystems;
|
using Robust.Server.GameObjects.EntitySystems;
|
||||||
using Robust.Shared.Audio;
|
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.GameObjects.Systems;
|
using Robust.Shared.GameObjects.Systems;
|
||||||
using Robust.Shared.Interfaces.GameObjects;
|
|
||||||
using Robust.Shared.Interfaces.Timers;
|
|
||||||
using Robust.Shared.Interfaces.Timing;
|
using Robust.Shared.Interfaces.Timing;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Log;
|
|
||||||
using Robust.Shared.Maths;
|
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
using Robust.Shared.ViewVariables;
|
using Robust.Shared.ViewVariables;
|
||||||
using Timer = Robust.Shared.Timers.Timer;
|
using Timer = Robust.Shared.Timers.Timer;
|
||||||
using CannyFastMath;
|
using Content.Shared.GameObjects.Components.Movement;
|
||||||
using Math = CannyFastMath.Math;
|
using Math = CannyFastMath.Math;
|
||||||
using MathF = CannyFastMath.MathF;
|
using MathF = CannyFastMath.MathF;
|
||||||
|
|
||||||
namespace Content.Server.GameObjects.Components.Mobs
|
namespace Content.Server.GameObjects.Components.Mobs
|
||||||
{
|
{
|
||||||
[RegisterComponent]
|
[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
|
#pragma warning disable 649
|
||||||
[Dependency] private IGameTiming _gameTiming;
|
[Dependency] private IGameTiming _gameTiming;
|
||||||
#pragma warning restore 649
|
#pragma warning restore 649
|
||||||
|
|
||||||
private TimeSpan? _lastStun;
|
private TimeSpan? _lastStun;
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables] public TimeSpan? StunStart => _lastStun;
|
||||||
public TimeSpan? StunStart => _lastStun;
|
|
||||||
|
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public TimeSpan? StunEnd => _lastStun == null
|
public TimeSpan? StunEnd => _lastStun == null
|
||||||
? (TimeSpan?) 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;
|
private const int StunLevels = 8;
|
||||||
|
|
||||||
@@ -59,14 +49,12 @@ namespace Content.Server.GameObjects.Components.Mobs
|
|||||||
private float _knockdownTimer = 0f;
|
private float _knockdownTimer = 0f;
|
||||||
private float _slowdownTimer = 0f;
|
private float _slowdownTimer = 0f;
|
||||||
|
|
||||||
private float _walkModifierOverride = 0f;
|
|
||||||
private float _runModifierOverride = 0f;
|
|
||||||
private string _stunTexture;
|
private string _stunTexture;
|
||||||
private CancellationTokenSource _statusRemoveCancellation = new CancellationTokenSource();
|
private CancellationTokenSource _statusRemoveCancellation = new CancellationTokenSource();
|
||||||
|
|
||||||
[ViewVariables] public bool Stunned => _stunnedTimer > 0f;
|
[ViewVariables] public override bool Stunned => _stunnedTimer > 0f;
|
||||||
[ViewVariables] public bool KnockedDown => _knockdownTimer > 0f;
|
[ViewVariables] public override bool KnockedDown => _knockdownTimer > 0f;
|
||||||
[ViewVariables] public bool SlowedDown => _slowdownTimer > 0f;
|
[ViewVariables] public override bool SlowedDown => _slowdownTimer > 0f;
|
||||||
[ViewVariables] public float StunCap => _stunCap;
|
[ViewVariables] public float StunCap => _stunCap;
|
||||||
[ViewVariables] public float KnockdownCap => _knockdownCap;
|
[ViewVariables] public float KnockdownCap => _knockdownCap;
|
||||||
[ViewVariables] public float SlowdownCap => _slowdownCap;
|
[ViewVariables] public float SlowdownCap => _slowdownCap;
|
||||||
@@ -79,7 +67,8 @@ namespace Content.Server.GameObjects.Components.Mobs
|
|||||||
serializer.DataField(ref _slowdownCap, "slowdownCap", 20f);
|
serializer.DataField(ref _slowdownCap, "slowdownCap", 20f);
|
||||||
serializer.DataField(ref _helpInterval, "helpInterval", 1f);
|
serializer.DataField(ref _helpInterval, "helpInterval", 1f);
|
||||||
serializer.DataField(ref _helpKnockdownRemove, "helpKnockdownRemove", 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>
|
/// <summary>
|
||||||
@@ -99,6 +88,7 @@ namespace Content.Server.GameObjects.Components.Mobs
|
|||||||
_lastStun = _gameTiming.CurTime;
|
_lastStun = _gameTiming.CurTime;
|
||||||
|
|
||||||
SetStatusEffect();
|
SetStatusEffect();
|
||||||
|
Dirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -118,6 +108,7 @@ namespace Content.Server.GameObjects.Components.Mobs
|
|||||||
_lastStun = _gameTiming.CurTime;
|
_lastStun = _gameTiming.CurTime;
|
||||||
|
|
||||||
SetStatusEffect();
|
SetStatusEffect();
|
||||||
|
Dirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -143,8 +134,8 @@ namespace Content.Server.GameObjects.Components.Mobs
|
|||||||
if (seconds <= 0f)
|
if (seconds <= 0f)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
_walkModifierOverride = walkModifierOverride;
|
WalkModifierOverride = walkModifierOverride;
|
||||||
_runModifierOverride = runModifierOverride;
|
RunModifierOverride = runModifierOverride;
|
||||||
|
|
||||||
_slowdownTimer = seconds;
|
_slowdownTimer = seconds;
|
||||||
_lastStun = _gameTiming.CurTime;
|
_lastStun = _gameTiming.CurTime;
|
||||||
@@ -153,6 +144,7 @@ namespace Content.Server.GameObjects.Components.Mobs
|
|||||||
movement.RefreshMovementSpeedModifiers();
|
movement.RefreshMovementSpeedModifiers();
|
||||||
|
|
||||||
SetStatusEffect();
|
SetStatusEffect();
|
||||||
|
Dirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -162,6 +154,7 @@ namespace Content.Server.GameObjects.Components.Mobs
|
|||||||
{
|
{
|
||||||
_knockdownTimer = 0f;
|
_knockdownTimer = 0f;
|
||||||
_stunnedTimer = 0f;
|
_stunnedTimer = 0f;
|
||||||
|
Dirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool InteractHand(InteractHandEventArgs eventArgs)
|
public bool InteractHand(InteractHandEventArgs eventArgs)
|
||||||
@@ -179,6 +172,7 @@ namespace Content.Server.GameObjects.Components.Mobs
|
|||||||
|
|
||||||
SetStatusEffect();
|
SetStatusEffect();
|
||||||
|
|
||||||
|
Dirty();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,7 +181,8 @@ namespace Content.Server.GameObjects.Components.Mobs
|
|||||||
if (!Owner.TryGetComponent(out ServerStatusEffectsComponent status))
|
if (!Owner.TryGetComponent(out ServerStatusEffectsComponent status))
|
||||||
return;
|
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.Cancel();
|
||||||
_statusRemoveCancellation = new CancellationTokenSource();
|
_statusRemoveCancellation = new CancellationTokenSource();
|
||||||
}
|
}
|
||||||
@@ -201,6 +196,7 @@ namespace Content.Server.GameObjects.Components.Mobs
|
|||||||
if (_stunnedTimer <= 0)
|
if (_stunnedTimer <= 0)
|
||||||
{
|
{
|
||||||
_stunnedTimer = 0f;
|
_stunnedTimer = 0f;
|
||||||
|
Dirty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -213,6 +209,7 @@ namespace Content.Server.GameObjects.Components.Mobs
|
|||||||
StandingStateHelper.Standing(Owner);
|
StandingStateHelper.Standing(Owner);
|
||||||
|
|
||||||
_knockdownTimer = 0f;
|
_knockdownTimer = 0f;
|
||||||
|
Dirty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -226,10 +223,12 @@ namespace Content.Server.GameObjects.Components.Mobs
|
|||||||
|
|
||||||
if (Owner.TryGetComponent(out MovementSpeedModifierComponent movement))
|
if (Owner.TryGetComponent(out MovementSpeedModifierComponent movement))
|
||||||
movement.RefreshMovementSpeedModifiers();
|
movement.RefreshMovementSpeedModifiers();
|
||||||
|
Dirty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!StunStart.HasValue || !StunEnd.HasValue || !Owner.TryGetComponent(out ServerStatusEffectsComponent status))
|
if (!StunStart.HasValue || !StunEnd.HasValue ||
|
||||||
|
!Owner.TryGetComponent(out ServerStatusEffectsComponent status))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
var start = StunStart.Value;
|
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
|
public float StunTimeModifier
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
@@ -318,8 +292,11 @@ namespace Content.Server.GameObjects.Components.Mobs
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public float WalkSpeedModifier => (SlowedDown ? (_walkModifierOverride <= 0f ? 0.5f : _walkModifierOverride) : 1f);
|
public override ComponentState GetComponentState()
|
||||||
public float SprintSpeedModifier => (SlowedDown ? (_runModifierOverride <= 0f ? 0.5f : _runModifierOverride) : 1f);
|
{
|
||||||
|
return new StunnableComponentState(Stunned, KnockedDown, SlowedDown, WalkModifierOverride,
|
||||||
|
RunModifierOverride);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -1,6 +1,4 @@
|
|||||||
using Content.Server.AI.Utility;
|
using Content.Shared.GameObjects.Components.Movement;
|
||||||
using Content.Server.AI.Utility.AiLogic;
|
|
||||||
using Content.Server.Interfaces.GameObjects.Components.Movement;
|
|
||||||
using Robust.Server.AI;
|
using Robust.Server.AI;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
@@ -111,7 +109,7 @@ namespace Content.Server.GameObjects.Components.Movement
|
|||||||
/// Is the entity Sprinting (running)?
|
/// Is the entity Sprinting (running)?
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public bool Sprinting { get; set; } = true;
|
public bool Sprinting { get; } = true;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Calculated linear velocity direction of the entity.
|
/// Calculated linear velocity direction of the entity.
|
||||||
@@ -119,11 +117,14 @@ namespace Content.Server.GameObjects.Components.Movement
|
|||||||
[ViewVariables]
|
[ViewVariables]
|
||||||
public Vector2 VelocityDir { get; set; }
|
public Vector2 VelocityDir { get; set; }
|
||||||
|
|
||||||
|
(Vector2 walking, Vector2 sprinting) IMoverComponent.VelocityDir =>
|
||||||
|
Sprinting ? (Vector2.Zero, VelocityDir) : (VelocityDir, Vector2.Zero);
|
||||||
|
|
||||||
public GridCoordinates LastPosition { get; set; }
|
public GridCoordinates LastPosition { get; set; }
|
||||||
|
|
||||||
[ViewVariables(VVAccess.ReadWrite)]
|
[ViewVariables(VVAccess.ReadWrite)] public float StepSoundDistance { get; set; }
|
||||||
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,17 +1,11 @@
|
|||||||
|
using Content.Shared.GameObjects.Components.Movement;
|
||||||
using Content.Server.Interfaces.GameObjects.Components.Movement;
|
|
||||||
using Robust.Server.GameObjects;
|
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.GameObjects.Components;
|
using Robust.Shared.GameObjects.Components;
|
||||||
using Robust.Shared.Log;
|
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.Maths;
|
|
||||||
using Robust.Shared.Physics;
|
using Robust.Shared.Physics;
|
||||||
using Robust.Shared.Serialization;
|
|
||||||
using Robust.Shared.ViewVariables;
|
using Robust.Shared.ViewVariables;
|
||||||
using Robust.Shared.IoC;
|
|
||||||
using Robust.Shared.Interfaces.Configuration;
|
#nullable enable
|
||||||
using Robust.Shared.Configuration;
|
|
||||||
|
|
||||||
namespace Content.Server.GameObjects.Components.Movement
|
namespace Content.Server.GameObjects.Components.Movement
|
||||||
{
|
{
|
||||||
@@ -20,138 +14,11 @@ namespace Content.Server.GameObjects.Components.Movement
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
[ComponentReference(typeof(IMoverComponent))]
|
[ComponentReference(typeof(IMoverComponent))]
|
||||||
public class PlayerInputMoverComponent : Component, IMoverComponent, ICollideSpecial
|
public class PlayerInputMoverComponent : SharedPlayerInputMoverComponent, IMoverComponent, ICollideSpecial
|
||||||
{
|
{
|
||||||
#pragma warning disable 649
|
public override GridCoordinates LastPosition { get; set; }
|
||||||
[Dependency] private readonly IConfigurationManager _configurationManager;
|
|
||||||
#pragma warning restore 649
|
|
||||||
|
|
||||||
private bool _movingUp;
|
public override float StepSoundDistance { get; set; }
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Special collision override, can be used to give custom behaviors deciding when to collide
|
/// 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;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
using Content.Server.GameObjects.Components.Mobs;
|
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;
|
||||||
using Robust.Server.GameObjects.Components.Container;
|
using Robust.Server.GameObjects.Components.Container;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
@@ -44,11 +44,11 @@ namespace Content.Server.GameObjects.Components.Movement
|
|||||||
public float GrabRange => 0.0f;
|
public float GrabRange => 0.0f;
|
||||||
|
|
||||||
public bool Sprinting { get; set; }
|
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 GridCoordinates LastPosition { get; set; }
|
||||||
public float StepSoundDistance { 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;
|
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)
|
private Vector2 CalcNewVelocity(Direction direction, bool enabled)
|
||||||
{
|
{
|
||||||
switch (direction)
|
switch (direction)
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ using Content.Server.GameObjects.Components.Mobs;
|
|||||||
using Content.Server.GameObjects.Components.Movement;
|
using Content.Server.GameObjects.Components.Movement;
|
||||||
using Content.Shared.GameObjects;
|
using Content.Shared.GameObjects;
|
||||||
using Content.Shared.GameObjects.Components.Mobs;
|
using Content.Shared.GameObjects.Components.Mobs;
|
||||||
|
using Content.Shared.GameObjects.Components.Movement;
|
||||||
|
using Content.Shared.GameObjects.Components.Nutrition;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.Interfaces.Random;
|
using Robust.Shared.Interfaces.Random;
|
||||||
@@ -15,14 +17,12 @@ using Robust.Shared.ViewVariables;
|
|||||||
namespace Content.Server.GameObjects.Components.Nutrition
|
namespace Content.Server.GameObjects.Components.Nutrition
|
||||||
{
|
{
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public sealed class HungerComponent : Component, IMoveSpeedModifier
|
public sealed class HungerComponent : SharedHungerComponent
|
||||||
{
|
{
|
||||||
#pragma warning disable 649
|
#pragma warning disable 649
|
||||||
[Dependency] private readonly IRobustRandom _random;
|
[Dependency] private readonly IRobustRandom _random;
|
||||||
#pragma warning restore 649
|
#pragma warning restore 649
|
||||||
|
|
||||||
public override string Name => "Hunger";
|
|
||||||
|
|
||||||
// Base stuff
|
// Base stuff
|
||||||
public float BaseDecayRate => _baseDecayRate;
|
public float BaseDecayRate => _baseDecayRate;
|
||||||
[ViewVariables] private float _baseDecayRate;
|
[ViewVariables] private float _baseDecayRate;
|
||||||
@@ -30,7 +30,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
|||||||
[ViewVariables] private float _actualDecayRate;
|
[ViewVariables] private float _actualDecayRate;
|
||||||
|
|
||||||
// Hunger
|
// Hunger
|
||||||
public HungerThreshold CurrentHungerThreshold => _currentHungerThreshold;
|
public override HungerThreshold CurrentHungerThreshold => _currentHungerThreshold;
|
||||||
private HungerThreshold _currentHungerThreshold;
|
private HungerThreshold _currentHungerThreshold;
|
||||||
private HungerThreshold _lastHungerThreshold;
|
private HungerThreshold _lastHungerThreshold;
|
||||||
public float CurrentHunger => _currentHunger;
|
public float CurrentHunger => _currentHunger;
|
||||||
@@ -127,6 +127,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
|||||||
_currentHungerThreshold = GetHungerThreshold(_currentHunger);
|
_currentHungerThreshold = GetHungerThreshold(_currentHunger);
|
||||||
_lastHungerThreshold = HungerThreshold.Okay; // TODO: Potentially change this -> Used Okay because no effects.
|
_lastHungerThreshold = HungerThreshold.Okay; // TODO: Potentially change this -> Used Okay because no effects.
|
||||||
HungerThresholdEffect(true);
|
HungerThresholdEffect(true);
|
||||||
|
Dirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public HungerThreshold GetHungerThreshold(float food)
|
public HungerThreshold GetHungerThreshold(float food)
|
||||||
@@ -161,6 +162,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
|||||||
{
|
{
|
||||||
_currentHungerThreshold = calculatedHungerThreshold;
|
_currentHungerThreshold = calculatedHungerThreshold;
|
||||||
HungerThresholdEffect();
|
HungerThresholdEffect();
|
||||||
|
Dirty();
|
||||||
}
|
}
|
||||||
if (_currentHungerThreshold == HungerThreshold.Dead)
|
if (_currentHungerThreshold == HungerThreshold.Dead)
|
||||||
{
|
{
|
||||||
@@ -179,36 +181,11 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
|||||||
_currentHunger = HungerThresholds[HungerThreshold.Okay];
|
_currentHunger = HungerThresholds[HungerThreshold.Okay];
|
||||||
}
|
}
|
||||||
|
|
||||||
float IMoveSpeedModifier.WalkSpeedModifier
|
public override ComponentState GetComponentState()
|
||||||
{
|
{
|
||||||
get
|
return new HungerComponentState(_currentHungerThreshold);
|
||||||
{
|
|
||||||
if (_currentHungerThreshold == HungerThreshold.Starving)
|
|
||||||
{
|
|
||||||
return 0.5f;
|
|
||||||
}
|
|
||||||
return 1.0f;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
float IMoveSpeedModifier.SprintSpeedModifier
|
|
||||||
{
|
|
||||||
get
|
|
||||||
{
|
|
||||||
if (_currentHungerThreshold == HungerThreshold.Starving)
|
|
||||||
{
|
|
||||||
return 0.5f;
|
|
||||||
}
|
|
||||||
return 1.0f;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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.Server.GameObjects.Components.Movement;
|
||||||
using Content.Shared.GameObjects;
|
using Content.Shared.GameObjects;
|
||||||
using Content.Shared.GameObjects.Components.Mobs;
|
using Content.Shared.GameObjects.Components.Mobs;
|
||||||
|
using Content.Shared.GameObjects.Components.Movement;
|
||||||
|
using Content.Shared.GameObjects.Components.Nutrition;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.Interfaces.Random;
|
using Robust.Shared.Interfaces.Random;
|
||||||
@@ -15,14 +17,12 @@ using Robust.Shared.ViewVariables;
|
|||||||
namespace Content.Server.GameObjects.Components.Nutrition
|
namespace Content.Server.GameObjects.Components.Nutrition
|
||||||
{
|
{
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public sealed class ThirstComponent : Component, IMoveSpeedModifier
|
public sealed class ThirstComponent : SharedThirstComponent, IMoveSpeedModifier
|
||||||
{
|
{
|
||||||
#pragma warning disable 649
|
#pragma warning disable 649
|
||||||
[Dependency] private readonly IRobustRandom _random;
|
[Dependency] private readonly IRobustRandom _random;
|
||||||
#pragma warning restore 649
|
#pragma warning restore 649
|
||||||
|
|
||||||
public override string Name => "Thirst";
|
|
||||||
|
|
||||||
// Base stuff
|
// Base stuff
|
||||||
public float BaseDecayRate => _baseDecayRate;
|
public float BaseDecayRate => _baseDecayRate;
|
||||||
[ViewVariables] private float _baseDecayRate;
|
[ViewVariables] private float _baseDecayRate;
|
||||||
@@ -30,7 +30,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
|||||||
[ViewVariables] private float _actualDecayRate;
|
[ViewVariables] private float _actualDecayRate;
|
||||||
|
|
||||||
// Thirst
|
// Thirst
|
||||||
public ThirstThreshold CurrentThirstThreshold => _currentThirstThreshold;
|
public override ThirstThreshold CurrentThirstThreshold => _currentThirstThreshold;
|
||||||
private ThirstThreshold _currentThirstThreshold;
|
private ThirstThreshold _currentThirstThreshold;
|
||||||
private ThirstThreshold _lastThirstThreshold;
|
private ThirstThreshold _lastThirstThreshold;
|
||||||
public float CurrentThirst => _currentThirst;
|
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.
|
_lastThirstThreshold = ThirstThreshold.Okay; // TODO: Potentially change this -> Used Okay because no effects.
|
||||||
// TODO: Check all thresholds make sense and throw if they don't.
|
// TODO: Check all thresholds make sense and throw if they don't.
|
||||||
ThirstThresholdEffect(true);
|
ThirstThresholdEffect(true);
|
||||||
|
Dirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public ThirstThreshold GetThirstThreshold(float drink)
|
public ThirstThreshold GetThirstThreshold(float drink)
|
||||||
@@ -160,6 +161,7 @@ namespace Content.Server.GameObjects.Components.Nutrition
|
|||||||
{
|
{
|
||||||
_currentThirstThreshold = calculatedThirstThreshold;
|
_currentThirstThreshold = calculatedThirstThreshold;
|
||||||
ThirstThresholdEffect();
|
ThirstThresholdEffect();
|
||||||
|
Dirty();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_currentThirstThreshold == ThirstThreshold.Dead)
|
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()
|
public void ResetThirst()
|
||||||
{
|
{
|
||||||
_currentThirst = ThirstThresholds[ThirstThreshold.Okay];
|
_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.GameObjects.EntitySystems;
|
||||||
using Content.Server.Players;
|
using Content.Server.Players;
|
||||||
using Content.Shared.GameObjects.Components.Observer;
|
using Content.Shared.GameObjects.Components.Observer;
|
||||||
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Server.GameObjects.Components;
|
using Robust.Server.GameObjects.Components;
|
||||||
using Robust.Server.Interfaces.GameObjects;
|
using Robust.Server.Interfaces.GameObjects;
|
||||||
@@ -15,7 +16,7 @@ using Timer = Robust.Shared.Timers.Timer;
|
|||||||
namespace Content.Server.GameObjects.Components.Observer
|
namespace Content.Server.GameObjects.Components.Observer
|
||||||
{
|
{
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public class GhostComponent : SharedGhostComponent, IActionBlocker
|
public class GhostComponent : SharedGhostComponent
|
||||||
{
|
{
|
||||||
private bool _canReturnToBody = true;
|
private bool _canReturnToBody = true;
|
||||||
|
|
||||||
@@ -75,13 +76,5 @@ namespace Content.Server.GameObjects.Components.Observer
|
|||||||
break;
|
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 System;
|
||||||
using Content.Server.GameObjects.Components.Mobs;
|
using Content.Server.GameObjects.Components.Mobs;
|
||||||
using Content.Server.GameObjects.EntitySystems;
|
|
||||||
using Content.Server.GameObjects.Components.Movement;
|
using Content.Server.GameObjects.Components.Movement;
|
||||||
using Content.Shared.GameObjects.Components.Weapons.Ranged;
|
using Content.Shared.GameObjects.Components.Weapons.Ranged;
|
||||||
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.Interfaces.GameObjects;
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
using Robust.Shared.Interfaces.Network;
|
using Robust.Shared.Interfaces.Network;
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using Content.Server.AI.Utility.AiLogic;
|
using Content.Server.AI.Utility.AiLogic;
|
||||||
using Content.Server.GameObjects.Components.Movement;
|
using Content.Server.GameObjects.Components.Movement;
|
||||||
using Content.Server.Interfaces.GameObjects.Components.Movement;
|
using Content.Shared.GameObjects.Components.Movement;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Server.AI;
|
using Robust.Server.AI;
|
||||||
using Robust.Server.Interfaces.Console;
|
using Robust.Server.Interfaces.Console;
|
||||||
|
|||||||
@@ -2,56 +2,43 @@
|
|||||||
using Content.Server.GameObjects.Components.Mobs;
|
using Content.Server.GameObjects.Components.Mobs;
|
||||||
using Content.Server.GameObjects.Components.Movement;
|
using Content.Server.GameObjects.Components.Movement;
|
||||||
using Content.Server.GameObjects.Components.Sound;
|
using Content.Server.GameObjects.Components.Sound;
|
||||||
using Content.Server.Interfaces.GameObjects.Components.Movement;
|
|
||||||
using Content.Shared.Audio;
|
using Content.Shared.Audio;
|
||||||
using Content.Shared.GameObjects.Components.Inventory;
|
using Content.Shared.GameObjects.Components.Inventory;
|
||||||
using Content.Shared.GameObjects.Components.Movement;
|
using Content.Shared.GameObjects.Components.Movement;
|
||||||
using Content.Shared.Input;
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
using Content.Shared.Maps;
|
using Content.Shared.Maps;
|
||||||
using Content.Shared.Physics;
|
using Content.Shared.Physics;
|
||||||
using JetBrains.Annotations;
|
using JetBrains.Annotations;
|
||||||
using Robust.Server.GameObjects;
|
using Robust.Server.GameObjects;
|
||||||
using Robust.Server.GameObjects.EntitySystems;
|
using Robust.Server.GameObjects.EntitySystems;
|
||||||
using Robust.Server.Interfaces.Player;
|
|
||||||
using Robust.Server.Interfaces.Timing;
|
using Robust.Server.Interfaces.Timing;
|
||||||
using Robust.Shared.Configuration;
|
|
||||||
using Robust.Shared.GameObjects;
|
|
||||||
using Robust.Shared.GameObjects.Components;
|
using Robust.Shared.GameObjects.Components;
|
||||||
using Robust.Shared.GameObjects.Components.Transform;
|
using Robust.Shared.GameObjects.Components.Transform;
|
||||||
using Robust.Shared.GameObjects.Systems;
|
|
||||||
using Robust.Shared.Input;
|
|
||||||
using Robust.Shared.Input.Binding;
|
|
||||||
using Robust.Shared.Interfaces.Configuration;
|
|
||||||
using Robust.Shared.Interfaces.GameObjects;
|
|
||||||
using Robust.Shared.Interfaces.GameObjects.Components;
|
|
||||||
using Robust.Shared.Interfaces.Map;
|
using Robust.Shared.Interfaces.Map;
|
||||||
using Robust.Shared.Interfaces.Physics;
|
|
||||||
using Robust.Shared.Interfaces.Random;
|
using Robust.Shared.Interfaces.Random;
|
||||||
using Robust.Shared.IoC;
|
using Robust.Shared.IoC;
|
||||||
using Robust.Shared.Log;
|
using Robust.Shared.Log;
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.Maths;
|
using Robust.Shared.Physics;
|
||||||
using Robust.Shared.Players;
|
|
||||||
using Robust.Shared.Prototypes;
|
using Robust.Shared.Prototypes;
|
||||||
using Robust.Shared.Random;
|
using Robust.Shared.Random;
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
namespace Content.Server.GameObjects.EntitySystems
|
namespace Content.Server.GameObjects.EntitySystems
|
||||||
{
|
{
|
||||||
[UsedImplicitly]
|
[UsedImplicitly]
|
||||||
internal class MoverSystem : EntitySystem
|
internal class MoverSystem : SharedMoverSystem
|
||||||
{
|
{
|
||||||
#pragma warning disable 649
|
#pragma warning disable 649
|
||||||
[Dependency] private readonly IPauseManager _pauseManager;
|
[Dependency] private readonly IPauseManager _pauseManager = default!;
|
||||||
[Dependency] private readonly IPrototypeManager _prototypeManager;
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||||
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager;
|
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
|
||||||
[Dependency] private readonly IMapManager _mapManager;
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||||
[Dependency] private readonly IRobustRandom _robustRandom;
|
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
||||||
[Dependency] private readonly IConfigurationManager _configurationManager;
|
|
||||||
[Dependency] private readonly IEntityManager _entityManager;
|
|
||||||
[Dependency] private readonly IPhysicsManager _physicsManager;
|
|
||||||
#pragma warning restore 649
|
#pragma warning restore 649
|
||||||
|
|
||||||
private AudioSystem _audioSystem;
|
private AudioSystem _audioSystem = default!;
|
||||||
|
|
||||||
private const float StepSoundMoveDistanceRunning = 2;
|
private const float StepSoundMoveDistanceRunning = 2;
|
||||||
private const float StepSoundMoveDistanceWalking = 1.5f;
|
private const float StepSoundMoveDistanceWalking = 1.5f;
|
||||||
@@ -59,40 +46,41 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void Initialize()
|
public override void Initialize()
|
||||||
{
|
{
|
||||||
EntityQuery = new TypeEntityQuery(typeof(IMoverComponent));
|
base.Initialize();
|
||||||
|
|
||||||
var moveUpCmdHandler = InputCmdHandler.FromDelegate(
|
|
||||||
session => HandleDirChange(session, Direction.North, true),
|
|
||||||
session => HandleDirChange(session, Direction.North, false));
|
|
||||||
var moveLeftCmdHandler = InputCmdHandler.FromDelegate(
|
|
||||||
session => HandleDirChange(session, Direction.West, true),
|
|
||||||
session => HandleDirChange(session, Direction.West, false));
|
|
||||||
var moveRightCmdHandler = InputCmdHandler.FromDelegate(
|
|
||||||
session => HandleDirChange(session, Direction.East, true),
|
|
||||||
session => HandleDirChange(session, Direction.East, false));
|
|
||||||
var moveDownCmdHandler = InputCmdHandler.FromDelegate(
|
|
||||||
session => HandleDirChange(session, Direction.South, true),
|
|
||||||
session => HandleDirChange(session, Direction.South, false));
|
|
||||||
var runCmdHandler = InputCmdHandler.FromDelegate(
|
|
||||||
session => HandleRunChange(session, false),
|
|
||||||
session => HandleRunChange(session, true));
|
|
||||||
|
|
||||||
var input = EntitySystemManager.GetEntitySystem<InputSystem>();
|
|
||||||
|
|
||||||
CommandBinds.Builder
|
|
||||||
.Bind(EngineKeyFunctions.MoveUp, moveUpCmdHandler)
|
|
||||||
.Bind(EngineKeyFunctions.MoveLeft, moveLeftCmdHandler)
|
|
||||||
.Bind(EngineKeyFunctions.MoveRight, moveRightCmdHandler)
|
|
||||||
.Bind(EngineKeyFunctions.MoveDown, moveDownCmdHandler)
|
|
||||||
.Bind(EngineKeyFunctions.Run, runCmdHandler)
|
|
||||||
.Register<MoverSystem>();
|
|
||||||
|
|
||||||
SubscribeLocalEvent<PlayerAttachSystemMessage>(PlayerAttached);
|
SubscribeLocalEvent<PlayerAttachSystemMessage>(PlayerAttached);
|
||||||
SubscribeLocalEvent<PlayerDetachedSystemMessage>(PlayerDetached);
|
SubscribeLocalEvent<PlayerDetachedSystemMessage>(PlayerDetached);
|
||||||
|
|
||||||
_audioSystem = EntitySystemManager.GetEntitySystem<AudioSystem>();
|
_audioSystem = EntitySystemManager.GetEntitySystem<AudioSystem>();
|
||||||
|
|
||||||
_configurationManager.RegisterCVar("game.diagonalmovement", true, CVar.ARCHIVE);
|
UpdatesBefore.Add(typeof(PhysicsSystem));
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void Update(float frameTime)
|
||||||
|
{
|
||||||
|
foreach (var entity in RelevantEntities)
|
||||||
|
{
|
||||||
|
if (_pauseManager.IsEntityPaused(entity))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var mover = entity.GetComponent<IMoverComponent>();
|
||||||
|
var physics = entity.GetComponent<SharedPhysicsComponent>();
|
||||||
|
if (entity.TryGetComponent<CollidableComponent>(out var collider))
|
||||||
|
{
|
||||||
|
UpdateKinematics(entity.Transform, mover, physics, collider);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
UpdateKinematics(entity.Transform, mover, physics);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void SetController(SharedPhysicsComponent physics)
|
||||||
|
{
|
||||||
|
((PhysicsComponent) physics).SetController<MoverController>();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void PlayerAttached(PlayerAttachSystemMessage ev)
|
private static void PlayerAttached(PlayerAttachSystemMessage ev)
|
||||||
@@ -111,73 +99,9 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
protected override void HandleFootsteps(IMoverComponent mover)
|
||||||
public override void Shutdown()
|
|
||||||
{
|
{
|
||||||
CommandBinds.Unregister<MoverSystem>();
|
var transform = mover.Owner.Transform;
|
||||||
base.Shutdown();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
|
||||||
public override void Update(float frameTime)
|
|
||||||
{
|
|
||||||
foreach (var entity in RelevantEntities)
|
|
||||||
{
|
|
||||||
if (_pauseManager.IsEntityPaused(entity))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
var mover = entity.GetComponent<IMoverComponent>();
|
|
||||||
var physics = entity.GetComponent<PhysicsComponent>();
|
|
||||||
if (entity.TryGetComponent<CollidableComponent>(out var collider))
|
|
||||||
{
|
|
||||||
UpdateKinematics(entity.Transform, mover, physics, collider);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
UpdateKinematics(entity.Transform, mover, physics);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void UpdateKinematics(ITransformComponent transform, IMoverComponent mover, PhysicsComponent physics, CollidableComponent collider = null)
|
|
||||||
{
|
|
||||||
if (physics.Controller == null)
|
|
||||||
{
|
|
||||||
// Set up controller
|
|
||||||
physics.SetController<MoverController>();
|
|
||||||
}
|
|
||||||
|
|
||||||
var weightless = !transform.Owner.HasComponent<MovementIgnoreGravityComponent>() &&
|
|
||||||
_physicsManager.IsWeightless(transform.GridPosition);
|
|
||||||
|
|
||||||
if (weightless && collider != null)
|
|
||||||
{
|
|
||||||
// No gravity: is our entity touching anything?
|
|
||||||
var touching = IsAroundCollider(transform, mover, collider);
|
|
||||||
|
|
||||||
if (!touching)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mover.VelocityDir.LengthSquared < 0.001 || !ActionBlockerSystem.CanMove(mover.Owner) && !weightless)
|
|
||||||
{
|
|
||||||
(physics.Controller as MoverController)?.StopMoving();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (weightless)
|
|
||||||
{
|
|
||||||
(physics.Controller as MoverController)?.Push(mover.VelocityDir, mover.CurrentPushSpeed);
|
|
||||||
transform.LocalRotation = mover.VelocityDir.GetDir().ToAngle();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
(physics.Controller as MoverController)?.Move(mover.VelocityDir,
|
|
||||||
mover.Sprinting ? mover.CurrentSprintSpeed : mover.CurrentWalkSpeed);
|
|
||||||
transform.LocalRotation = mover.VelocityDir.GetDir().ToAngle();
|
|
||||||
|
|
||||||
// Handle footsteps.
|
// Handle footsteps.
|
||||||
if (_mapManager.GridExists(mover.LastPosition.GridID))
|
if (_mapManager.GridExists(mover.LastPosition.GridID))
|
||||||
{
|
{
|
||||||
@@ -196,6 +120,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
{
|
{
|
||||||
distanceNeeded = StepSoundMoveDistanceWalking;
|
distanceNeeded = StepSoundMoveDistanceWalking;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mover.StepSoundDistance > distanceNeeded)
|
if (mover.StepSoundDistance > distanceNeeded)
|
||||||
{
|
{
|
||||||
mover.StepSoundDistance = 0;
|
mover.StepSoundDistance = 0;
|
||||||
@@ -217,78 +142,6 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private bool IsAroundCollider(ITransformComponent transform, IMoverComponent mover, CollidableComponent collider)
|
|
||||||
{
|
|
||||||
foreach (var entity in _entityManager.GetEntitiesInRange(transform.Owner, mover.GrabRange, true))
|
|
||||||
{
|
|
||||||
if (entity == transform.Owner)
|
|
||||||
{
|
|
||||||
continue; // Don't try to push off of yourself!
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!entity.TryGetComponent<CollidableComponent>(out var otherCollider))
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
var touching = ((collider.CollisionMask & otherCollider.CollisionLayer) != 0x0
|
|
||||||
|| (otherCollider.CollisionMask & collider.CollisionLayer) != 0x0) // Ensure collision
|
|
||||||
&& !entity.HasComponent<ItemComponent>(); // This can't be an item
|
|
||||||
|
|
||||||
if (touching)
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void HandleDirChange(ICommonSession session, Direction dir, bool state)
|
|
||||||
{
|
|
||||||
var playerSes = session as IPlayerSession;
|
|
||||||
if (!TryGetAttachedComponent(playerSes, out IMoverComponent moverComp))
|
|
||||||
return;
|
|
||||||
|
|
||||||
var owner = playerSes?.AttachedEntity;
|
|
||||||
|
|
||||||
if (owner != null)
|
|
||||||
{
|
|
||||||
foreach (var comp in owner.GetAllComponents<IRelayMoveInput>())
|
|
||||||
{
|
|
||||||
comp.MoveInputPressed(playerSes);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
moverComp.SetVelocityDirection(dir, state);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void HandleRunChange(ICommonSession session, bool running)
|
|
||||||
{
|
|
||||||
if (!TryGetAttachedComponent(session as IPlayerSession, out PlayerInputMoverComponent moverComp))
|
|
||||||
return;
|
|
||||||
|
|
||||||
moverComp.Sprinting = running;
|
|
||||||
}
|
|
||||||
|
|
||||||
private static bool TryGetAttachedComponent<T>(IPlayerSession session, out T component)
|
|
||||||
where T : IComponent
|
|
||||||
{
|
|
||||||
component = default;
|
|
||||||
|
|
||||||
var ent = session.AttachedEntity;
|
|
||||||
|
|
||||||
if (ent == null || !ent.IsValid())
|
|
||||||
return false;
|
|
||||||
|
|
||||||
if (!ent.TryGetComponent(out T comp))
|
|
||||||
return false;
|
|
||||||
|
|
||||||
component = comp;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void PlayFootstepSound(GridCoordinates coordinates)
|
private void PlayFootstepSound(GridCoordinates coordinates)
|
||||||
{
|
{
|
||||||
@@ -322,6 +175,7 @@ namespace Content.Server.GameObjects.EntitySystems
|
|||||||
// Nothing to play, oh well.
|
// Nothing to play, oh well.
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
soundCollectionName = def.FootstepSounds;
|
soundCollectionName = def.FootstepSounds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +0,0 @@
|
|||||||
using Robust.Server.Interfaces.Player;
|
|
||||||
|
|
||||||
namespace Content.Server.Interfaces.GameObjects.Components.Movement
|
|
||||||
{
|
|
||||||
public interface IRelayMoveInput
|
|
||||||
{
|
|
||||||
void MoveInputPressed(IPlayerSession session);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -83,7 +83,7 @@ namespace Content.Server.Throw
|
|||||||
physComp = thrownEnt.AddComponent<PhysicsComponent>();
|
physComp = thrownEnt.AddComponent<PhysicsComponent>();
|
||||||
|
|
||||||
var timing = IoCManager.Resolve<IGameTiming>();
|
var timing = IoCManager.Resolve<IGameTiming>();
|
||||||
var spd = throwForce / (1f / timing.TickRate); // acceleration is applied in 1 tick instead of 1 second, scale appropriately
|
var spd = throwForce * 60; // acceleration is applied in 1 tick instead of 1 second, scale appropriately
|
||||||
|
|
||||||
physComp.SetController<ThrowController>();
|
physComp.SetController<ThrowController>();
|
||||||
(physComp.Controller as ThrowController)?.StartThrow(angle.ToVec() * spd);
|
(physComp.Controller as ThrowController)?.StartThrow(angle.ToVec() * spd);
|
||||||
|
|||||||
@@ -0,0 +1,71 @@
|
|||||||
|
using System;
|
||||||
|
using Content.Shared.GameObjects.Components.Movement;
|
||||||
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Serialization;
|
||||||
|
using Robust.Shared.ViewVariables;
|
||||||
|
|
||||||
|
namespace Content.Shared.GameObjects.Components.Mobs
|
||||||
|
{
|
||||||
|
public abstract class SharedStunnableComponent : Component, IMoveSpeedModifier, IActionBlocker
|
||||||
|
{
|
||||||
|
public sealed override string Name => "Stunnable";
|
||||||
|
public override uint? NetID => ContentNetIDs.STUNNABLE;
|
||||||
|
|
||||||
|
[ViewVariables] protected float WalkModifierOverride = 0f;
|
||||||
|
[ViewVariables] protected float RunModifierOverride = 0f;
|
||||||
|
|
||||||
|
[ViewVariables] public abstract bool Stunned { get; }
|
||||||
|
[ViewVariables] public abstract bool KnockedDown { get; }
|
||||||
|
[ViewVariables] public abstract bool SlowedDown { get; }
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
||||||
|
[ViewVariables]
|
||||||
|
public float WalkSpeedModifier => (SlowedDown ? (WalkModifierOverride <= 0f ? 0.5f : WalkModifierOverride) : 1f);
|
||||||
|
[ViewVariables]
|
||||||
|
public float SprintSpeedModifier => (SlowedDown ? (RunModifierOverride <= 0f ? 0.5f : RunModifierOverride) : 1f);
|
||||||
|
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
protected sealed class StunnableComponentState : ComponentState
|
||||||
|
{
|
||||||
|
public bool Stunned { get; }
|
||||||
|
public bool KnockedDown { get; }
|
||||||
|
public bool SlowedDown { get; }
|
||||||
|
public float WalkModifierOverride { get; }
|
||||||
|
public float RunModifierOverride { get; }
|
||||||
|
|
||||||
|
public StunnableComponentState(bool stunned, bool knockedDown, bool slowedDown, float walkModifierOverride, float runModifierOverride) : base(ContentNetIDs.STUNNABLE)
|
||||||
|
{
|
||||||
|
Stunned = stunned;
|
||||||
|
KnockedDown = knockedDown;
|
||||||
|
SlowedDown = slowedDown;
|
||||||
|
WalkModifierOverride = walkModifierOverride;
|
||||||
|
RunModifierOverride = runModifierOverride;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
using Content.Server.GameObjects.Components.Movement;
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
using Robust.Shared.Interfaces.GameObjects;
|
|
||||||
using Robust.Shared.Map;
|
using Robust.Shared.Map;
|
||||||
using Robust.Shared.Maths;
|
using Robust.Shared.Maths;
|
||||||
|
|
||||||
namespace Content.Server.Interfaces.GameObjects.Components.Movement
|
namespace Content.Shared.GameObjects.Components.Movement
|
||||||
{
|
{
|
||||||
// Does nothing except ensure uniqueness between mover components.
|
// Does nothing except ensure uniqueness between mover components.
|
||||||
// There can only be one.
|
// There can only be one.
|
||||||
@@ -33,12 +32,12 @@ namespace Content.Server.Interfaces.GameObjects.Components.Movement
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Is the entity Sprinting (running)?
|
/// Is the entity Sprinting (running)?
|
||||||
/// </summary>
|
/// </summary>
|
||||||
bool Sprinting { get; set; }
|
bool Sprinting { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Calculated linear velocity direction of the entity.
|
/// Calculated linear velocity direction of the entity.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Vector2 VelocityDir { get; }
|
(Vector2 walking, Vector2 sprinting) VelocityDir { get; }
|
||||||
|
|
||||||
GridCoordinates LastPosition { get; set; }
|
GridCoordinates LastPosition { get; set; }
|
||||||
|
|
||||||
@@ -50,7 +49,11 @@ namespace Content.Server.Interfaces.GameObjects.Components.Movement
|
|||||||
/// opposite directions will cancel each other out, resulting in no direction.
|
/// opposite directions will cancel each other out, resulting in no direction.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="direction">Direction to toggle.</param>
|
/// <param name="direction">Direction to toggle.</param>
|
||||||
|
/// <param name="subTick"></param>
|
||||||
/// <param name="enabled">If the direction is active.</param>
|
/// <param name="enabled">If the direction is active.</param>
|
||||||
void SetVelocityDirection(Direction direction, bool enabled);
|
void SetVelocityDirection(Direction direction, ushort subTick, bool enabled);
|
||||||
|
|
||||||
|
void SetSprinting(ushort subTick, bool enabled);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
using Robust.Shared.Players;
|
||||||
|
|
||||||
|
namespace Content.Shared.GameObjects.Components.Movement
|
||||||
|
{
|
||||||
|
public interface IRelayMoveInput
|
||||||
|
{
|
||||||
|
void MoveInputPressed(ICommonSession session);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,8 @@
|
|||||||
|
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
using Robust.Shared.ViewVariables;
|
using Robust.Shared.ViewVariables;
|
||||||
|
|
||||||
namespace Content.Server.GameObjects.Components.Movement
|
namespace Content.Shared.GameObjects.Components.Movement
|
||||||
{
|
{
|
||||||
[RegisterComponent]
|
[RegisterComponent]
|
||||||
public class MovementSpeedModifierComponent : Component
|
public class MovementSpeedModifierComponent : Component
|
||||||
@@ -85,7 +84,7 @@ namespace Content.Server.GameObjects.Components.Movement
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
interface IMoveSpeedModifier
|
public interface IMoveSpeedModifier
|
||||||
{
|
{
|
||||||
float WalkSpeedModifier { get; }
|
float WalkSpeedModifier { get; }
|
||||||
float SprintSpeedModifier { get; }
|
float SprintSpeedModifier { get; }
|
||||||
@@ -0,0 +1,287 @@
|
|||||||
|
using System;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Interfaces.Configuration;
|
||||||
|
using Robust.Shared.Interfaces.Timing;
|
||||||
|
using Robust.Shared.IoC;
|
||||||
|
using Robust.Shared.Log;
|
||||||
|
using Robust.Shared.Map;
|
||||||
|
using Robust.Shared.Maths;
|
||||||
|
using Robust.Shared.Physics;
|
||||||
|
using Robust.Shared.Serialization;
|
||||||
|
using Robust.Shared.Timing;
|
||||||
|
using Robust.Shared.ViewVariables;
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
|
namespace Content.Shared.GameObjects.Components.Movement
|
||||||
|
{
|
||||||
|
public abstract class SharedPlayerInputMoverComponent : Component, IMoverComponent
|
||||||
|
{
|
||||||
|
// This class has to be able to handle server TPS being lower than client FPS.
|
||||||
|
// While still having perfectly responsive movement client side.
|
||||||
|
// We do this by keeping track of the exact sub-tick values that inputs are pressed on the client,
|
||||||
|
// and then building a total movement vector based on those sub-tick steps.
|
||||||
|
//
|
||||||
|
// We keep track of the last sub-tick a movement input came in,
|
||||||
|
// Then when a new input comes in, we calculate the fraction of the tick the LAST input was active for
|
||||||
|
// (new sub-tick - last sub-tick)
|
||||||
|
// and then add to the total-this-tick movement vector
|
||||||
|
// by multiplying that fraction by the movement direction for the last input.
|
||||||
|
// This allows us to incrementally build the movement vector for the current tick,
|
||||||
|
// without having to keep track of some kind of list of inputs and calculating it later.
|
||||||
|
//
|
||||||
|
// We have to keep track of a separate movement vector for walking and sprinting,
|
||||||
|
// since we don't actually know our current movement speed while processing inputs.
|
||||||
|
// We change which vector we write into based on whether we were sprinting after the previous input.
|
||||||
|
// (well maybe we do but the code is designed such that MoverSystem applies movement speed)
|
||||||
|
// (and I'm not changing that)
|
||||||
|
|
||||||
|
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
|
||||||
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
||||||
|
|
||||||
|
public sealed override string Name => "PlayerInputMover";
|
||||||
|
public sealed override uint? NetID => ContentNetIDs.PLAYER_INPUT_MOVER;
|
||||||
|
|
||||||
|
private GameTick _lastInputTick;
|
||||||
|
private ushort _lastInputSubTick;
|
||||||
|
private Vector2 _curTickWalkMovement;
|
||||||
|
private Vector2 _curTickSprintMovement;
|
||||||
|
|
||||||
|
private MoveButtons _heldMoveButtons = MoveButtons.None;
|
||||||
|
|
||||||
|
public float CurrentWalkSpeed
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (Owner.TryGetComponent(out MovementSpeedModifierComponent component))
|
||||||
|
{
|
||||||
|
return component.CurrentWalkSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MovementSpeedModifierComponent.DefaultBaseWalkSpeed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public float CurrentSprintSpeed
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (Owner.TryGetComponent(out MovementSpeedModifierComponent component))
|
||||||
|
{
|
||||||
|
return component.CurrentSprintSpeed;
|
||||||
|
}
|
||||||
|
|
||||||
|
return MovementSpeedModifierComponent.DefaultBaseSprintSpeed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public float CurrentPushSpeed => 5;
|
||||||
|
public float GrabRange => 0.2f;
|
||||||
|
public bool Sprinting => !_heldMoveButtons.HasFlag(MoveButtons.Sprint);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Calculated linear velocity direction of the entity.
|
||||||
|
/// </summary>
|
||||||
|
[ViewVariables]
|
||||||
|
public (Vector2 walking, Vector2 sprinting) VelocityDir
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (!_gameTiming.InSimulation)
|
||||||
|
{
|
||||||
|
// Outside of simulation we'll be running client predicted movement per-frame.
|
||||||
|
// So return a full-length vector as if it's a full tick.
|
||||||
|
// Physics system will have the correct time step anyways.
|
||||||
|
var immediateDir = DirVecForButtons(_heldMoveButtons);
|
||||||
|
return Sprinting ? (Vector2.Zero, immediateDir) : (immediateDir, Vector2.Zero);
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2 walk;
|
||||||
|
Vector2 sprint;
|
||||||
|
float remainingFraction;
|
||||||
|
|
||||||
|
if (_gameTiming.CurTick > _lastInputTick)
|
||||||
|
{
|
||||||
|
walk = Vector2.Zero;
|
||||||
|
sprint = Vector2.Zero;
|
||||||
|
remainingFraction = 1;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
walk = _curTickWalkMovement;
|
||||||
|
sprint = _curTickSprintMovement;
|
||||||
|
remainingFraction = (ushort.MaxValue - _lastInputSubTick) / (float) ushort.MaxValue;
|
||||||
|
}
|
||||||
|
|
||||||
|
var curDir = DirVecForButtons(_heldMoveButtons) * remainingFraction;
|
||||||
|
|
||||||
|
if (Sprinting)
|
||||||
|
{
|
||||||
|
sprint += curDir;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
walk += curDir;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Logger.Info($"{curDir}{walk}{sprint}");
|
||||||
|
return (walk, sprint);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract GridCoordinates LastPosition { get; set; }
|
||||||
|
public abstract 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<SharedPhysicsComponent>())
|
||||||
|
Logger.Error(
|
||||||
|
$"[ECS] {Owner.Prototype?.Name} - {nameof(SharedPlayerInputMoverComponent)} requires" +
|
||||||
|
$" {nameof(SharedPhysicsComponent)}. ");
|
||||||
|
|
||||||
|
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="subTick"></param>
|
||||||
|
/// <param name="enabled">If the direction is active.</param>
|
||||||
|
public void SetVelocityDirection(Direction direction, ushort subTick, bool enabled)
|
||||||
|
{
|
||||||
|
// Logger.Info($"[{_gameTiming.CurTick}/{subTick}] {direction}: {enabled}");
|
||||||
|
|
||||||
|
var bit = direction switch
|
||||||
|
{
|
||||||
|
Direction.East => MoveButtons.Right,
|
||||||
|
Direction.North => MoveButtons.Up,
|
||||||
|
Direction.West => MoveButtons.Left,
|
||||||
|
Direction.South => MoveButtons.Down,
|
||||||
|
_ => throw new ArgumentException(nameof(direction))
|
||||||
|
};
|
||||||
|
|
||||||
|
SetMoveInput(subTick, enabled, bit);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void SetMoveInput(ushort subTick, bool enabled, MoveButtons bit)
|
||||||
|
{
|
||||||
|
// Modifies held state of a movement button at a certain sub tick and updates current tick movement vectors.
|
||||||
|
|
||||||
|
if (_gameTiming.CurTick > _lastInputTick)
|
||||||
|
{
|
||||||
|
_curTickWalkMovement = Vector2.Zero;
|
||||||
|
_curTickSprintMovement = Vector2.Zero;
|
||||||
|
_lastInputTick = _gameTiming.CurTick;
|
||||||
|
_lastInputSubTick = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
var fraction = (subTick - _lastInputSubTick) / (float) ushort.MaxValue;
|
||||||
|
|
||||||
|
ref var lastMoveAmount = ref Sprinting ? ref _curTickSprintMovement : ref _curTickWalkMovement;
|
||||||
|
|
||||||
|
lastMoveAmount += DirVecForButtons(_heldMoveButtons) * fraction;
|
||||||
|
|
||||||
|
if (enabled)
|
||||||
|
{
|
||||||
|
_heldMoveButtons |= bit;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
_heldMoveButtons &= ~bit;
|
||||||
|
}
|
||||||
|
|
||||||
|
_lastInputSubTick = subTick;
|
||||||
|
|
||||||
|
Dirty();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetSprinting(ushort subTick, bool enabled)
|
||||||
|
{
|
||||||
|
// Logger.Info($"[{_gameTiming.CurTick}/{subTick}] Sprint: {enabled}");
|
||||||
|
|
||||||
|
SetMoveInput(subTick, enabled, MoveButtons.Sprint);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||||
|
{
|
||||||
|
if (curState is MoverComponentState state)
|
||||||
|
{
|
||||||
|
_heldMoveButtons = state.Buttons;
|
||||||
|
_lastInputTick = GameTick.Zero;
|
||||||
|
_lastInputSubTick = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public override ComponentState GetComponentState()
|
||||||
|
{
|
||||||
|
return new MoverComponentState(_heldMoveButtons);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Retrieves the normalized direction vector for a specified combination of movement keys.
|
||||||
|
/// </summary>
|
||||||
|
private Vector2 DirVecForButtons(MoveButtons buttons)
|
||||||
|
{
|
||||||
|
// 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 -= buttons.HasFlag(MoveButtons.Left) ? 1 : 0;
|
||||||
|
x += buttons.HasFlag(MoveButtons.Right) ? 1 : 0;
|
||||||
|
|
||||||
|
var y = 0;
|
||||||
|
if (DiagonalMovementEnabled || x == 0)
|
||||||
|
{
|
||||||
|
y -= buttons.HasFlag(MoveButtons.Down) ? 1 : 0;
|
||||||
|
y += buttons.HasFlag(MoveButtons.Up) ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
var vec = new Vector2(x, y);
|
||||||
|
|
||||||
|
// can't normalize zero length vector
|
||||||
|
if (vec.LengthSquared > 1.0e-6)
|
||||||
|
{
|
||||||
|
// Normalize so that diagonals aren't faster or something.
|
||||||
|
vec = vec.Normalized;
|
||||||
|
}
|
||||||
|
|
||||||
|
return vec;
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
private sealed class MoverComponentState : ComponentState
|
||||||
|
{
|
||||||
|
public MoveButtons Buttons { get; }
|
||||||
|
|
||||||
|
public MoverComponentState(MoveButtons buttons) : base(ContentNetIDs
|
||||||
|
.PLAYER_INPUT_MOVER)
|
||||||
|
{
|
||||||
|
Buttons = buttons;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Flags]
|
||||||
|
private enum MoveButtons : byte
|
||||||
|
{
|
||||||
|
None = 0,
|
||||||
|
Up = 1,
|
||||||
|
Down = 2,
|
||||||
|
Left = 4,
|
||||||
|
Right = 8,
|
||||||
|
Sprint = 16,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
using System;
|
||||||
|
using Content.Shared.GameObjects.Components.Movement;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
|
namespace Content.Shared.GameObjects.Components.Nutrition
|
||||||
|
{
|
||||||
|
public abstract class SharedHungerComponent : Component, IMoveSpeedModifier
|
||||||
|
{
|
||||||
|
public sealed override string Name => "Hunger";
|
||||||
|
|
||||||
|
public sealed override uint? NetID => ContentNetIDs.HUNGER;
|
||||||
|
|
||||||
|
public abstract HungerThreshold CurrentHungerThreshold { get; }
|
||||||
|
|
||||||
|
|
||||||
|
float IMoveSpeedModifier.WalkSpeedModifier
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
protected sealed class HungerComponentState : ComponentState
|
||||||
|
{
|
||||||
|
public HungerThreshold CurrentThreshold { get; }
|
||||||
|
|
||||||
|
public HungerComponentState(HungerThreshold currentThreshold) : base(ContentNetIDs.HUNGER)
|
||||||
|
{
|
||||||
|
CurrentThreshold = currentThreshold;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum HungerThreshold : byte
|
||||||
|
{
|
||||||
|
Overfed,
|
||||||
|
Okay,
|
||||||
|
Peckish,
|
||||||
|
Starving,
|
||||||
|
Dead,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,61 @@
|
|||||||
|
using System;
|
||||||
|
using Content.Shared.GameObjects.Components.Movement;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
|
namespace Content.Shared.GameObjects.Components.Nutrition
|
||||||
|
{
|
||||||
|
public abstract class SharedThirstComponent : Component, IMoveSpeedModifier
|
||||||
|
{
|
||||||
|
public sealed override string Name => "Thirst";
|
||||||
|
|
||||||
|
public sealed override uint? NetID => ContentNetIDs.THIRST;
|
||||||
|
|
||||||
|
public abstract ThirstThreshold CurrentThirstThreshold { get; }
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
[Serializable, NetSerializable]
|
||||||
|
protected sealed class ThirstComponentState : ComponentState
|
||||||
|
{
|
||||||
|
public ThirstThreshold CurrentThreshold { get; }
|
||||||
|
|
||||||
|
public ThirstComponentState(ThirstThreshold currentThreshold) : base(ContentNetIDs.THIRST)
|
||||||
|
{
|
||||||
|
CurrentThreshold = currentThreshold;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum ThirstThreshold : byte
|
||||||
|
{
|
||||||
|
// Hydrohomies
|
||||||
|
OverHydrated,
|
||||||
|
Okay,
|
||||||
|
Thirsty,
|
||||||
|
Parched,
|
||||||
|
Dead,
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,13 +1,22 @@
|
|||||||
using System;
|
using System;
|
||||||
|
using Content.Shared.GameObjects.EntitySystems;
|
||||||
using Robust.Shared.GameObjects;
|
using Robust.Shared.GameObjects;
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
namespace Content.Shared.GameObjects.Components.Observer
|
namespace Content.Shared.GameObjects.Components.Observer
|
||||||
{
|
{
|
||||||
public class SharedGhostComponent : Component
|
public class SharedGhostComponent : Component, IActionBlocker
|
||||||
{
|
{
|
||||||
public override string Name => "Ghost";
|
public override string Name => "Ghost";
|
||||||
public override uint? NetID => ContentNetIDs.GHOST;
|
public override uint? NetID => ContentNetIDs.GHOST;
|
||||||
|
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
|
|||||||
@@ -50,6 +50,10 @@
|
|||||||
public const uint PDA = 1044;
|
public const uint PDA = 1044;
|
||||||
public const uint PATHFINDER_DEBUG = 1045;
|
public const uint PATHFINDER_DEBUG = 1045;
|
||||||
public const uint AI_DEBUG = 1046;
|
public const uint AI_DEBUG = 1046;
|
||||||
|
public const uint PLAYER_INPUT_MOVER = 1047;
|
||||||
|
public const uint STUNNABLE = 1048;
|
||||||
|
public const uint HUNGER = 1049;
|
||||||
|
public const uint THIRST = 1050;
|
||||||
|
|
||||||
// Net IDs for integration tests.
|
// Net IDs for integration tests.
|
||||||
public const uint PREDICTION_TEST = 10001;
|
public const uint PREDICTION_TEST = 10001;
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
using Robust.Shared.GameObjects.Systems;
|
using Robust.Shared.GameObjects.Systems;
|
||||||
using Robust.Shared.Interfaces.GameObjects;
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
|
|
||||||
namespace Content.Server.GameObjects.EntitySystems
|
namespace Content.Shared.GameObjects.EntitySystems
|
||||||
{
|
{
|
||||||
public interface IActionBlocker
|
public interface IActionBlocker
|
||||||
{
|
{
|
||||||
235
Content.Shared/GameObjects/EntitySystems/SharedMoverSystem.cs
Normal file
235
Content.Shared/GameObjects/EntitySystems/SharedMoverSystem.cs
Normal file
@@ -0,0 +1,235 @@
|
|||||||
|
using System.Diagnostics.CodeAnalysis;
|
||||||
|
using Content.Shared.GameObjects.Components.Movement;
|
||||||
|
using Content.Shared.Physics;
|
||||||
|
using Robust.Shared.Configuration;
|
||||||
|
using Robust.Shared.GameObjects;
|
||||||
|
using Robust.Shared.GameObjects.Components;
|
||||||
|
using Robust.Shared.GameObjects.Systems;
|
||||||
|
using Robust.Shared.Input;
|
||||||
|
using Robust.Shared.Input.Binding;
|
||||||
|
using Robust.Shared.Interfaces.Configuration;
|
||||||
|
using Robust.Shared.Interfaces.GameObjects;
|
||||||
|
using Robust.Shared.Interfaces.GameObjects.Components;
|
||||||
|
using Robust.Shared.Interfaces.Map;
|
||||||
|
using Robust.Shared.Interfaces.Physics;
|
||||||
|
using Robust.Shared.Interfaces.Random;
|
||||||
|
using Robust.Shared.IoC;
|
||||||
|
using Robust.Shared.Maths;
|
||||||
|
using Robust.Shared.Physics;
|
||||||
|
using Robust.Shared.Players;
|
||||||
|
using Robust.Shared.Prototypes;
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
|
namespace Content.Shared.GameObjects.EntitySystems
|
||||||
|
{
|
||||||
|
public abstract class SharedMoverSystem : EntitySystem
|
||||||
|
{
|
||||||
|
// [Dependency] private readonly IPauseManager _pauseManager;
|
||||||
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
||||||
|
[Dependency] private readonly ITileDefinitionManager _tileDefinitionManager = default!;
|
||||||
|
[Dependency] private readonly IMapManager _mapManager = default!;
|
||||||
|
[Dependency] private readonly IRobustRandom _robustRandom = default!;
|
||||||
|
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||||
|
[Dependency] private readonly IPhysicsManager _physicsManager = default!;
|
||||||
|
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
|
||||||
|
|
||||||
|
public override void Initialize()
|
||||||
|
{
|
||||||
|
base.Initialize();
|
||||||
|
|
||||||
|
EntityQuery = new TypeEntityQuery(typeof(IMoverComponent));
|
||||||
|
|
||||||
|
var moveUpCmdHandler = new MoverDirInputCmdHandler(Direction.North);
|
||||||
|
var moveLeftCmdHandler = new MoverDirInputCmdHandler(Direction.West);
|
||||||
|
var moveRightCmdHandler = new MoverDirInputCmdHandler(Direction.East);
|
||||||
|
var moveDownCmdHandler = new MoverDirInputCmdHandler(Direction.South);
|
||||||
|
|
||||||
|
CommandBinds.Builder
|
||||||
|
.Bind(EngineKeyFunctions.MoveUp, moveUpCmdHandler)
|
||||||
|
.Bind(EngineKeyFunctions.MoveLeft, moveLeftCmdHandler)
|
||||||
|
.Bind(EngineKeyFunctions.MoveRight, moveRightCmdHandler)
|
||||||
|
.Bind(EngineKeyFunctions.MoveDown, moveDownCmdHandler)
|
||||||
|
.Bind(EngineKeyFunctions.Run, new SprintInputCmdHandler())
|
||||||
|
.Register<SharedMoverSystem>();
|
||||||
|
|
||||||
|
_configurationManager.RegisterCVar("game.diagonalmovement", true, CVar.ARCHIVE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public override void Shutdown()
|
||||||
|
{
|
||||||
|
CommandBinds.Unregister<SharedMoverSystem>();
|
||||||
|
base.Shutdown();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void UpdateKinematics(ITransformComponent transform, IMoverComponent mover, SharedPhysicsComponent physics,
|
||||||
|
CollidableComponent? collider = null)
|
||||||
|
{
|
||||||
|
if (physics.Controller == null)
|
||||||
|
{
|
||||||
|
// Set up controller
|
||||||
|
SetController(physics);
|
||||||
|
}
|
||||||
|
|
||||||
|
var weightless = !transform.Owner.HasComponent<MovementIgnoreGravityComponent>() &&
|
||||||
|
_physicsManager.IsWeightless(transform.GridPosition);
|
||||||
|
|
||||||
|
if (weightless && collider != null)
|
||||||
|
{
|
||||||
|
// No gravity: is our entity touching anything?
|
||||||
|
var touching = IsAroundCollider(transform, mover, collider);
|
||||||
|
|
||||||
|
if (!touching)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: movement check.
|
||||||
|
var (walkDir, sprintDir) = mover.VelocityDir;
|
||||||
|
var combined = walkDir + sprintDir;
|
||||||
|
if (combined.LengthSquared < 0.001 || !ActionBlockerSystem.CanMove(mover.Owner) && !weightless)
|
||||||
|
{
|
||||||
|
(physics.Controller as MoverController)?.StopMoving();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//Console.WriteLine($"{IoCManager.Resolve<IGameTiming>().TickStamp}: {combined}");
|
||||||
|
|
||||||
|
if (weightless)
|
||||||
|
{
|
||||||
|
(physics.Controller as MoverController)?.Push(combined, mover.CurrentPushSpeed);
|
||||||
|
transform.LocalRotation = walkDir.GetDir().ToAngle();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var total = walkDir * mover.CurrentWalkSpeed + sprintDir * mover.CurrentSprintSpeed;
|
||||||
|
//Console.WriteLine($"{walkDir} ({mover.CurrentWalkSpeed}) + {sprintDir} ({mover.CurrentSprintSpeed}): {total}");
|
||||||
|
|
||||||
|
(physics.Controller as MoverController)?.Move(total, 1);
|
||||||
|
transform.LocalRotation = total.GetDir().ToAngle();
|
||||||
|
|
||||||
|
HandleFootsteps(mover);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected virtual void HandleFootsteps(IMoverComponent mover)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract void SetController(SharedPhysicsComponent physics);
|
||||||
|
|
||||||
|
private bool IsAroundCollider(ITransformComponent transform, IMoverComponent mover,
|
||||||
|
CollidableComponent collider)
|
||||||
|
{
|
||||||
|
foreach (var entity in _entityManager.GetEntitiesInRange(transform.Owner, mover.GrabRange, true))
|
||||||
|
{
|
||||||
|
if (entity == transform.Owner)
|
||||||
|
{
|
||||||
|
continue; // Don't try to push off of yourself!
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!entity.TryGetComponent<CollidableComponent>(out var otherCollider))
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: Item check.
|
||||||
|
var touching = ((collider.CollisionMask & otherCollider.CollisionLayer) != 0x0
|
||||||
|
|| (otherCollider.CollisionMask & collider.CollisionLayer) != 0x0) // Ensure collision
|
||||||
|
&& true; // !entity.HasComponent<ItemComponent>(); // This can't be an item
|
||||||
|
|
||||||
|
if (touching)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private static void HandleDirChange(ICommonSession? session, Direction dir, ushort subTick, bool state)
|
||||||
|
{
|
||||||
|
if (!TryGetAttachedComponent<IMoverComponent>(session, out var moverComp))
|
||||||
|
return;
|
||||||
|
|
||||||
|
var owner = session?.AttachedEntity;
|
||||||
|
|
||||||
|
if (owner != null)
|
||||||
|
{
|
||||||
|
foreach (var comp in owner.GetAllComponents<IRelayMoveInput>())
|
||||||
|
{
|
||||||
|
comp.MoveInputPressed(session);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
moverComp.SetVelocityDirection(dir, subTick, state);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void HandleRunChange(ICommonSession? session, ushort subTick, bool running)
|
||||||
|
{
|
||||||
|
if (!TryGetAttachedComponent<IMoverComponent>(session, out var moverComp))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
moverComp.SetSprinting(subTick, running);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool TryGetAttachedComponent<T>(ICommonSession? session, [MaybeNullWhen(false)] out T component)
|
||||||
|
where T : IComponent
|
||||||
|
{
|
||||||
|
component = default;
|
||||||
|
|
||||||
|
var ent = session?.AttachedEntity;
|
||||||
|
|
||||||
|
if (ent == null || !ent.IsValid())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (!ent.TryGetComponent(out T comp))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
component = comp;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class MoverDirInputCmdHandler : InputCmdHandler
|
||||||
|
{
|
||||||
|
private readonly Direction _dir;
|
||||||
|
|
||||||
|
public MoverDirInputCmdHandler(Direction dir)
|
||||||
|
{
|
||||||
|
_dir = dir;
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool HandleCmdMessage(ICommonSession? session, InputCmdMessage message)
|
||||||
|
{
|
||||||
|
if (!(message is FullInputCmdMessage full))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
HandleDirChange(session, _dir, message.SubTick, full.State == BoundKeyState.Down);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private sealed class SprintInputCmdHandler : InputCmdHandler
|
||||||
|
{
|
||||||
|
public override bool HandleCmdMessage(ICommonSession? session, InputCmdMessage message)
|
||||||
|
{
|
||||||
|
if (!(message is FullInputCmdMessage full))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
HandleRunChange(session, full.SubTick, full.State == BoundKeyState.Down);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -30,7 +30,7 @@ namespace Content.Shared.Physics
|
|||||||
public void Move(Vector2 velocityDirection, float speed)
|
public void Move(Vector2 velocityDirection, float speed)
|
||||||
{
|
{
|
||||||
if (!_component.Owner.HasComponent<MovementIgnoreGravityComponent>() && IoCManager
|
if (!_component.Owner.HasComponent<MovementIgnoreGravityComponent>() && IoCManager
|
||||||
.Resolve<IPhysicsManager>().IsWeightless(_component.Owner.Transform.GridPosition)) return;
|
.Resolve<IPhysicsManager>().IsWeightless(_component.Owner.Transform.GridPosition) && false) return;
|
||||||
Push(velocityDirection, speed);
|
Push(velocityDirection, speed);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -143,7 +143,7 @@
|
|||||||
is_subfloor: false
|
is_subfloor: false
|
||||||
can_crowbar: true
|
can_crowbar: true
|
||||||
footstep_sounds: footstep_floor
|
footstep_sounds: footstep_floor
|
||||||
friction: 0.35
|
#friction: 0.35
|
||||||
item_drop: FloorTileItemSteel
|
item_drop: FloorTileItemSteel
|
||||||
|
|
||||||
- type: tile
|
- type: tile
|
||||||
|
|||||||
Reference in New Issue
Block a user