Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
Rxup committed Apr 14, 2024
1 parent 6b5f9bb commit 72d0b78
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
using Content.Shared.Backmen.Economy;
using Content.Shared.Database;
using Content.Shared.FixedPoint;
using Content.Shared.Store;
using Robust.Shared.Console;
using Robust.Shared.Player;
using Robust.Shared.Prototypes;

namespace Content.Server.Backmen.Administration.Commands;

Expand Down Expand Up @@ -73,7 +75,7 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)
if (args.Length >= 3 && int.TryParse(args[2], out var banalce) && banalce != 0)
{
bankManagerSystem.TryInsertToBankAccount(account,
new KeyValuePair<string, FixedPoint2>(account.Value.Comp.CurrencyType, FixedPoint2.New(banalce)));
new KeyValuePair<ProtoId<CurrencyPrototype>, FixedPoint2>(account.Value.Comp.CurrencyType, FixedPoint2.New(banalce)));
}

_adminLogger.Add(LogType.AdminMessage, LogImpact.Extreme,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
using System.Linq;
using Content.Shared.Database;
using Content.Shared.FixedPoint;
using Content.Shared.Store;
using Robust.Shared.Prototypes;

namespace Content.Server.Backmen.Administration.Commands;

Expand Down Expand Up @@ -52,7 +54,7 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)
case > 0:
{
if (!bankManagerSystem.TryInsertToBankAccount(bankAccount,
new KeyValuePair<string, FixedPoint2>(bankAccount.Value.Comp.CurrencyType, FixedPoint2.New(balance))))
new KeyValuePair<ProtoId<CurrencyPrototype>, FixedPoint2>(bankAccount.Value.Comp.CurrencyType, FixedPoint2.New(balance))))
{
shell.WriteError($"Добавить на счет не удалось! Баланс аккаунта: {bankAccount.Value.Comp.Balance}");
return;
Expand All @@ -63,7 +65,7 @@ public void Execute(IConsoleShell shell, string argStr, string[] args)
case < 0:
{
if (!bankManagerSystem.TryWithdrawFromBankAccount(bankAccount,
new KeyValuePair<string, FixedPoint2>(bankAccount.Value.Comp.CurrencyType, FixedPoint2.New(Math.Abs(balance)))))
new KeyValuePair<ProtoId<CurrencyPrototype>, FixedPoint2>(bankAccount.Value.Comp.CurrencyType, FixedPoint2.New(Math.Abs(balance)))))
{
shell.WriteError($"Списать со счета не удалось! Баланс аккаунта: {bankAccount.Value.Comp.Balance}");
return;
Expand Down
28 changes: 22 additions & 6 deletions Content.Server/Backmen/Economy/ATM/ATMSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,29 @@ private void OnInteract(Entity<AtmComponent> uid, ref AfterActivatableUIOpenEven
UpdateComponentUserInterface(uid);
}

public Dictionary<string, FixedPoint2> GetCurrencyValue(EntityUid uid, PhysicalCompositionComponent component)
[ValidatePrototypeId<MaterialPrototype>]
private const string Credit = "Credit";

[ValidatePrototypeId<CurrencyPrototype>]
private const string SpaceCash = "SpaceCash";
public Dictionary<ProtoId<CurrencyPrototype>, FixedPoint2> GetCurrencyValue(EntityUid uid, PhysicalCompositionComponent component)
{
var amount = EntityManager.GetComponentOrNull<StackComponent>(uid)?.Count ?? 1;
var rt = new Dictionary<ProtoId<CurrencyPrototype>, FixedPoint2>();
if (component.MaterialComposition.TryGetValue(Credit, out var value))
{
rt.Add(SpaceCash, value * (FixedPoint2)amount);
}
return rt;
}
[Obsolete]
public Dictionary<string, FixedPoint2> GetCurrencyValueOld(EntityUid uid, PhysicalCompositionComponent component)
{
var amount = EntityManager.GetComponentOrNull<StackComponent>(uid)?.Count ?? 1;
var rt = new Dictionary<string, FixedPoint2>();
if (component.MaterialComposition.TryGetValue("Credit", out var value))
if (component.MaterialComposition.TryGetValue(Credit, out var value))
{
rt.Add("SpaceCash", value * (FixedPoint2)amount);
rt.Add(SpaceCash, value * (FixedPoint2)amount);
}
return rt;
}
Expand All @@ -84,7 +100,7 @@ private void OnAfterInteract(EntityUid uid, AtmCurrencyComponent _, AfterInterac
}
else if (TryComp<StoreComponent>(args.Target, out var store))
{
args.Handled = _storeSystem.TryAddCurrency(GetCurrencyValue(args.Used, component), args.Target.Value, store);
args.Handled = _storeSystem.TryAddCurrency(GetCurrencyValueOld(args.Used, component), args.Target.Value, store);
}

if (!args.Handled)
Expand Down Expand Up @@ -207,7 +223,7 @@ private void OnRequestWithdraw(Entity<AtmComponent> uid, ref ATMRequestWithdrawM
var amountRemaining = msg.Amount;
if (!_bankManagerSystem.TryWithdrawFromBankAccount(
bankAccountNumber,
new KeyValuePair<string, FixedPoint2>(currency, amountRemaining)))
new KeyValuePair<ProtoId<CurrencyPrototype>, FixedPoint2>(currency, amountRemaining)))
{
Deny(uid);
return;
Expand All @@ -228,7 +244,7 @@ private void OnRequestWithdraw(Entity<AtmComponent> uid, ref ATMRequestWithdrawM
_audioSystem.PlayPvs(uid.Comp.SoundWithdrawCurrency, uid, AudioParams.Default.WithVolume(-2f));
UpdateComponentUserInterface(uid);
}
public bool TryAddCurrency(Dictionary<string, FixedPoint2> currency, Entity<AtmComponent> atm)
public bool TryAddCurrency(Dictionary<ProtoId<CurrencyPrototype>, FixedPoint2> currency, Entity<AtmComponent> atm)
{
foreach (var type in currency)
{
Expand Down
14 changes: 8 additions & 6 deletions Content.Server/Backmen/Economy/BankManagerSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
using Content.Shared.FixedPoint;
using Content.Shared.GameTicking;
using Content.Shared.Roles;
using Content.Shared.Store;
using Robust.Shared.GameStates;
using Robust.Shared.Prototypes;
using Robust.Shared.Random;
using Robust.Shared.Utility;

Expand Down Expand Up @@ -167,7 +169,7 @@ private string GenerateBankAccountPin()
return pin;
}

public bool TryWithdrawFromBankAccount(Entity<BankAccountComponent>? bankAccount, KeyValuePair<string, FixedPoint2> currency)
public bool TryWithdrawFromBankAccount(Entity<BankAccountComponent>? bankAccount, KeyValuePair<ProtoId<CurrencyPrototype>, FixedPoint2> currency)
{
if (bankAccount == null)
{
Expand All @@ -177,12 +179,12 @@ public bool TryWithdrawFromBankAccount(Entity<BankAccountComponent>? bankAccount
}

public bool TryWithdrawFromBankAccount(EntityUid bankAccount,
KeyValuePair<string, FixedPoint2> currency, BankAccountComponent? bankAccountComponent)
KeyValuePair<ProtoId<CurrencyPrototype>, FixedPoint2> currency, BankAccountComponent? bankAccountComponent)
{
return Resolve(bankAccount, ref bankAccountComponent, false) && TryWithdrawFromBankAccount((bankAccount, bankAccountComponent), currency);
}

public bool TryWithdrawFromBankAccount(Entity<BankAccountComponent> bankAccount, KeyValuePair<string, FixedPoint2> currency)
public bool TryWithdrawFromBankAccount(Entity<BankAccountComponent> bankAccount, KeyValuePair<ProtoId<CurrencyPrototype>, FixedPoint2> currency)
{
if (currency.Key != bankAccount.Comp.CurrencyType)
return false;
Expand All @@ -200,7 +202,7 @@ public bool TryWithdrawFromBankAccount(Entity<BankAccountComponent> bankAccount,
return result;
}

public bool TryInsertToBankAccount(string? bankAccountNumber, KeyValuePair<string, FixedPoint2> currency)
public bool TryInsertToBankAccount(string? bankAccountNumber, KeyValuePair<ProtoId<CurrencyPrototype>, FixedPoint2> currency)
{
if (!TryGetBankAccount(bankAccountNumber, out var bankAccount))
return false;
Expand All @@ -211,15 +213,15 @@ public bool TryInsertToBankAccount(string? bankAccountNumber, KeyValuePair<strin
return true;
}

public bool TryInsertToBankAccount(Entity<BankAccountComponent>? bankAccount, KeyValuePair<string, FixedPoint2> currency)
public bool TryInsertToBankAccount(Entity<BankAccountComponent>? bankAccount, KeyValuePair<ProtoId<CurrencyPrototype>, FixedPoint2> currency)
{
if (bankAccount == null)
return false;

return TryInsertToBankAccount(bankAccount.Value, currency);
}

public bool TryInsertToBankAccount(Entity<BankAccountComponent> bankAccount, KeyValuePair<string, FixedPoint2> currency)
public bool TryInsertToBankAccount(Entity<BankAccountComponent> bankAccount, KeyValuePair<ProtoId<CurrencyPrototype>, FixedPoint2> currency)
{
if (currency.Key != bankAccount.Comp.CurrencyType)
return false;
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Backmen/Economy/StoreBankSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ private void TryRestockInventory(EntityUid uid, IEnumerable<string>? category =

//var _category = category?.ToArray() ?? Array.Empty<string>();
foreach (var storeComponentListing in storeComponent.Listings.Where(x =>
storeComponent.Categories.Any(x.Categories.Contains)))
storeComponent.Categories.Any(z=>x.Categories.Contains(z))))
{
var limit = storeComponentListing?.Conditions?.OfType<ListingLimitedStockCondition>().FirstOrDefault();
if ((limit == null && category != null) || storeComponentListing == null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ private void Teleport(EntityUid uid, ShadowkinTeleportPowerComponent component,

// Resume pulling
// TODO: This does nothing? // This does things sometimes, but the client never knows
_pulling.TryStartPull(args.Performer, puller.Pulling.Value, null, puller, pullable);
_pulling.TryStartPull(args.Performer, puller.Pulling.Value, puller, pullable);
}


Expand Down

0 comments on commit 72d0b78

Please sign in to comment.