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>
This commit is contained in:
deltanedas
2024-12-13 09:09:48 +00:00
committed by tommy
parent 3e33dc5936
commit 1c2f200762
12 changed files with 256 additions and 2 deletions

View File

@@ -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)

View File

@@ -151,6 +151,12 @@
<ui:MaterialStorageControl Name="MaterialsList" SizeFlagsStretchRatio="8"/>
</BoxContainer>
</PanelContainer>
<!-- Begin DeltaV Additions: Mining points -->
<BoxContainer Orientation="Horizontal" Name="MiningPointsContainer" Visible="False">
<Label Name="MiningPointsLabel" HorizontalExpand="True"/>
<Button Name="MiningPointsClaimButton" Text="{Loc 'lathe-menu-mining-points-claim-button'}"/>
</BoxContainer>
<!-- End DeltaV Additions: Mining points -->
</BoxContainer>
</BoxContainer>

View File

@@ -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<BaseButton.ButtonEventArgs>? OnServerListButtonPressed;
public event Action<string, int>? RecipeQueueAction;
@@ -31,15 +37,16 @@ public sealed partial class LatheMenu : DefaultWindow
public event Action<int>? QueueMoveUpAction;
public event Action<int>? QueueMoveDownAction;
public event Action? DeleteFabricatingAction;
public event Action? OnClaimMiningPoints; // DeltaV
public List<ProtoId<LatheRecipePrototype>> Recipes = new();
public List<ProtoId<LatheCategoryPrototype>>? Categories;
public ProtoId<LatheCategoryPrototype>? 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<SpriteSystem>();
_lathe = _entityManager.System<LatheSystem>();
_materialStorage = _entityManager.System<MaterialStorageSystem>();
_miningPoints = _entityManager.System<MiningPointsSystem>(); // 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<MiningPointsComponent>(Entity, out var points);
MiningPointsClaimButton.OnPressed += _ => OnClaimMiningPoints?.Invoke();
if (points != null)
UpdateMiningPoints(points.Points);
// End DeltaV Additions
MaterialsList.SetOwner(Entity);
}
/// <summary>
/// DeltaV: Updates the UI elements for mining points.
/// </summary>
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<LatheComponent>(Entity, out var latheComp))
{
AmountLineEdit.SetText(latheComp.DefaultProductionAmount.ToString());
}
}
/// <summary>
/// DeltaV: Update mining points UI whenever it changes.
/// </summary>
protected override void FrameUpdate(FrameEventArgs args)
{
base.FrameUpdate(args);
if (_entityManager.TryGetComponent<MiningPointsComponent>(Entity, out var points))
UpdateMiningPoints(points.Points);
}
/// <summary>
/// Populates the list of all the recipes
/// </summary>

View File

@@ -0,0 +1,26 @@
using Content.Shared.DeltaV.Salvage.Systems;
using Robust.Shared.Audio;
using Robust.Shared.GameStates;
namespace Content.Shared.DeltaV.Salvage.Components;
/// <summary>
/// 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.
/// </summary>
[RegisterComponent, NetworkedComponent, Access(typeof(MiningPointsSystem))]
[AutoGenerateComponentState]
public sealed partial class MiningPointsComponent : Component
{
/// <summary>
/// The number of points stored.
/// </summary>
[DataField, AutoNetworkedField]
public uint Points;
/// <summary>
/// Sound played when successfully transferring points to another holder.
/// </summary>
[DataField]
public SoundSpecifier? TransferSound;
}

View File

@@ -0,0 +1,9 @@
using Robust.Shared.GameStates;
namespace Content.Shared.DeltaV.Salvage.Components;
/// <summary>
/// Adds points to <see cref="MiningPointsComponent"/> when making a recipe that has miningPoints set.
/// </summary>
[RegisterComponent, NetworkedComponent]
public sealed partial class MiningPointsLatheComponent : Component;

View File

@@ -0,0 +1,9 @@
using Robust.Shared.Serialization;
namespace Content.Shared.DeltaV.Salvage;
/// <summary>
/// Message for a lathe to transfer its mining points to the user's id card.
/// </summary>
[Serializable, NetSerializable]
public sealed class LatheClaimMiningPointsMessage : BoundUserInterfaceMessage;

View File

@@ -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<MiningPointsComponent> _query;
public override void Initialize()
{
base.Initialize();
_query = GetEntityQuery<MiningPointsComponent>();
SubscribeLocalEvent<MiningPointsLatheComponent, LatheStartPrintingEvent>(OnStartPrinting);
Subs.BuiEvents<MiningPointsLatheComponent>(LatheUiKey.Key, subs =>
{
subs.Event<LatheClaimMiningPointsMessage>(OnClaimMiningPoints);
});
}
#region Event Handlers
private void OnStartPrinting(Entity<MiningPointsLatheComponent> ent, ref LatheStartPrintingEvent args)
{
var points = args.Recipe.MiningPoints;
if (points > 0)
AddPoints(ent.Owner, points);
}
private void OnClaimMiningPoints(Entity<MiningPointsLatheComponent> ent, ref LatheClaimMiningPointsMessage args)
{
var user = args.Actor;
if (TryFindIdCard(user) is {} dest)
TransferAll(ent.Owner, dest);
}
#endregion
#region Public API
/// <summary>
/// Tries to find the user's id card and gets its <see cref="MiningPointsComponent"/>.
/// </summary>
/// <remarks>
/// Component is nullable for easy usage with the API due to Entity&lt;T&gt; not being usable for Entity&lt;T?&gt; arguments.
/// </remarks>
public Entity<MiningPointsComponent?>? TryFindIdCard(EntityUid user)
{
if (!_idCard.TryFindIdCard(user, out var idCard))
return null;
if (!_query.TryComp(idCard, out var comp))
return null;
return (idCard, comp);
}
/// <summary>
/// Removes points from a holder, returning true if it succeeded.
/// </summary>
public bool RemovePoints(Entity<MiningPointsComponent?> ent, uint amount)
{
if (!_query.Resolve(ent, ref ent.Comp) || amount > ent.Comp.Points)
return false;
ent.Comp.Points -= amount;
Dirty(ent);
return true;
}
/// <summary>
/// Add points to a holder.
/// </summary>
public bool AddPoints(Entity<MiningPointsComponent?> ent, uint amount)
{
if (!_query.Resolve(ent, ref ent.Comp))
return false;
ent.Comp.Points += amount;
Dirty(ent);
return true;
}
/// <summary>
/// Transfer a number of points from source to destination.
/// Returns true if the transfer succeeded.
/// </summary>
public bool Transfer(Entity<MiningPointsComponent?> src, Entity<MiningPointsComponent?> 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;
}
/// <summary>
/// Transfers all points from source to destination.
/// Returns true if the transfer succeeded.
/// </summary>
public bool TransferAll(Entity<MiningPointsComponent?> src, Entity<MiningPointsComponent?> dest)
{
return _query.Resolve(src, ref src.Comp) && Transfer(src, dest, src.Comp.Points);
}
#endregion
}

View File

@@ -69,5 +69,13 @@ namespace Content.Shared.Research.Prototypes
/// </summary>
[DataField]
public List<ProtoId<LatheCategoryPrototype>> Categories = new();
public ProtoId<LatheCategoryPrototype>? Category;
/// <summary>
/// DeltaV: Number of mining points this recipe adds to an oreproc when printed.
/// Scales with stack count.
/// </summary>
[DataField]
public uint MiningPoints;
}
}

View File

@@ -0,0 +1,2 @@
lathe-menu-mining-points = Mining Points: {$points}
lathe-menu-mining-points-claim-button = Claim Points

View File

@@ -25,6 +25,7 @@
- WhitelistChameleonIdCard
- type: StealTarget
stealGroup: IDCard
- type: MiningPoints # DeltaV
#IDs with layers

View File

@@ -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

View File

@@ -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