diff --git a/Content.Server/StationEvents/Components/CargoGiftsRuleComponent.cs b/Content.Server/StationEvents/Components/CargoGiftsRuleComponent.cs index bb4f834cb3..5c433e0d2c 100644 --- a/Content.Server/StationEvents/Components/CargoGiftsRuleComponent.cs +++ b/Content.Server/StationEvents/Components/CargoGiftsRuleComponent.cs @@ -1,6 +1,8 @@ using Content.Server.StationEvents.Events; +using Content.Shared.Cargo.Prototypes; using Robust.Shared.Prototypes; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; +using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary; namespace Content.Server.StationEvents.Components; @@ -38,8 +40,8 @@ public sealed class CargoGiftsRuleComponent : Component /// Cargo that you would like gifted to the station, with the quantity for each /// Use Ids from cargoProduct Prototypes /// - [DataField("gifts"), ViewVariables(VVAccess.ReadWrite)] - public Dictionary Gifts = new Dictionary(); + [DataField("gifts", required: true, customTypeSerializer:typeof(PrototypeIdDictionarySerializer)), ViewVariables(VVAccess.ReadWrite)] + public Dictionary Gifts = new(); /// /// How much space (minimum) you want to leave in the order database for supply to actually do their work diff --git a/Content.Server/StationEvents/Events/CargoGiftsRule.cs b/Content.Server/StationEvents/Events/CargoGiftsRule.cs index f6ee90a568..51fafd6cb3 100644 --- a/Content.Server/StationEvents/Events/CargoGiftsRule.cs +++ b/Content.Server/StationEvents/Events/CargoGiftsRule.cs @@ -30,16 +30,15 @@ public sealed class CargoGiftsRule : StationEventSystem protected override void ActiveTick(EntityUid uid, CargoGiftsRuleComponent component, GameRuleComponent gameRule, float frameTime) { if (component.Gifts.Count == 0) - { return; - } if (component.TimeUntilNextGifts > 0) { component.TimeUntilNextGifts -= frameTime; return; } - component.TimeUntilNextGifts = 30f; + + component.TimeUntilNextGifts += 30f; if (!TryGetRandomStation(out var station, HasComp)) return; diff --git a/Content.Server/StationEvents/Events/StationEventSystem.cs b/Content.Server/StationEvents/Events/StationEventSystem.cs index 93ad069665..ac3d2980b9 100644 --- a/Content.Server/StationEvents/Events/StationEventSystem.cs +++ b/Content.Server/StationEvents/Events/StationEventSystem.cs @@ -9,6 +9,7 @@ using Content.Server.Station.Components; using Content.Server.Station.Systems; using Content.Server.StationEvents.Components; using Content.Shared.Database; +using Robust.Shared.Collections; using Robust.Shared.Map; using Robust.Shared.Map.Components; using Robust.Shared.Player; @@ -135,20 +136,32 @@ public abstract class StationEventSystem : GameRuleSystem where T : Compon protected bool TryGetRandomStation([NotNullWhen(true)] out EntityUid? station, Func? filter = null) { + var stations = new ValueList(); + + if (filter == null) + { + stations.EnsureCapacity(Count()); + } + filter ??= _ => true; + var query = AllEntityQuery(); - // augh. sorry sloth there's no better API and my goal today isn't adding 50 entitymanager methods :waa: - var stations = EntityManager.GetAllComponents(typeof(StationEventEligibleComponent)).Select(x => x.Uid).Where(filter).ToArray(); + while (query.MoveNext(out var uid, out _)) + { + if (!filter(uid)) + continue; - if (stations.Length == 0) + stations.Add(uid); + } + + if (stations.Count == 0) { station = null; return false; } - - station = RobustRandom.Pick(stations); - + // TODO: Engine PR. + station = stations[RobustRandom.Next(stations.Count)]; return true; } diff --git a/Content.Shared/Cargo/Prototypes/CargoProductPrototype.cs b/Content.Shared/Cargo/Prototypes/CargoProductPrototype.cs index e918f1c062..a08fc00eb5 100644 --- a/Content.Shared/Cargo/Prototypes/CargoProductPrototype.cs +++ b/Content.Shared/Cargo/Prototypes/CargoProductPrototype.cs @@ -5,7 +5,7 @@ using Robust.Shared.Utility; namespace Content.Shared.Cargo.Prototypes { - [NetSerializable, Serializable, Prototype("cargoProduct")] + [Prototype("cargoProduct")] public sealed class CargoProductPrototype : IPrototype { [DataField("name")] private string _name = string.Empty; diff --git a/Resources/Prototypes/GameRules/cargo_gifts.yml b/Resources/Prototypes/GameRules/cargo_gifts.yml index aaf4cbadc0..799805272d 100644 --- a/Resources/Prototypes/GameRules/cargo_gifts.yml +++ b/Resources/Prototypes/GameRules/cargo_gifts.yml @@ -184,7 +184,7 @@ sender: cargo-gift-default-sender dest: cargo-gift-dest-sec gifts: - CrateSecurityArmor: 3 + SecurityArmor: 3 ArmorySmg: 1 ArmoryShotgun: 1 ArmoryLaser: 1 @@ -206,5 +206,5 @@ dest: cargo-gift-dest-sec gifts: SecurityRiot: 2 - CrateRestraints: 2 - CrateSecurityNonlethal: 2 + SecurityRestraints: 2 + SecurityNonLethal: 2