Content update for ECS physics (#13291)
This commit is contained in:
@@ -9,12 +9,15 @@ using Robust.Shared.Enums;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
|
||||
namespace Content.Server.Administration.Commands
|
||||
{
|
||||
[AdminCommand(AdminFlags.Admin)]
|
||||
public sealed class WarpCommand : IConsoleCommand
|
||||
{
|
||||
[Dependency] private readonly IEntityManager _entManager = default!;
|
||||
|
||||
public string Command => "warp";
|
||||
public string Description => "Teleports you to predefined areas on the map.";
|
||||
|
||||
@@ -37,11 +40,10 @@ namespace Content.Server.Administration.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
var entMan = IoCManager.Resolve<IEntityManager>();
|
||||
var location = args[0];
|
||||
if (location == "?")
|
||||
{
|
||||
var locations = string.Join(", ", GetWarpPointNames(entMan));
|
||||
var locations = string.Join(", ", GetWarpPointNames());
|
||||
|
||||
shell.WriteLine(locations);
|
||||
}
|
||||
@@ -53,20 +55,19 @@ namespace Content.Server.Administration.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
var mapManager = IoCManager.Resolve<IMapManager>();
|
||||
var currentMap = entMan.GetComponent<TransformComponent>(playerEntity).MapID;
|
||||
var currentGrid = entMan.GetComponent<TransformComponent>(playerEntity).GridUid;
|
||||
var currentMap = _entManager.GetComponent<TransformComponent>(playerEntity).MapID;
|
||||
var currentGrid = _entManager.GetComponent<TransformComponent>(playerEntity).GridUid;
|
||||
|
||||
var found = entMan.EntityQuery<WarpPointComponent>(true)
|
||||
var found = _entManager.EntityQuery<WarpPointComponent>(true)
|
||||
.Where(p => p.Location == location)
|
||||
.Select(p => (entMan.GetComponent<TransformComponent>(p.Owner).Coordinates, p.Follow))
|
||||
.Select(p => (_entManager.GetComponent<TransformComponent>(p.Owner).Coordinates, p.Follow))
|
||||
.OrderBy(p => p.Item1, Comparer<EntityCoordinates>.Create((a, b) =>
|
||||
{
|
||||
// Sort so that warp points on the same grid/map are first.
|
||||
// So if you have two maps loaded with the same warp points,
|
||||
// it will prefer the warp points on the map you're currently on.
|
||||
var aGrid = a.GetGridUid(entMan);
|
||||
var bGrid = b.GetGridUid(entMan);
|
||||
var aGrid = a.GetGridUid(_entManager);
|
||||
var bGrid = b.GetGridUid(_entManager);
|
||||
|
||||
if (aGrid == bGrid)
|
||||
{
|
||||
@@ -83,8 +84,8 @@ namespace Content.Server.Administration.Commands
|
||||
return 1;
|
||||
}
|
||||
|
||||
var mapA = a.GetMapId(entMan);
|
||||
var mapB = a.GetMapId(entMan);
|
||||
var mapA = a.GetMapId(_entManager);
|
||||
var mapB = a.GetMapId(_entManager);
|
||||
|
||||
if (mapA == mapB)
|
||||
{
|
||||
@@ -113,25 +114,25 @@ namespace Content.Server.Administration.Commands
|
||||
return;
|
||||
}
|
||||
|
||||
if (follow && entMan.HasComponent<GhostComponent>(playerEntity))
|
||||
if (follow && _entManager.HasComponent<GhostComponent>(playerEntity))
|
||||
{
|
||||
entMan.EntitySysManager.GetEntitySystem<FollowerSystem>().StartFollowingEntity(playerEntity, coords.EntityId);
|
||||
_entManager.System<FollowerSystem>().StartFollowingEntity(playerEntity, coords.EntityId);
|
||||
return;
|
||||
}
|
||||
|
||||
var xform = entMan.GetComponent<TransformComponent>(playerEntity);
|
||||
var xform = _entManager.GetComponent<TransformComponent>(playerEntity);
|
||||
xform.Coordinates = coords;
|
||||
xform.AttachToGridOrMap();
|
||||
if (entMan.TryGetComponent(playerEntity, out PhysicsComponent? physics))
|
||||
if (_entManager.TryGetComponent(playerEntity, out PhysicsComponent? physics))
|
||||
{
|
||||
physics.LinearVelocity = Vector2.Zero;
|
||||
_entManager.System<SharedPhysicsSystem>().SetLinearVelocity(playerEntity, Vector2.Zero, body: physics);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static IEnumerable<string> GetWarpPointNames(IEntityManager entMan)
|
||||
private IEnumerable<string> GetWarpPointNames()
|
||||
{
|
||||
return entMan.EntityQuery<WarpPointComponent>(true)
|
||||
return _entManager.EntityQuery<WarpPointComponent>(true)
|
||||
.Select(p => p.Location)
|
||||
.Where(p => p != null)
|
||||
.OrderBy(p => p)
|
||||
@@ -142,8 +143,7 @@ namespace Content.Server.Administration.Commands
|
||||
{
|
||||
if (args.Length == 1)
|
||||
{
|
||||
var ent = IoCManager.Resolve<IEntityManager>();
|
||||
var options = new[] { "?" }.Concat(GetWarpPointNames(ent));
|
||||
var options = new[] { "?" }.Concat(GetWarpPointNames());
|
||||
|
||||
return CompletionResult.FromHintOptions(options, "<warp point | ?>");
|
||||
}
|
||||
|
||||
@@ -47,6 +47,7 @@ using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Random;
|
||||
using Timer = Robust.Shared.Timing.Timer;
|
||||
@@ -63,18 +64,20 @@ public sealed partial class AdminVerbSystem
|
||||
[Dependency] private readonly ElectrocutionSystem _electrocutionSystem = default!;
|
||||
[Dependency] private readonly EntityStorageSystem _entityStorageSystem = default!;
|
||||
[Dependency] private readonly ExplosionSystem _explosionSystem = default!;
|
||||
[Dependency] private readonly FixtureSystem _fixtures = default!;
|
||||
[Dependency] private readonly FlammableSystem _flammableSystem = default!;
|
||||
[Dependency] private readonly GhostKickManager _ghostKickManager = default!;
|
||||
[Dependency] private readonly GodmodeSystem _godmodeSystem = default!;
|
||||
[Dependency] private readonly InventorySystem _inventorySystem = default!;
|
||||
[Dependency] private readonly MovementSpeedModifierSystem _movementSpeedModifierSystem = default!;
|
||||
[Dependency] private readonly PolymorphableSystem _polymorphableSystem = default!;
|
||||
[Dependency] private readonly MobStateSystem _mobStateSystem = default!;
|
||||
[Dependency] private readonly MobThresholdSystem _mobThresholdSystem = default!;
|
||||
[Dependency] private readonly PopupSystem _popupSystem = default!;
|
||||
[Dependency] private readonly SharedPhysicsSystem _physics = default!;
|
||||
[Dependency] private readonly TabletopSystem _tabletopSystem = default!;
|
||||
[Dependency] private readonly VomitSystem _vomitSystem = default!;
|
||||
[Dependency] private readonly WeldableSystem _weldableSystem = default!;
|
||||
[Dependency] private readonly MovementSpeedModifierSystem _movementSpeedModifierSystem = default!;
|
||||
|
||||
// All smite verbs have names so invokeverb works.
|
||||
private void AddSmiteVerbs(GetVerbsEvent<Verb> args)
|
||||
@@ -422,20 +425,24 @@ public sealed partial class AdminVerbSystem
|
||||
var xform = Transform(args.Target);
|
||||
var fixtures = Comp<FixturesComponent>(args.Target);
|
||||
xform.Anchored = false; // Just in case.
|
||||
physics.BodyType = BodyType.Dynamic;
|
||||
physics.BodyStatus = BodyStatus.InAir;
|
||||
physics.WakeBody();
|
||||
foreach (var (_, fixture) in fixtures.Fixtures)
|
||||
_physics.SetBodyType(args.Target, BodyType.Dynamic, manager: fixtures, body: physics);
|
||||
_physics.SetBodyStatus(physics, BodyStatus.InAir);
|
||||
_physics.WakeBody(args.Target, manager: fixtures, body: physics);
|
||||
|
||||
foreach (var fixture in fixtures.Fixtures.Values)
|
||||
{
|
||||
if (!fixture.Hard)
|
||||
continue;
|
||||
fixture.Restitution = 1.1f;
|
||||
|
||||
_physics.SetRestitution(args.Target, fixture, 1.1f, false, fixtures);
|
||||
}
|
||||
|
||||
physics.LinearVelocity = _random.NextVector2(1.5f, 1.5f);
|
||||
physics.AngularVelocity = MathF.PI * 12;
|
||||
physics.LinearDamping = 0.0f;
|
||||
physics.AngularDamping = 0.0f;
|
||||
_fixtures.FixtureUpdate(args.Target, manager: fixtures, body: physics);
|
||||
|
||||
_physics.SetLinearVelocity(args.Target, _random.NextVector2(1.5f, 1.5f), manager: fixtures, body: physics);
|
||||
_physics.SetAngularVelocity(args.Target, MathF.PI * 12, manager: fixtures, body: physics);
|
||||
_physics.SetLinearDamping(physics, 0f);
|
||||
_physics.SetAngularDamping(physics, 0f);
|
||||
},
|
||||
Impact = LogImpact.Extreme,
|
||||
Message = Loc.GetString("admin-smite-pinball-description")
|
||||
@@ -452,18 +459,20 @@ public sealed partial class AdminVerbSystem
|
||||
var xform = Transform(args.Target);
|
||||
var fixtures = Comp<FixturesComponent>(args.Target);
|
||||
xform.Anchored = false; // Just in case.
|
||||
physics.BodyType = BodyType.Dynamic;
|
||||
physics.BodyStatus = BodyStatus.InAir;
|
||||
physics.WakeBody();
|
||||
foreach (var (_, fixture) in fixtures.Fixtures)
|
||||
|
||||
_physics.SetBodyType(args.Target, BodyType.Dynamic, body: physics);
|
||||
_physics.SetBodyStatus(physics, BodyStatus.InAir);
|
||||
_physics.WakeBody(args.Target, manager: fixtures, body: physics);
|
||||
|
||||
foreach (var fixture in fixtures.Fixtures.Values)
|
||||
{
|
||||
fixture.Hard = false;
|
||||
_physics.SetHard(args.Target, fixture, false, manager: fixtures);
|
||||
}
|
||||
|
||||
physics.LinearVelocity = _random.NextVector2(8.0f, 8.0f);
|
||||
physics.AngularVelocity = MathF.PI * 12;
|
||||
physics.LinearDamping = 0.0f;
|
||||
physics.AngularDamping = 0.0f;
|
||||
_physics.SetLinearVelocity(args.Target, _random.NextVector2(8.0f, 8.0f), manager: fixtures, body: physics);
|
||||
_physics.SetAngularVelocity(args.Target, MathF.PI * 12, manager: fixtures, body: physics);
|
||||
_physics.SetLinearDamping(physics, 0f);
|
||||
_physics.SetAngularDamping(physics, 0f);
|
||||
},
|
||||
Impact = LogImpact.Extreme,
|
||||
Message = Loc.GetString("admin-smite-yeet-description")
|
||||
|
||||
@@ -679,8 +679,8 @@ public sealed partial class AdminVerbSystem
|
||||
IconTexture = "/Textures/Interface/AdminActions/halt.png",
|
||||
Act = () =>
|
||||
{
|
||||
physics.LinearVelocity = Vector2.Zero;
|
||||
physics.AngularVelocity = 0.0f;
|
||||
_physics.SetLinearVelocity(args.Target, Vector2.Zero, body: physics);
|
||||
_physics.SetAngularVelocity(args.Target, 0f, body: physics);
|
||||
},
|
||||
Impact = LogImpact.Medium,
|
||||
Message = Loc.GetString("admin-trick-halt-movement-description"),
|
||||
|
||||
Reference in New Issue
Block a user