-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* add mining points * add claim points button to oreproc * funny * its over * * xml fail Signed-off-by: deltanedas <[email protected]> --------- Signed-off-by: deltanedas <[email protected]> Co-authored-by: deltanedas <@deltanedas:kde.org>
- Loading branch information
1 parent
711367e
commit 54583f5
Showing
12 changed files
with
308 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 26 additions & 0 deletions
26
Content.Shared/DeltaV/Salvage/Components/MiningPointsComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} |
9 changes: 9 additions & 0 deletions
9
Content.Shared/DeltaV/Salvage/Components/MiningPointsLatheComponent.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; |
121 changes: 121 additions & 0 deletions
121
Content.Shared/DeltaV/Salvage/Systems/MiningPointsSystem.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
lathe-menu-mining-points = Mining Points: {$points} | ||
lathe-menu-mining-points-claim-button = Claim Points |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.