Fix cargo gifts (#18449)
Some of the IDs were invalid and no typeserializer.
This commit is contained in:
@@ -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
|
||||
/// </summary>
|
||||
[DataField("gifts"), ViewVariables(VVAccess.ReadWrite)]
|
||||
public Dictionary<string, int> Gifts = new Dictionary<string, int>();
|
||||
[DataField("gifts", required: true, customTypeSerializer:typeof(PrototypeIdDictionarySerializer<int, CargoProductPrototype>)), ViewVariables(VVAccess.ReadWrite)]
|
||||
public Dictionary<string, int> Gifts = new();
|
||||
|
||||
/// <summary>
|
||||
/// How much space (minimum) you want to leave in the order database for supply to actually do their work
|
||||
|
||||
@@ -30,16 +30,15 @@ public sealed class CargoGiftsRule : StationEventSystem<CargoGiftsRuleComponent>
|
||||
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<StationCargoOrderDatabaseComponent>))
|
||||
return;
|
||||
|
||||
@@ -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<T> : GameRuleSystem<T> where T : Compon
|
||||
|
||||
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>());
|
||||
}
|
||||
|
||||
filter ??= _ => true;
|
||||
var query = AllEntityQuery<StationEventEligibleComponent>();
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user