Fix cargo gifts (#18449)

Some of the IDs were invalid and no typeserializer.
This commit is contained in:
metalgearsloth
2023-07-31 04:53:54 +10:00
committed by GitHub
parent 9647d2cf59
commit b0b1597aad
5 changed files with 29 additions and 15 deletions

View File

@@ -1,6 +1,8 @@
using Content.Server.StationEvents.Events; using Content.Server.StationEvents.Events;
using Content.Shared.Cargo.Prototypes;
using Robust.Shared.Prototypes; using Robust.Shared.Prototypes;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype; using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.Dictionary;
namespace Content.Server.StationEvents.Components; 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 /// Cargo that you would like gifted to the station, with the quantity for each
/// Use Ids from cargoProduct Prototypes /// Use Ids from cargoProduct Prototypes
/// </summary> /// </summary>
[DataField("gifts"), ViewVariables(VVAccess.ReadWrite)] [DataField("gifts", required: true, customTypeSerializer:typeof(PrototypeIdDictionarySerializer<int, CargoProductPrototype>)), ViewVariables(VVAccess.ReadWrite)]
public Dictionary<string, int> Gifts = new Dictionary<string, int>(); public Dictionary<string, int> Gifts = new();
/// <summary> /// <summary>
/// How much space (minimum) you want to leave in the order database for supply to actually do their work /// How much space (minimum) you want to leave in the order database for supply to actually do their work

View File

@@ -30,16 +30,15 @@ public sealed class CargoGiftsRule : StationEventSystem<CargoGiftsRuleComponent>
protected override void ActiveTick(EntityUid uid, CargoGiftsRuleComponent component, GameRuleComponent gameRule, float frameTime) protected override void ActiveTick(EntityUid uid, CargoGiftsRuleComponent component, GameRuleComponent gameRule, float frameTime)
{ {
if (component.Gifts.Count == 0) if (component.Gifts.Count == 0)
{
return; return;
}
if (component.TimeUntilNextGifts > 0) if (component.TimeUntilNextGifts > 0)
{ {
component.TimeUntilNextGifts -= frameTime; component.TimeUntilNextGifts -= frameTime;
return; return;
} }
component.TimeUntilNextGifts = 30f;
component.TimeUntilNextGifts += 30f;
if (!TryGetRandomStation(out var station, HasComp<StationCargoOrderDatabaseComponent>)) if (!TryGetRandomStation(out var station, HasComp<StationCargoOrderDatabaseComponent>))
return; return;

View File

@@ -9,6 +9,7 @@ using Content.Server.Station.Components;
using Content.Server.Station.Systems; using Content.Server.Station.Systems;
using Content.Server.StationEvents.Components; using Content.Server.StationEvents.Components;
using Content.Shared.Database; using Content.Shared.Database;
using Robust.Shared.Collections;
using Robust.Shared.Map; using Robust.Shared.Map;
using Robust.Shared.Map.Components; using Robust.Shared.Map.Components;
using Robust.Shared.Player; 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) 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; 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: while (query.MoveNext(out var uid, out _))
var stations = EntityManager.GetAllComponents(typeof(StationEventEligibleComponent)).Select(x => x.Uid).Where(filter).ToArray(); {
if (!filter(uid))
continue;
if (stations.Length == 0) stations.Add(uid);
}
if (stations.Count == 0)
{ {
station = null; station = null;
return false; return false;
} }
// TODO: Engine PR.
station = RobustRandom.Pick(stations); station = stations[RobustRandom.Next(stations.Count)];
return true; return true;
} }

View File

@@ -5,7 +5,7 @@ using Robust.Shared.Utility;
namespace Content.Shared.Cargo.Prototypes namespace Content.Shared.Cargo.Prototypes
{ {
[NetSerializable, Serializable, Prototype("cargoProduct")] [Prototype("cargoProduct")]
public sealed class CargoProductPrototype : IPrototype public sealed class CargoProductPrototype : IPrototype
{ {
[DataField("name")] private string _name = string.Empty; [DataField("name")] private string _name = string.Empty;

View File

@@ -184,7 +184,7 @@
sender: cargo-gift-default-sender sender: cargo-gift-default-sender
dest: cargo-gift-dest-sec dest: cargo-gift-dest-sec
gifts: gifts:
CrateSecurityArmor: 3 SecurityArmor: 3
ArmorySmg: 1 ArmorySmg: 1
ArmoryShotgun: 1 ArmoryShotgun: 1
ArmoryLaser: 1 ArmoryLaser: 1
@@ -206,5 +206,5 @@
dest: cargo-gift-dest-sec dest: cargo-gift-dest-sec
gifts: gifts:
SecurityRiot: 2 SecurityRiot: 2
CrateRestraints: 2 SecurityRestraints: 2
CrateSecurityNonlethal: 2 SecurityNonLethal: 2