Remove buyer from store messages (#11230)
This commit is contained in:
@@ -26,21 +26,18 @@ public sealed class StoreBoundUserInterface : BoundUserInterface
|
|||||||
|
|
||||||
_menu.OnListingButtonPressed += (_, listing) =>
|
_menu.OnListingButtonPressed += (_, listing) =>
|
||||||
{
|
{
|
||||||
if (_menu.CurrentBuyer != null)
|
SendMessage(new StoreBuyListingMessage(listing));
|
||||||
SendMessage(new StoreBuyListingMessage(_menu.CurrentBuyer.Value, listing));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
_menu.OnCategoryButtonPressed += (_, category) =>
|
_menu.OnCategoryButtonPressed += (_, category) =>
|
||||||
{
|
{
|
||||||
_menu.CurrentCategory = category;
|
_menu.CurrentCategory = category;
|
||||||
if (_menu.CurrentBuyer != null)
|
SendMessage(new StoreRequestUpdateInterfaceMessage());
|
||||||
SendMessage(new StoreRequestUpdateInterfaceMessage(_menu.CurrentBuyer.Value));
|
|
||||||
};
|
};
|
||||||
|
|
||||||
_menu.OnWithdrawAttempt += (_, type, amount) =>
|
_menu.OnWithdrawAttempt += (_, type, amount) =>
|
||||||
{
|
{
|
||||||
if (_menu.CurrentBuyer != null)
|
SendMessage(new StoreRequestWithdrawMessage(type, amount));
|
||||||
SendMessage(new StoreRequestWithdrawMessage(_menu.CurrentBuyer.Value, type, amount));
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
protected override void UpdateState(BoundUserInterfaceState state)
|
protected override void UpdateState(BoundUserInterfaceState state)
|
||||||
@@ -53,8 +50,6 @@ public sealed class StoreBoundUserInterface : BoundUserInterface
|
|||||||
switch (state)
|
switch (state)
|
||||||
{
|
{
|
||||||
case StoreUpdateState msg:
|
case StoreUpdateState msg:
|
||||||
if (msg.Buyer != null)
|
|
||||||
_menu.CurrentBuyer = msg.Buyer;
|
|
||||||
_menu.UpdateBalance(msg.Balance);
|
_menu.UpdateBalance(msg.Balance);
|
||||||
_menu.PopulateStoreCategoryButtons(msg.Listings);
|
_menu.PopulateStoreCategoryButtons(msg.Listings);
|
||||||
_menu.UpdateListing(msg.Listings.ToList());
|
_menu.UpdateListing(msg.Listings.ToList());
|
||||||
|
|||||||
@@ -25,7 +25,6 @@ public sealed partial class StoreMenu : DefaultWindow
|
|||||||
public event Action<BaseButton.ButtonEventArgs, string>? OnCategoryButtonPressed;
|
public event Action<BaseButton.ButtonEventArgs, string>? OnCategoryButtonPressed;
|
||||||
public event Action<BaseButton.ButtonEventArgs, string, int>? OnWithdrawAttempt;
|
public event Action<BaseButton.ButtonEventArgs, string, int>? OnWithdrawAttempt;
|
||||||
|
|
||||||
public EntityUid? CurrentBuyer;
|
|
||||||
public Dictionary<string, FixedPoint2> Balance = new();
|
public Dictionary<string, FixedPoint2> Balance = new();
|
||||||
public string CurrentCategory = string.Empty;
|
public string CurrentCategory = string.Empty;
|
||||||
|
|
||||||
@@ -212,7 +211,6 @@ public sealed partial class StoreMenu : DefaultWindow
|
|||||||
public override void Close()
|
public override void Close()
|
||||||
{
|
{
|
||||||
base.Close();
|
base.Close();
|
||||||
CurrentBuyer = null;
|
|
||||||
_withdrawWindow?.Close();
|
_withdrawWindow?.Close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,23 +63,23 @@ public sealed partial class StoreSystem : EntitySystem
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the available listings for a store
|
/// Gets the available listings for a store
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="user">The person getting the listings.</param>
|
/// <param name="buyer">Either the account owner, user, or an inanimate object (e.g., surplus bundle)</param>
|
||||||
/// <param name="component">The store the listings are coming from.</param>
|
/// <param name="component">The store the listings are coming from.</param>
|
||||||
/// <returns>The available listings.</returns>
|
/// <returns>The available listings.</returns>
|
||||||
public IEnumerable<ListingData> GetAvailableListings(EntityUid user, StoreComponent component)
|
public IEnumerable<ListingData> GetAvailableListings(EntityUid buyer, StoreComponent component)
|
||||||
{
|
{
|
||||||
return GetAvailableListings(user, component.Listings, component.Categories, component.Owner);
|
return GetAvailableListings(buyer, component.Listings, component.Categories, component.Owner);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the available listings for a user given an overall set of listings and categories to filter by.
|
/// Gets the available listings for a user given an overall set of listings and categories to filter by.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="user">The person getting the listings.</param>
|
/// <param name="buyer">Either the account owner, user, or an inanimate object (e.g., surplus bundle)</param>
|
||||||
/// <param name="listings">All of the listings that are available. If null, will just get all listings from the prototypes.</param>
|
/// <param name="listings">All of the listings that are available. If null, will just get all listings from the prototypes.</param>
|
||||||
/// <param name="categories">What categories to filter by.</param>
|
/// <param name="categories">What categories to filter by.</param>
|
||||||
/// <param name="storeEntity">The physial entity of the store. Can be null.</param>
|
/// <param name="storeEntity">The physial entity of the store. Can be null.</param>
|
||||||
/// <returns>The available listings.</returns>
|
/// <returns>The available listings.</returns>
|
||||||
public IEnumerable<ListingData> GetAvailableListings(EntityUid user, HashSet<ListingData>? listings, HashSet<string> categories, EntityUid? storeEntity = null)
|
public IEnumerable<ListingData> GetAvailableListings(EntityUid buyer, HashSet<ListingData>? listings, HashSet<string> categories, EntityUid? storeEntity = null)
|
||||||
{
|
{
|
||||||
if (listings == null)
|
if (listings == null)
|
||||||
listings = GetAllListings();
|
listings = GetAllListings();
|
||||||
@@ -91,7 +91,7 @@ public sealed partial class StoreSystem : EntitySystem
|
|||||||
|
|
||||||
if (listing.Conditions != null)
|
if (listing.Conditions != null)
|
||||||
{
|
{
|
||||||
var args = new ListingConditionArgs(user, storeEntity, listing, EntityManager);
|
var args = new ListingConditionArgs(buyer, storeEntity, listing, EntityManager);
|
||||||
var conditionsMet = true;
|
var conditionsMet = true;
|
||||||
|
|
||||||
foreach (var condition in listing.Conditions)
|
foreach (var condition in listing.Conditions)
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public sealed partial class StoreSystem : EntitySystem
|
|||||||
|
|
||||||
private void InitializeUi()
|
private void InitializeUi()
|
||||||
{
|
{
|
||||||
SubscribeLocalEvent<StoreComponent, StoreRequestUpdateInterfaceMessage>((_,c,r) => UpdateUserInterface(r.CurrentBuyer, c));
|
SubscribeLocalEvent<StoreComponent, StoreRequestUpdateInterfaceMessage>((_,c,r) => UpdateUserInterface(r.Session.AttachedEntity, c));
|
||||||
SubscribeLocalEvent<StoreComponent, StoreBuyListingMessage>(OnBuyRequest);
|
SubscribeLocalEvent<StoreComponent, StoreBuyListingMessage>(OnBuyRequest);
|
||||||
SubscribeLocalEvent<StoreComponent, StoreRequestWithdrawMessage>(OnRequestWithdraw);
|
SubscribeLocalEvent<StoreComponent, StoreRequestWithdrawMessage>(OnRequestWithdraw);
|
||||||
}
|
}
|
||||||
@@ -72,13 +72,9 @@ public sealed partial class StoreSystem : EntitySystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
//this is the person who will be passed into logic for all listing filtering.
|
//this is the person who will be passed into logic for all listing filtering.
|
||||||
var buyer = user;
|
if (user != null) //if we have no "buyer" for this update, then don't update the listings
|
||||||
if (buyer != null) //if we have no "buyer" for this update, then don't update the listings
|
|
||||||
{
|
{
|
||||||
if (component.AccountOwner != null) //if we have one stored, then use that instead
|
component.LastAvailableListings = GetAvailableListings(component.AccountOwner ?? user.Value, component).ToHashSet();
|
||||||
buyer = component.AccountOwner.Value;
|
|
||||||
|
|
||||||
component.LastAvailableListings = GetAvailableListings(buyer.Value, component).ToHashSet();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//dictionary for all currencies, including 0 values for currencies on the whitelist
|
//dictionary for all currencies, including 0 values for currencies on the whitelist
|
||||||
@@ -91,7 +87,10 @@ public sealed partial class StoreSystem : EntitySystem
|
|||||||
allCurrency[supported] = component.Balance[supported];
|
allCurrency[supported] = component.Balance[supported];
|
||||||
}
|
}
|
||||||
|
|
||||||
var state = new StoreUpdateState(buyer, component.LastAvailableListings, allCurrency);
|
// TODO: if multiple users are supposed to be able to interact with a single BUI & see different
|
||||||
|
// stores/listings, this needs to use session specific BUI states.
|
||||||
|
|
||||||
|
var state = new StoreUpdateState(component.LastAvailableListings, allCurrency);
|
||||||
_ui.SetUiState(ui, state);
|
_ui.SetUiState(ui, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -107,13 +106,17 @@ public sealed partial class StoreSystem : EntitySystem
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (msg.Session.AttachedEntity is not { Valid: true } buyer)
|
||||||
|
return;
|
||||||
|
|
||||||
//verify that we can actually buy this listing and it wasn't added
|
//verify that we can actually buy this listing and it wasn't added
|
||||||
if (!ListingHasCategory(listing, component.Categories))
|
if (!ListingHasCategory(listing, component.Categories))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
//condition checking because why not
|
//condition checking because why not
|
||||||
if (listing.Conditions != null)
|
if (listing.Conditions != null)
|
||||||
{
|
{
|
||||||
var args = new ListingConditionArgs(msg.Buyer, component.Owner, listing, EntityManager);
|
var args = new ListingConditionArgs(component.AccountOwner ?? buyer, component.Owner, listing, EntityManager);
|
||||||
var conditionsMet = listing.Conditions.All(condition => condition.Condition(args));
|
var conditionsMet = listing.Conditions.All(condition => condition.Condition(args));
|
||||||
|
|
||||||
if (!conditionsMet)
|
if (!conditionsMet)
|
||||||
@@ -135,15 +138,15 @@ public sealed partial class StoreSystem : EntitySystem
|
|||||||
//spawn entity
|
//spawn entity
|
||||||
if (listing.ProductEntity != null)
|
if (listing.ProductEntity != null)
|
||||||
{
|
{
|
||||||
var product = Spawn(listing.ProductEntity, Transform(msg.Buyer).Coordinates);
|
var product = Spawn(listing.ProductEntity, Transform(buyer).Coordinates);
|
||||||
_hands.TryPickupAnyHand(msg.Buyer, product);
|
_hands.PickupOrDrop(buyer, product);
|
||||||
}
|
}
|
||||||
|
|
||||||
//give action
|
//give action
|
||||||
if (listing.ProductAction != null)
|
if (listing.ProductAction != null)
|
||||||
{
|
{
|
||||||
var action = new InstantAction(_proto.Index<InstantActionPrototype>(listing.ProductAction));
|
var action = new InstantAction(_proto.Index<InstantActionPrototype>(listing.ProductAction));
|
||||||
_actions.AddAction(msg.Buyer, action, null);
|
_actions.AddAction(buyer, action, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
//broadcast event
|
//broadcast event
|
||||||
@@ -153,7 +156,7 @@ public sealed partial class StoreSystem : EntitySystem
|
|||||||
}
|
}
|
||||||
|
|
||||||
//log dat shit.
|
//log dat shit.
|
||||||
if (TryComp<MindComponent>(msg.Buyer, out var mind))
|
if (TryComp<MindComponent>(buyer, out var mind))
|
||||||
{
|
{
|
||||||
_admin.Add(LogType.StorePurchase, LogImpact.Low,
|
_admin.Add(LogType.StorePurchase, LogImpact.Low,
|
||||||
$"{ToPrettyString(mind.Owner):player} purchased listing \"{listing.Name}\" from {ToPrettyString(uid)}");
|
$"{ToPrettyString(mind.Owner):player} purchased listing \"{listing.Name}\" from {ToPrettyString(uid)}");
|
||||||
@@ -162,7 +165,7 @@ public sealed partial class StoreSystem : EntitySystem
|
|||||||
listing.PurchaseAmount++; //track how many times something has been purchased
|
listing.PurchaseAmount++; //track how many times something has been purchased
|
||||||
_audio.Play(component.BuySuccessSound, Filter.SinglePlayer(msg.Session), uid); //cha-ching!
|
_audio.Play(component.BuySuccessSound, Filter.SinglePlayer(msg.Session), uid); //cha-ching!
|
||||||
|
|
||||||
UpdateUserInterface(msg.Buyer, component);
|
UpdateUserInterface(buyer, component);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@@ -186,8 +189,11 @@ public sealed partial class StoreSystem : EntitySystem
|
|||||||
if (proto.Cash == null || !proto.CanWithdraw)
|
if (proto.Cash == null || !proto.CanWithdraw)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (msg.Session.AttachedEntity is not { Valid: true} buyer)
|
||||||
|
return;
|
||||||
|
|
||||||
FixedPoint2 amountRemaining = msg.Amount;
|
FixedPoint2 amountRemaining = msg.Amount;
|
||||||
var coordinates = Transform(msg.Buyer).Coordinates;
|
var coordinates = Transform(buyer).Coordinates;
|
||||||
|
|
||||||
var sortedCashValues = proto.Cash.Keys.OrderByDescending(x => x).ToList();
|
var sortedCashValues = proto.Cash.Keys.OrderByDescending(x => x).ToList();
|
||||||
foreach (var value in sortedCashValues)
|
foreach (var value in sortedCashValues)
|
||||||
@@ -210,7 +216,7 @@ public sealed partial class StoreSystem : EntitySystem
|
|||||||
|
|
||||||
var maxAmount = Math.Min(amountToRemove, stack.MaxCount); //limit it based on max stack amount
|
var maxAmount = Math.Min(amountToRemove, stack.MaxCount); //limit it based on max stack amount
|
||||||
_stack.SetCount(ent, maxAmount, stack);
|
_stack.SetCount(ent, maxAmount, stack);
|
||||||
_hands.TryPickupAnyHand(msg.Buyer, ent);
|
_hands.PickupOrDrop(buyer, ent);
|
||||||
amountToRemove -= maxAmount;
|
amountToRemove -= maxAmount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -219,13 +225,13 @@ public sealed partial class StoreSystem : EntitySystem
|
|||||||
for (var i = 0; i < amountToSpawn; i++)
|
for (var i = 0; i < amountToSpawn; i++)
|
||||||
{
|
{
|
||||||
var ent = Spawn(cashId, coordinates);
|
var ent = Spawn(cashId, coordinates);
|
||||||
_hands.TryPickupAnyHand(msg.Buyer, ent);
|
_hands.PickupOrDrop(buyer, ent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
amountRemaining -= value * amountToSpawn;
|
amountRemaining -= value * amountToSpawn;
|
||||||
}
|
}
|
||||||
|
|
||||||
component.Balance[msg.Currency] -= msg.Amount;
|
component.Balance[msg.Currency] -= msg.Amount;
|
||||||
UpdateUserInterface(msg.Buyer, component);
|
UpdateUserInterface(buyer, component);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ public abstract class ListingCondition
|
|||||||
public abstract bool Condition(ListingConditionArgs args);
|
public abstract bool Condition(ListingConditionArgs args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <param name="Buyer">The person purchasing the listing</param>
|
/// <param name="Buyer">Either the account owner, user, or an inanimate object (e.g., surplus bundle)</param>
|
||||||
/// <param name="Listing">The liting itself</param>
|
/// <param name="Listing">The listing itself</param>
|
||||||
/// <param name="EntityManager">An entitymanager for sane coding</param>
|
/// <param name="EntityManager">An entitymanager for sane coding</param>
|
||||||
public readonly record struct ListingConditionArgs(EntityUid Buyer, EntityUid? StoreEntity, ListingData Listing, IEntityManager EntityManager);
|
public readonly record struct ListingConditionArgs(EntityUid Buyer, EntityUid? StoreEntity, ListingData Listing, IEntityManager EntityManager);
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
using Content.Shared.FixedPoint;
|
using Content.Shared.FixedPoint;
|
||||||
using Content.Shared.MobState;
|
|
||||||
using Robust.Shared.Serialization;
|
using Robust.Shared.Serialization;
|
||||||
|
|
||||||
namespace Content.Shared.Store;
|
namespace Content.Shared.Store;
|
||||||
@@ -13,15 +12,12 @@ public enum StoreUiKey : byte
|
|||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed class StoreUpdateState : BoundUserInterfaceState
|
public sealed class StoreUpdateState : BoundUserInterfaceState
|
||||||
{
|
{
|
||||||
public readonly EntityUid? Buyer;
|
|
||||||
|
|
||||||
public readonly HashSet<ListingData> Listings;
|
public readonly HashSet<ListingData> Listings;
|
||||||
|
|
||||||
public readonly Dictionary<string, FixedPoint2> Balance;
|
public readonly Dictionary<string, FixedPoint2> Balance;
|
||||||
|
|
||||||
public StoreUpdateState(EntityUid? buyer, HashSet<ListingData> listings, Dictionary<string, FixedPoint2> balance)
|
public StoreUpdateState(HashSet<ListingData> listings, Dictionary<string, FixedPoint2> balance)
|
||||||
{
|
{
|
||||||
Buyer = buyer;
|
|
||||||
Listings = listings;
|
Listings = listings;
|
||||||
Balance = balance;
|
Balance = balance;
|
||||||
}
|
}
|
||||||
@@ -44,24 +40,18 @@ public sealed class StoreInitializeState : BoundUserInterfaceState
|
|||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed class StoreRequestUpdateInterfaceMessage : BoundUserInterfaceMessage
|
public sealed class StoreRequestUpdateInterfaceMessage : BoundUserInterfaceMessage
|
||||||
{
|
{
|
||||||
public EntityUid CurrentBuyer;
|
public StoreRequestUpdateInterfaceMessage()
|
||||||
|
|
||||||
public StoreRequestUpdateInterfaceMessage(EntityUid currentBuyer)
|
|
||||||
{
|
{
|
||||||
CurrentBuyer = currentBuyer;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed class StoreBuyListingMessage : BoundUserInterfaceMessage
|
public sealed class StoreBuyListingMessage : BoundUserInterfaceMessage
|
||||||
{
|
{
|
||||||
public EntityUid Buyer;
|
|
||||||
|
|
||||||
public ListingData Listing;
|
public ListingData Listing;
|
||||||
|
|
||||||
public StoreBuyListingMessage(EntityUid buyer, ListingData listing)
|
public StoreBuyListingMessage(ListingData listing)
|
||||||
{
|
{
|
||||||
Buyer = buyer;
|
|
||||||
Listing = listing;
|
Listing = listing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,15 +59,12 @@ public sealed class StoreBuyListingMessage : BoundUserInterfaceMessage
|
|||||||
[Serializable, NetSerializable]
|
[Serializable, NetSerializable]
|
||||||
public sealed class StoreRequestWithdrawMessage : BoundUserInterfaceMessage
|
public sealed class StoreRequestWithdrawMessage : BoundUserInterfaceMessage
|
||||||
{
|
{
|
||||||
public EntityUid Buyer;
|
|
||||||
|
|
||||||
public string Currency;
|
public string Currency;
|
||||||
|
|
||||||
public int Amount;
|
public int Amount;
|
||||||
|
|
||||||
public StoreRequestWithdrawMessage(EntityUid buyer, string currency, int amount)
|
public StoreRequestWithdrawMessage(string currency, int amount)
|
||||||
{
|
{
|
||||||
Buyer = buyer;
|
|
||||||
Currency = currency;
|
Currency = currency;
|
||||||
Amount = amount;
|
Amount = amount;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user