Skip to content

Commit

Permalink
implement wreck pull cost
Browse files Browse the repository at this point in the history
  • Loading branch information
deltanedas committed Dec 17, 2024
1 parent 0f49d67 commit 92f3f13
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 2 deletions.
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
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

0 comments on commit 92f3f13

Please sign in to comment.