Skip to content
Open
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
95 changes: 82 additions & 13 deletions Content.Server/_Crescent/Shipyard/ShipyardPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,15 @@ public bool TrySellShuttle(EntityUid stationUid, EntityUid shuttleUid, out int b
_station.DeleteStation(shuttleStationUid);
}

bill = (int) _pricing.AppraiseGrid(shuttleUid);
var value = _pricing.AppraiseGrid(shuttleUid);

if (TryComp<ShipPriceMultiplierComponent>(shuttleUid, out var mult))
{
value *= mult.priceMultiplier;
}

bill = (int) value;

_mapManager.DeleteGrid(shuttleUid);
_sawmill.Info($"Sold shuttle {shuttleUid} for {bill}");
return true;
Expand All @@ -291,6 +299,27 @@ private void SetupShipyard()
_mapManager.SetMapPaused(ShipyardMap.Value, false);
}


private int GetShuttleSellValue(EntityUid shuttleUid, ShipyardConsoleUiKey? uiKey = null)
{
var value = _pricing.AppraiseGrid(shuttleUid);

if (TryComp<ShipPriceMultiplierComponent>(shuttleUid, out var mult))
{
value *= mult.priceMultiplier;
}

// Existing tax logic
if (uiKey is ShipyardConsoleUiKey.BlackMarket
or ShipyardConsoleUiKey.Syndicate)
{
value -= (int)(value * 0.30f);
}

return (int) value;
}


// <summary>
// Tries to rename a shuttle deed and update the respective components.
// Returns true if successful.
Expand Down Expand Up @@ -406,6 +435,25 @@ private void OnPurchaseMessage(EntityUid uid, ShipyardConsoleComponent component
PlayDenySound(uid, component);
return;
}

// Apply resale depreciation to purchased ships
var priceMult = EnsureComp<ShipPriceMultiplierComponent>(shuttle.Owner);
priceMult.priceMultiplier = 0.80f;

var sellValue = (int)(_pricing.AppraiseGrid(shuttle.Owner) * 0.8f);

RefreshState(
uid,
bank.Balance,
true,
name,
sellValue,
true,
(ShipyardConsoleUiKey) args.UiKey
);



EntityUid? shuttleStation = null;
// setting up any stations if we have a matching game map prototype to allow late joins directly onto the vessel
if (_prototypeManager.TryIndex<GameMapPrototype>(vessel.ID, out var stationProto))
Expand Down Expand Up @@ -455,10 +503,6 @@ private void OnPurchaseMessage(EntityUid uid, ShipyardConsoleComponent component



int sellValue = 0;
if (TryComp<ShuttleDeedComponent>(product, out var deed))
sellValue = (int) _pricing.AppraiseGrid((EntityUid) (deed?.ShuttleUid!));

EnsureComp<ShipSpeedByMassAdjusterComponent>(shuttle.Owner);
if (TryComp<DynamicCodeHolderComponent>(shuttle.Owner, out var shuttleCodes))
{
Expand Down Expand Up @@ -670,6 +714,37 @@ private void SendSellMessage(EntityUid uid, EntityUid? player, string name, stri
}
}

private void ForceRefreshUi(
EntityUid console,
EntityUid shuttle,
string shipName,
ShipyardConsoleUiKey uiKey)
{
if (!TryComp<ActivatableUIComponent>(console, out var uiComp))
return;

var actors = _ui.GetActors(console, uiKey);

foreach (var actor in actors)
{
if (!TryComp<BankAccountComponent>(actor, out var bank))
continue;

var sellValue = GetShuttleSellValue(shuttle, uiKey);

RefreshState(
console,
bank.Balance,
true,
shipName,
sellValue,
true,
uiKey
);
}
}


private void PlayDenySound(EntityUid uid, ShipyardConsoleComponent component)
{
_audio.PlayPvs(_audio.GetSound(component.DenySound), uid, AudioParams.Default.WithMaxDistance(0.01f));
Expand Down Expand Up @@ -708,15 +783,9 @@ private void OnItemSlotChanged(EntityUid uid, ShipyardConsoleComponent component
}

var sellValue = deed?.ShuttleUid != null
? (int)_pricing.AppraiseGrid((EntityUid)deed.ShuttleUid)
? GetShuttleSellValue((EntityUid) deed.ShuttleUid, (ShipyardConsoleUiKey) uiComp.Key)
: 0;

if (uiComp.Key is ShipyardConsoleUiKey.BlackMarket
or ShipyardConsoleUiKey.Syndicate)
{
var tax = (int)(sellValue * 0.30f);
sellValue -= tax;
}

var fullName = deed != null ? GetFullName(deed) : null;
RefreshState(uid, bank.Balance, true, fullName, sellValue, targetId.HasValue, (ShipyardConsoleUiKey)uiComp.Key);
Expand Down Expand Up @@ -932,7 +1001,7 @@ private bool TryRedeemShip(EntityUid uid, ShipyardConsoleComponent component, En
});
_shuttle.AddIFFFlag(shuttle.Owner, IFFFlags.IsPlayerShuttle);
var comp = EnsureComp<ShipPriceMultiplierComponent>(shuttle.Owner);
comp.priceMultiplier = 0.25f;
comp.priceMultiplier = 0.80f;

// match our IFF faction with our spawner's
if (TryComp<IFFComponent>(Transform(uid).GridUid, out var stationIFF))
Expand Down
Loading