Salvage magnet revamp (#23119)
* Generic offering window * More work * weh * Parity * Progression meter * magnet * rona * PG asteroid work * code red * Asteroid spawnings * clams * a * Marker fixes * More fixes * Workings of biome asteroids * A * Fix this loading code * a * Fix masking * weh * Fixes * Magnet claiming * toe * petogue * magnet * Bunch of fixes * Fix default * Fixes * asteroids * Fix offerings * Localisation and a bunch of fixes * a * Fixes * Preliminary draft * Announcement fixes * Fixes and bump spawn rate * Fix asteroid spawns and UI * More fixes * Expeditions fix * fix * Gravity * Fix announcement rounding * a * Offset tweak * sus * jankass * Fix merge
This commit is contained in:
@@ -21,14 +21,11 @@ using Robust.Shared.Configuration;
|
||||
using Robust.Shared.Console;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Noise;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Physics.Systems;
|
||||
using Robust.Shared.Player;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Serialization.Manager;
|
||||
using Robust.Shared.Threading;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
@@ -327,7 +324,8 @@ public sealed partial class BiomeSystem : SharedBiomeSystem
|
||||
{
|
||||
if (_xformQuery.TryGetComponent(pSession.AttachedEntity, out var xform) &&
|
||||
_handledEntities.Add(pSession.AttachedEntity.Value) &&
|
||||
_biomeQuery.TryGetComponent(xform.MapUid, out var biome))
|
||||
_biomeQuery.TryGetComponent(xform.MapUid, out var biome) &&
|
||||
biome.Enabled)
|
||||
{
|
||||
var worldPos = _transform.GetWorldPosition(xform);
|
||||
AddChunksInRange(biome, worldPos);
|
||||
@@ -343,7 +341,8 @@ public sealed partial class BiomeSystem : SharedBiomeSystem
|
||||
{
|
||||
if (!_handledEntities.Add(viewer) ||
|
||||
!_xformQuery.TryGetComponent(viewer, out xform) ||
|
||||
!_biomeQuery.TryGetComponent(xform.MapUid, out biome))
|
||||
!_biomeQuery.TryGetComponent(xform.MapUid, out biome) ||
|
||||
!biome.Enabled)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
@@ -363,8 +362,11 @@ public sealed partial class BiomeSystem : SharedBiomeSystem
|
||||
|
||||
while (loadBiomes.MoveNext(out var gridUid, out var biome, out var grid))
|
||||
{
|
||||
if (!biome.Enabled)
|
||||
continue;
|
||||
|
||||
// Load new chunks
|
||||
LoadChunks(biome, gridUid, grid, biome.Seed, _xformQuery);
|
||||
LoadChunks(biome, gridUid, grid, biome.Seed);
|
||||
// Unload old chunks
|
||||
UnloadChunks(biome, gridUid, grid, biome.Seed);
|
||||
}
|
||||
@@ -414,8 +416,29 @@ public sealed partial class BiomeSystem : SharedBiomeSystem
|
||||
BiomeComponent component,
|
||||
EntityUid gridUid,
|
||||
MapGridComponent grid,
|
||||
int seed,
|
||||
EntityQuery<TransformComponent> xformQuery)
|
||||
int seed)
|
||||
{
|
||||
BuildMarkerChunks(component, gridUid, grid, seed);
|
||||
|
||||
var active = _activeChunks[component];
|
||||
|
||||
foreach (var chunk in active)
|
||||
{
|
||||
LoadChunkMarkers(component, gridUid, grid, chunk, seed);
|
||||
|
||||
if (!component.LoadedChunks.Add(chunk))
|
||||
continue;
|
||||
|
||||
// Load NOW!
|
||||
LoadChunk(component, gridUid, grid, chunk, seed);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Goes through all marker chunks that haven't been calculated, then calculates what spawns there are and
|
||||
/// allocates them to the relevant actual chunks in the biome (marker chunks may be many times larger than biome chunks).
|
||||
/// </summary>
|
||||
private void BuildMarkerChunks(BiomeComponent component, EntityUid gridUid, MapGridComponent grid, int seed)
|
||||
{
|
||||
var markers = _markerChunks[component];
|
||||
var loadedMarkers = component.LoadedMarkers;
|
||||
@@ -432,128 +455,57 @@ public sealed partial class BiomeSystem : SharedBiomeSystem
|
||||
if (loadedMarkers.TryGetValue(layer, out var mobChunks) && mobChunks.Contains(chunk))
|
||||
return;
|
||||
|
||||
// Get the set of spawned nodes to avoid overlap.
|
||||
var forced = component.ForcedMarkerLayers.Contains(layer);
|
||||
var spawnSet = _tilePool.Get();
|
||||
var frontier = new ValueList<Vector2i>(32);
|
||||
|
||||
// Make a temporary version and copy back in later.
|
||||
var pending = new Dictionary<Vector2i, Dictionary<string, List<Vector2i>>>();
|
||||
|
||||
// Essentially get the seed + work out a buffer to adjacent chunks so we don't
|
||||
// inadvertantly spawn too many near the edges.
|
||||
var layerProto = ProtoManager.Index<BiomeMarkerLayerPrototype>(layer);
|
||||
var buffer = layerProto.Radius / 2f;
|
||||
var markerSeed = seed + chunk.X * ChunkSize + chunk.Y + localIdx;
|
||||
var rand = new Random(markerSeed);
|
||||
|
||||
// We treat a null entity mask as requiring nothing else on the tile
|
||||
var lower = (int) Math.Floor(buffer);
|
||||
var upper = (int) Math.Ceiling(layerProto.Size - buffer);
|
||||
|
||||
// TODO: Need poisson but crashes whenever I use moony's due to inputs or smth idk
|
||||
// Get the total amount of groups to spawn across the entire chunk.
|
||||
var count = (int) ((layerProto.Size - buffer) * (layerProto.Size - buffer) /
|
||||
(layerProto.Radius * layerProto.Radius));
|
||||
var buffer = (int) (layerProto.Radius / 2f);
|
||||
var bounds = new Box2i(chunk + buffer, chunk + layerProto.Size - buffer);
|
||||
var count = (int) (bounds.Area / (layerProto.Radius * layerProto.Radius));
|
||||
count = Math.Min(count, layerProto.MaxCount);
|
||||
|
||||
// Pick a random tile then BFS outwards from it
|
||||
// It will bias edge tiles significantly more but will make the CPU cry less.
|
||||
for (var i = 0; i < count; i++)
|
||||
GetMarkerNodes(gridUid, component, grid, layerProto, forced, bounds, count, rand,
|
||||
out var spawnSet, out var existing);
|
||||
|
||||
// Forcing markers to spawn so delete any that were found to be in the way.
|
||||
if (forced && existing.Count > 0)
|
||||
{
|
||||
var groupSize = rand.Next(layerProto.MinGroupSize, layerProto.MaxGroupSize + 1);
|
||||
var startNodeX = rand.Next(lower, upper + 1);
|
||||
var startNodeY = rand.Next(lower, upper + 1);
|
||||
var startNode = new Vector2i(startNodeX, startNodeY);
|
||||
frontier.Clear();
|
||||
frontier.Add(startNode + chunk);
|
||||
|
||||
while (groupSize >= 0 && frontier.Count > 0)
|
||||
// Lock something so we can delete these safely.
|
||||
lock (component.PendingMarkers)
|
||||
{
|
||||
var frontierIndex = rand.Next(frontier.Count);
|
||||
var node = frontier[frontierIndex];
|
||||
frontier.RemoveSwap(frontierIndex);
|
||||
|
||||
// Add neighbors regardless.
|
||||
for (var x = -1; x <= 1; x++)
|
||||
foreach (var ent in existing)
|
||||
{
|
||||
for (var y = -1; y <= 1; y++)
|
||||
{
|
||||
if (x != 0 && y != 0)
|
||||
continue;
|
||||
|
||||
var neighbor = new Vector2i(node.X + x, node.Y + y);
|
||||
var chunkOffset = neighbor - chunk;
|
||||
|
||||
// Check if it's inbounds.
|
||||
if (chunkOffset.X < lower ||
|
||||
chunkOffset.Y < lower ||
|
||||
chunkOffset.X > upper ||
|
||||
chunkOffset.Y > upper)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!spawnSet.Add(neighbor))
|
||||
continue;
|
||||
|
||||
frontier.Add(neighbor);
|
||||
}
|
||||
}
|
||||
|
||||
// Check if it's a valid spawn, if so then use it.
|
||||
var enumerator = _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, node);
|
||||
enumerator.MoveNext(out var existing);
|
||||
|
||||
if (!forced && existing != null)
|
||||
continue;
|
||||
|
||||
// Check if mask matches // anything blocking.
|
||||
TryGetEntity(node, component, grid, out var proto);
|
||||
|
||||
// If there's an existing entity and it doesn't match the mask then skip.
|
||||
if (layerProto.EntityMask.Count > 0 &&
|
||||
(proto == null ||
|
||||
!layerProto.EntityMask.ContainsKey(proto)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// If it's just a flat spawn then just check for anything blocking.
|
||||
if (proto != null && layerProto.Prototype != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
DebugTools.Assert(layerProto.EntityMask.Count == 0 || !string.IsNullOrEmpty(proto));
|
||||
var chunkOrigin = SharedMapSystem.GetChunkIndices(node, ChunkSize) * ChunkSize;
|
||||
|
||||
if (!pending.TryGetValue(chunkOrigin, out var pendingMarkers))
|
||||
{
|
||||
pendingMarkers = new Dictionary<string, List<Vector2i>>();
|
||||
pending[chunkOrigin] = pendingMarkers;
|
||||
}
|
||||
|
||||
if (!pendingMarkers.TryGetValue(layer, out var layerMarkers))
|
||||
{
|
||||
layerMarkers = new List<Vector2i>();
|
||||
pendingMarkers[layer] = layerMarkers;
|
||||
}
|
||||
|
||||
layerMarkers.Add(node);
|
||||
groupSize--;
|
||||
spawnSet.Add(node);
|
||||
|
||||
if (forced && existing != null)
|
||||
{
|
||||
// Just lock anything so we can dump this
|
||||
lock (component.PendingMarkers)
|
||||
{
|
||||
Del(existing.Value);
|
||||
}
|
||||
Del(ent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
lock (component.PendingMarkers)
|
||||
foreach (var node in spawnSet.Keys)
|
||||
{
|
||||
var chunkOrigin = SharedMapSystem.GetChunkIndices(node, ChunkSize) * ChunkSize;
|
||||
|
||||
if (!pending.TryGetValue(chunkOrigin, out var pendingMarkers))
|
||||
{
|
||||
pendingMarkers = new Dictionary<string, List<Vector2i>>();
|
||||
pending[chunkOrigin] = pendingMarkers;
|
||||
}
|
||||
|
||||
if (!pendingMarkers.TryGetValue(layer, out var layerMarkers))
|
||||
{
|
||||
layerMarkers = new List<Vector2i>();
|
||||
pendingMarkers[layer] = layerMarkers;
|
||||
}
|
||||
|
||||
layerMarkers.Add(node);
|
||||
}
|
||||
|
||||
lock (loadedMarkers)
|
||||
{
|
||||
if (!loadedMarkers.TryGetValue(layer, out var lockMobChunks))
|
||||
{
|
||||
@@ -576,28 +528,130 @@ public sealed partial class BiomeSystem : SharedBiomeSystem
|
||||
lockMarkers[lockLayer] = nodes;
|
||||
}
|
||||
}
|
||||
|
||||
_tilePool.Return(spawnSet);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
component.ForcedMarkerLayers.Clear();
|
||||
var active = _activeChunks[component];
|
||||
|
||||
foreach (var chunk in active)
|
||||
{
|
||||
LoadMarkerChunk(component, gridUid, grid, chunk, seed);
|
||||
|
||||
if (!component.LoadedChunks.Add(chunk))
|
||||
continue;
|
||||
|
||||
// Load NOW!
|
||||
LoadChunk(component, gridUid, grid, chunk, seed);
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadMarkerChunk(
|
||||
/// <summary>
|
||||
/// Gets the marker nodes for the specified area.
|
||||
/// </summary>
|
||||
/// <param name="emptyTiles">Should we include empty tiles when determine markers (e.g. if they are yet to be loaded)</param>
|
||||
public void GetMarkerNodes(
|
||||
EntityUid gridUid,
|
||||
BiomeComponent biome,
|
||||
MapGridComponent grid,
|
||||
BiomeMarkerLayerPrototype layerProto,
|
||||
bool forced,
|
||||
Box2i bounds,
|
||||
int count,
|
||||
Random rand,
|
||||
out Dictionary<Vector2i, string?> spawnSet,
|
||||
out HashSet<EntityUid> existingEnts,
|
||||
bool emptyTiles = true)
|
||||
{
|
||||
DebugTools.Assert(count > 0);
|
||||
|
||||
var frontier = new ValueList<Vector2i>(32);
|
||||
// TODO: Need poisson but crashes whenever I use moony's due to inputs or smth idk
|
||||
// Get the total amount of groups to spawn across the entire chunk.
|
||||
// We treat a null entity mask as requiring nothing else on the tile
|
||||
|
||||
spawnSet = new Dictionary<Vector2i, string?>();
|
||||
var visited = _tilePool.Get();
|
||||
existingEnts = new HashSet<EntityUid>();
|
||||
|
||||
// Pick a random tile then BFS outwards from it
|
||||
// It will bias edge tiles significantly more but will make the CPU cry less.
|
||||
for (var i = 0; i < count; i++)
|
||||
{
|
||||
var groupSize = rand.Next(layerProto.MinGroupSize, layerProto.MaxGroupSize + 1);
|
||||
var startNodeX = rand.Next(bounds.Left, bounds.Right);
|
||||
var startNodeY = rand.Next(bounds.Bottom, bounds.Top);
|
||||
var startNode = new Vector2i(startNodeX, startNodeY);
|
||||
frontier.Clear();
|
||||
frontier.Add(startNode);
|
||||
visited.Add(startNode);
|
||||
|
||||
while (groupSize >= 0 && frontier.Count > 0)
|
||||
{
|
||||
var frontierIndex = rand.Next(frontier.Count);
|
||||
var node = frontier[frontierIndex];
|
||||
frontier.RemoveSwap(frontierIndex);
|
||||
|
||||
// Add neighbors regardless.
|
||||
for (var x = -1; x <= 1; x++)
|
||||
{
|
||||
for (var y = -1; y <= 1; y++)
|
||||
{
|
||||
if (x != 0 && y != 0)
|
||||
continue;
|
||||
|
||||
var neighbor = new Vector2i(node.X + x, node.Y + y);
|
||||
|
||||
// Check if it's inbounds.
|
||||
if (!bounds.Contains(neighbor))
|
||||
continue;
|
||||
|
||||
if (!visited.Add(neighbor))
|
||||
continue;
|
||||
|
||||
frontier.Add(neighbor);
|
||||
}
|
||||
}
|
||||
|
||||
// Empty tile, skip if relevant.
|
||||
if (!emptyTiles && (!_mapSystem.TryGetTile(grid, node, out var tile) || tile.IsEmpty))
|
||||
continue;
|
||||
|
||||
// Check if it's a valid spawn, if so then use it.
|
||||
var enumerator = _mapSystem.GetAnchoredEntitiesEnumerator(gridUid, grid, node);
|
||||
enumerator.MoveNext(out var existing);
|
||||
|
||||
if (!forced && existing != null)
|
||||
continue;
|
||||
|
||||
// Check if mask matches // anything blocking.
|
||||
TryGetEntity(node, biome, grid, out var proto);
|
||||
|
||||
// If there's an existing entity and it doesn't match the mask then skip.
|
||||
if (layerProto.EntityMask.Count > 0 &&
|
||||
(proto == null ||
|
||||
!layerProto.EntityMask.ContainsKey(proto)))
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
// If it's just a flat spawn then just check for anything blocking.
|
||||
if (proto != null && layerProto.Prototype != null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
DebugTools.Assert(layerProto.EntityMask.Count == 0 || !string.IsNullOrEmpty(proto));
|
||||
groupSize--;
|
||||
spawnSet.Add(node, proto);
|
||||
|
||||
if (existing != null)
|
||||
{
|
||||
existingEnts.Add(existing.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_tilePool.Return(visited);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Loads the pre-deteremined marker nodes for a particular chunk.
|
||||
/// This is calculated in <see cref="BuildMarkerChunks"/>
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// Note that the marker chunks do not correspond to this chunk.
|
||||
/// </remarks>
|
||||
private void LoadChunkMarkers(
|
||||
BiomeComponent component,
|
||||
EntityUid gridUid,
|
||||
MapGridComponent grid,
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using System.Numerics;
|
||||
using Content.Server.Shuttle.Components;
|
||||
using Content.Server.Shuttles.Components;
|
||||
using Content.Server.Shuttles.Systems;
|
||||
using Content.Shared.Movement.Components;
|
||||
@@ -9,6 +8,7 @@ using Content.Shared.Shuttles.Systems;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Physics.Components;
|
||||
using Robust.Shared.Player;
|
||||
using DroneConsoleComponent = Content.Server.Shuttles.DroneConsoleComponent;
|
||||
|
||||
namespace Content.Server.Physics.Controllers
|
||||
{
|
||||
|
||||
146
Content.Server/Procedural/DungeonJob.NoiseDunGen.cs
Normal file
146
Content.Server/Procedural/DungeonJob.NoiseDunGen.cs
Normal file
@@ -0,0 +1,146 @@
|
||||
using System.Numerics;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Shared.Maps;
|
||||
using Content.Shared.Procedural;
|
||||
using Content.Shared.Procedural.DungeonGenerators;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Procedural;
|
||||
|
||||
public sealed partial class DungeonJob
|
||||
{
|
||||
private async Task<Dungeon> GenerateNoiseDungeon(NoiseDunGen dungen, EntityUid gridUid, MapGridComponent grid,
|
||||
int seed)
|
||||
{
|
||||
var rand = new Random(seed);
|
||||
var tiles = new List<(Vector2i, Tile)>();
|
||||
|
||||
foreach (var layer in dungen.Layers)
|
||||
{
|
||||
layer.Noise.SetSeed(seed);
|
||||
}
|
||||
|
||||
// First we have to find a seed tile, then floodfill from there until we get to noise
|
||||
// at which point we floodfill the entire noise.
|
||||
var iterations = dungen.Iterations;
|
||||
var area = new Box2i();
|
||||
var frontier = new Queue<Vector2i>();
|
||||
var rooms = new List<DungeonRoom>();
|
||||
var tileCount = 0;
|
||||
var tileCap = rand.NextGaussian(dungen.TileCap, dungen.CapStd);
|
||||
var visited = new HashSet<Vector2i>();
|
||||
|
||||
while (iterations > 0 && tileCount < tileCap)
|
||||
{
|
||||
var roomTiles = new HashSet<Vector2i>();
|
||||
iterations--;
|
||||
|
||||
// Get a random exterior tile to start floodfilling from.
|
||||
var edge = rand.Next(4);
|
||||
Vector2i seedTile;
|
||||
|
||||
switch (edge)
|
||||
{
|
||||
case 0:
|
||||
seedTile = new Vector2i(rand.Next(area.Left - 2, area.Right + 1), area.Bottom - 2);
|
||||
break;
|
||||
case 1:
|
||||
seedTile = new Vector2i(area.Right + 1, rand.Next(area.Bottom - 2, area.Top + 1));
|
||||
break;
|
||||
case 2:
|
||||
seedTile = new Vector2i(rand.Next(area.Left - 2, area.Right + 1), area.Top + 1);
|
||||
break;
|
||||
case 3:
|
||||
seedTile = new Vector2i(area.Left - 2, rand.Next(area.Bottom - 2, area.Top + 1));
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
DebugTools.Assert(!visited.Contains(seedTile));
|
||||
var noiseFill = false;
|
||||
frontier.Clear();
|
||||
visited.Add(seedTile);
|
||||
frontier.Enqueue(seedTile);
|
||||
area = area.UnionTile(seedTile);
|
||||
Box2i roomArea = new Box2i(seedTile, seedTile + Vector2i.One);
|
||||
|
||||
// Time to floodfill again
|
||||
while (frontier.TryDequeue(out var node) && tileCount < tileCap)
|
||||
{
|
||||
var foundNoise = false;
|
||||
|
||||
foreach (var layer in dungen.Layers)
|
||||
{
|
||||
var value = layer.Noise.GetNoise(node.X, node.Y);
|
||||
|
||||
if (value < layer.Threshold)
|
||||
continue;
|
||||
|
||||
roomArea = roomArea.UnionTile(node);
|
||||
foundNoise = true;
|
||||
noiseFill = true;
|
||||
var tileDef = _tileDefManager[layer.Tile];
|
||||
var variant = rand.NextByte(tileDef.Variants);
|
||||
|
||||
tiles.Add((node, new Tile(tileDef.TileId, variant: variant)));
|
||||
roomTiles.Add(node);
|
||||
tileCount++;
|
||||
break;
|
||||
}
|
||||
|
||||
// Don't get neighbors if they don't have noise.
|
||||
// only if we've already found any noise.
|
||||
if (noiseFill && !foundNoise)
|
||||
continue;
|
||||
|
||||
for (var x = -1; x <= 1; x++)
|
||||
{
|
||||
for (var y = -1; y <= 1; y++)
|
||||
{
|
||||
// Cardinals only
|
||||
if (x != 0 && y != 0)
|
||||
continue;
|
||||
|
||||
var neighbor = new Vector2i(node.X + x, node.Y + y);
|
||||
|
||||
if (!visited.Add(neighbor))
|
||||
continue;
|
||||
|
||||
area = area.UnionTile(neighbor);
|
||||
frontier.Enqueue(neighbor);
|
||||
}
|
||||
}
|
||||
|
||||
await SuspendIfOutOfTime();
|
||||
ValidateResume();
|
||||
}
|
||||
|
||||
var center = Vector2.Zero;
|
||||
|
||||
foreach (var tile in roomTiles)
|
||||
{
|
||||
center += tile + grid.TileSizeHalfVector;
|
||||
}
|
||||
|
||||
center /= roomTiles.Count;
|
||||
rooms.Add(new DungeonRoom(roomTiles, center, roomArea, new HashSet<Vector2i>()));
|
||||
await SuspendIfOutOfTime();
|
||||
ValidateResume();
|
||||
}
|
||||
|
||||
grid.SetTiles(tiles);
|
||||
|
||||
var dungeon = new Dungeon(rooms);
|
||||
|
||||
foreach (var tile in tiles)
|
||||
{
|
||||
dungeon.RoomTiles.Add(tile.Item1);
|
||||
}
|
||||
|
||||
return dungeon;
|
||||
}
|
||||
}
|
||||
@@ -790,7 +790,7 @@ public sealed partial class DungeonJob
|
||||
foreach (var entrance in room.Entrances)
|
||||
{
|
||||
// Just so we can still actually get in to the entrance we won't deter from a tile away from it.
|
||||
var normal = ((Vector2) entrance + grid.TileSizeHalfVector - room.Center).ToWorldAngle().GetCardinalDir().ToIntVec();
|
||||
var normal = (entrance + grid.TileSizeHalfVector - room.Center).ToWorldAngle().GetCardinalDir().ToIntVec();
|
||||
deterredTiles.Remove(entrance + normal);
|
||||
}
|
||||
}
|
||||
|
||||
138
Content.Server/Procedural/DungeonJob.PostGenBiome.cs
Normal file
138
Content.Server/Procedural/DungeonJob.PostGenBiome.cs
Normal file
@@ -0,0 +1,138 @@
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Parallax;
|
||||
using Content.Shared.Parallax.Biomes;
|
||||
using Content.Shared.Parallax.Biomes.Markers;
|
||||
using Content.Shared.Procedural;
|
||||
using Content.Shared.Procedural.PostGeneration;
|
||||
using Content.Shared.Random.Helpers;
|
||||
using Robust.Shared.Map;
|
||||
using Robust.Shared.Map.Components;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Procedural;
|
||||
|
||||
public sealed partial class DungeonJob
|
||||
{
|
||||
/*
|
||||
* Handles PostGen code for marker layers + biomes.
|
||||
*/
|
||||
|
||||
private async Task PostGen(BiomePostGen postGen, Dungeon dungeon, EntityUid gridUid, MapGridComponent grid, Random random)
|
||||
{
|
||||
if (_entManager.TryGetComponent(gridUid, out BiomeComponent? biomeComp))
|
||||
return;
|
||||
|
||||
biomeComp = _entManager.AddComponent<BiomeComponent>(gridUid);
|
||||
var biomeSystem = _entManager.System<BiomeSystem>();
|
||||
biomeSystem.SetTemplate(gridUid, biomeComp, _prototype.Index(postGen.BiomeTemplate));
|
||||
var seed = random.Next();
|
||||
var xformQuery = _entManager.GetEntityQuery<TransformComponent>();
|
||||
|
||||
foreach (var node in dungeon.RoomTiles)
|
||||
{
|
||||
// Need to set per-tile to override data.
|
||||
if (biomeSystem.TryGetTile(node, biomeComp.Layers, seed, grid, out var tile))
|
||||
{
|
||||
_maps.SetTile(gridUid, grid, node, tile.Value);
|
||||
}
|
||||
|
||||
if (biomeSystem.TryGetDecals(node, biomeComp.Layers, seed, grid, out var decals))
|
||||
{
|
||||
foreach (var decal in decals)
|
||||
{
|
||||
_decals.TryAddDecal(decal.ID, new EntityCoordinates(gridUid, decal.Position), out _);
|
||||
}
|
||||
}
|
||||
|
||||
if (biomeSystem.TryGetEntity(node, biomeComp, grid, out var entityProto))
|
||||
{
|
||||
var ent = _entManager.SpawnEntity(entityProto, new EntityCoordinates(gridUid, node + grid.TileSizeHalfVector));
|
||||
var xform = xformQuery.Get(ent);
|
||||
|
||||
if (!xform.Comp.Anchored)
|
||||
{
|
||||
_transform.AnchorEntity(ent, xform);
|
||||
}
|
||||
|
||||
// TODO: Engine bug with SpawnAtPosition
|
||||
DebugTools.Assert(xform.Comp.Anchored);
|
||||
}
|
||||
|
||||
await SuspendIfOutOfTime();
|
||||
ValidateResume();
|
||||
}
|
||||
|
||||
biomeComp.Enabled = false;
|
||||
}
|
||||
|
||||
private async Task PostGen(BiomeMarkerLayerPostGen postGen, Dungeon dungeon, EntityUid gridUid, MapGridComponent grid, Random random)
|
||||
{
|
||||
if (!_entManager.TryGetComponent(gridUid, out BiomeComponent? biomeComp))
|
||||
return;
|
||||
|
||||
var biomeSystem = _entManager.System<BiomeSystem>();
|
||||
var weightedRandom = _prototype.Index(postGen.MarkerTemplate);
|
||||
var xformQuery = _entManager.GetEntityQuery<TransformComponent>();
|
||||
var templates = new Dictionary<string, int>();
|
||||
|
||||
for (var i = 0; i < postGen.Count; i++)
|
||||
{
|
||||
var template = weightedRandom.Pick(random);
|
||||
var count = templates.GetOrNew(template);
|
||||
count++;
|
||||
templates[template] = count;
|
||||
}
|
||||
|
||||
foreach (var (template, count) in templates)
|
||||
{
|
||||
var markerTemplate = _prototype.Index<BiomeMarkerLayerPrototype>(template);
|
||||
|
||||
var bounds = new Box2i();
|
||||
|
||||
foreach (var tile in dungeon.RoomTiles)
|
||||
{
|
||||
bounds = bounds.UnionTile(tile);
|
||||
}
|
||||
|
||||
await SuspendIfOutOfTime();
|
||||
ValidateResume();
|
||||
|
||||
biomeSystem.GetMarkerNodes(gridUid, biomeComp, grid, markerTemplate, true, bounds, count,
|
||||
random, out var spawnSet, out var existing, false);
|
||||
|
||||
await SuspendIfOutOfTime();
|
||||
ValidateResume();
|
||||
|
||||
foreach (var ent in existing)
|
||||
{
|
||||
_entManager.DeleteEntity(ent);
|
||||
}
|
||||
|
||||
await SuspendIfOutOfTime();
|
||||
ValidateResume();
|
||||
|
||||
foreach (var (node, mask) in spawnSet)
|
||||
{
|
||||
string? proto;
|
||||
|
||||
if (mask != null && markerTemplate.EntityMask.TryGetValue(mask, out var maskedProto))
|
||||
{
|
||||
proto = maskedProto;
|
||||
}
|
||||
else
|
||||
{
|
||||
proto = markerTemplate.Prototype;
|
||||
}
|
||||
|
||||
var ent = _entManager.SpawnAtPosition(proto, new EntityCoordinates(gridUid, node + grid.TileSizeHalfVector));
|
||||
var xform = xformQuery.Get(ent);
|
||||
|
||||
if (!xform.Comp.Anchored)
|
||||
_transform.AnchorEntity(ent, xform);
|
||||
|
||||
await SuspendIfOutOfTime();
|
||||
ValidateResume();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ public sealed partial class DungeonJob : Job<Dungeon>
|
||||
private readonly DecalSystem _decals;
|
||||
private readonly DungeonSystem _dungeon;
|
||||
private readonly EntityLookupSystem _lookup;
|
||||
private readonly SharedMapSystem _maps;
|
||||
private readonly SharedTransformSystem _transform;
|
||||
private EntityQuery<TagComponent> _tagQuery;
|
||||
|
||||
@@ -68,6 +69,7 @@ public sealed partial class DungeonJob : Job<Dungeon>
|
||||
_decals = decals;
|
||||
_dungeon = dungeon;
|
||||
_lookup = lookup;
|
||||
_maps = _entManager.System<SharedMapSystem>();
|
||||
_transform = transform;
|
||||
_tagQuery = _entManager.GetEntityQuery<TagComponent>();
|
||||
|
||||
@@ -86,15 +88,18 @@ public sealed partial class DungeonJob : Job<Dungeon>
|
||||
|
||||
switch (_gen.Generator)
|
||||
{
|
||||
case NoiseDunGen noise:
|
||||
dungeon = await GenerateNoiseDungeon(noise, _gridUid, _grid, _seed);
|
||||
break;
|
||||
case PrefabDunGen prefab:
|
||||
dungeon = await GeneratePrefabDungeon(prefab, _gridUid, _grid, _seed);
|
||||
DebugTools.Assert(dungeon.RoomExteriorTiles.Count > 0);
|
||||
break;
|
||||
default:
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
DebugTools.Assert(dungeon.RoomTiles.Count > 0);
|
||||
DebugTools.Assert(dungeon.RoomExteriorTiles.Count > 0);
|
||||
|
||||
// To make it slightly more deterministic treat this RNG as separate ig.
|
||||
var random = new Random(_seed);
|
||||
@@ -108,6 +113,9 @@ public sealed partial class DungeonJob : Job<Dungeon>
|
||||
case AutoCablingPostGen cabling:
|
||||
await PostGen(cabling, dungeon, _gridUid, _grid, random);
|
||||
break;
|
||||
case BiomePostGen biome:
|
||||
await PostGen(biome, dungeon, _gridUid, _grid, random);
|
||||
break;
|
||||
case BoundaryWallPostGen boundary:
|
||||
await PostGen(boundary, dungeon, _gridUid, _grid, random);
|
||||
break;
|
||||
@@ -138,6 +146,9 @@ public sealed partial class DungeonJob : Job<Dungeon>
|
||||
case InternalWindowPostGen internalWindow:
|
||||
await PostGen(internalWindow, dungeon, _gridUid, _grid, random);
|
||||
break;
|
||||
case BiomeMarkerLayerPostGen markerPost:
|
||||
await PostGen(markerPost, dungeon, _gridUid, _grid, random);
|
||||
break;
|
||||
case RoomEntrancePostGen rEntrance:
|
||||
await PostGen(rEntrance, dungeon, _gridUid, _grid, random);
|
||||
break;
|
||||
@@ -154,6 +165,7 @@ public sealed partial class DungeonJob : Job<Dungeon>
|
||||
break;
|
||||
}
|
||||
|
||||
// Defer splitting so they don't get spammed and so we don't have to worry about tracking the grid along the way.
|
||||
_grid.CanSplit = true;
|
||||
_entManager.System<GridFixtureSystem>().CheckSplits(_gridUid);
|
||||
return dungeon;
|
||||
|
||||
@@ -227,7 +227,6 @@ public sealed partial class DungeonSystem : SharedDungeonSystem
|
||||
|
||||
_dungeonJobs.Add(job, cancelToken);
|
||||
_dungeonJobQueue.EnqueueJob(job);
|
||||
job.Run();
|
||||
await job.AsTask;
|
||||
|
||||
if (job.Exception != null)
|
||||
|
||||
@@ -5,6 +5,9 @@ using Robust.Shared.Random;
|
||||
|
||||
namespace Content.Server.Salvage;
|
||||
|
||||
/// <summary>
|
||||
/// Transports attached entities to the linked beacon after a timer has elapsed.
|
||||
/// </summary>
|
||||
public sealed class FultonSystem : SharedFultonSystem
|
||||
{
|
||||
[Dependency] private readonly IRobustRandom _random = default!;
|
||||
|
||||
7
Content.Server/Salvage/Magnet/SalvageMagnetComponent.cs
Normal file
7
Content.Server/Salvage/Magnet/SalvageMagnetComponent.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace Content.Server.Salvage.Magnet;
|
||||
|
||||
[RegisterComponent]
|
||||
public sealed partial class SalvageMagnetComponent : Component
|
||||
{
|
||||
|
||||
}
|
||||
57
Content.Server/Salvage/Magnet/SalvageMagnetDataComponent.cs
Normal file
57
Content.Server/Salvage/Magnet/SalvageMagnetDataComponent.cs
Normal file
@@ -0,0 +1,57 @@
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom;
|
||||
|
||||
namespace Content.Server.Salvage.Magnet;
|
||||
|
||||
/// <summary>
|
||||
/// Added to the station to hold salvage magnet data.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed partial class SalvageMagnetDataComponent : Component
|
||||
{
|
||||
// May be multiple due to splitting.
|
||||
|
||||
/// <summary>
|
||||
/// Entities currently magnetised.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public List<EntityUid>? ActiveEntities;
|
||||
|
||||
/// <summary>
|
||||
/// If the magnet is currently active when does it end.
|
||||
/// </summary>
|
||||
[DataField(customTypeSerializer:typeof(TimeOffsetSerializer))]
|
||||
public TimeSpan? EndTime;
|
||||
|
||||
[DataField(customTypeSerializer:typeof(TimeOffsetSerializer))]
|
||||
public TimeSpan NextOffer;
|
||||
|
||||
/// <summary>
|
||||
/// How long salvage will be active for before despawning.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public TimeSpan ActiveTime = TimeSpan.FromMinutes(6);
|
||||
|
||||
/// <summary>
|
||||
/// Cooldown between offerings after one ends.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public TimeSpan OfferCooldown = TimeSpan.FromMinutes(3);
|
||||
|
||||
/// <summary>
|
||||
/// Seeds currently offered
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public List<int> Offered = new();
|
||||
|
||||
[DataField]
|
||||
public int OfferCount = 6;
|
||||
|
||||
[DataField]
|
||||
public int ActiveSeed;
|
||||
|
||||
/// <summary>
|
||||
/// Final countdown announcement.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public bool Announced;
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
namespace Content.Server.Salvage.Magnet;
|
||||
|
||||
/// <summary>
|
||||
/// Indicates the entity is a salvage target for tracking.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed partial class SalvageMagnetTargetComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// Entity that spawned us.
|
||||
/// </summary>
|
||||
[DataField]
|
||||
public EntityUid DataTarget;
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
namespace Content.Server.Salvage.Magnet;
|
||||
|
||||
// This is dumb
|
||||
/// <summary>
|
||||
/// Deletes the attached entity if the linked entity is deleted.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed partial class SalvageMobRestrictionsComponent : Component
|
||||
{
|
||||
[DataField, ViewVariables(VVAccess.ReadWrite)]
|
||||
public EntityUid LinkedEntity;
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
namespace Content.Server.Salvage
|
||||
{
|
||||
/// <summary>
|
||||
/// A grid spawned by a salvage magnet.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed partial class SalvageGridComponent : Component
|
||||
{
|
||||
/// <summary>
|
||||
/// The magnet that spawned this grid.
|
||||
/// </summary>
|
||||
public EntityUid? SpawnerMagnet;
|
||||
}
|
||||
}
|
||||
@@ -1,138 +0,0 @@
|
||||
using Content.Shared.Radio;
|
||||
using Content.Shared.Random;
|
||||
using Content.Shared.Salvage;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
|
||||
namespace Content.Server.Salvage
|
||||
{
|
||||
/// <summary>
|
||||
/// A salvage magnet.
|
||||
/// </summary>
|
||||
[NetworkedComponent, RegisterComponent]
|
||||
[Access(typeof(SalvageSystem))]
|
||||
public sealed partial class SalvageMagnetComponent : SharedSalvageMagnetComponent
|
||||
{
|
||||
/// <summary>
|
||||
/// Maximum distance from the offset position that will be used as a salvage's spawnpoint.
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("offsetRadiusMax")]
|
||||
public float OffsetRadiusMax = 32;
|
||||
|
||||
/// <summary>
|
||||
/// The entity attached to the magnet
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadOnly)]
|
||||
[DataField("attachedEntity")]
|
||||
public EntityUid? AttachedEntity;
|
||||
|
||||
/// <summary>
|
||||
/// Current state of this magnet
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadOnly)]
|
||||
[DataField("magnetState")]
|
||||
public MagnetState MagnetState = MagnetState.Inactive;
|
||||
|
||||
/// <summary>
|
||||
/// How long it takes for the magnet to pull in the debris
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("baseAttachingTime")]
|
||||
public TimeSpan BaseAttachingTime = TimeSpan.FromSeconds(30);
|
||||
|
||||
/// <summary>
|
||||
/// How long it actually takes for the magnet to pull in the debris
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("attachingTime")]
|
||||
public TimeSpan AttachingTime = TimeSpan.FromSeconds(30);
|
||||
|
||||
/// <summary>
|
||||
/// How long the magnet can hold the debris until it starts losing the lock
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("holdTime")]
|
||||
public TimeSpan HoldTime = TimeSpan.FromSeconds(240);
|
||||
|
||||
/// <summary>
|
||||
/// How long the magnet can hold the debris while losing the lock
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("detachingTime")]
|
||||
public TimeSpan DetachingTime = TimeSpan.FromSeconds(30);
|
||||
|
||||
/// <summary>
|
||||
/// How long the magnet has to cool down for after use
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("baseCooldownTime")]
|
||||
public TimeSpan BaseCooldownTime = TimeSpan.FromSeconds(60);
|
||||
|
||||
/// <summary>
|
||||
/// How long the magnet actually has to cool down for after use
|
||||
/// </summary>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("cooldownTime")]
|
||||
public TimeSpan CooldownTime = TimeSpan.FromSeconds(60);
|
||||
|
||||
[DataField("salvageChannel", customTypeSerializer: typeof(PrototypeIdSerializer<RadioChannelPrototype>))]
|
||||
public string SalvageChannel = "Supply";
|
||||
|
||||
/// <summary>
|
||||
/// Current how much charge the magnet currently has
|
||||
/// </summary>
|
||||
[DataField("chargeRemaining")]
|
||||
public int ChargeRemaining = 5;
|
||||
|
||||
/// <summary>
|
||||
/// How much capacity the magnet can hold
|
||||
/// </summary>
|
||||
[DataField("chargeCapacity")]
|
||||
public int ChargeCapacity = 5;
|
||||
|
||||
/// <summary>
|
||||
/// Used as a guard to prevent spamming the appearance system
|
||||
/// </summary>
|
||||
[DataField("previousCharge")]
|
||||
public int PreviousCharge = 5;
|
||||
|
||||
/// <summary>
|
||||
/// The chance that a random procgen asteroid will be
|
||||
/// generated rather than a static salvage prototype.
|
||||
/// </summary>
|
||||
[DataField("asteroidChance"), ViewVariables(VVAccess.ReadWrite)]
|
||||
public float AsteroidChance = 0.6f;
|
||||
|
||||
/// <summary>
|
||||
/// A weighted random prototype corresponding to
|
||||
/// what asteroid entities will be generated.
|
||||
/// </summary>
|
||||
[DataField("asteroidPool", customTypeSerializer: typeof(PrototypeIdSerializer<WeightedRandomEntityPrototype>)), ViewVariables(VVAccess.ReadWrite)]
|
||||
public string AsteroidPool = "RandomAsteroidPool";
|
||||
}
|
||||
|
||||
[CopyByRef, DataRecord]
|
||||
public record struct MagnetState(MagnetStateType StateType, TimeSpan Until)
|
||||
{
|
||||
public static readonly MagnetState Inactive = new (MagnetStateType.Inactive, TimeSpan.Zero);
|
||||
};
|
||||
|
||||
public sealed class SalvageMagnetActivatedEvent : EntityEventArgs
|
||||
{
|
||||
public EntityUid Magnet;
|
||||
|
||||
public SalvageMagnetActivatedEvent(EntityUid magnet)
|
||||
{
|
||||
Magnet = magnet;
|
||||
}
|
||||
}
|
||||
public enum MagnetStateType
|
||||
{
|
||||
Inactive,
|
||||
Attaching,
|
||||
Holding,
|
||||
Detaching,
|
||||
CoolingDown,
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Utility;
|
||||
|
||||
namespace Content.Server.Salvage;
|
||||
|
||||
[Prototype("salvageMap")]
|
||||
public sealed partial class SalvageMapPrototype : IPrototype
|
||||
{
|
||||
[ViewVariables] [IdDataField] public string ID { get; } = default!;
|
||||
|
||||
/// <summary>
|
||||
/// Relative directory path to the given map, i.e. `Maps/Salvage/template.yml`
|
||||
/// </summary>
|
||||
[DataField("mapPath", required: true)] public ResPath MapPath;
|
||||
|
||||
/// <summary>
|
||||
/// Name for admin use
|
||||
/// </summary>
|
||||
[DataField("name")] public string Name = string.Empty;
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using System;
|
||||
|
||||
namespace Content.Server.Salvage;
|
||||
|
||||
/// <summary>
|
||||
/// This component exists as a sort of stateful marker for a
|
||||
/// killswitch meant to keep salvage mobs from doing stuff they
|
||||
/// really shouldn't (attacking station).
|
||||
/// The main thing is that adding this component ties the mob to
|
||||
/// whatever it's currently parented to.
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed partial class SalvageMobRestrictionsComponent : Component
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadOnly)]
|
||||
[DataField("linkedGridEntity")]
|
||||
public EntityUid LinkedGridEntity = EntityUid.Invalid;
|
||||
}
|
||||
|
||||
@@ -1,23 +0,0 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using System;
|
||||
|
||||
namespace Content.Server.Salvage;
|
||||
|
||||
/// <summary>
|
||||
/// This component is attached to grids when a salvage mob is
|
||||
/// spawned on them.
|
||||
/// This attachment is done by SalvageMobRestrictionsSystem.
|
||||
/// *Simply put, when this component is removed, the mobs die.*
|
||||
/// *This applies even if the mobs are off-grid at the time.*
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public sealed partial class SalvageMobRestrictionsGridComponent : Component
|
||||
{
|
||||
[ViewVariables(VVAccess.ReadOnly)]
|
||||
[DataField("mobsToKill")]
|
||||
public List<EntityUid> MobsToKill = new();
|
||||
}
|
||||
|
||||
@@ -1,70 +0,0 @@
|
||||
using Content.Server.Body.Systems;
|
||||
using Content.Shared.Body.Components;
|
||||
using Content.Shared.Damage;
|
||||
using Content.Shared.Mobs.Systems;
|
||||
|
||||
namespace Content.Server.Salvage;
|
||||
|
||||
public sealed class SalvageMobRestrictionsSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly BodySystem _bodySystem = default!;
|
||||
[Dependency] private readonly DamageableSystem _damageableSystem = default!;
|
||||
[Dependency] private readonly MobStateSystem _mobStateSystem = default!;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<SalvageMobRestrictionsComponent, ComponentInit>(OnInit);
|
||||
SubscribeLocalEvent<SalvageMobRestrictionsComponent, ComponentRemove>(OnRemove);
|
||||
SubscribeLocalEvent<SalvageMobRestrictionsGridComponent, ComponentRemove>(OnRemoveGrid);
|
||||
}
|
||||
|
||||
private void OnInit(EntityUid uid, SalvageMobRestrictionsComponent component, ComponentInit args)
|
||||
{
|
||||
var gridUid = Transform(uid).ParentUid;
|
||||
if (!EntityManager.EntityExists(gridUid))
|
||||
{
|
||||
// Give up, we were spawned improperly
|
||||
return;
|
||||
}
|
||||
// When this code runs, the salvage magnet hasn't actually gotten ahold of the entity yet.
|
||||
// So it therefore isn't in a position to do this.
|
||||
if (!TryComp(gridUid, out SalvageMobRestrictionsGridComponent? rg))
|
||||
{
|
||||
rg = AddComp<SalvageMobRestrictionsGridComponent>(gridUid);
|
||||
}
|
||||
rg.MobsToKill.Add(uid);
|
||||
component.LinkedGridEntity = gridUid;
|
||||
}
|
||||
|
||||
private void OnRemove(EntityUid uid, SalvageMobRestrictionsComponent component, ComponentRemove args)
|
||||
{
|
||||
if (TryComp(component.LinkedGridEntity, out SalvageMobRestrictionsGridComponent? rg))
|
||||
{
|
||||
rg.MobsToKill.Remove(uid);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnRemoveGrid(EntityUid uid, SalvageMobRestrictionsGridComponent component, ComponentRemove args)
|
||||
{
|
||||
var metaQuery = GetEntityQuery<MetaDataComponent>();
|
||||
var bodyQuery = GetEntityQuery<BodyComponent>();
|
||||
var damageQuery = GetEntityQuery<DamageableComponent>();
|
||||
foreach (var target in component.MobsToKill)
|
||||
{
|
||||
if (Deleted(target, metaQuery)) continue;
|
||||
if (_mobStateSystem.IsDead(target)) continue; // DONT WASTE BIOMASS
|
||||
if (bodyQuery.TryGetComponent(target, out var body))
|
||||
{
|
||||
// Just because.
|
||||
_bodySystem.GibBody(target, body: body);
|
||||
}
|
||||
else if (damageQuery.TryGetComponent(target, out var damageableComponent))
|
||||
{
|
||||
_damageableSystem.SetAllDamage(target, damageableComponent, 200);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,7 @@ sealed class SalvageRulerCommand : IConsoleCommand
|
||||
var first = true;
|
||||
foreach (var mapGrid in _maps.GetAllGrids(entityTransform.MapID))
|
||||
{
|
||||
var aabb = _entities.GetComponent<TransformComponent>(mapGrid).WorldMatrix.TransformBox(mapGrid.Comp.LocalAABB);
|
||||
var aabb = _entities.System<SharedTransformSystem>().GetWorldMatrix(mapGrid).TransformBox(mapGrid.Comp.LocalAABB);
|
||||
if (first)
|
||||
{
|
||||
total = aabb;
|
||||
|
||||
408
Content.Server/Salvage/SalvageSystem.Magnet.cs
Normal file
408
Content.Server/Salvage/SalvageSystem.Magnet.cs
Normal file
@@ -0,0 +1,408 @@
|
||||
using System.Linq;
|
||||
using System.Numerics;
|
||||
using System.Threading.Tasks;
|
||||
using Content.Server.Salvage.Magnet;
|
||||
using Content.Shared.Humanoid;
|
||||
using Content.Shared.Mobs.Components;
|
||||
using Content.Shared.Radio;
|
||||
using Content.Shared.Salvage.Magnet;
|
||||
using Robust.Server.Maps;
|
||||
using Robust.Shared.Map;
|
||||
|
||||
namespace Content.Server.Salvage;
|
||||
|
||||
public sealed partial class SalvageSystem
|
||||
{
|
||||
[ValidatePrototypeId<RadioChannelPrototype>]
|
||||
private const string MagnetChannel = "Supply";
|
||||
|
||||
private EntityQuery<SalvageMobRestrictionsComponent> _salvMobQuery;
|
||||
|
||||
private void InitializeMagnet()
|
||||
{
|
||||
_salvMobQuery = GetEntityQuery<SalvageMobRestrictionsComponent>();
|
||||
|
||||
SubscribeLocalEvent<SalvageMagnetDataComponent, MapInitEvent>(OnMagnetDataMapInit);
|
||||
|
||||
SubscribeLocalEvent<SalvageMagnetTargetComponent, GridSplitEvent>(OnMagnetTargetSplit);
|
||||
|
||||
SubscribeLocalEvent<SalvageMagnetComponent, MagnetClaimOfferEvent>(OnMagnetClaim);
|
||||
SubscribeLocalEvent<SalvageMagnetComponent, ComponentStartup>(OnMagnetStartup);
|
||||
SubscribeLocalEvent<SalvageMagnetComponent, AnchorStateChangedEvent>(OnMagnetAnchored);
|
||||
}
|
||||
|
||||
private void OnMagnetClaim(EntityUid uid, SalvageMagnetComponent component, ref MagnetClaimOfferEvent args)
|
||||
{
|
||||
var player = args.Session.AttachedEntity;
|
||||
|
||||
if (player is null)
|
||||
return;
|
||||
|
||||
var station = _station.GetOwningStation(uid);
|
||||
|
||||
if (!TryComp(station, out SalvageMagnetDataComponent? dataComp) ||
|
||||
dataComp.EndTime != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TakeMagnetOffer((station.Value, dataComp), args.Index, (uid, component));
|
||||
}
|
||||
|
||||
private void OnMagnetStartup(EntityUid uid, SalvageMagnetComponent component, ComponentStartup args)
|
||||
{
|
||||
UpdateMagnetUI((uid, component), Transform(uid));
|
||||
}
|
||||
|
||||
private void OnMagnetAnchored(EntityUid uid, SalvageMagnetComponent component, ref AnchorStateChangedEvent args)
|
||||
{
|
||||
if (!args.Anchored)
|
||||
return;
|
||||
|
||||
UpdateMagnetUI((uid, component), args.Transform);
|
||||
}
|
||||
|
||||
private void OnMagnetDataMapInit(EntityUid uid, SalvageMagnetDataComponent component, ref MapInitEvent args)
|
||||
{
|
||||
CreateMagnetOffers((uid, component));
|
||||
}
|
||||
|
||||
private void OnMagnetTargetSplit(EntityUid uid, SalvageMagnetTargetComponent component, ref GridSplitEvent args)
|
||||
{
|
||||
// Don't think I'm not onto you people splitting to make new grids.
|
||||
if (TryComp(component.DataTarget, out SalvageMagnetDataComponent? dataComp))
|
||||
{
|
||||
foreach (var gridUid in args.NewGrids)
|
||||
{
|
||||
dataComp.ActiveEntities?.Add(gridUid);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateMagnet()
|
||||
{
|
||||
var dataQuery = EntityQueryEnumerator<SalvageMagnetDataComponent>();
|
||||
var curTime = _timing.CurTime;
|
||||
|
||||
while (dataQuery.MoveNext(out var uid, out var magnetData))
|
||||
{
|
||||
// Magnet currently active.
|
||||
if (magnetData.EndTime != null)
|
||||
{
|
||||
if (magnetData.EndTime.Value < curTime)
|
||||
{
|
||||
EndMagnet((uid, magnetData));
|
||||
}
|
||||
else if (!magnetData.Announced && (magnetData.EndTime.Value - curTime).TotalSeconds < 31)
|
||||
{
|
||||
var magnet = GetMagnet((uid, magnetData));
|
||||
|
||||
if (magnet != null)
|
||||
{
|
||||
Report(magnet.Value.Owner, MagnetChannel,
|
||||
"salvage-system-announcement-losing",
|
||||
("timeLeft", (magnetData.EndTime.Value - curTime).Seconds));
|
||||
}
|
||||
|
||||
magnetData.Announced = true;
|
||||
}
|
||||
}
|
||||
if (magnetData.NextOffer < curTime)
|
||||
{
|
||||
CreateMagnetOffers((uid, magnetData));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Ends the magnet attachment and deletes the relevant grids.
|
||||
/// </summary>
|
||||
private void EndMagnet(Entity<SalvageMagnetDataComponent> data)
|
||||
{
|
||||
if (data.Comp.ActiveEntities != null)
|
||||
{
|
||||
// Handle mobrestrictions getting deleted
|
||||
var query = AllEntityQuery<SalvageMobRestrictionsComponent>();
|
||||
|
||||
while (query.MoveNext(out var salvUid, out var salvMob))
|
||||
{
|
||||
if (data.Comp.ActiveEntities.Contains(salvMob.LinkedEntity))
|
||||
{
|
||||
QueueDel(salvUid);
|
||||
}
|
||||
}
|
||||
|
||||
// Uhh yeah don't delete mobs or whatever
|
||||
var mobQuery = AllEntityQuery<HumanoidAppearanceComponent, MobStateComponent, TransformComponent>();
|
||||
|
||||
while (mobQuery.MoveNext(out var mobUid, out _, out _, out var xform))
|
||||
{
|
||||
if (xform.GridUid == null || !data.Comp.ActiveEntities.Contains(xform.GridUid.Value) || xform.MapUid == null)
|
||||
continue;
|
||||
|
||||
_transform.SetParent(mobUid, xform.MapUid.Value);
|
||||
}
|
||||
|
||||
// Go and cleanup the active ents.
|
||||
foreach (var ent in data.Comp.ActiveEntities)
|
||||
{
|
||||
Del(ent);
|
||||
}
|
||||
|
||||
data.Comp.ActiveEntities = null;
|
||||
}
|
||||
|
||||
data.Comp.EndTime = null;
|
||||
UpdateMagnetUIs(data);
|
||||
}
|
||||
|
||||
private void CreateMagnetOffers(Entity<SalvageMagnetDataComponent> data)
|
||||
{
|
||||
data.Comp.Offered.Clear();
|
||||
|
||||
for (var i = 0; i < data.Comp.OfferCount; i++)
|
||||
{
|
||||
var seed = _random.Next();
|
||||
|
||||
// Fuck with the seed to mix wrecks and asteroids.
|
||||
seed = (int) (seed / 10f) * 10;
|
||||
|
||||
if (i >= data.Comp.OfferCount / 2)
|
||||
{
|
||||
seed++;
|
||||
}
|
||||
|
||||
data.Comp.Offered.Add(seed);
|
||||
}
|
||||
|
||||
data.Comp.NextOffer = _timing.CurTime + data.Comp.OfferCooldown;
|
||||
UpdateMagnetUIs(data);
|
||||
}
|
||||
|
||||
// Just need something to announce.
|
||||
private Entity<SalvageMagnetComponent>? GetMagnet(Entity<SalvageMagnetDataComponent> data)
|
||||
{
|
||||
var query = AllEntityQuery<SalvageMagnetComponent, TransformComponent>();
|
||||
|
||||
while (query.MoveNext(out var magnetUid, out var magnet, out var xform))
|
||||
{
|
||||
var stationUid = _station.GetOwningStation(magnetUid, xform);
|
||||
|
||||
if (stationUid != data.Owner)
|
||||
continue;
|
||||
|
||||
return (magnetUid, magnet);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void UpdateMagnetUI(Entity<SalvageMagnetComponent> entity, TransformComponent xform)
|
||||
{
|
||||
var station = _station.GetOwningStation(entity, xform);
|
||||
|
||||
if (!TryComp(station, out SalvageMagnetDataComponent? dataComp))
|
||||
return;
|
||||
|
||||
_ui.TrySetUiState(entity, SalvageMagnetUiKey.Key,
|
||||
new SalvageMagnetBoundUserInterfaceState(dataComp.Offered)
|
||||
{
|
||||
Cooldown = dataComp.OfferCooldown,
|
||||
Duration = dataComp.ActiveTime,
|
||||
EndTime = dataComp.EndTime,
|
||||
NextOffer = dataComp.NextOffer,
|
||||
ActiveSeed = dataComp.ActiveSeed,
|
||||
});
|
||||
}
|
||||
|
||||
private void UpdateMagnetUIs(Entity<SalvageMagnetDataComponent> data)
|
||||
{
|
||||
var query = AllEntityQuery<SalvageMagnetComponent, TransformComponent>();
|
||||
|
||||
while (query.MoveNext(out var magnetUid, out var magnet, out var xform))
|
||||
{
|
||||
var station = _station.GetOwningStation(magnetUid, xform);
|
||||
|
||||
if (station != data.Owner)
|
||||
continue;
|
||||
|
||||
_ui.TrySetUiState(magnetUid, SalvageMagnetUiKey.Key,
|
||||
new SalvageMagnetBoundUserInterfaceState(data.Comp.Offered)
|
||||
{
|
||||
Cooldown = data.Comp.OfferCooldown,
|
||||
Duration = data.Comp.ActiveTime,
|
||||
EndTime = data.Comp.EndTime,
|
||||
NextOffer = data.Comp.NextOffer,
|
||||
ActiveSeed = data.Comp.ActiveSeed,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private async Task TakeMagnetOffer(Entity<SalvageMagnetDataComponent> data, int index, Entity<SalvageMagnetComponent> magnet)
|
||||
{
|
||||
var seed = data.Comp.Offered[index];
|
||||
|
||||
var offering = GetSalvageOffering(seed);
|
||||
var salvMap = _mapManager.CreateMap();
|
||||
|
||||
// Set values while awaiting asteroid dungeon if relevant so we can't double-take offers.
|
||||
data.Comp.ActiveSeed = seed;
|
||||
data.Comp.EndTime = _timing.CurTime + data.Comp.ActiveTime;
|
||||
data.Comp.NextOffer = data.Comp.EndTime.Value;
|
||||
UpdateMagnetUIs(data);
|
||||
|
||||
switch (offering)
|
||||
{
|
||||
case AsteroidOffering asteroid:
|
||||
var grid = _mapManager.CreateGrid(salvMap);
|
||||
await _dungeon.GenerateDungeonAsync(asteroid.DungeonConfig, grid.Owner, grid, Vector2i.Zero, seed);
|
||||
break;
|
||||
case SalvageOffering wreck:
|
||||
var salvageProto = wreck.SalvageMap;
|
||||
|
||||
var opts = new MapLoadOptions
|
||||
{
|
||||
Offset = new Vector2(0, 0)
|
||||
};
|
||||
|
||||
if (!_map.TryLoad(salvMap, salvageProto.MapPath.ToString(), out var roots, opts))
|
||||
{
|
||||
Report(magnet, MagnetChannel, "salvage-system-announcement-spawn-debris-disintegrated");
|
||||
_mapManager.DeleteMap(salvMap);
|
||||
return;
|
||||
}
|
||||
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
|
||||
Box2? bounds = null;
|
||||
var mapXform = _xformQuery.GetComponent(_mapManager.GetMapEntityId(salvMap));
|
||||
|
||||
if (mapXform.ChildCount == 0)
|
||||
{
|
||||
Report(magnet.Owner, MagnetChannel, "salvage-system-announcement-spawn-no-debris-available");
|
||||
return;
|
||||
}
|
||||
|
||||
var mapChildren = mapXform.ChildEnumerator;
|
||||
|
||||
while (mapChildren.MoveNext(out var mapChild))
|
||||
{
|
||||
// If something went awry in dungen.
|
||||
if (!_gridQuery.TryGetComponent(mapChild, out var childGrid))
|
||||
continue;
|
||||
|
||||
var childAABB = _transform.GetWorldMatrix(mapChild).TransformBox(childGrid.LocalAABB);
|
||||
bounds = bounds?.Union(childAABB) ?? childAABB;
|
||||
|
||||
// Update mass scanner names as relevant.
|
||||
if (offering is AsteroidOffering)
|
||||
{
|
||||
_metaData.SetEntityName(mapChild, Loc.GetString("salvage-asteroid-name"));
|
||||
_gravity.EnableGravity(mapChild);
|
||||
}
|
||||
}
|
||||
|
||||
var magnetGridUid = _xformQuery.GetComponent(magnet.Owner).GridUid;
|
||||
Box2 attachedBounds = Box2.Empty;
|
||||
MapId mapId = MapId.Nullspace;
|
||||
|
||||
if (magnetGridUid != null)
|
||||
{
|
||||
var magnetGridXform = _xformQuery.GetComponent(magnetGridUid.Value);
|
||||
attachedBounds = _transform.GetWorldMatrix(magnetGridXform)
|
||||
.TransformBox(_gridQuery.GetComponent(magnetGridUid.Value).LocalAABB);
|
||||
|
||||
mapId = magnetGridXform.MapID;
|
||||
}
|
||||
|
||||
if (!TryGetSalvagePlacementLocation(mapId, attachedBounds, bounds!.Value, out var spawnLocation, out var spawnAngle))
|
||||
{
|
||||
Report(magnet.Owner, MagnetChannel, "salvage-system-announcement-spawn-no-debris-available");
|
||||
_mapManager.DeleteMap(salvMap);
|
||||
return;
|
||||
}
|
||||
|
||||
data.Comp.ActiveEntities = null;
|
||||
mapChildren = mapXform.ChildEnumerator;
|
||||
|
||||
// It worked, move it into position and cleanup values.
|
||||
while (mapChildren.MoveNext(out var mapChild))
|
||||
{
|
||||
var salvXForm = _xformQuery.GetComponent(mapChild);
|
||||
var localPos = salvXForm.LocalPosition;
|
||||
_transform.SetParent(mapChild, salvXForm, _mapManager.GetMapEntityId(spawnLocation.MapId));
|
||||
_transform.SetWorldPositionRotation(mapChild, spawnLocation.Position + localPos, spawnAngle, salvXForm);
|
||||
|
||||
data.Comp.ActiveEntities ??= new List<EntityUid>();
|
||||
data.Comp.ActiveEntities?.Add(mapChild);
|
||||
|
||||
// Handle mob restrictions
|
||||
var children = salvXForm.ChildEnumerator;
|
||||
|
||||
while (children.MoveNext(out var child))
|
||||
{
|
||||
if (!_salvMobQuery.TryGetComponent(child, out var salvMob))
|
||||
continue;
|
||||
|
||||
salvMob.LinkedEntity = mapChild;
|
||||
}
|
||||
}
|
||||
|
||||
Report(magnet.Owner, MagnetChannel, "salvage-system-announcement-arrived", ("timeLeft", data.Comp.ActiveTime.TotalSeconds));
|
||||
_mapManager.DeleteMap(salvMap);
|
||||
|
||||
data.Comp.Announced = false;
|
||||
|
||||
var active = new SalvageMagnetActivatedEvent()
|
||||
{
|
||||
Magnet = magnet,
|
||||
};
|
||||
|
||||
RaiseLocalEvent(ref active);
|
||||
}
|
||||
|
||||
private bool TryGetSalvagePlacementLocation(MapId mapId, Box2 attachedBounds, Box2 bounds, out MapCoordinates coords, out Angle angle)
|
||||
{
|
||||
const float OffsetRadiusMin = 4f;
|
||||
const float OffsetRadiusMax = 16f;
|
||||
|
||||
var minDistance = (attachedBounds.Height < attachedBounds.Width ? attachedBounds.Width : attachedBounds.Height) / 2f;
|
||||
var minActualDistance = bounds.Height < bounds.Width ? minDistance + bounds.Width / 2f : minDistance + bounds.Height / 2f;
|
||||
|
||||
var attachedCenter = attachedBounds.Center;
|
||||
|
||||
angle = _random.NextAngle();
|
||||
|
||||
// Thanks 20kdc
|
||||
for (var i = 0; i < 20; i++)
|
||||
{
|
||||
var randomPos = attachedCenter +
|
||||
_random.NextAngle().ToVec() * (minActualDistance +
|
||||
_random.NextFloat(OffsetRadiusMin, OffsetRadiusMax));
|
||||
var finalCoords = new MapCoordinates(randomPos, mapId);
|
||||
|
||||
var box2 = Box2.CenteredAround(finalCoords.Position, bounds.Size);
|
||||
var box2Rot = new Box2Rotated(box2, angle, finalCoords.Position);
|
||||
|
||||
// This doesn't stop it from spawning on top of random things in space
|
||||
// Might be better like this, ghosts could stop it before
|
||||
if (_mapManager.FindGridsIntersecting(finalCoords.MapId, box2Rot).Any())
|
||||
continue;
|
||||
|
||||
coords = finalCoords;
|
||||
return true;
|
||||
}
|
||||
|
||||
coords = MapCoordinates.Nullspace;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
[ByRefEvent]
|
||||
public record struct SalvageMagnetActivatedEvent
|
||||
{
|
||||
public EntityUid Magnet;
|
||||
}
|
||||
@@ -17,6 +17,7 @@ using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Random;
|
||||
using Robust.Shared.Utility;
|
||||
using Content.Server.Chat.Managers;
|
||||
using Content.Server.Gravity;
|
||||
using Content.Server.Parallax;
|
||||
using Content.Server.Procedural;
|
||||
using Content.Server.Shuttles.Systems;
|
||||
@@ -46,39 +47,29 @@ namespace Content.Server.Salvage
|
||||
[Dependency] private readonly AnchorableSystem _anchorable = default!;
|
||||
[Dependency] private readonly BiomeSystem _biome = default!;
|
||||
[Dependency] private readonly DungeonSystem _dungeon = default!;
|
||||
[Dependency] private readonly GravitySystem _gravity = default!;
|
||||
[Dependency] private readonly MapLoaderSystem _map = default!;
|
||||
[Dependency] private readonly SharedPopupSystem _popupSystem = default!;
|
||||
[Dependency] private readonly MetaDataSystem _metaData = default!;
|
||||
[Dependency] private readonly RadioSystem _radioSystem = default!;
|
||||
[Dependency] private readonly SharedAppearanceSystem _appearanceSystem = default!;
|
||||
[Dependency] private readonly SharedAudioSystem _audio = default!;
|
||||
[Dependency] private readonly SharedTransformSystem _transform = default!;
|
||||
[Dependency] private readonly ShuttleSystem _shuttle = default!;
|
||||
[Dependency] private readonly ShuttleConsoleSystem _shuttleConsoles = default!;
|
||||
[Dependency] private readonly StationSystem _station = default!;
|
||||
[Dependency] private readonly UserInterfaceSystem _ui = default!;
|
||||
[Dependency] private readonly MetaDataSystem _metaData = default!;
|
||||
|
||||
private const int SalvageLocationPlaceAttempts = 25;
|
||||
|
||||
// TODO: This is probably not compatible with multi-station
|
||||
private readonly Dictionary<EntityUid, SalvageGridState> _salvageGridStates = new();
|
||||
private EntityQuery<MapGridComponent> _gridQuery;
|
||||
private EntityQuery<TransformComponent> _xformQuery;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<SalvageMagnetComponent, InteractHandEvent>(OnInteractHand);
|
||||
SubscribeLocalEvent<SalvageMagnetComponent, RefreshPartsEvent>(OnRefreshParts);
|
||||
SubscribeLocalEvent<SalvageMagnetComponent, UpgradeExamineEvent>(OnUpgradeExamine);
|
||||
SubscribeLocalEvent<SalvageMagnetComponent, ExaminedEvent>(OnExamined);
|
||||
SubscribeLocalEvent<SalvageMagnetComponent, ToolUseAttemptEvent>(OnToolUseAttempt);
|
||||
SubscribeLocalEvent<SalvageMagnetComponent, ComponentShutdown>(OnMagnetRemoval);
|
||||
SubscribeLocalEvent<GridRemovalEvent>(OnGridRemoval);
|
||||
|
||||
// Can't use RoundRestartCleanupEvent, I need to clean up before the grid, and components are gone to prevent the announcements
|
||||
SubscribeLocalEvent<GameRunLevelChangedEvent>(OnRoundEnd);
|
||||
_gridQuery = GetEntityQuery<MapGridComponent>();
|
||||
_xformQuery = GetEntityQuery<TransformComponent>();
|
||||
|
||||
InitializeExpeditions();
|
||||
InitializeMagnet();
|
||||
InitializeRunner();
|
||||
}
|
||||
|
||||
@@ -88,327 +79,6 @@ namespace Content.Server.Salvage
|
||||
ShutdownExpeditions();
|
||||
}
|
||||
|
||||
private void OnRoundEnd(GameRunLevelChangedEvent ev)
|
||||
{
|
||||
if(ev.New != GameRunLevel.InRound)
|
||||
{
|
||||
_salvageGridStates.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateAppearance(EntityUid uid, SalvageMagnetComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component, false))
|
||||
return;
|
||||
|
||||
_appearanceSystem.SetData(uid, SalvageMagnetVisuals.ReadyBlinking, component.MagnetState.StateType == MagnetStateType.Attaching);
|
||||
_appearanceSystem.SetData(uid, SalvageMagnetVisuals.Ready, component.MagnetState.StateType == MagnetStateType.Holding);
|
||||
_appearanceSystem.SetData(uid, SalvageMagnetVisuals.Unready, component.MagnetState.StateType == MagnetStateType.CoolingDown);
|
||||
_appearanceSystem.SetData(uid, SalvageMagnetVisuals.UnreadyBlinking, component.MagnetState.StateType == MagnetStateType.Detaching);
|
||||
}
|
||||
|
||||
private void UpdateChargeStateAppearance(EntityUid uid, TimeSpan currentTime, SalvageMagnetComponent? component = null)
|
||||
{
|
||||
if (!Resolve(uid, ref component, false))
|
||||
return;
|
||||
|
||||
var timeLeft = Convert.ToInt32(component.MagnetState.Until.TotalSeconds - currentTime.TotalSeconds);
|
||||
|
||||
component.ChargeRemaining = component.MagnetState.StateType switch
|
||||
{
|
||||
MagnetStateType.Inactive => 5,
|
||||
MagnetStateType.Holding => timeLeft / (Convert.ToInt32(component.HoldTime.TotalSeconds) / component.ChargeCapacity) + 1,
|
||||
MagnetStateType.Detaching => 0,
|
||||
MagnetStateType.CoolingDown => component.ChargeCapacity - timeLeft / (Convert.ToInt32(component.CooldownTime.TotalSeconds) / component.ChargeCapacity) - 1,
|
||||
_ => component.ChargeRemaining
|
||||
};
|
||||
|
||||
if (component.PreviousCharge == component.ChargeRemaining)
|
||||
return;
|
||||
_appearanceSystem.SetData(uid, SalvageMagnetVisuals.ChargeState, component.ChargeRemaining);
|
||||
component.PreviousCharge = component.ChargeRemaining;
|
||||
}
|
||||
|
||||
private void OnGridRemoval(GridRemovalEvent ev)
|
||||
{
|
||||
// If we ever want to give magnets names, and announce them individually, we would need to loop this, before removing it.
|
||||
if (_salvageGridStates.Remove(ev.EntityUid))
|
||||
{
|
||||
if (TryComp<SalvageGridComponent>(ev.EntityUid, out var salvComp) &&
|
||||
TryComp<SalvageMagnetComponent>(salvComp.SpawnerMagnet, out var magnet))
|
||||
Report(salvComp.SpawnerMagnet.Value, magnet.SalvageChannel, "salvage-system-announcement-spawn-magnet-lost");
|
||||
// For the very unlikely possibility that the salvage magnet was on a salvage, we will not return here
|
||||
}
|
||||
foreach(var gridState in _salvageGridStates)
|
||||
{
|
||||
foreach(var magnet in gridState.Value.ActiveMagnets)
|
||||
{
|
||||
if (!TryComp<SalvageMagnetComponent>(magnet, out var magnetComponent))
|
||||
continue;
|
||||
|
||||
if (magnetComponent.AttachedEntity != ev.EntityUid)
|
||||
continue;
|
||||
magnetComponent.AttachedEntity = null;
|
||||
magnetComponent.MagnetState = MagnetState.Inactive;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMagnetRemoval(EntityUid uid, SalvageMagnetComponent component, ComponentShutdown args)
|
||||
{
|
||||
if (component.MagnetState.StateType == MagnetStateType.Inactive)
|
||||
return;
|
||||
|
||||
var magnetTranform = Transform(uid);
|
||||
if (magnetTranform.GridUid is not { } gridId || !_salvageGridStates.TryGetValue(gridId, out var salvageGridState))
|
||||
return;
|
||||
|
||||
salvageGridState.ActiveMagnets.Remove(uid);
|
||||
Report(uid, component.SalvageChannel, "salvage-system-announcement-spawn-magnet-lost");
|
||||
if (component.AttachedEntity.HasValue)
|
||||
{
|
||||
SafeDeleteSalvage(component.AttachedEntity.Value);
|
||||
component.AttachedEntity = null;
|
||||
Report(uid, component.SalvageChannel, "salvage-system-announcement-lost");
|
||||
}
|
||||
else if (component.MagnetState is { StateType: MagnetStateType.Attaching })
|
||||
{
|
||||
Report(uid, component.SalvageChannel, "salvage-system-announcement-spawn-no-debris-available");
|
||||
}
|
||||
|
||||
component.MagnetState = MagnetState.Inactive;
|
||||
}
|
||||
|
||||
private void OnRefreshParts(EntityUid uid, SalvageMagnetComponent component, RefreshPartsEvent args)
|
||||
{
|
||||
var rating = args.PartRatings[component.MachinePartDelay] - 1;
|
||||
var factor = MathF.Pow(component.PartRatingDelay, rating);
|
||||
component.AttachingTime = component.BaseAttachingTime * factor;
|
||||
component.CooldownTime = component.BaseCooldownTime * factor;
|
||||
}
|
||||
|
||||
private void OnUpgradeExamine(EntityUid uid, SalvageMagnetComponent component, UpgradeExamineEvent args)
|
||||
{
|
||||
args.AddPercentageUpgrade("salvage-system-magnet-delay-upgrade", (float) (component.CooldownTime / component.BaseCooldownTime));
|
||||
}
|
||||
|
||||
private void OnExamined(EntityUid uid, SalvageMagnetComponent component, ExaminedEvent args)
|
||||
{
|
||||
if (!args.IsInDetailsRange)
|
||||
return;
|
||||
|
||||
var gotGrid = false;
|
||||
var remainingTime = TimeSpan.Zero;
|
||||
|
||||
if (Transform(uid).GridUid is { } gridId &&
|
||||
_salvageGridStates.TryGetValue(gridId, out var salvageGridState))
|
||||
{
|
||||
remainingTime = component.MagnetState.Until - salvageGridState.CurrentTime;
|
||||
gotGrid = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Warning("Failed to load salvage grid state, can't display remaining time");
|
||||
}
|
||||
|
||||
switch (component.MagnetState.StateType)
|
||||
{
|
||||
case MagnetStateType.Inactive:
|
||||
args.PushMarkup(Loc.GetString("salvage-system-magnet-examined-inactive"));
|
||||
break;
|
||||
case MagnetStateType.Attaching:
|
||||
args.PushMarkup(Loc.GetString("salvage-system-magnet-examined-pulling-in"));
|
||||
break;
|
||||
case MagnetStateType.Detaching:
|
||||
args.PushMarkup(Loc.GetString("salvage-system-magnet-examined-releasing"));
|
||||
break;
|
||||
case MagnetStateType.CoolingDown:
|
||||
if (gotGrid)
|
||||
args.PushMarkup(Loc.GetString("salvage-system-magnet-examined-cooling-down", ("timeLeft", Math.Ceiling(remainingTime.TotalSeconds))));
|
||||
break;
|
||||
case MagnetStateType.Holding:
|
||||
if (gotGrid)
|
||||
args.PushMarkup(Loc.GetString("salvage-system-magnet-examined-active", ("timeLeft", Math.Ceiling(remainingTime.TotalSeconds))));
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnToolUseAttempt(EntityUid uid, SalvageMagnetComponent comp, ToolUseAttemptEvent args)
|
||||
{
|
||||
// prevent reconstruct exploit to "leak" wrecks or skip cooldowns
|
||||
if (comp.MagnetState != MagnetState.Inactive)
|
||||
{
|
||||
args.Cancel();
|
||||
}
|
||||
}
|
||||
|
||||
private void OnInteractHand(EntityUid uid, SalvageMagnetComponent component, InteractHandEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
args.Handled = true;
|
||||
StartMagnet(uid, component, args.User);
|
||||
UpdateAppearance(uid, component);
|
||||
}
|
||||
|
||||
private void StartMagnet(EntityUid uid, SalvageMagnetComponent component, EntityUid user)
|
||||
{
|
||||
switch (component.MagnetState.StateType)
|
||||
{
|
||||
case MagnetStateType.Inactive:
|
||||
ShowPopup(uid, "salvage-system-report-activate-success", user);
|
||||
var magnetTransform = Transform(uid);
|
||||
var gridId = magnetTransform.GridUid ?? throw new InvalidOperationException("Magnet had no grid associated");
|
||||
if (!_salvageGridStates.TryGetValue(gridId, out var gridState))
|
||||
{
|
||||
gridState = new SalvageGridState();
|
||||
_salvageGridStates[gridId] = gridState;
|
||||
}
|
||||
gridState.ActiveMagnets.Add(uid);
|
||||
component.MagnetState = new MagnetState(MagnetStateType.Attaching, gridState.CurrentTime + component.AttachingTime);
|
||||
RaiseLocalEvent(new SalvageMagnetActivatedEvent(uid));
|
||||
Report(uid, component.SalvageChannel, "salvage-system-report-activate-success");
|
||||
break;
|
||||
case MagnetStateType.Attaching:
|
||||
case MagnetStateType.Holding:
|
||||
ShowPopup(uid, "salvage-system-report-already-active", user);
|
||||
break;
|
||||
case MagnetStateType.Detaching:
|
||||
case MagnetStateType.CoolingDown:
|
||||
ShowPopup(uid, "salvage-system-report-cooling-down", user);
|
||||
break;
|
||||
default:
|
||||
throw new ArgumentOutOfRangeException();
|
||||
}
|
||||
}
|
||||
private void ShowPopup(EntityUid uid, string messageKey, EntityUid user)
|
||||
{
|
||||
_popupSystem.PopupEntity(Loc.GetString(messageKey), uid, user);
|
||||
}
|
||||
|
||||
private void SafeDeleteSalvage(EntityUid salvage)
|
||||
{
|
||||
if(!EntityManager.TryGetComponent<TransformComponent>(salvage, out var salvageTransform))
|
||||
{
|
||||
Log.Error("Salvage entity was missing transform component");
|
||||
return;
|
||||
}
|
||||
|
||||
if (salvageTransform.GridUid == null)
|
||||
{
|
||||
Log.Error( "Salvage entity has no associated grid?");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var player in Filter.Empty().AddInGrid(salvageTransform.GridUid.Value, EntityManager).Recipients)
|
||||
{
|
||||
if (player.AttachedEntity.HasValue)
|
||||
{
|
||||
var playerEntityUid = player.AttachedEntity.Value;
|
||||
if (HasComp<SalvageMobRestrictionsComponent>(playerEntityUid))
|
||||
{
|
||||
// Salvage mobs are NEVER immune (even if they're from a different salvage, they shouldn't be here)
|
||||
continue;
|
||||
}
|
||||
_transform.SetParent(playerEntityUid, salvageTransform.ParentUid);
|
||||
}
|
||||
}
|
||||
|
||||
// Deletion has to happen before grid traversal re-parents players.
|
||||
Del(salvage);
|
||||
}
|
||||
|
||||
private bool TryGetSalvagePlacementLocation(EntityUid uid, SalvageMagnetComponent component, Box2 bounds, out MapCoordinates coords, out Angle angle)
|
||||
{
|
||||
var xform = Transform(uid);
|
||||
var smallestBound = (bounds.Height < bounds.Width
|
||||
? bounds.Height
|
||||
: bounds.Width) / 2f;
|
||||
var maxRadius = component.OffsetRadiusMax + smallestBound;
|
||||
|
||||
angle = Angle.Zero;
|
||||
coords = new EntityCoordinates(uid, new Vector2(0, -maxRadius)).ToMap(EntityManager, _transform);
|
||||
|
||||
if (xform.GridUid is not null)
|
||||
angle = _transform.GetWorldRotation(Transform(xform.GridUid.Value));
|
||||
|
||||
for (var i = 0; i < SalvageLocationPlaceAttempts; i++)
|
||||
{
|
||||
var randomRadius = _random.NextFloat(component.OffsetRadiusMax);
|
||||
var randomOffset = _random.NextAngle().ToVec() * randomRadius;
|
||||
var finalCoords = new MapCoordinates(coords.Position + randomOffset, coords.MapId);
|
||||
|
||||
var box2 = Box2.CenteredAround(finalCoords.Position, bounds.Size);
|
||||
var box2Rot = new Box2Rotated(box2, angle, finalCoords.Position);
|
||||
|
||||
// This doesn't stop it from spawning on top of random things in space
|
||||
// Might be better like this, ghosts could stop it before
|
||||
if (_mapManager.FindGridsIntersecting(finalCoords.MapId, box2Rot).Any())
|
||||
continue;
|
||||
coords = finalCoords;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool SpawnSalvage(EntityUid uid, SalvageMagnetComponent component)
|
||||
{
|
||||
var salvMap = _mapManager.CreateMap();
|
||||
|
||||
EntityUid? salvageEnt;
|
||||
if (_random.Prob(component.AsteroidChance))
|
||||
{
|
||||
var asteroidProto = _prototypeManager.Index<WeightedRandomEntityPrototype>(component.AsteroidPool).Pick(_random);
|
||||
salvageEnt = Spawn(asteroidProto, new MapCoordinates(0, 0, salvMap));
|
||||
}
|
||||
else
|
||||
{
|
||||
var forcedSalvage = _configurationManager.GetCVar(CCVars.SalvageForced);
|
||||
var salvageProto = string.IsNullOrWhiteSpace(forcedSalvage)
|
||||
? _random.Pick(_prototypeManager.EnumeratePrototypes<SalvageMapPrototype>().ToList())
|
||||
: _prototypeManager.Index<SalvageMapPrototype>(forcedSalvage);
|
||||
|
||||
var opts = new MapLoadOptions
|
||||
{
|
||||
Offset = new Vector2(0, 0)
|
||||
};
|
||||
|
||||
if (!_map.TryLoad(salvMap, salvageProto.MapPath.ToString(), out var roots, opts) ||
|
||||
roots.FirstOrNull() is not { } root)
|
||||
{
|
||||
Report(uid, component.SalvageChannel, "salvage-system-announcement-spawn-debris-disintegrated");
|
||||
_mapManager.DeleteMap(salvMap);
|
||||
return false;
|
||||
}
|
||||
|
||||
salvageEnt = root;
|
||||
}
|
||||
|
||||
var bounds = Comp<MapGridComponent>(salvageEnt.Value).LocalAABB;
|
||||
if (!TryGetSalvagePlacementLocation(uid, component, bounds, out var spawnLocation, out var spawnAngle))
|
||||
{
|
||||
Report(uid, component.SalvageChannel, "salvage-system-announcement-spawn-no-debris-available");
|
||||
_mapManager.DeleteMap(salvMap);
|
||||
return false;
|
||||
}
|
||||
|
||||
var salvXForm = Transform(salvageEnt.Value);
|
||||
_transform.SetParent(salvageEnt.Value, salvXForm, _mapManager.GetMapEntityId(spawnLocation.MapId));
|
||||
_transform.SetWorldPosition(salvXForm, spawnLocation.Position);
|
||||
|
||||
component.AttachedEntity = salvageEnt;
|
||||
var gridcomp = EnsureComp<SalvageGridComponent>(salvageEnt.Value);
|
||||
gridcomp.SpawnerMagnet = uid;
|
||||
_transform.SetWorldRotation(salvageEnt.Value, spawnAngle);
|
||||
|
||||
Report(uid, component.SalvageChannel, "salvage-system-announcement-arrived", ("timeLeft", component.HoldTime.TotalSeconds));
|
||||
_mapManager.DeleteMap(salvMap);
|
||||
return true;
|
||||
}
|
||||
|
||||
private void Report(EntityUid source, string channelName, string messageKey, params (string, object)[] args)
|
||||
{
|
||||
var message = args.Length == 0 ? Loc.GetString(messageKey) : Loc.GetString(messageKey, args);
|
||||
@@ -416,87 +86,12 @@ namespace Content.Server.Salvage
|
||||
_radioSystem.SendRadioMessage(source, message, channel, source);
|
||||
}
|
||||
|
||||
private void Transition(EntityUid uid, SalvageMagnetComponent magnet, TimeSpan currentTime)
|
||||
{
|
||||
switch (magnet.MagnetState.StateType)
|
||||
{
|
||||
case MagnetStateType.Attaching:
|
||||
if (SpawnSalvage(uid, magnet))
|
||||
{
|
||||
magnet.MagnetState = new MagnetState(MagnetStateType.Holding, currentTime + magnet.HoldTime);
|
||||
}
|
||||
else
|
||||
{
|
||||
magnet.MagnetState = new MagnetState(MagnetStateType.CoolingDown, currentTime + magnet.CooldownTime);
|
||||
}
|
||||
break;
|
||||
case MagnetStateType.Holding:
|
||||
Report(uid, magnet.SalvageChannel, "salvage-system-announcement-losing", ("timeLeft", magnet.DetachingTime.TotalSeconds));
|
||||
magnet.MagnetState = new MagnetState(MagnetStateType.Detaching, currentTime + magnet.DetachingTime);
|
||||
break;
|
||||
case MagnetStateType.Detaching:
|
||||
if (magnet.AttachedEntity.HasValue)
|
||||
{
|
||||
SafeDeleteSalvage(magnet.AttachedEntity.Value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.Error("Salvage detaching was expecting attached entity but it was null");
|
||||
}
|
||||
Report(uid, magnet.SalvageChannel, "salvage-system-announcement-lost");
|
||||
magnet.MagnetState = new MagnetState(MagnetStateType.CoolingDown, currentTime + magnet.CooldownTime);
|
||||
break;
|
||||
case MagnetStateType.CoolingDown:
|
||||
magnet.MagnetState = MagnetState.Inactive;
|
||||
break;
|
||||
}
|
||||
UpdateAppearance(uid, magnet);
|
||||
UpdateChargeStateAppearance(uid, currentTime, magnet);
|
||||
}
|
||||
|
||||
public override void Update(float frameTime)
|
||||
{
|
||||
var secondsPassed = TimeSpan.FromSeconds(frameTime);
|
||||
// Keep track of time, and state per grid
|
||||
foreach (var (uid, state) in _salvageGridStates)
|
||||
{
|
||||
if (state.ActiveMagnets.Count == 0) continue;
|
||||
// Not handling the case where the salvage we spawned got paused
|
||||
// They both need to be paused, or it doesn't make sense
|
||||
if (MetaData(uid).EntityPaused) continue;
|
||||
state.CurrentTime += secondsPassed;
|
||||
|
||||
var deleteQueue = new RemQueue<EntityUid>();
|
||||
|
||||
foreach(var magnet in state.ActiveMagnets)
|
||||
{
|
||||
if (!TryComp<SalvageMagnetComponent>(magnet, out var magnetComp))
|
||||
continue;
|
||||
|
||||
UpdateChargeStateAppearance(magnet, state.CurrentTime, magnetComp);
|
||||
if (magnetComp.MagnetState.Until > state.CurrentTime) continue;
|
||||
Transition(magnet, magnetComp, state.CurrentTime);
|
||||
if (magnetComp.MagnetState.StateType == MagnetStateType.Inactive)
|
||||
{
|
||||
deleteQueue.Add(magnet);
|
||||
}
|
||||
}
|
||||
|
||||
foreach(var magnet in deleteQueue)
|
||||
{
|
||||
state.ActiveMagnets.Remove(magnet);
|
||||
}
|
||||
}
|
||||
|
||||
UpdateExpeditions();
|
||||
UpdateMagnet();
|
||||
UpdateRunner();
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class SalvageGridState
|
||||
{
|
||||
public TimeSpan CurrentTime { get; set; }
|
||||
public List<EntityUid> ActiveMagnets { get; } = new();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
using Content.Server.Shuttles.Components;
|
||||
using Robust.Shared.Prototypes;
|
||||
|
||||
namespace Content.Server.Shuttle.Components;
|
||||
namespace Content.Server.Shuttles;
|
||||
|
||||
// Primo shitcode
|
||||
/// <summary>
|
||||
@@ -1,4 +1,3 @@
|
||||
using Content.Server.Shuttle.Components;
|
||||
using Content.Server.Shuttles.Components;
|
||||
using Content.Server.Shuttles.Events;
|
||||
using Content.Server.Station.Components;
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
using Content.Server.Power.Components;
|
||||
using Content.Server.Power.EntitySystems;
|
||||
using Content.Server.Shuttle.Components;
|
||||
using Content.Server.Shuttles.Components;
|
||||
using Content.Server.Shuttles.Events;
|
||||
using Content.Server.Station.Systems;
|
||||
|
||||
@@ -10,20 +10,25 @@ namespace Content.Server.Shuttles.Systems;
|
||||
/// </summary>
|
||||
public sealed class SpaceGarbageSystem : EntitySystem
|
||||
{
|
||||
private EntityQuery<TransformComponent> _xformQuery;
|
||||
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
_xformQuery = GetEntityQuery<TransformComponent>();
|
||||
SubscribeLocalEvent<SpaceGarbageComponent, StartCollideEvent>(OnCollide);
|
||||
}
|
||||
|
||||
private void OnCollide(EntityUid uid, SpaceGarbageComponent component, ref StartCollideEvent args)
|
||||
{
|
||||
if (args.OtherBody.BodyType != BodyType.Static) return;
|
||||
if (args.OtherBody.BodyType != BodyType.Static)
|
||||
return;
|
||||
|
||||
var ourXform = Transform(uid);
|
||||
var otherXform = Transform(args.OtherEntity);
|
||||
var ourXform = _xformQuery.GetComponent(uid);
|
||||
var otherXform = _xformQuery.GetComponent(args.OtherEntity);
|
||||
|
||||
if (ourXform.GridUid == otherXform.GridUid) return;
|
||||
if (ourXform.GridUid == otherXform.GridUid)
|
||||
return;
|
||||
|
||||
QueueDel(uid);
|
||||
}
|
||||
|
||||
@@ -401,6 +401,14 @@ public sealed class StationSystem : EntitySystem
|
||||
QueueDel(station);
|
||||
}
|
||||
|
||||
public EntityUid? GetOwningStation(EntityUid? entity, TransformComponent? xform = null)
|
||||
{
|
||||
if (entity == null)
|
||||
return null;
|
||||
|
||||
return GetOwningStation(entity.Value, xform);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets the station that "owns" the given entity (essentially, the station the grid it's on is attached to)
|
||||
/// </summary>
|
||||
|
||||
@@ -12,6 +12,8 @@ public sealed class ArtifactMagnetTriggerSystem : EntitySystem
|
||||
{
|
||||
[Dependency] private readonly ArtifactSystem _artifact = default!;
|
||||
|
||||
private readonly List<EntityUid> _toActivate = new();
|
||||
|
||||
/// <inheritdoc/>
|
||||
public override void Initialize()
|
||||
{
|
||||
@@ -25,7 +27,7 @@ public sealed class ArtifactMagnetTriggerSystem : EntitySystem
|
||||
if (!EntityQuery<ArtifactMagnetTriggerComponent>().Any())
|
||||
return;
|
||||
|
||||
List<EntityUid> toActivate = new();
|
||||
_toActivate.Clear();
|
||||
|
||||
//assume that there's more instruments than artifacts
|
||||
var query = EntityQueryEnumerator<MagbootsComponent, TransformComponent>();
|
||||
@@ -43,21 +45,20 @@ public sealed class ArtifactMagnetTriggerSystem : EntitySystem
|
||||
if (distance > trigger.Range)
|
||||
continue;
|
||||
|
||||
toActivate.Add(artifactUid);
|
||||
_toActivate.Add(artifactUid);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var a in toActivate)
|
||||
foreach (var a in _toActivate)
|
||||
{
|
||||
_artifact.TryActivateArtifact(a);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMagnetActivated(SalvageMagnetActivatedEvent ev)
|
||||
private void OnMagnetActivated(ref SalvageMagnetActivatedEvent ev)
|
||||
{
|
||||
var magXform = Transform(ev.Magnet);
|
||||
|
||||
var toActivate = new List<EntityUid>();
|
||||
var query = EntityQueryEnumerator<ArtifactMagnetTriggerComponent, TransformComponent>();
|
||||
while (query.MoveNext(out var uid, out var artifact, out var xform))
|
||||
{
|
||||
@@ -67,10 +68,10 @@ public sealed class ArtifactMagnetTriggerSystem : EntitySystem
|
||||
if (distance > artifact.Range)
|
||||
continue;
|
||||
|
||||
toActivate.Add(uid);
|
||||
_toActivate.Add(uid);
|
||||
}
|
||||
|
||||
foreach (var a in toActivate)
|
||||
foreach (var a in _toActivate)
|
||||
{
|
||||
_artifact.TryActivateArtifact(a);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user