Add new entity spawn test & fix misc bugs (#19953)

This commit is contained in:
Leon Friedrich
2023-10-16 16:54:10 +11:00
committed by GitHub
parent 1f0c9314fd
commit 00e274ea38
14 changed files with 149 additions and 36 deletions

View File

@@ -1,3 +1,4 @@
using System.Linq;
using Content.Server.Administration.Commands;
using Content.Server.GameTicking.Rules.Components;
using Content.Server.KillTracking;
@@ -95,7 +96,7 @@ public sealed class DeathMatchRuleSystem : GameRuleSystem<DeathMatchRuleComponen
if (ev.Assist is KillPlayerSource assist && dm.Victor == null)
_point.AdjustPointValue(assist.PlayerId, 1, uid, point);
var spawns = EntitySpawnCollection.GetSpawns(dm.RewardSpawns);
var spawns = EntitySpawnCollection.GetSpawns(dm.RewardSpawns).Cast<string?>().ToList();
EntityManager.SpawnEntities(Transform(ev.Entity).MapPosition, spawns);
}
}

View File

@@ -70,7 +70,7 @@ public sealed partial class GatherableSystem : EntitySystem
continue;
}
var getLoot = _prototypeManager.Index<EntityLootTablePrototype>(table);
var spawnLoot = getLoot.GetSpawns();
var spawnLoot = getLoot.GetSpawns(_random);
var spawnPos = pos.Offset(_random.NextVector2(0.3f));
Spawn(spawnLoot[0], spawnPos);
}

View File

@@ -35,6 +35,7 @@ public class IdentitySystem : SharedIdentitySystem
SubscribeLocalEvent<IdentityComponent, DidEquipHandEvent>((uid, _, _) => QueueIdentityUpdate(uid));
SubscribeLocalEvent<IdentityComponent, DidUnequipEvent>((uid, _, _) => QueueIdentityUpdate(uid));
SubscribeLocalEvent<IdentityComponent, DidUnequipHandEvent>((uid, _, _) => QueueIdentityUpdate(uid));
SubscribeLocalEvent<IdentityComponent, MapInitEvent>(OnMapInit);
}
public override void Update(float frameTime)
@@ -53,10 +54,8 @@ public class IdentitySystem : SharedIdentitySystem
}
// This is where the magic happens
protected override void OnComponentInit(EntityUid uid, IdentityComponent component, ComponentInit args)
private void OnMapInit(EntityUid uid, IdentityComponent component, MapInitEvent args)
{
base.OnComponentInit(uid, component, args);
var ident = Spawn(null, Transform(uid).Coordinates);
QueueIdentityUpdate(uid);

View File

@@ -110,7 +110,8 @@ namespace Content.Server.Kitchen.EntitySystems
if (args.Handled)
return;
if (component.PrototypesToSpawn?.Count > 0) {
if (component.PrototypesToSpawn?.Count > 0)
{
_popupSystem.PopupEntity(Loc.GetString("comp-kitchen-spike-knife-needed"), uid, args.User);
args.Handled = true;
}

View File

@@ -136,12 +136,7 @@ public abstract partial class StationEventSystem<T> : GameRuleSystem<T> where T
protected bool TryGetRandomStation([NotNullWhen(true)] out EntityUid? station, Func<EntityUid, bool>? filter = null)
{
var stations = new ValueList<EntityUid>();
if (filter == null)
{
stations.EnsureCapacity(Count<StationEventEligibleComponent>());
}
var stations = new ValueList<EntityUid>(Count<StationEventEligibleComponent>());
filter ??= _ => true;
var query = AllEntityQuery<StationEventEligibleComponent>();

View File

@@ -1,6 +1,10 @@
using Content.Server.Spawners.Components;
using Content.Server.Storage.Components;
using Content.Shared.Prototypes;
using Content.Shared.Storage;
using Content.Shared.Storage.Components;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Server.Storage.EntitySystems;
@@ -25,10 +29,13 @@ public sealed partial class StorageSystem
var spawnItems = EntitySpawnCollection.GetSpawns(component.Contents, Random);
foreach (var item in spawnItems)
{
// No, you are not allowed to fill a container with entity spawners.
DebugTools.Assert(!_prototype.Index<EntityPrototype>(item)
.HasComponent(typeof(RandomSpawnerComponent)));
var ent = EntityManager.SpawnEntity(item, coordinates);
// handle depending on storage component, again this should be unified after ECS
if (entityStorageComp != null && EntityStorage.Insert(ent, uid))
if (entityStorageComp != null && EntityStorage.Insert(ent, uid, entityStorageComp))
continue;
if (storageComp != null && Insert(uid, ent, out _, storageComp: storageComp, playSound: false))

View File

@@ -12,7 +12,7 @@ using Robust.Server.GameObjects;
using Robust.Server.Player;
using Robust.Shared.Map;
using Robust.Shared.Player;
using Robust.Shared.Players;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
namespace Content.Server.Storage.EntitySystems;
@@ -20,6 +20,7 @@ namespace Content.Server.Storage.EntitySystems;
public sealed partial class StorageSystem : SharedStorageSystem
{
[Dependency] private readonly IAdminManager _admin = default!;
[Dependency] private readonly IPrototypeManager _prototype = default!;
[Dependency] private readonly UserInterfaceSystem _uiSystem = default!;
public override void Initialize()