Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

make wrecks cost mining points to pull #2457

Merged
merged 3 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions Content.Client/Salvage/UI/SalvageMagnetBoundUserInterface.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
using System.Linq;
using Content.Client.Message;
using Content.Shared.DeltaV.Salvage.Systems; // DeltaV
using Content.Shared.Salvage;
using Content.Shared.Salvage.Magnet;
using Robust.Client.Player; // DeltaV
using Robust.Client.UserInterface;
using Robust.Client.UserInterface.Controls;

Expand All @@ -10,12 +12,16 @@ namespace Content.Client.Salvage.UI;
public sealed class SalvageMagnetBoundUserInterface : BoundUserInterface
{
[Dependency] private readonly IEntityManager _entManager = default!;
[Dependency] private readonly IPlayerManager _player = default!; // DeltaV

private readonly MiningPointsSystem _points; // DeltaV

private OfferingWindow? _window;

public SalvageMagnetBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
IoCManager.InjectDependencies(this);
_points = _entManager.System<MiningPointsSystem>(); // DeltaV
}

protected override void Open()
Expand Down Expand Up @@ -61,6 +67,21 @@ protected override void UpdateState(BoundUserInterfaceState state)
});
};

// Begin DeltaV Additions: Mining points cost for wrecks
if (offer.Cost > 0)
{
if (_player.LocalSession?.AttachedEntity is not {} user || !_points.UserHasPoints(user, offer.Cost))
option.Disabled = true;

var label = new Label
{
Text = Loc.GetString("salvage-magnet-mining-points-cost", ("points", offer.Cost)),
HorizontalAlignment = Control.HAlignment.Center
};
option.AddContent(label);
}
// End DeltaV Additions

switch (offer)
{
case AsteroidOffering asteroid:
Expand Down
8 changes: 6 additions & 2 deletions Content.Server/Salvage/SalvageSystem.Magnet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private void OnMagnetClaim(EntityUid uid, SalvageMagnetComponent component, ref
return;
}

TakeMagnetOffer((station.Value, dataComp), args.Index, (uid, component));
TakeMagnetOffer((station.Value, dataComp), args.Index, (uid, component), args.Actor); // DeltaV: pass the user entity
}

private void OnMagnetStartup(EntityUid uid, SalvageMagnetComponent component, ComponentStartup args)
Expand Down Expand Up @@ -250,11 +250,15 @@ private void UpdateMagnetUIs(Entity<SalvageMagnetDataComponent> data)
}
}

private async Task TakeMagnetOffer(Entity<SalvageMagnetDataComponent> data, int index, Entity<SalvageMagnetComponent> magnet)
private async Task TakeMagnetOffer(Entity<SalvageMagnetDataComponent> data, int index, Entity<SalvageMagnetComponent> magnet, EntityUid user) // DeltaV: add user param
{
var seed = data.Comp.Offered[index];

var offering = GetSalvageOffering(seed);
// Begin DeltaV Addition: make wrecks cost mining points to pull
if (offering.Cost > 0 && !(_points.TryFindIdCard(user) is {} idCard && _points.RemovePoints(idCard, offering.Cost)))
return;
// End DeltaV Addition
var salvMap = _mapSystem.CreateMap();
var salvMapXform = Transform(salvMap);

Expand Down
2 changes: 2 additions & 0 deletions Content.Server/Salvage/SalvageSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Content.Server.Construction;
using Content.Server.GameTicking;
using Content.Server.Radio.EntitySystems;
using Content.Shared.DeltaV.Salvage.Systems; // DeltaV
using Content.Shared.Examine;
using Content.Shared.Interaction;
using Content.Shared.Popups;
Expand Down Expand Up @@ -52,6 +53,7 @@ public sealed partial class SalvageSystem : SharedSalvageSystem
[Dependency] private readonly LabelSystem _labelSystem = default!;
[Dependency] private readonly MapLoaderSystem _map = default!;
[Dependency] private readonly MetaDataSystem _metaData = default!;
[Dependency] private readonly MiningPointsSystem _points = default!; // DeltaV
[Dependency] private readonly RadioSystem _radioSystem = default!;
[Dependency] private readonly SharedAudioSystem _audio = default!;
[Dependency] private readonly SharedTransformSystem _transform = default!;
Expand Down
11 changes: 11 additions & 0 deletions Content.Shared/DeltaV/Salvage/Systems/MiningPointsSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,17 @@ private void OnClaimMiningPoints(Entity<MiningPointsLatheComponent> ent, ref Lat
return (idCard, comp);
}

/// <summary>
/// Returns true if the user has at least some number of points on their ID card.
/// </summary>
public bool UserHasPoints(EntityUid user, uint points)
{
if (TryFindIdCard(user)?.Comp is not {} comp)
return false;

return comp.Points >= points;
}

/// <summary>
/// Removes points from a holder, returning true if it succeeded.
/// </summary>
Expand Down
2 changes: 2 additions & 0 deletions Content.Shared/Salvage/Magnet/AsteroidOffering.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,6 @@ public record struct AsteroidOffering : ISalvageMagnetOffering
/// Calculated marker layers for the asteroid.
/// </summary>
public Dictionary<string, int> MarkerLayers;

uint ISalvageMagnetOffering.Cost => 0; // DeltaV
}
2 changes: 2 additions & 0 deletions Content.Shared/Salvage/Magnet/DebrisOffering.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ namespace Content.Shared.Salvage.Magnet;
public record struct DebrisOffering : ISalvageMagnetOffering
{
public string Id;

uint ISalvageMagnetOffering.Cost => 0; // DeltaV: Debris is a very good source of materials for the station, so no cost
}
7 changes: 5 additions & 2 deletions Content.Shared/Salvage/Magnet/ISalvageMagnetOffering.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,8 @@ namespace Content.Shared.Salvage.Magnet;

public interface ISalvageMagnetOffering
{

}
/// <summary>
/// DeltaV: How many mining points this offering costs to accept.
/// </summary>
public uint Cost { get; }
}
2 changes: 2 additions & 0 deletions Content.Shared/Salvage/Magnet/SalvageOffering.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,6 @@ namespace Content.Shared.Salvage.Magnet;
public record struct SalvageOffering : ISalvageMagnetOffering
{
public SalvageMapPrototype SalvageMap;

uint ISalvageMagnetOffering.Cost => 1000; // DeltaV: Station gets next to no benefit from you pulling wrecks, force you to mine first.
}
2 changes: 2 additions & 0 deletions Resources/Locale/en-US/deltav/salvage/salvage-magnet.ftl
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
salvage-map-wreck-size-unknown = [color=purple]Unidentified[/color]

salvage-magnet-mining-points-cost = Cost: {$points} Mining Points
Loading