Storagefill component refactor (#2093)

* refactored storagefill component to allow for random items, amount, and conditional exclusion

* i fudged it

* yaml for the already deleted filler components

* ignoredcomponents & janifill

* remainder of toolboxes done

* emergencyclosetfill

* really makes you think

* it DOES really make you think

* orGroup

* exp111 suggestions

* last touches

* isNullOrEmpty
This commit is contained in:
Paul Ritter
2020-09-21 12:47:52 +02:00
committed by GitHub
parent 8238a89190
commit 37d6ca556f
23 changed files with 247 additions and 562 deletions

View File

@@ -1,29 +0,0 @@
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
namespace Content.Server.GameObjects.Components.Items.Storage.Fill
{
[RegisterComponent]
internal sealed class CustodialClosetFillComponent : Component, IMapInit
{
public override string Name => "CustodialClosetFill";
void IMapInit.MapInit()
{
var storage = Owner.GetComponent<IStorageComponent>();
void Spawn(string prototype)
{
storage.Insert(Owner.EntityManager.SpawnEntity(prototype, Owner.Transform.Coordinates));
}
Spawn("MopItem");
Spawn("MopBucket");
Spawn("WetFloorSign");
Spawn("WetFloorSign");
Spawn("WetFloorSign");
Spawn("TrashBag");
Spawn("TrashBag");
}
}
}

View File

@@ -1,65 +0,0 @@
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.Random;
using Robust.Shared.IoC;
using Robust.Shared.Random;
namespace Content.Server.GameObjects.Components.Items.Storage.Fill
{
[RegisterComponent]
internal sealed class EmergencyClosetFillComponent : Component, IMapInit
{
public override string Name => "EmergencyClosetFill";
void IMapInit.MapInit()
{
var storage = Owner.GetComponent<IStorageComponent>();
var random = IoCManager.Resolve<IRobustRandom>();
void Spawn(string prototype)
{
storage.Insert(Owner.EntityManager.SpawnEntity(prototype, Owner.Transform.Coordinates));
}
if (random.Prob(0.4f))
{
Spawn("ToolboxEmergencyFilled");
}
var pick = random.Next(0, 100);
if (pick < 40) // 40%
{
// TODO: uncomment when we actually have these items.
// Spawn("TankOxygenSmallFilled");
// Spawn("TankOxygenSmallFilled");
Spawn("BreathMaskClothing");
Spawn("BreathMaskClothing");
}
else if (pick < 65) // 25%
{
// Spawn("TankOxygenSmallFilled");
// Spawn("MedkitOxygenFilled");
Spawn("BreathMaskClothing");
}
else if (pick < 85) // 20%
{
// Spawn("TankOxygenFilled");
Spawn("BreathMaskClothing");
}
else if (pick < 95) // 10%
{
// Spawn("TankOxygenSmallFilled");
Spawn("BreathMaskClothing");
}
else if (pick < 99) // 4%
{
// nothing, doot
}
else // 1%
{
// teehee
Owner.Delete();
}
}
}
}

View File

@@ -1,32 +0,0 @@
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.GameObjects.Components.Items.Storage.Fill
{
[RegisterComponent]
internal sealed class MedkitFillComponent : Component, IMapInit
{
[Dependency] private readonly IEntityManager _entityManager = default!;
public override string Name => "MedkitFill";
void IMapInit.MapInit()
{
var storage = Owner.GetComponent<IStorageComponent>();
void Spawn(string prototype)
{
storage.Insert(_entityManager.SpawnEntity(prototype, Owner.Transform.Coordinates));
}
Spawn("Brutepack");
Spawn("Brutepack");
Spawn("Brutepack");
Spawn("Ointment");
Spawn("Ointment");
Spawn("Ointment");
}
}
}

View File

@@ -1,48 +0,0 @@
using System.Collections.Generic;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
namespace Content.Server.GameObjects.Components.Items.Storage.Fill
{
[RegisterComponent]
internal sealed class StorageFillComponent : Component, IMapInit
{
[Dependency] private readonly IEntityManager _entityManager = default!;
public override string Name => "StorageFill";
[ViewVariables]
private List<string> _contents = new List<string>();
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref _contents, "contents", new List<string>());
}
void IMapInit.MapInit()
{
if (_contents.Count == 0)
{
return;
}
var storage = Owner.GetComponent<IStorageComponent>();
void Spawn(string prototype)
{
storage.Insert(_entityManager.SpawnEntity(prototype, Owner.Transform.Coordinates));
}
foreach (var prototype in _contents)
{
Spawn(prototype);
}
}
}
}

View File

@@ -1,88 +0,0 @@
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.Random;
using Robust.Shared.IoC;
using Robust.Shared.Random;
namespace Content.Server.GameObjects.Components.Items.Storage.Fill
{
[RegisterComponent]
internal sealed class ToolLockerFillComponent : Component, IMapInit
{
public override string Name => "ToolLockerFill";
void IMapInit.MapInit()
{
var storage = Owner.GetComponent<IStorageComponent>();
var random = IoCManager.Resolve<IRobustRandom>();
void Spawn(string prototype)
{
storage.Insert(Owner.EntityManager.SpawnEntity(prototype, Owner.Transform.Coordinates));
}
if (random.Prob(0.4f))
{
Spawn("OuterclothingHazard");
}
if (random.Prob(0.7f))
{
Spawn("FlashlightLantern");
}
if (random.Prob(0.7f))
{
Spawn("Screwdriver");
}
if (random.Prob(0.7f))
{
Spawn("Wrench");
}
if (random.Prob(0.7f))
{
Spawn("Welder");
}
if (random.Prob(0.7f))
{
Spawn("Crowbar");
}
if (random.Prob(0.7f))
{
Spawn("Wirecutter");
}
if (random.Prob(0.2f))
{
Spawn("Multitool");
}
if (random.Prob(0.2f))
{
Spawn("UtilityBeltClothing");
}
if (random.Prob(0.05f))
{
Spawn("GlovesYellow");
}
if (random.Prob(0.4f))
{
Spawn("HatHardhatRed");
}
for (var i = 0; i < 3; i++)
{
if (random.Prob(0.3f))
{
Spawn("ApcExtensionCableStack");
}
}
}
}
}

View File

@@ -1,35 +0,0 @@
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Random;
using Robust.Shared.IoC;
using Robust.Shared.Random;
namespace Content.Server.GameObjects.Components.Items.Storage.Fill
{
[RegisterComponent]
internal sealed class ToolboxElectricalFillComponent : Component, IMapInit
{
[Dependency] private readonly IEntityManager _entityManager = default!;
public override string Name => "ToolboxElectricalFill";
void IMapInit.MapInit()
{
var storage = Owner.GetComponent<IStorageComponent>();
var random = IoCManager.Resolve<IRobustRandom>();
void Spawn(string prototype)
{
storage.Insert(_entityManager.SpawnEntity(prototype, Owner.Transform.Coordinates));
}
Spawn("Screwdriver");
Spawn("Crowbar");
Spawn("Wirecutter");
Spawn("ApcExtensionCableStack");
Spawn("MVWireStack");
Spawn(random.Prob(0.05f) ? "GlovesYellow" : "HVWireStack");
}
}
}

View File

@@ -1,36 +0,0 @@
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Random;
using Robust.Shared.IoC;
using Robust.Shared.Random;
namespace Content.Server.GameObjects.Components.Items.Storage.Fill
{
[RegisterComponent]
internal sealed class ToolboxEmergencyFillComponent : Component, IMapInit
{
[Dependency] private readonly IEntityManager _entityManager = default!;
public override string Name => "ToolboxEmergencyFill";
void IMapInit.MapInit()
{
var storage = Owner.GetComponent<IStorageComponent>();
var random = IoCManager.Resolve<IRobustRandom>();
void Spawn(string prototype)
{
storage.Insert(_entityManager.SpawnEntity(prototype, Owner.Transform.Coordinates));
}
Spawn("BreathMaskClothing");
Spawn("BreathMaskClothing");
Spawn("FoodChocolateBar");
Spawn("FlashlightLantern");
Spawn("FlashlightLantern");
Spawn(random.Prob(0.15f) ? "HarmonicaInstrument" : "FoodChocolateBar");
}
}
}

View File

@@ -1,36 +0,0 @@
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Random;
using Robust.Shared.IoC;
using Robust.Shared.Random;
namespace Content.Server.GameObjects.Components.Items.Storage.Fill
{
[RegisterComponent]
internal sealed class ToolboxGoldFillComponent : Component, IMapInit
{
[Dependency] private readonly IEntityManager _entityManager = default!;
public override string Name => "ToolboxGoldFill";
void IMapInit.MapInit()
{
var storage = Owner.GetComponent<IStorageComponent>();
var random = IoCManager.Resolve<IRobustRandom>();
void Spawn(string prototype)
{
storage.Insert(_entityManager.SpawnEntity(prototype, Owner.Transform.Coordinates));
}
Spawn("GoldStack");
Spawn("GoldStack");
Spawn("GoldStack");
Spawn("GoldStack");
Spawn("GoldStack");
Spawn(random.Prob(0.05f) ? "DrinkGoldenCup" : "GoldStack");
}
}
}

View File

@@ -1,33 +0,0 @@
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.IoC;
namespace Content.Server.GameObjects.Components.Items.Storage.Fill
{
[RegisterComponent]
internal sealed class UtilityBeltClothingFillComponent : Component, IMapInit
{
[Dependency] private readonly IEntityManager _entityManager = default!;
public override string Name => "UtilityBeltClothingFill";
void IMapInit.MapInit()
{
var storage = Owner.GetComponent<IStorageComponent>();
void Spawn(string prototype)
{
storage.Insert(_entityManager.SpawnEntity(prototype, Owner.Transform.Coordinates));
}
Spawn("Crowbar");
Spawn("Wrench");
Spawn("Screwdriver");
Spawn("Wirecutter");
Spawn("Welder");
Spawn("Multitool");
Spawn("ApcExtensionCableStack");
}
}
}

View File

@@ -0,0 +1,79 @@
using System;
using System.Collections.Generic;
using Robust.Server.Interfaces.GameObjects;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.GameObjects;
using Robust.Shared.Interfaces.Random;
using Robust.Shared.Interfaces.Serialization;
using Robust.Shared.IoC;
using Robust.Shared.Random;
using Robust.Shared.Serialization;
using Logger = Robust.Shared.Log.Logger;
namespace Content.Server.GameObjects.Components.Items.Storage
{
[RegisterComponent]
internal sealed class StorageFillComponent : Component, IMapInit
{
[Dependency] private readonly IEntityManager _entityManager;
public override string Name => "StorageFill";
private List<PrototypeItemData> _contents;
public override void ExposeData(ObjectSerializer serializer)
{
base.ExposeData(serializer);
serializer.DataField(ref _contents, "contents", new List<PrototypeItemData>());
}
void IMapInit.MapInit()
{
if (_contents.Count == 0)
{
return;
}
if (!Owner.TryGetComponent(out IStorageComponent storage))
{
Logger.Error($"StorageFillComponent couldn't find any StorageComponent ({Owner})");
return;
}
var random = IoCManager.Resolve<IRobustRandom>();
var alreadySpawnedGroups = new List<string>();
foreach (var storageItem in _contents)
{
if (string.IsNullOrEmpty(storageItem.PrototypeName)) continue;
if (string.IsNullOrEmpty(storageItem.GroupId) && alreadySpawnedGroups.Contains(storageItem.GroupId)) continue;
if (storageItem.SpawnProbability != 1f &&
!random.Prob(storageItem.SpawnProbability))
{
continue;
}
storage.Insert(_entityManager.SpawnEntity(storageItem.PrototypeName, Owner.Transform.Coordinates));
if(string.IsNullOrEmpty(storageItem.GroupId)) alreadySpawnedGroups.Add(storageItem.GroupId);
}
}
[Serializable]
private struct PrototypeItemData : IExposeData
{
public string PrototypeName;
public float SpawnProbability;
public string GroupId;
public int Amount;
public void ExposeData(ObjectSerializer serializer)
{
serializer.DataField(ref PrototypeName, "name", null);
serializer.DataField(ref Amount, "amount", 1);
serializer.DataField(ref SpawnProbability, "prob", 1f);
serializer.DataField(ref GroupId, "orGroup", null);
}
}
}
}