fix retarded code (#744)

This commit is contained in:
Valtos
2024-10-24 17:15:00 +03:00
committed by GitHub
parent 350ce8e297
commit 64ab042551
4 changed files with 88 additions and 29 deletions

View File

@@ -94,14 +94,12 @@ public sealed partial class StoreSystem : EntitySystem
if (ev.Cancelled)
return;
args.Handled = TryAddCurrency(GetCurrencyValue(uid, component), args.Target.Value, store);
if (!TryAddCurrency((uid, component), (args.Target.Value, store)))
return;
if (args.Handled)
{
var msg = Loc.GetString("store-currency-inserted", ("used", args.Used), ("target", args.Target));
_popup.PopupEntity(msg, args.Target.Value, args.User);
QueueDel(args.Used);
}
args.Handled = true;
var msg = Loc.GetString("store-currency-inserted", ("used", args.Used), ("target", args.Target));
_popup.PopupEntity(msg, args.Target.Value, args.User);
}
private void OnImplantActivate(EntityUid uid, StoreComponent component, OpenUplinkImplantEvent args)
@@ -123,19 +121,29 @@ public sealed partial class StoreSystem : EntitySystem
}
/// <summary>
/// Tries to add a currency to a store's balance.
/// Tries to add a currency to a store's balance. Note that if successful, this will consume the currency in the process.
/// </summary>
/// <param name="currencyEnt"></param>
/// <param name="storeEnt"></param>
/// <param name="currency">The currency to add</param>
/// <param name="store">The store to add it to</param>
/// <returns>Whether or not the currency was succesfully added</returns>
[PublicAPI]
public bool TryAddCurrency(EntityUid currencyEnt, EntityUid storeEnt, StoreComponent? store = null, CurrencyComponent? currency = null)
public bool TryAddCurrency(Entity<CurrencyComponent?> currency, Entity<StoreComponent?> store)
{
if (!Resolve(currencyEnt, ref currency) || !Resolve(storeEnt, ref store))
if (!Resolve(currency.Owner, ref currency.Comp))
return false;
return TryAddCurrency(GetCurrencyValue(currencyEnt, currency), storeEnt, store);
if (!Resolve(store.Owner, ref store.Comp))
return false;
var value = currency.Comp.Price;
if (TryComp(currency.Owner, out StackComponent? stack) && stack.Count != 1)
{
value = currency.Comp.Price
.ToDictionary(v => v.Key, p => p.Value * stack.Count);
}
if (!TryAddCurrency(value, store, store.Comp))
return false;
// Avoid having the currency accidentally be re-used. E.g., if multiple clients try to use the currency in the
// same tick
currency.Comp.Price.Clear();
if (stack != null)
_stack.SetCount(currency.Owner, 0, stack);
QueueDel(currency);
return true;
}
/// <summary>