Skip to content

Commit

Permalink
Chem dispenser Upgradability (#220)
Browse files Browse the repository at this point in the history
* Adds a system that allows developers to make reagent dispensers upgradeable. In a nutshell, additional reagents will become available on a reagent dispenser when all their machine parts have been upgraded to a higher tier. Currently this system only works on chem dispensers, because it is the only one that requires machine parts to build.

* Removed a repeated reference and updated the prototype documentation

* - Fix an issue where a necessary reference was accidentally removed

* UpgragableChemTweaks

* Исправление конфликта

---------

Co-authored-by: chromiumboy <[email protected]>
  • Loading branch information
GuakeTheAcinid and chromiumboy authored Aug 18, 2023
1 parent 896c7c7 commit a7eeadf
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Content.Client/Chemistry/UI/ReagentDispenserWindow.xaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<DefaultWindow xmlns="https://spacestation14.io"
xmlns:gfx="clr-namespace:Robust.Client.Graphics;assembly=Robust.Client"
Title="{Loc 'reagent-dispenser-bound-user-interface-title'}"
SetSize="620 450"
SetSize="620 550"
MinSize="620 450">
<BoxContainer Orientation="Vertical">
<BoxContainer Orientation="Horizontal">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using Content.Shared.Chemistry.Dispenser;
using Robust.Shared.Audio;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;

namespace Content.Server.Chemistry.Components
{
Expand All @@ -22,6 +23,10 @@ public sealed class ReagentDispenserComponent : Component
[ViewVariables(VVAccess.ReadWrite)]
public string? EmagPackPrototypeId = default!;

[DataField("upgradePacks", customTypeSerializer: typeof(PrototypeIdListSerializer<ReagentDispenserInventoryTieredPrototype>))]
[ViewVariables(VVAccess.ReadWrite)]
public List<string>? UpgradePacksPrototypeId = default!;

[DataField("clickSound"), ViewVariables(VVAccess.ReadWrite)]
public SoundSpecifier ClickSound = new SoundPathSpecifier("/Audio/Machines/machine_switch.ogg");

Expand Down
25 changes: 25 additions & 0 deletions Content.Server/Chemistry/EntitySystems/ReagentDispenserSystem.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
using System.Linq;
using Content.Server.Administration.Logs;
using Content.Server.Chemistry.Components;
using Content.Server.Construction;
using Content.Server.Construction.Components;
using Content.Shared.Chemistry;
using Content.Shared.Chemistry.Dispenser;
using Content.Shared.Construction.Components;
using Content.Shared.Containers.ItemSlots;
using Content.Shared.Database;
using Content.Shared.Emag.Components;
Expand All @@ -29,6 +32,7 @@ public sealed class ReagentDispenserSystem : EntitySystem
[Dependency] private readonly UserInterfaceSystem _userInterfaceSystem = default!;
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
[Dependency] private readonly IAdminLogManager _adminLogger = default!;
[Dependency] private readonly ConstructionSystem _construction = default!;
public override void Initialize()
{
base.Initialize();
Expand Down Expand Up @@ -87,6 +91,27 @@ private List<string> GetInventory(ReagentDispenserComponent reagentDispenser)
inventory.AddRange(emagPackPrototype.Inventory);
}

if (reagentDispenser.UpgradePacksPrototypeId is not null
&& TryComp(reagentDispenser.Owner, out MachineComponent? machineComponent)
&& machineComponent?.PartContainer?.ContainedEntities != null)
{
List<MachinePartComponent>? machineParts = _construction.GetAllParts(machineComponent);

if (machineParts != null && machineParts.Count > 0)
{
int minRating = machineParts.Min(x => x.Rating);

foreach (string upgradePackPrototypeId in reagentDispenser.UpgradePacksPrototypeId)
{
if (_prototypeManager.TryIndex(upgradePackPrototypeId, out ReagentDispenserInventoryTieredPrototype? upgradePackPrototype)
&& (upgradePackPrototype.Tier == null || upgradePackPrototype.Tier <= minRating))
{
inventory.AddRange(upgradePackPrototype.Inventory);
}
}
}
}

return inventory;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using Content.Shared.Chemistry.Reagent;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype.List;

namespace Content.Shared.Chemistry.Dispenser
{
/// <summary>
/// This is used to define a list of reagents that a machine can dispense
/// when its machine parts have all be upgraded to the specified tier.
/// </summary>
[Serializable, NetSerializable, Prototype("reagentDispenserInventoryTiered")]
public sealed class ReagentDispenserInventoryTieredPrototype : IPrototype
{
[DataField("inventory", customTypeSerializer: typeof(PrototypeIdListSerializer<ReagentPrototype>))]
private List<string> _inventory = new();

[DataField("tier")]
public int? Tier { get; set; }

[ViewVariables]
[IdDataField]
public string ID { get; } = default!;

public List<string> Inventory => _inventory;
}
}
26 changes: 25 additions & 1 deletion Resources/Prototypes/Catalog/ReagentDispensers/chemical.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,28 @@
- Napalm
- Toxin
- Epinephrine
- Ultravasculine
- Uranium

- type: reagentDispenserInventoryTiered
id: ChemDispenserTier2Inventory
tier: 2
inventory:
- Ammonia
- Oil
- SulfuricAcid

- type: reagentDispenserInventoryTiered
id: ChemDispenserTier3Inventory
tier: 3
inventory:
- Acetone
- Phenol
- SodiumCarbonate
- Water

- type: reagentDispenserInventoryTiered
id: ChemDispenserTier4Inventory
tier: 4
inventory:
- Plasma

4 changes: 4 additions & 0 deletions Resources/Prototypes/Entities/Structures/Dispensers/chem.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
- type: ReagentDispenser
pack: ChemDispenserStandardInventory
emagPack: ChemDispenserEmaggedInventory
upgradePacks:
- ChemDispenserTier2Inventory
- ChemDispenserTier3Inventory
- ChemDispenserTier4Inventory
- type: ApcPowerReceiver
- type: ExtensionCableReceiver
- type: Destructible
Expand Down

0 comments on commit a7eeadf

Please sign in to comment.