Content update for NetEntities (#18935)

This commit is contained in:
metalgearsloth
2023-09-11 09:42:41 +10:00
committed by GitHub
parent 389c8d1a2c
commit 5a0fc68be2
526 changed files with 3058 additions and 2215 deletions

View File

@@ -24,29 +24,27 @@ namespace Content.Server.Atmos.Commands
return;
}
var entMan = IoCManager.Resolve<IEntityManager>();
if (!EntityUid.TryParse(args[0], out var euid))
if (!NetEntity.TryParse(args[0], out var eNet) || !_entities.TryGetEntity(eNet, out var euid))
{
shell.WriteError($"Failed to parse euid '{args[0]}'.");
return;
}
if (!entMan.HasComponent<MapGridComponent>(euid))
if (!_entities.HasComponent<MapGridComponent>(euid))
{
shell.WriteError($"Euid '{euid}' does not exist or is not a grid.");
return;
}
var atmos = entMan.EntitySysManager.GetEntitySystem<AtmosphereSystem>();
var atmos = _entities.EntitySysManager.GetEntitySystem<AtmosphereSystem>();
if (atmos.HasAtmosphere(euid))
if (atmos.HasAtmosphere(euid.Value))
{
shell.WriteLine("Grid already has an atmosphere.");
return;
}
_entities.AddComponent<GridAtmosphereComponent>(euid);
_entities.AddComponent<GridAtmosphereComponent>(euid.Value);
shell.WriteLine($"Added atmosphere to grid {euid}.");
}

View File

@@ -11,28 +11,34 @@ namespace Content.Server.Atmos.Commands
[AdminCommand(AdminFlags.Debug)]
public sealed class AddGasCommand : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entManager = default!;
public string Command => "addgas";
public string Description => "Adds gas at a certain position.";
public string Help => "addgas <X> <Y> <GridEid> <Gas> <moles>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length < 5) return;
if (args.Length < 5)
return;
if(!int.TryParse(args[0], out var x)
|| !int.TryParse(args[1], out var y)
|| !EntityUid.TryParse(args[2], out var euid)
|| !(AtmosCommandUtils.TryParseGasID(args[3], out var gasId))
|| !float.TryParse(args[4], out var moles)) return;
if (!int.TryParse(args[0], out var x)
|| !int.TryParse(args[1], out var y)
|| !NetEntity.TryParse(args[2], out var netEnt)
|| !_entManager.TryGetEntity(netEnt, out var euid)
|| !(AtmosCommandUtils.TryParseGasID(args[3], out var gasId))
|| !float.TryParse(args[4], out var moles))
{
return;
}
var entMan = IoCManager.Resolve<IEntityManager>();
if (!entMan.HasComponent<MapGridComponent>(euid))
if (!_entManager.HasComponent<MapGridComponent>(euid))
{
shell.WriteError($"Euid '{euid}' does not exist or is not a grid.");
return;
}
var atmosphereSystem = entMan.EntitySysManager.GetEntitySystem<AtmosphereSystem>();
var atmosphereSystem = _entManager.EntitySysManager.GetEntitySystem<AtmosphereSystem>();
var indices = new Vector2i(x, y);
var tile = atmosphereSystem.GetTileMixture(euid, null, indices, true);

View File

@@ -11,6 +11,9 @@ namespace Content.Server.Atmos.Commands
[AdminCommand(AdminFlags.Debug)]
public sealed class DeleteGasCommand : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
public string Command => "deletegas";
public string Description => "Removes all gases from a grid, or just of one type if specified.";
public string Help => $"Usage: {Command} <GridId> <Gas> / {Command} <GridId> / {Command} <Gas> / {Command}";
@@ -21,8 +24,6 @@ namespace Content.Server.Atmos.Commands
EntityUid? gridId;
Gas? gas = null;
var entMan = IoCManager.Resolve<IEntityManager>();
switch (args.Length)
{
case 0:
@@ -39,7 +40,7 @@ namespace Content.Server.Atmos.Commands
return;
}
gridId = entMan.GetComponent<TransformComponent>(playerEntity).GridUid;
gridId = _entManager.GetComponent<TransformComponent>(playerEntity).GridUid;
if (gridId == null)
{
@@ -51,7 +52,7 @@ namespace Content.Server.Atmos.Commands
}
case 1:
{
if (!EntityUid.TryParse(args[0], out var number))
if (!NetEntity.TryParse(args[0], out var numberEnt) || !_entManager.TryGetEntity(numberEnt, out var number))
{
// Argument is a gas
if (player == null)
@@ -66,7 +67,7 @@ namespace Content.Server.Atmos.Commands
return;
}
gridId = entMan.GetComponent<TransformComponent>(playerEntity).GridUid;
gridId = _entManager.GetComponent<TransformComponent>(playerEntity).GridUid;
if (gridId == null)
{
@@ -90,7 +91,7 @@ namespace Content.Server.Atmos.Commands
}
case 2:
{
if (!EntityUid.TryParse(args[0], out var first))
if (!NetEntity.TryParse(args[0], out var firstNet) || !_entManager.TryGetEntity(firstNet, out var first))
{
shell.WriteLine($"{args[0]} is not a valid integer for a grid id.");
return;
@@ -119,15 +120,13 @@ namespace Content.Server.Atmos.Commands
return;
}
var mapManager = IoCManager.Resolve<IMapManager>();
if (!mapManager.TryGetGrid(gridId, out _))
if (!_mapManager.TryGetGrid(gridId, out _))
{
shell.WriteLine($"No grid exists with id {gridId}");
return;
}
var atmosphereSystem = EntitySystem.Get<AtmosphereSystem>();
var atmosphereSystem = _entManager.System<AtmosphereSystem>();
var tiles = 0;
var moles = 0f;
@@ -136,7 +135,8 @@ namespace Content.Server.Atmos.Commands
{
foreach (var tile in atmosphereSystem.GetAllMixtures(gridId.Value, true))
{
if (tile.Immutable) continue;
if (tile.Immutable)
continue;
tiles++;
moles += tile.TotalMoles;
@@ -148,7 +148,8 @@ namespace Content.Server.Atmos.Commands
{
foreach (var tile in atmosphereSystem.GetAllMixtures(gridId.Value, true))
{
if (tile.Immutable) continue;
if (tile.Immutable)
continue;
tiles++;
moles += tile.TotalMoles;

View File

@@ -10,26 +10,33 @@ namespace Content.Server.Atmos.Commands
[AdminCommand(AdminFlags.Debug)]
public sealed class FillGas : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
public string Command => "fillgas";
public string Description => "Adds gas to all tiles in a grid.";
public string Help => "fillgas <GridEid> <Gas> <moles>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length < 3) return;
if(!EntityUid.TryParse(args[0], out var gridId)
|| !(AtmosCommandUtils.TryParseGasID(args[1], out var gasId))
|| !float.TryParse(args[2], out var moles)) return;
if (args.Length < 3)
return;
var mapMan = IoCManager.Resolve<IMapManager>();
if (!NetEntity.TryParse(args[0], out var gridIdNet)
|| !_entManager.TryGetEntity(gridIdNet, out var gridId)
|| !(AtmosCommandUtils.TryParseGasID(args[1], out var gasId))
|| !float.TryParse(args[2], out var moles))
{
return;
}
if (!mapMan.TryGetGrid(gridId, out var grid))
if (!_mapManager.TryGetGrid(gridId, out var grid))
{
shell.WriteLine("Invalid grid ID.");
return;
}
var atmosphereSystem = EntitySystem.Get<AtmosphereSystem>();
var atmosphereSystem = _entManager.System<AtmosphereSystem>();
foreach (var tile in atmosphereSystem.GetAllMixtures(grid.Owner, true))
{

View File

@@ -9,20 +9,28 @@ namespace Content.Server.Atmos.Commands
[AdminCommand(AdminFlags.Debug)]
public sealed class RemoveGasCommand : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entManager = default!;
public string Command => "removegas";
public string Description => "Removes an amount of gases.";
public string Help => "removegas <X> <Y> <GridId> <amount> <ratio>\nIf <ratio> is true, amount will be treated as the ratio of gas to be removed.";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length < 5) return;
if(!int.TryParse(args[0], out var x)
|| !int.TryParse(args[1], out var y)
|| !EntityUid.TryParse(args[2], out var id)
|| !float.TryParse(args[3], out var amount)
|| !bool.TryParse(args[4], out var ratio)) return;
if (args.Length < 5)
return;
var atmosphereSystem = EntitySystem.Get<AtmosphereSystem>();
if (!int.TryParse(args[0], out var x)
|| !int.TryParse(args[1], out var y)
|| !NetEntity.TryParse(args[2], out var idNet)
|| !_entManager.TryGetEntity(idNet, out var id)
|| !float.TryParse(args[3], out var amount)
|| !bool.TryParse(args[4], out var ratio))
{
return;
}
var atmosphereSystem = _entManager.System<AtmosphereSystem>();
var indices = new Vector2i(x, y);
var tile = atmosphereSystem.GetTileMixture(id, null, indices, true);

View File

@@ -10,17 +10,23 @@ namespace Content.Server.Atmos.Commands
[AdminCommand(AdminFlags.Debug)]
public sealed class SetAtmosTemperatureCommand : IConsoleCommand
{
[Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly IMapManager _mapManager = default!;
public string Command => "setatmostemp";
public string Description => "Sets a grid's temperature (in kelvin).";
public string Help => "Usage: setatmostemp <GridId> <Temperature>";
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length < 2) return;
if(!EntityUid.TryParse(args[0], out var gridId)
|| !float.TryParse(args[1], out var temperature)) return;
if (args.Length < 2)
return;
var mapMan = IoCManager.Resolve<IMapManager>();
if (!_entManager.TryParseNetEntity(args[0], out var gridId)
|| !float.TryParse(args[1], out var temperature))
{
return;
}
if (temperature < Atmospherics.TCMB)
{
@@ -28,13 +34,13 @@ namespace Content.Server.Atmos.Commands
return;
}
if (!gridId.IsValid() || !mapMan.TryGetGrid(gridId, out var gridComp))
if (!gridId.Value.IsValid() || !_mapManager.TryGetGrid(gridId, out var gridComp))
{
shell.WriteLine("Invalid grid ID.");
return;
}
var atmosphereSystem = EntitySystem.Get<AtmosphereSystem>();
var atmosphereSystem = _entManager.System<AtmosphereSystem>();
var tiles = 0;
foreach (var tile in atmosphereSystem.GetAllMixtures(gridComp.Owner, true))

View File

@@ -22,11 +22,17 @@ namespace Content.Server.Atmos.Commands
public void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length < 4) return;
if(!int.TryParse(args[0], out var x)
|| !int.TryParse(args[1], out var y)
|| !EntityUid.TryParse(args[2], out var gridId)
|| !float.TryParse(args[3], out var temperature)) return;
if (args.Length < 4)
return;
if (!int.TryParse(args[0], out var x)
|| !int.TryParse(args[1], out var y)
|| !NetEntity.TryParse(args[2], out var gridIdNet)
|| !_entities.TryGetEntity(gridIdNet, out var gridId)
|| !float.TryParse(args[3], out var temperature))
{
return;
}
if (temperature < Atmospherics.TCMB)
{