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

Shipyard Changes #422

Merged
merged 5 commits into from
Oct 16, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public sealed class ShipyardConsoleBoundUserInterface : BoundUserInterface
private ShipyardRulesPopup? _rulesWindow;
public int Balance { get; private set; }

public int? ShipSellValue { get; private set; }

public ShipyardConsoleBoundUserInterface(EntityUid owner, Enum uiKey) : base(owner, uiKey)
{
}
Expand Down Expand Up @@ -57,6 +59,7 @@ protected override void UpdateState(BoundUserInterfaceState state)
return;

Balance = cState.Balance;
ShipSellValue = cState.ShipSellValue;
var castState = (ShipyardConsoleInterfaceState) state;
Populate(castState.UiKey);
_menu?.UpdateState(castState);
Expand Down
1 change: 1 addition & 0 deletions Content.Client/Shipyard/UI/ShipyardConsoleMenu.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
MinSize="460 280">
<BoxContainer Orientation="Vertical" Margin="5 0 5 0">
<Label Name="BankAccountLabel" />
<Label Name="ShipSellValueLabel" />
<BoxContainer Orientation="Horizontal">
<OptionButton Name="Categories"
Prefix="{Loc 'cargo-console-menu-categories-label'}"
Expand Down
3 changes: 2 additions & 1 deletion Content.Client/Shipyard/UI/ShipyardConsoleMenu.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ public void PopulateCategories()

public void UpdateState(ShipyardConsoleInterfaceState state)
{
BankAccountLabel.Text = Loc.GetString("cargo-console-menu-points-amount", ("amount", state.Balance.ToString()));
BankAccountLabel.Text = Loc.GetString("cargo-shipyard-console-bank-amount", ("amount", state.Balance.ToString()));
ShipSellValueLabel.Text = Loc.GetString("cargo-shipyard-console-sell-value", ("value", state.ShipSellValue.ToString()));
SellShipButton.Disabled = state.ShipDeedTitle == null;
TargetIdButton.Text = state.IsTargetIdPresent
? Loc.GetString("id-card-console-window-eject-button")
Expand Down
45 changes: 37 additions & 8 deletions Content.Server/Shipyard/Systems/ShipyardSystem.Consoles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ private void OnPurchaseMessage(EntityUid uid, ShipyardConsoleComponent component
var channel = _prototypeManager.Index<RadioChannelPrototype>(component.ShipyardChannel);
newDeed.ShuttleUid = shuttle.Owner;
newDeed.ShuttleName = name;
_idSystem.TryChangeJobTitle(targetId, $"Captain", idCard, player);
if (ShipyardConsoleUiKey.Security != (ShipyardConsoleUiKey) args.UiKey)
_idSystem.TryChangeJobTitle(targetId, $"Captain", idCard, player);
_radio.SendRadioMessage(uid, Loc.GetString("shipyard-console-docking", ("vessel", name)), channel, uid);
_chat.TrySendInGameICMessage(uid, Loc.GetString("shipyard-console-docking", ("vessel", name)), InGameICChatType.Speak, true);

Expand All @@ -183,9 +184,19 @@ private void OnPurchaseMessage(EntityUid uid, ShipyardConsoleComponent component
_records.Synchronize(station);
}

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

if (ShipyardConsoleUiKey.BlackMarket == (ShipyardConsoleUiKey) args.UiKey)
{
var tax = (int) (sellValue * 0.30f);
sellValue -= tax;
}

PlayConfirmSound(uid, component);
_adminLogger.Add(LogType.ShipYardUsage, LogImpact.Low, $"{ToPrettyString(player):actor} purchased shuttle {ToPrettyString(shuttle.Owner)} for {vessel.Price} credits via {ToPrettyString(component.Owner)}");
RefreshState(uid, bank.Balance, true, name, true, (ShipyardConsoleUiKey) args.UiKey);
RefreshState(uid, bank.Balance, true, name, sellValue, true, (ShipyardConsoleUiKey) args.UiKey);
}

public void OnSellMessage(EntityUid uid, ShipyardConsoleComponent component, ShipyardConsoleSellMessage args)
Expand Down Expand Up @@ -269,7 +280,7 @@ public void OnSellMessage(EntityUid uid, ShipyardConsoleComponent component, Shi
_bank.TryBankDeposit(player, bill);
PlayConfirmSound(uid, component);
_adminLogger.Add(LogType.ShipYardUsage, LogImpact.Low, $"{ToPrettyString(player):actor} sold {shuttleName} for {bill} credits via {ToPrettyString(component.Owner)}");
RefreshState(uid, bank.Balance, true, null, true, (ShipyardConsoleUiKey) args.UiKey);
RefreshState(uid, bank.Balance, true, null, 0, true, (ShipyardConsoleUiKey) args.UiKey);
}

private void OnConsoleUIOpened(EntityUid uid, ShipyardConsoleComponent component, BoundUIOpenedEvent args)
Expand All @@ -286,11 +297,19 @@ private void OnConsoleUIOpened(EntityUid uid, ShipyardConsoleComponent component
{
return;
}

var targetId = component.TargetIdSlot.ContainerSlot?.ContainedEntity;
int sellValue = 0;
if (TryComp<ShuttleDeedComponent>(targetId, out var deed))
sellValue = (int) _pricing.AppraiseGrid((EntityUid) (deed?.ShuttleUid!));

TryComp<ShuttleDeedComponent>(targetId, out var deed);
if (ShipyardConsoleUiKey.BlackMarket == (ShipyardConsoleUiKey) args.UiKey)
{
var tax = (int) (sellValue * 0.30f);
sellValue -= tax;
}

RefreshState(uid, bank.Balance, true, deed?.ShuttleName, targetId.HasValue, (ShipyardConsoleUiKey) args.UiKey);
RefreshState(uid, bank.Balance, true, deed?.ShuttleName, sellValue, targetId.HasValue, (ShipyardConsoleUiKey) args.UiKey);
}

private void ConsolePopup(ICommonSession session, string text)
Expand Down Expand Up @@ -330,8 +349,17 @@ private void OnItemSlotChanged(EntityUid uid, ShipyardConsoleComponent component
}

var targetId = component.TargetIdSlot.ContainerSlot?.ContainedEntity;
TryComp<ShuttleDeedComponent>(targetId, out var deed);
RefreshState(uid, bank.Balance, true, deed?.ShuttleName, targetId.HasValue, (ShipyardConsoleUiKey) uiComp.Key);
int sellValue = 0;
if (TryComp<ShuttleDeedComponent>(targetId, out var deed))
sellValue = (int) _pricing.AppraiseGrid((EntityUid) (deed?.ShuttleUid!));

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

RefreshState(uid, bank.Balance, true, deed?.ShuttleName, sellValue, targetId.HasValue, (ShipyardConsoleUiKey) uiComp.Key);
}

public bool FoundOrganics(EntityUid uid, EntityQuery<MobStateComponent> mobQuery, EntityQuery<TransformComponent> xformQuery)
Expand All @@ -348,12 +376,13 @@ public bool FoundOrganics(EntityUid uid, EntityQuery<MobStateComponent> mobQuery
return false;
}

private void RefreshState(EntityUid uid, int balance, bool access, string? shipDeed, bool isTargetIdPresent, ShipyardConsoleUiKey uiKey)
private void RefreshState(EntityUid uid, int balance, bool access, string? shipDeed, int shipSellValue, bool isTargetIdPresent, ShipyardConsoleUiKey uiKey)
{
var newState = new ShipyardConsoleInterfaceState(
balance,
access,
shipDeed,
shipSellValue,
isTargetIdPresent,
((byte)uiKey));

Expand Down
3 changes: 3 additions & 0 deletions Content.Shared/Shipyard/BUI/ShipyardConsoleInterfaceState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,22 @@ public sealed class ShipyardConsoleInterfaceState : BoundUserInterfaceState
public int Balance;
public readonly bool AccessGranted;
public readonly string? ShipDeedTitle;
public int ShipSellValue;
public readonly bool IsTargetIdPresent;
public readonly byte UiKey;

public ShipyardConsoleInterfaceState(
int balance,
bool accessGranted,
string? shipDeedTitle,
int shipSellValue,
bool isTargetIdPresent,
byte uiKey)
{
Balance = balance;
AccessGranted = accessGranted;
ShipDeedTitle = shipDeedTitle;
ShipSellValue = shipSellValue;
IsTargetIdPresent = isTargetIdPresent;
UiKey = uiKey;
}
Expand Down
3 changes: 3 additions & 0 deletions Resources/Locale/en-US/_NF/cargo/cargo-console-component.ftl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Cargo shipyard console
cargo-shipyard-console-bank-amount = Bank spesos:${$amount}
cargo-shipyard-console-sell-value = Shuttle estimated value:${$value}
Loading