Skip to content

Commit

Permalink
Merge branch 'DeltaV-Station:master' into CybersunShuttle
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyndomen authored Sep 30, 2024
2 parents db4a84f + 8987f68 commit 2987fd0
Show file tree
Hide file tree
Showing 179 changed files with 6,367 additions and 4,179 deletions.
27 changes: 25 additions & 2 deletions Content.Client/Commands/ActionsCommands.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using Content.Client.Actions;
using Content.Client.Actions;
using System.IO;
using Content.Shared.Administration;
using Robust.Client.UserInterface;
using YamlDotNet.RepresentationModel;
using Robust.Shared.Console;

namespace Content.Client.Commands;
Expand Down Expand Up @@ -46,7 +49,7 @@ public override void Execute(IConsoleShell shell, string argStr, string[] args)
{
if (args.Length != 1)
{
shell.WriteLine(Help);
LoadActs(); // DeltaV - Load from a file dialogue instead
return;
}

Expand All @@ -59,4 +62,24 @@ public override void Execute(IConsoleShell shell, string argStr, string[] args)
shell.WriteError(LocalizationManager.GetString($"cmd-{Command}-error"));
}
}

/// <summary>
/// DeltaV - Load actions from a file stream instead
/// </summary>
private static async void LoadActs()
{
var fileMan = IoCManager.Resolve<IFileDialogManager>();
var actMan = IoCManager.Resolve<IEntitySystemManager>().GetEntitySystem<ActionsSystem>();

var stream = await fileMan.OpenFile(new FileDialogFilters(new FileDialogFilters.Group("yml")));
if (stream is null)
return;

var reader = new StreamReader(stream);
var yamlStream = new YamlStream();
yamlStream.Load(reader);

actMan.LoadActionAssignments(yamlStream);
reader.Close();
}
}
6 changes: 2 additions & 4 deletions Content.Server/Implants/SubdermalImplantSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,14 +74,12 @@ private void OnStoreRelay(EntityUid uid, StoreComponent store, ImplantRelayEvent
return;

// same as store code, but message is only shown to yourself
args.Handled = _store.TryAddCurrency(_store.GetCurrencyValue(args.Used, currency), uid, store);

if (!args.Handled)
if (!_store.TryAddCurrency((args.Used, currency), (uid, store)))
return;

args.Handled = true;
var msg = Loc.GetString("store-currency-inserted-implant", ("used", args.Used));
_popup.PopupEntity(msg, args.User, args.User);
QueueDel(args.Used);
}

private void OnFreedomImplant(EntityUid uid, SubdermalImplantComponent component, UseFreedomImplantEvent args)
Expand Down
14 changes: 14 additions & 0 deletions Content.Server/Stack/StackSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,13 @@ public EntityUid Spawn(int amount, StackPrototype prototype, EntityCoordinates s
/// </summary>
public List<EntityUid> SpawnMultiple(string entityPrototype, int amount, EntityCoordinates spawnPosition)
{
if (amount <= 0)
{
Log.Error(
$"Attempted to spawn an invalid stack: {entityPrototype}, {amount}. Trace: {Environment.StackTrace}");
return new();
}

var spawns = CalculateSpawns(entityPrototype, amount);

var spawnedEnts = new List<EntityUid>();
Expand All @@ -116,6 +123,13 @@ public List<EntityUid> SpawnMultiple(string entityPrototype, int amount, EntityC
/// <inheritdoc cref="SpawnMultiple(string,int,EntityCoordinates)"/>
public List<EntityUid> SpawnMultiple(string entityPrototype, int amount, EntityUid target)
{
if (amount <= 0)
{
Log.Error(
$"Attempted to spawn an invalid stack: {entityPrototype}, {amount}. Trace: {Environment.StackTrace}");
return new();
}

var spawns = CalculateSpawns(entityPrototype, amount);

var spawnedEnts = new List<EntityUid>();
Expand Down
11 changes: 11 additions & 0 deletions Content.Server/Store/Components/CurrencyComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ namespace Content.Server.Store.Components;
/// Identifies a component that can be inserted into a store
/// to increase its balance.
/// </summary>
/// <remarks>
/// Note that if this entity is a stack of items, then this is meant to represent the value per stack item, not
/// the whole stack. This also means that in general, the actual value should not be modified from the initial
/// prototype value because otherwise stack merging/splitting may modify the total value.
/// </remarks>
[RegisterComponent]
public sealed partial class CurrencyComponent : Component
{
Expand All @@ -16,6 +21,12 @@ public sealed partial class CurrencyComponent : Component
/// The string is the currency type that will be added.
/// The FixedPoint2 is the value of each individual currency entity.
/// </summary>
/// <remarks>
/// Note that if this entity is a stack of items, then this is meant to represent the value per stack item, not
/// the whole stack. This also means that in general, the actual value should not be modified from the initial
/// prototype value
/// because otherwise stack merging/splitting may modify the total value.
/// </remarks>
[ViewVariables(VVAccess.ReadWrite)]
[DataField("price", customTypeSerializer: typeof(PrototypeIdDictionarySerializer<FixedPoint2, CurrencyPrototype>))]
public Dictionary<string, FixedPoint2> Price = new();
Expand Down
6 changes: 5 additions & 1 deletion Content.Server/Store/Systems/StoreSystem.Ui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,9 @@ private void OnBuyRequest(EntityUid uid, StoreComponent component, StoreBuyListi
/// </remarks>
private void OnRequestWithdraw(EntityUid uid, StoreComponent component, StoreRequestWithdrawMessage msg)
{
if (msg.Amount <= 0)
return;

//make sure we have enough cash in the bank and we actually support this currency
if (!component.Balance.TryGetValue(msg.Currency, out var currentAmount) || currentAmount < msg.Amount)
return;
Expand All @@ -307,7 +310,8 @@ private void OnRequestWithdraw(EntityUid uid, StoreComponent component, StoreReq
var cashId = proto.Cash[value];
var amountToSpawn = (int) MathF.Floor((float) (amountRemaining / value));
var ents = _stack.SpawnMultiple(cashId, amountToSpawn, coordinates);
_hands.PickupOrDrop(buyer, ents.First());
if (ents.FirstOrDefault() is {} ent)
_hands.PickupOrDrop(buyer, ent);
amountRemaining -= value * amountToSpawn;
}

Expand Down
51 changes: 34 additions & 17 deletions Content.Server/Store/Systems/StoreSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,12 @@ private void OnAfterInteract(EntityUid uid, CurrencyComponent component, AfterIn
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)
Expand All @@ -111,6 +109,10 @@ private void OnImplantActivate(EntityUid uid, StoreComponent component, OpenUpli
/// Gets the value from an entity's currency component.
/// Scales with stacks.
/// </summary>
/// <remarks>
/// If this result is intended to be used with <see cref="TryAddCurrency(Robust.Shared.GameObjects.Entity{Content.Server.Store.Components.CurrencyComponent?},Robust.Shared.GameObjects.Entity{Content.Shared.Store.Components.StoreComponent?})"/>,
/// consider using <see cref="TryAddCurrency(Robust.Shared.GameObjects.Entity{Content.Server.Store.Components.CurrencyComponent?},Robust.Shared.GameObjects.Entity{Content.Shared.Store.Components.StoreComponent?})"/> instead to ensure that the currency is consumed in the process.
/// </remarks>
/// <param name="uid"></param>
/// <param name="component"></param>
/// <returns>The value of the currency</returns>
Expand All @@ -121,19 +123,34 @@ public Dictionary<string, FixedPoint2> GetCurrencyValue(EntityUid uid, CurrencyC
}

/// <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;

if (!Resolve(store.Owner, ref store.Comp))
return false;
return TryAddCurrency(GetCurrencyValue(currencyEnt, currency), storeEnt, store);

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>
Expand Down
42 changes: 24 additions & 18 deletions Resources/Changelog/DeltaVChangelog.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,4 @@
Entries:
- author: VMSolidus
changes:
- message: Harpies can now be stripped, and can randomly be psychic
type: Fix
id: 83
time: '2023-10-23T23:32:00.0000000+00:00'
- author: FluffiestFloof
changes:
- message: Fixed Mantis not having their Metapsionic Pulse.
type: Fix
id: 84
time: '2023-10-23T23:40:59.0000000+00:00'
- author: JJ
changes:
- message: Tweaked round weighting and lowered instances of Revs
type: Tweak
id: 85
time: '2023-10-24T00:05:22.0000000+00:00'
- author: FluffiestFloof
changes:
- message: Fixed Felinids not being able to eat certain food.
Expand Down Expand Up @@ -3631,3 +3613,27 @@
id: 582
time: '2024-09-24T19:48:45.0000000+00:00'
url: https://github.com/DeltaV-Station/Delta-v/pull/1908
- author: TadJohnson00
changes:
- message: Added turtlenecks to most security roles. Helps to keep the chill out
on cool nights.
type: Add
- message: Removed security greatcoats from loadouts and the vendor.
type: Remove
id: 583
time: '2024-09-26T20:35:41.0000000+00:00'
url: https://github.com/DeltaV-Station/Delta-v/pull/1901
- author: MilonPL
changes:
- message: Fixed the description of large mail packages.
type: Fix
id: 584
time: '2024-09-27T23:42:30.0000000+00:00'
url: https://github.com/DeltaV-Station/Delta-v/pull/1925
- author: Radezolid
changes:
- message: Fixed deep fryer not being repairable after being broken.
type: Fix
id: 585
time: '2024-09-30T14:41:21.0000000+00:00'
url: https://github.com/DeltaV-Station/Delta-v/pull/1940
Loading

0 comments on commit 2987fd0

Please sign in to comment.