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:
parent
3b9fa30bb8
commit
6879e50c4e
|
|
@ -1,3 +1,4 @@
|
|||
using Content.Shared.DeltaV.Salvage; // DeltaV
|
||||
using Content.Shared.Lathe;
|
||||
using Content.Shared.Research.Components;
|
||||
using JetBrains.Annotations;
|
||||
|
|
@ -31,6 +32,8 @@ namespace Content.Client.Lathe.UI
|
|||
{
|
||||
SendMessage(new LatheQueueRecipeMessage(recipe, amount));
|
||||
};
|
||||
|
||||
_menu.OnClaimMiningPoints += () => SendMessage(new LatheClaimMiningPointsMessage()); // DeltaV
|
||||
}
|
||||
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
|
|
|
|||
|
|
@ -132,6 +132,12 @@
|
|||
HorizontalExpand="True">
|
||||
<ui:MaterialStorageControl Name="MaterialsList" SizeFlagsStretchRatio="8"/>
|
||||
</BoxContainer>
|
||||
<!-- 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>
|
||||
|
||||
|
|
|
|||
|
|
@ -1,16 +1,20 @@
|
|||
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.Timing; // DeltaV
|
||||
|
||||
namespace Content.Client.Lathe.UI;
|
||||
|
||||
|
|
@ -18,14 +22,17 @@ 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;
|
||||
public event Action? OnClaimMiningPoints; // DeltaV
|
||||
|
||||
public List<ProtoId<LatheRecipePrototype>> Recipes = new();
|
||||
|
||||
|
|
@ -35,6 +42,8 @@ public sealed partial class LatheMenu : DefaultWindow
|
|||
|
||||
public EntityUid Entity;
|
||||
|
||||
private uint? _lastMiningPoints; // DeltaV: used to avoid Loc.GetString every frame
|
||||
|
||||
public LatheMenu()
|
||||
{
|
||||
RobustXamlLoader.Load(this);
|
||||
|
|
@ -43,6 +52,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 += _ =>
|
||||
{
|
||||
|
|
@ -70,9 +80,31 @@ public sealed partial class LatheMenu : DefaultWindow
|
|||
}
|
||||
}
|
||||
|
||||
// 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();
|
||||
|
|
@ -83,6 +115,17 @@ public sealed partial class LatheMenu : DefaultWindow
|
|||
}
|
||||
}
|
||||
|
||||
/// <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>
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
@ -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;
|
||||
|
|
@ -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;
|
||||
|
|
@ -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<T> not being usable for Entity<T?> 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
|
||||
}
|
||||
|
|
@ -70,5 +70,12 @@ namespace Content.Shared.Research.Prototypes
|
|||
/// </summary>
|
||||
[DataField]
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,2 @@
|
|||
lathe-menu-mining-points = Mining Points: {$points}
|
||||
lathe-menu-mining-points-claim-button = Claim Points
|
||||
|
|
@ -25,6 +25,7 @@
|
|||
- type: StealTarget
|
||||
stealGroup: IDCard
|
||||
- type: NanoChatCard # DeltaV
|
||||
- type: MiningPoints # DeltaV
|
||||
|
||||
#IDs with layers
|
||||
|
||||
|
|
|
|||
|
|
@ -1368,6 +1368,10 @@
|
|||
- type: MaterialStorageMagnetPickup # Delta V - Summary: Adds magnet pull from Frontier
|
||||
magnetEnabled: True
|
||||
range: 0.30 # Delta V - End Magnet Pull
|
||||
- type: MiningPoints # DeltaV - Source of mining points for miners
|
||||
transferSound:
|
||||
path: /Audio/Effects/Cargo/ping.ogg
|
||||
- type: MiningPointsLathe # DeltaV
|
||||
|
||||
- type: entity
|
||||
parent: OreProcessor
|
||||
|
|
@ -1383,6 +1387,7 @@
|
|||
materialUseMultiplier: 0.75
|
||||
timeMultiplier: 0.5
|
||||
staticRecipes:
|
||||
- BluespaceCrystal # DeltaV - Bluespace Crystals can be created here.
|
||||
- SheetSteel
|
||||
- SheetGlass1
|
||||
- SheetRGlass
|
||||
|
|
|
|||
|
|
@ -17,5 +17,6 @@
|
|||
state: bluespace
|
||||
result: MaterialBluespace1
|
||||
completetime: 0
|
||||
miningPoints: 50 # DeltaV
|
||||
materials:
|
||||
RawBluespace: 100
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
@ -32,6 +34,7 @@
|
|||
id: SheetRGlass
|
||||
result: SheetRGlass1
|
||||
completetime: 0
|
||||
miningPoints: 1 # DeltaV: not using float so unlucky, dont print this anyway
|
||||
materials:
|
||||
RawQuartz: 100
|
||||
RawIron: 50
|
||||
|
|
@ -50,6 +53,7 @@
|
|||
id: SheetPGlass1
|
||||
result: SheetPGlass1
|
||||
completetime: 0
|
||||
miningPoints: 16 # DeltaV
|
||||
materials:
|
||||
RawQuartz: 100
|
||||
RawPlasma: 100
|
||||
|
|
@ -66,6 +70,7 @@
|
|||
id: SheetRPGlass1
|
||||
result: SheetRPGlass1
|
||||
completetime: 0
|
||||
miningPoints: 16 # DeltaV
|
||||
materials:
|
||||
RawQuartz: 100
|
||||
RawPlasma: 100
|
||||
|
|
@ -86,6 +91,7 @@
|
|||
id: SheetPlasma1
|
||||
result: SheetPlasma1
|
||||
completetime: 0
|
||||
miningPoints: 15 # DeltaV
|
||||
materials:
|
||||
RawPlasma: 100
|
||||
|
||||
|
|
@ -100,6 +106,7 @@
|
|||
id: SheetPlasteel1
|
||||
result: SheetPlasteel1
|
||||
completetime: 0
|
||||
miningPoints: 17 # DeltaV
|
||||
materials:
|
||||
RawPlasma: 100
|
||||
RawIron: 200 #Twice as durable as steel, Twice the material cost
|
||||
|
|
@ -125,6 +132,7 @@
|
|||
id: SheetUGlass1
|
||||
result: SheetUGlass1
|
||||
completetime: 0
|
||||
miningPoints: 31 # DeltaV
|
||||
materials:
|
||||
RawUranium: 100
|
||||
RawQuartz: 100
|
||||
|
|
@ -141,6 +149,7 @@
|
|||
id: SheetRUGlass1
|
||||
result: SheetRUGlass1
|
||||
completetime: 0
|
||||
miningPoints: 31 # DeltaV
|
||||
materials:
|
||||
RawUranium: 100
|
||||
RawQuartz: 100
|
||||
|
|
@ -182,6 +191,7 @@
|
|||
id: MaterialDiamond
|
||||
result: MaterialDiamond1
|
||||
completetime: 0
|
||||
miningPoints: 50 # DeltaV
|
||||
materials:
|
||||
RawDiamond: 100
|
||||
|
||||
|
|
@ -189,6 +199,7 @@
|
|||
id: SheetUranium1
|
||||
result: SheetUranium1
|
||||
completetime: 0
|
||||
miningPoints: 30 # DeltaV
|
||||
materials:
|
||||
RawUranium: 100
|
||||
|
||||
|
|
@ -196,6 +207,7 @@
|
|||
id: IngotGold1
|
||||
result: IngotGold1
|
||||
completetime: 0
|
||||
miningPoints: 18 # DeltaV
|
||||
materials:
|
||||
RawGold: 100
|
||||
|
||||
|
|
@ -203,6 +215,7 @@
|
|||
id: IngotSilver1
|
||||
result: IngotSilver1
|
||||
completetime: 0
|
||||
miningPoints: 16 # DeltaV
|
||||
materials:
|
||||
RawSilver: 100
|
||||
|
||||
|
|
@ -218,6 +231,7 @@
|
|||
id: MaterialBananium1
|
||||
result: MaterialBananium1
|
||||
completetime: 0
|
||||
miningPoints: 60 # DeltaV
|
||||
materials:
|
||||
RawBananium: 100
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue