From 1c2f2007629b3e3166e280bde1189e418a6f4a53 Mon Sep 17 00:00:00 2001
From: deltanedas <39013340+deltanedas@users.noreply.github.com>
Date: Fri, 13 Dec 2024 09:09:48 +0000
Subject: [PATCH] add mining points (#2419)
* add mining points
* add claim points button to oreproc
* funny
* its over
* :trollface:
* xml fail
Signed-off-by: deltanedas <39013340+deltanedas@users.noreply.github.com>
---------
Signed-off-by: deltanedas <39013340+deltanedas@users.noreply.github.com>
Co-authored-by: deltanedas <@deltanedas:kde.org>
---
.../Lathe/UI/LatheBoundUserInterface.cs | 3 +
Content.Client/Lathe/UI/LatheMenu.xaml | 6 +
Content.Client/Lathe/UI/LatheMenu.xaml.cs | 55 +++++++-
.../Components/MiningPointsComponent.cs | 26 ++++
.../Components/MiningPointsLatheComponent.cs | 9 ++
.../DeltaV/Salvage/MiningPointsUI.cs | 9 ++
.../Salvage/Systems/MiningPointsSystem.cs | 121 ++++++++++++++++++
.../Prototypes/LatheRecipePrototype.cs | 8 ++
.../en-US/deltav/lathe/ui/lathe-menu.ftl | 2 +
.../Objects/Misc/identification_cards.yml | 1 +
.../Entities/Structures/Machines/lathe.yml | 4 +
Resources/Prototypes/Recipes/Lathes/sheet.yml | 14 ++
12 files changed, 256 insertions(+), 2 deletions(-)
create mode 100644 Content.Shared/DeltaV/Salvage/Components/MiningPointsComponent.cs
create mode 100644 Content.Shared/DeltaV/Salvage/Components/MiningPointsLatheComponent.cs
create mode 100644 Content.Shared/DeltaV/Salvage/MiningPointsUI.cs
create mode 100644 Content.Shared/DeltaV/Salvage/Systems/MiningPointsSystem.cs
create mode 100644 Resources/Locale/en-US/deltav/lathe/ui/lathe-menu.ftl
diff --git a/Content.Client/Lathe/UI/LatheBoundUserInterface.cs b/Content.Client/Lathe/UI/LatheBoundUserInterface.cs
index 75b1704b0d..4f8e0c2ac3 100644
--- a/Content.Client/Lathe/UI/LatheBoundUserInterface.cs
+++ b/Content.Client/Lathe/UI/LatheBoundUserInterface.cs
@@ -1,3 +1,4 @@
+using Content.Shared.DeltaV.Salvage; // DeltaV
using Content.Shared.Lathe;
using Content.Shared.Research.Components;
using JetBrains.Annotations;
@@ -34,6 +35,8 @@ namespace Content.Client.Lathe.UI
_menu.QueueMoveUpAction += index => SendMessage(new LatheMoveRequestMessage(index, -1));
_menu.QueueMoveDownAction += index => SendMessage(new LatheMoveRequestMessage(index, 1));
_menu.DeleteFabricatingAction += () => SendMessage(new LatheAbortFabricationMessage());
+
+ _menu.OnClaimMiningPoints += () => SendMessage(new LatheClaimMiningPointsMessage()); // DeltaV
}
protected override void UpdateState(BoundUserInterfaceState state)
diff --git a/Content.Client/Lathe/UI/LatheMenu.xaml b/Content.Client/Lathe/UI/LatheMenu.xaml
index a5c8f6a85c..de3d51e087 100644
--- a/Content.Client/Lathe/UI/LatheMenu.xaml
+++ b/Content.Client/Lathe/UI/LatheMenu.xaml
@@ -151,6 +151,12 @@
+
+
+
+
+
+
diff --git a/Content.Client/Lathe/UI/LatheMenu.xaml.cs b/Content.Client/Lathe/UI/LatheMenu.xaml.cs
index f6688a63af..006cc0165a 100644
--- a/Content.Client/Lathe/UI/LatheMenu.xaml.cs
+++ b/Content.Client/Lathe/UI/LatheMenu.xaml.cs
@@ -1,17 +1,21 @@
using System.Linq;
using System.Text;
using Content.Client.Materials;
+using Content.Shared.DeltaV.Salvage.Components; // DeltaV
+using Content.Shared.DeltaV.Salvage.Systems; // DeltaV
using Content.Shared.Lathe;
using Content.Shared.Lathe.Prototypes;
using Content.Shared.Research.Prototypes;
using Robust.Client.AutoGenerated;
using Robust.Client.GameObjects;
+using Robust.Client.Player; // DeltaV
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;
using Robust.Client.UserInterface.CustomControls;
using Robust.Client.UserInterface.XAML;
using Robust.Shared.Prototypes;
using Robust.Shared.Utility;
+using Robust.Shared.Timing; // DeltaV
namespace Content.Client.Lathe.UI;
@@ -19,11 +23,13 @@ namespace Content.Client.Lathe.UI;
public sealed partial class LatheMenu : DefaultWindow
{
[Dependency] private readonly IEntityManager _entityManager = default!;
+ [Dependency] private readonly IPlayerManager _player = default!; // DeltaV
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
private readonly SpriteSystem _spriteSystem;
private readonly LatheSystem _lathe;
private readonly MaterialStorageSystem _materialStorage;
+ private readonly MiningPointsSystem _miningPoints; // DeltaV
public event Action? OnServerListButtonPressed;
public event Action? RecipeQueueAction;
@@ -31,15 +37,16 @@ public sealed partial class LatheMenu : DefaultWindow
public event Action? QueueMoveUpAction;
public event Action? QueueMoveDownAction;
public event Action? DeleteFabricatingAction;
-
+ public event Action? OnClaimMiningPoints; // DeltaV
public List> Recipes = new();
-
public List>? Categories;
public ProtoId? CurrentCategory;
public EntityUid Entity;
+ private uint? _lastMiningPoints; // DeltaV: used to avoid Loc.GetString every frame
+
public LatheMenu()
{
RobustXamlLoader.Load(this);
@@ -48,6 +55,7 @@ public sealed partial class LatheMenu : DefaultWindow
_spriteSystem = _entityManager.System();
_lathe = _entityManager.System();
_materialStorage = _entityManager.System();
+ _miningPoints = _entityManager.System(); // DeltaV
SearchBar.OnTextChanged += _ =>
{
@@ -86,9 +94,52 @@ public sealed partial class LatheMenu : DefaultWindow
AmountLineEdit.SetText(latheComponent.DefaultProductionAmount.ToString());
}
+ // Begin DeltaV Additions: Mining points UI
+ MiningPointsContainer.Visible = _entityManager.TryGetComponent(Entity, out var points);
+ MiningPointsClaimButton.OnPressed += _ => OnClaimMiningPoints?.Invoke();
+ if (points != null)
+ UpdateMiningPoints(points.Points);
+ // End DeltaV Additions
+
MaterialsList.SetOwner(Entity);
}
+ ///
+ /// DeltaV: Updates the UI elements for mining points.
+ ///
+ private void UpdateMiningPoints(uint points)
+ {
+ MiningPointsClaimButton.Disabled = points == 0 ||
+ _player.LocalSession?.AttachedEntity is not {} player ||
+ _miningPoints.TryFindIdCard(player) == null;
+ if (points == _lastMiningPoints)
+ return;
+
+ _lastMiningPoints = points;
+ MiningPointsLabel.Text = Loc.GetString("lathe-menu-mining-points", ("points", points));
+ }
+
+ protected override void Opened()
+ {
+ base.Opened();
+
+ if (_entityManager.TryGetComponent(Entity, out var latheComp))
+ {
+ AmountLineEdit.SetText(latheComp.DefaultProductionAmount.ToString());
+ }
+ }
+
+ ///
+ /// DeltaV: Update mining points UI whenever it changes.
+ ///
+ protected override void FrameUpdate(FrameEventArgs args)
+ {
+ base.FrameUpdate(args);
+
+ if (_entityManager.TryGetComponent(Entity, out var points))
+ UpdateMiningPoints(points.Points);
+ }
+
///
/// Populates the list of all the recipes
///
diff --git a/Content.Shared/DeltaV/Salvage/Components/MiningPointsComponent.cs b/Content.Shared/DeltaV/Salvage/Components/MiningPointsComponent.cs
new file mode 100644
index 0000000000..33ea80280f
--- /dev/null
+++ b/Content.Shared/DeltaV/Salvage/Components/MiningPointsComponent.cs
@@ -0,0 +1,26 @@
+using Content.Shared.DeltaV.Salvage.Systems;
+using Robust.Shared.Audio;
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.DeltaV.Salvage.Components;
+
+///
+/// Stores mining points for a holder, such as an ID card or ore processor.
+/// Mining points are gained by smelting ore and redeeming them to your ID card.
+///
+[RegisterComponent, NetworkedComponent, Access(typeof(MiningPointsSystem))]
+[AutoGenerateComponentState]
+public sealed partial class MiningPointsComponent : Component
+{
+ ///
+ /// The number of points stored.
+ ///
+ [DataField, AutoNetworkedField]
+ public uint Points;
+
+ ///
+ /// Sound played when successfully transferring points to another holder.
+ ///
+ [DataField]
+ public SoundSpecifier? TransferSound;
+}
diff --git a/Content.Shared/DeltaV/Salvage/Components/MiningPointsLatheComponent.cs b/Content.Shared/DeltaV/Salvage/Components/MiningPointsLatheComponent.cs
new file mode 100644
index 0000000000..fb7616e514
--- /dev/null
+++ b/Content.Shared/DeltaV/Salvage/Components/MiningPointsLatheComponent.cs
@@ -0,0 +1,9 @@
+using Robust.Shared.GameStates;
+
+namespace Content.Shared.DeltaV.Salvage.Components;
+
+///
+/// Adds points to when making a recipe that has miningPoints set.
+///
+[RegisterComponent, NetworkedComponent]
+public sealed partial class MiningPointsLatheComponent : Component;
diff --git a/Content.Shared/DeltaV/Salvage/MiningPointsUI.cs b/Content.Shared/DeltaV/Salvage/MiningPointsUI.cs
new file mode 100644
index 0000000000..c101fa0c71
--- /dev/null
+++ b/Content.Shared/DeltaV/Salvage/MiningPointsUI.cs
@@ -0,0 +1,9 @@
+using Robust.Shared.Serialization;
+
+namespace Content.Shared.DeltaV.Salvage;
+
+///
+/// Message for a lathe to transfer its mining points to the user's id card.
+///
+[Serializable, NetSerializable]
+public sealed class LatheClaimMiningPointsMessage : BoundUserInterfaceMessage;
diff --git a/Content.Shared/DeltaV/Salvage/Systems/MiningPointsSystem.cs b/Content.Shared/DeltaV/Salvage/Systems/MiningPointsSystem.cs
new file mode 100644
index 0000000000..33dca3ee01
--- /dev/null
+++ b/Content.Shared/DeltaV/Salvage/Systems/MiningPointsSystem.cs
@@ -0,0 +1,121 @@
+using Content.Shared.Access.Systems;
+using Content.Shared.DeltaV.Salvage.Components;
+using Content.Shared.Lathe;
+using Robust.Shared.Audio.Systems;
+
+namespace Content.Shared.DeltaV.Salvage.Systems;
+
+public sealed class MiningPointsSystem : EntitySystem
+{
+ [Dependency] private readonly SharedAudioSystem _audio = default!;
+ [Dependency] private readonly SharedIdCardSystem _idCard = default!;
+
+ private EntityQuery _query;
+
+ public override void Initialize()
+ {
+ base.Initialize();
+
+ _query = GetEntityQuery();
+
+ SubscribeLocalEvent(OnStartPrinting);
+ Subs.BuiEvents(LatheUiKey.Key, subs =>
+ {
+ subs.Event(OnClaimMiningPoints);
+ });
+ }
+
+ #region Event Handlers
+
+ private void OnStartPrinting(Entity ent, ref LatheStartPrintingEvent args)
+ {
+ var points = args.Recipe.MiningPoints;
+ if (points > 0)
+ AddPoints(ent.Owner, points);
+ }
+
+ private void OnClaimMiningPoints(Entity ent, ref LatheClaimMiningPointsMessage args)
+ {
+ var user = args.Actor;
+ if (TryFindIdCard(user) is {} dest)
+ TransferAll(ent.Owner, dest);
+ }
+
+ #endregion
+ #region Public API
+
+ ///
+ /// Tries to find the user's id card and gets its .
+ ///
+ ///
+ /// Component is nullable for easy usage with the API due to Entity<T> not being usable for Entity<T?> arguments.
+ ///
+ public Entity? TryFindIdCard(EntityUid user)
+ {
+ if (!_idCard.TryFindIdCard(user, out var idCard))
+ return null;
+
+ if (!_query.TryComp(idCard, out var comp))
+ return null;
+
+ return (idCard, comp);
+ }
+
+ ///
+ /// Removes points from a holder, returning true if it succeeded.
+ ///
+ public bool RemovePoints(Entity ent, uint amount)
+ {
+ if (!_query.Resolve(ent, ref ent.Comp) || amount > ent.Comp.Points)
+ return false;
+
+ ent.Comp.Points -= amount;
+ Dirty(ent);
+ return true;
+ }
+
+ ///
+ /// Add points to a holder.
+ ///
+ public bool AddPoints(Entity ent, uint amount)
+ {
+ if (!_query.Resolve(ent, ref ent.Comp))
+ return false;
+
+ ent.Comp.Points += amount;
+ Dirty(ent);
+ return true;
+ }
+
+ ///
+ /// Transfer a number of points from source to destination.
+ /// Returns true if the transfer succeeded.
+ ///
+ public bool Transfer(Entity src, Entity dest, uint amount)
+ {
+ // don't make a sound or anything
+ if (amount == 0)
+ return true;
+
+ if (!_query.Resolve(src, ref src.Comp) || !_query.Resolve(dest, ref dest.Comp))
+ return false;
+
+ if (!RemovePoints(src, amount))
+ return false;
+
+ AddPoints(dest, amount);
+ _audio.PlayPvs(src.Comp.TransferSound, src);
+ return true;
+ }
+
+ ///
+ /// Transfers all points from source to destination.
+ /// Returns true if the transfer succeeded.
+ ///
+ public bool TransferAll(Entity src, Entity dest)
+ {
+ return _query.Resolve(src, ref src.Comp) && Transfer(src, dest, src.Comp.Points);
+ }
+
+ #endregion
+}
diff --git a/Content.Shared/Research/Prototypes/LatheRecipePrototype.cs b/Content.Shared/Research/Prototypes/LatheRecipePrototype.cs
index 957526d802..d549e4c8df 100644
--- a/Content.Shared/Research/Prototypes/LatheRecipePrototype.cs
+++ b/Content.Shared/Research/Prototypes/LatheRecipePrototype.cs
@@ -69,5 +69,13 @@ namespace Content.Shared.Research.Prototypes
///
[DataField]
public List> Categories = new();
+ public ProtoId? Category;
+
+ ///
+ /// DeltaV: Number of mining points this recipe adds to an oreproc when printed.
+ /// Scales with stack count.
+ ///
+ [DataField]
+ public uint MiningPoints;
}
}
diff --git a/Resources/Locale/en-US/deltav/lathe/ui/lathe-menu.ftl b/Resources/Locale/en-US/deltav/lathe/ui/lathe-menu.ftl
new file mode 100644
index 0000000000..9f43b363f1
--- /dev/null
+++ b/Resources/Locale/en-US/deltav/lathe/ui/lathe-menu.ftl
@@ -0,0 +1,2 @@
+lathe-menu-mining-points = Mining Points: {$points}
+lathe-menu-mining-points-claim-button = Claim Points
diff --git a/Resources/Prototypes/Entities/Objects/Misc/identification_cards.yml b/Resources/Prototypes/Entities/Objects/Misc/identification_cards.yml
index b2e1dffbfc..539241853a 100644
--- a/Resources/Prototypes/Entities/Objects/Misc/identification_cards.yml
+++ b/Resources/Prototypes/Entities/Objects/Misc/identification_cards.yml
@@ -25,6 +25,7 @@
- WhitelistChameleonIdCard
- type: StealTarget
stealGroup: IDCard
+ - type: MiningPoints # DeltaV
#IDs with layers
diff --git a/Resources/Prototypes/Entities/Structures/Machines/lathe.yml b/Resources/Prototypes/Entities/Structures/Machines/lathe.yml
index 450fb43729..0f0c51528e 100644
--- a/Resources/Prototypes/Entities/Structures/Machines/lathe.yml
+++ b/Resources/Prototypes/Entities/Structures/Machines/lathe.yml
@@ -603,6 +603,10 @@
staticPacks:
- OreSmelting
- RGlassSmelting
+ - type: MiningPoints # DeltaV - Source of mining points for miners
+ transferSound:
+ path: /Audio/Effects/Cargo/ping.ogg
+ - type: MiningPointsLathe # DeltaV
- type: entity
parent: OreProcessor
diff --git a/Resources/Prototypes/Recipes/Lathes/sheet.yml b/Resources/Prototypes/Recipes/Lathes/sheet.yml
index 74c6ad3596..bde6fc1f6e 100644
--- a/Resources/Prototypes/Recipes/Lathes/sheet.yml
+++ b/Resources/Prototypes/Recipes/Lathes/sheet.yml
@@ -2,6 +2,7 @@
id: SheetSteel
result: SheetSteel1
completetime: 0
+ miningPoints: 1 # DeltaV
materials:
RawIron: 100
Coal: 30
@@ -18,6 +19,7 @@
id: SheetGlass1
result: SheetGlass1
completetime: 0
+ miningPoints: 1 # DeltaV
materials:
RawQuartz: 100
@@ -43,6 +45,7 @@
id: SheetRGlassRaw
result: SheetRGlass1
completetime: 0
+ miningPoints: 1 # DeltaV: not using float so unlucky, dont print this anyway
materials:
RawQuartz: 100
RawIron: 50
@@ -61,6 +64,7 @@
id: SheetPGlass1
result: SheetPGlass1
completetime: 0
+ miningPoints: 16 # DeltaV
materials:
RawQuartz: 100
RawPlasma: 100
@@ -77,6 +81,7 @@
id: SheetRPGlass1
result: SheetRPGlass1
completetime: 0
+ miningPoints: 16 # DeltaV
materials:
RawQuartz: 100
RawPlasma: 100
@@ -97,6 +102,7 @@
id: SheetPlasma1
result: SheetPlasma1
completetime: 0
+ miningPoints: 15 # DeltaV
materials:
RawPlasma: 100
@@ -111,6 +117,7 @@
id: SheetPlasteel1
result: SheetPlasteel1
completetime: 0
+ miningPoints: 17 # DeltaV
materials:
RawPlasma: 100
RawIron: 200 #Twice as durable as steel, Twice the material cost
@@ -136,6 +143,7 @@
id: SheetUGlass1
result: SheetUGlass1
completetime: 0
+ miningPoints: 31 # DeltaV
materials:
RawUranium: 100
RawQuartz: 100
@@ -152,6 +160,7 @@
id: SheetRUGlass1
result: SheetRUGlass1
completetime: 0
+ miningPoints: 31 # DeltaV
materials:
RawUranium: 100
RawQuartz: 100
@@ -193,6 +202,7 @@
id: MaterialDiamond
result: MaterialDiamond1
completetime: 0
+ miningPoints: 50 # DeltaV
materials:
RawDiamond: 100
@@ -200,6 +210,7 @@
id: SheetUranium1
result: SheetUranium1
completetime: 0
+ miningPoints: 30 # DeltaV
materials:
RawUranium: 100
@@ -207,6 +218,7 @@
id: IngotGold1
result: IngotGold1
completetime: 0
+ miningPoints: 18 # DeltaV
materials:
RawGold: 100
@@ -214,6 +226,7 @@
id: IngotSilver1
result: IngotSilver1
completetime: 0
+ miningPoints: 16 # DeltaV
materials:
RawSilver: 100
@@ -229,6 +242,7 @@
id: MaterialBananium1
result: MaterialBananium1
completetime: 0
+ miningPoints: 60 # DeltaV
materials:
RawBananium: 100