Skip to content

Commit

Permalink
add special type of voucher that still requires money
Browse files Browse the repository at this point in the history
  • Loading branch information
Alkheemist committed Jan 21, 2025
1 parent 06068a3 commit 2cc985d
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,11 @@ public sealed partial class ShipyardVoucherComponent : Component
/// </summary>
[DataField(required: true)]
public ShipyardConsoleUiKey ConsoleType;

// Frontier
/// <summary>
/// Whether this voucher allows for free purchase/sale or if it still costs money to purchase. Useful for allowing multiple ships without multiple IDs.
/// </summary>
[DataField]
public bool NoValue = true;
}
15 changes: 9 additions & 6 deletions Content.Server/Shipyard/Systems/ShipyardSystem.Consoles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ private void OnPurchaseMessage(EntityUid shipyardConsoleUid, ShipyardConsoleComp
// Keep track of whether or not a voucher was used.
// TODO: voucher purchase should be done in a separate function.
bool voucherUsed = false;
bool hasValue = false;
if (voucher is not null)
{
if (voucher!.RedemptionsLeft <= 0)
Expand All @@ -161,7 +162,8 @@ private void OnPurchaseMessage(EntityUid shipyardConsoleUid, ShipyardConsoleComp
voucher.RedemptionsLeft--;
voucherUsed = true;
}
else
// not using an else here because the voucher might still require a purchase cost
if (voucher is null || voucher.NoValue is false)
{
if (bank.Balance <= vessel.Price)
{
Expand All @@ -176,6 +178,7 @@ private void OnPurchaseMessage(EntityUid shipyardConsoleUid, ShipyardConsoleComp
PlayDenySound(player, shipyardConsoleUid, component);
return;
}
hasValue = true;
}


Expand Down Expand Up @@ -267,7 +270,7 @@ private void OnPurchaseMessage(EntityUid shipyardConsoleUid, ShipyardConsoleComp
EnsureComp<LinkedLifecycleGridParentComponent>(shuttleUid);

var sellValue = 0;
if (!voucherUsed)
if (hasValue)
{
if (TryComp<ShuttleDeedComponent>(targetId, out var deed))
sellValue = (int)_pricing.AppraiseGrid((EntityUid)(deed?.ShuttleUid!));
Expand All @@ -281,7 +284,7 @@ private void OnPurchaseMessage(EntityUid shipyardConsoleUid, ShipyardConsoleComp
SendPurchaseMessage(shipyardConsoleUid, player, name, secretChannel, secret: true);

PlayConfirmSound(player, shipyardConsoleUid, component);
if (voucherUsed)
if (voucherUsed && !hasValue)
_adminLogger.Add(LogType.ShipYardUsage, LogImpact.Low, $"{ToPrettyString(player):actor} used {ToPrettyString(targetId)} to purchase shuttle {ToPrettyString(shuttleUid)} with a voucher via {ToPrettyString(component.Owner)}");
else
_adminLogger.Add(LogType.ShipYardUsage, LogImpact.Low, $"{ToPrettyString(player):actor} used {ToPrettyString(targetId)} to purchase shuttle {ToPrettyString(shuttleUid)} for {vessel.Price} credits via {ToPrettyString(component.Owner)}");
Expand All @@ -296,7 +299,7 @@ private void OnPurchaseMessage(EntityUid shipyardConsoleUid, ShipyardConsoleComp
suffix: deedShuttle.ShuttleNameSuffix ?? "",
ownerName: shuttleOwner,
entityUid: _entityManager.GetNetEntity(shuttleUid),
purchasedWithVoucher: voucherUsed,
purchasedWithVoucher: !hasValue, // replace voucherUsed with hasValue for this, so resale has some value.
purchasePrice: (uint)vessel.Price
)
);
Expand Down Expand Up @@ -573,7 +576,7 @@ private void OnItemSlotChanged(EntityUid uid, ShipyardConsoleComponent component

int sellValue = 0;
if (deed?.ShuttleUid != null)
sellValue = (int) _pricing.AppraiseGrid(deed.ShuttleUid.Value);
sellValue = (int)_pricing.AppraiseGrid(deed.ShuttleUid.Value);

sellValue -= CalculateTotalSalesTax(component, sellValue);

Expand Down Expand Up @@ -795,7 +798,7 @@ private void OnInitDeedSpawner(EntityUid uid, StationDeedSpawnerComponent compon
if (xform.GridUid == null)
return;

if (!TryComp<ShuttleDeedComponent>(xform.GridUid.Value, out var shuttleDeed) || !TryComp<ShuttleComponent>(xform.GridUid.Value, out var shuttle) || !HasComp<TransformComponent>(xform.GridUid.Value) || shuttle == null || ShipyardMap == null)
if (!TryComp<ShuttleDeedComponent>(xform.GridUid.Value, out var shuttleDeed) || !TryComp<ShuttleComponent>(xform.GridUid.Value, out var shuttle) || !HasComp<TransformComponent>(xform.GridUid.Value) || shuttle == null || ShipyardMap == null)
return;

var output = Regex.Replace($"{shuttleDeed.ShuttleOwner}", @"\s*\([^()]*\)", ""); // Removes content inside parentheses along with parentheses and a preceding space
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,3 +120,18 @@
- type: ShipyardVoucher
access:
- Brig # odd, but potentially restricts cadets in lieu of a security guard-only access level

- type: entity
parent: ShipVoucherCargoShipment
id: ShipVoucherCargoShipment
name: cargo shipment docket
description: Allows for one cargo shipment purchase from the Cargo Shipyard. Destroyed on sale.
components:
- type: Sprite
layers:
- state: blue
- state: voucherstationguard
- type: ShipyardVoucher
access:
- Cargo
noValue: false
4 changes: 2 additions & 2 deletions Resources/Prototypes/_NF/Shipyard/Shipment/basicshipment1.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
# Discord: ???

# Shuttle Notes:
#
#
- type: vessel
id: BasicShipment1
#parent: BaseVessel #Todo: abstract shipment container parent
Expand All @@ -16,7 +16,7 @@
price: 4500
category: Small
group: Shipyard #todo: change when we get a shipment shipyard
#access: Shipment #todo: change when we get a shipment deed/voucher
access: Cargo
shuttlePath: /Maps/_NF/Shuttles/Shipment/basicshipment1.yml
guidebookPage: Null
addComponents:
Expand Down

0 comments on commit 2cc985d

Please sign in to comment.