Remove buyer from store messages (#11230)
This commit is contained in:
@@ -26,21 +26,18 @@ public sealed class StoreBoundUserInterface : BoundUserInterface
|
||||
|
||||
_menu.OnListingButtonPressed += (_, listing) =>
|
||||
{
|
||||
if (_menu.CurrentBuyer != null)
|
||||
SendMessage(new StoreBuyListingMessage(_menu.CurrentBuyer.Value, listing));
|
||||
SendMessage(new StoreBuyListingMessage(listing));
|
||||
};
|
||||
|
||||
_menu.OnCategoryButtonPressed += (_, category) =>
|
||||
{
|
||||
_menu.CurrentCategory = category;
|
||||
if (_menu.CurrentBuyer != null)
|
||||
SendMessage(new StoreRequestUpdateInterfaceMessage(_menu.CurrentBuyer.Value));
|
||||
SendMessage(new StoreRequestUpdateInterfaceMessage());
|
||||
};
|
||||
|
||||
_menu.OnWithdrawAttempt += (_, type, amount) =>
|
||||
{
|
||||
if (_menu.CurrentBuyer != null)
|
||||
SendMessage(new StoreRequestWithdrawMessage(_menu.CurrentBuyer.Value, type, amount));
|
||||
SendMessage(new StoreRequestWithdrawMessage(type, amount));
|
||||
};
|
||||
}
|
||||
protected override void UpdateState(BoundUserInterfaceState state)
|
||||
@@ -53,8 +50,6 @@ public sealed class StoreBoundUserInterface : BoundUserInterface
|
||||
switch (state)
|
||||
{
|
||||
case StoreUpdateState msg:
|
||||
if (msg.Buyer != null)
|
||||
_menu.CurrentBuyer = msg.Buyer;
|
||||
_menu.UpdateBalance(msg.Balance);
|
||||
_menu.PopulateStoreCategoryButtons(msg.Listings);
|
||||
_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, int>? OnWithdrawAttempt;
|
||||
|
||||
public EntityUid? CurrentBuyer;
|
||||
public Dictionary<string, FixedPoint2> Balance = new();
|
||||
public string CurrentCategory = string.Empty;
|
||||
|
||||
@@ -212,7 +211,6 @@ public sealed partial class StoreMenu : DefaultWindow
|
||||
public override void Close()
|
||||
{
|
||||
base.Close();
|
||||
CurrentBuyer = null;
|
||||
_withdrawWindow?.Close();
|
||||
}
|
||||
|
||||
|
||||
@@ -63,23 +63,23 @@ public sealed partial class StoreSystem : EntitySystem
|
||||
/// <summary>
|
||||
/// Gets the available listings for a store
|
||||
/// </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>
|
||||
/// <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>
|
||||
/// Gets the available listings for a user given an overall set of listings and categories to filter by.
|
||||
/// </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="categories">What categories to filter by.</param>
|
||||
/// <param name="storeEntity">The physial entity of the store. Can be null.</param>
|
||||
/// <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)
|
||||
listings = GetAllListings();
|
||||
@@ -91,7 +91,7 @@ public sealed partial class StoreSystem : EntitySystem
|
||||
|
||||
if (listing.Conditions != null)
|
||||
{
|
||||
var args = new ListingConditionArgs(user, storeEntity, listing, EntityManager);
|
||||
var args = new ListingConditionArgs(buyer, storeEntity, listing, EntityManager);
|
||||
var conditionsMet = true;
|
||||
|
||||
foreach (var condition in listing.Conditions)
|
||||
|
||||
@@ -27,7 +27,7 @@ public sealed partial class StoreSystem : EntitySystem
|
||||
|
||||
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, 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.
|
||||
var buyer = user;
|
||||
if (buyer != null) //if we have no "buyer" for this update, then don't update the listings
|
||||
if (user != 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
|
||||
buyer = component.AccountOwner.Value;
|
||||
|
||||
component.LastAvailableListings = GetAvailableListings(buyer.Value, component).ToHashSet();
|
||||
component.LastAvailableListings = GetAvailableListings(component.AccountOwner ?? user.Value, component).ToHashSet();
|
||||
}
|
||||
|
||||
//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];
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@@ -107,13 +106,17 @@ public sealed partial class StoreSystem : EntitySystem
|
||||
return;
|
||||
}
|
||||
|
||||
if (msg.Session.AttachedEntity is not { Valid: true } buyer)
|
||||
return;
|
||||
|
||||
//verify that we can actually buy this listing and it wasn't added
|
||||
if (!ListingHasCategory(listing, component.Categories))
|
||||
return;
|
||||
|
||||
//condition checking because why not
|
||||
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));
|
||||
|
||||
if (!conditionsMet)
|
||||
@@ -135,15 +138,15 @@ public sealed partial class StoreSystem : EntitySystem
|
||||
//spawn entity
|
||||
if (listing.ProductEntity != null)
|
||||
{
|
||||
var product = Spawn(listing.ProductEntity, Transform(msg.Buyer).Coordinates);
|
||||
_hands.TryPickupAnyHand(msg.Buyer, product);
|
||||
var product = Spawn(listing.ProductEntity, Transform(buyer).Coordinates);
|
||||
_hands.PickupOrDrop(buyer, product);
|
||||
}
|
||||
|
||||
//give action
|
||||
if (listing.ProductAction != null)
|
||||
{
|
||||
var action = new InstantAction(_proto.Index<InstantActionPrototype>(listing.ProductAction));
|
||||
_actions.AddAction(msg.Buyer, action, null);
|
||||
_actions.AddAction(buyer, action, null);
|
||||
}
|
||||
|
||||
//broadcast event
|
||||
@@ -153,7 +156,7 @@ public sealed partial class StoreSystem : EntitySystem
|
||||
}
|
||||
|
||||
//log dat shit.
|
||||
if (TryComp<MindComponent>(msg.Buyer, out var mind))
|
||||
if (TryComp<MindComponent>(buyer, out var mind))
|
||||
{
|
||||
_admin.Add(LogType.StorePurchase, LogImpact.Low,
|
||||
$"{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
|
||||
_audio.Play(component.BuySuccessSound, Filter.SinglePlayer(msg.Session), uid); //cha-ching!
|
||||
|
||||
UpdateUserInterface(msg.Buyer, component);
|
||||
UpdateUserInterface(buyer, component);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -186,8 +189,11 @@ public sealed partial class StoreSystem : EntitySystem
|
||||
if (proto.Cash == null || !proto.CanWithdraw)
|
||||
return;
|
||||
|
||||
if (msg.Session.AttachedEntity is not { Valid: true} buyer)
|
||||
return;
|
||||
|
||||
FixedPoint2 amountRemaining = msg.Amount;
|
||||
var coordinates = Transform(msg.Buyer).Coordinates;
|
||||
var coordinates = Transform(buyer).Coordinates;
|
||||
|
||||
var sortedCashValues = proto.Cash.Keys.OrderByDescending(x => x).ToList();
|
||||
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
|
||||
_stack.SetCount(ent, maxAmount, stack);
|
||||
_hands.TryPickupAnyHand(msg.Buyer, ent);
|
||||
_hands.PickupOrDrop(buyer, ent);
|
||||
amountToRemove -= maxAmount;
|
||||
}
|
||||
}
|
||||
@@ -219,13 +225,13 @@ public sealed partial class StoreSystem : EntitySystem
|
||||
for (var i = 0; i < amountToSpawn; i++)
|
||||
{
|
||||
var ent = Spawn(cashId, coordinates);
|
||||
_hands.TryPickupAnyHand(msg.Buyer, ent);
|
||||
_hands.PickupOrDrop(buyer, ent);
|
||||
}
|
||||
}
|
||||
amountRemaining -= value * amountToSpawn;
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/// <param name="Buyer">The person purchasing the listing</param>
|
||||
/// <param name="Listing">The liting itself</param>
|
||||
/// <param name="Buyer">Either the account owner, user, or an inanimate object (e.g., surplus bundle)</param>
|
||||
/// <param name="Listing">The listing itself</param>
|
||||
/// <param name="EntityManager">An entitymanager for sane coding</param>
|
||||
public readonly record struct ListingConditionArgs(EntityUid Buyer, EntityUid? StoreEntity, ListingData Listing, IEntityManager EntityManager);
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
using Content.Shared.FixedPoint;
|
||||
using Content.Shared.MobState;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.Store;
|
||||
@@ -13,15 +12,12 @@ public enum StoreUiKey : byte
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class StoreUpdateState : BoundUserInterfaceState
|
||||
{
|
||||
public readonly EntityUid? Buyer;
|
||||
|
||||
public readonly HashSet<ListingData> Listings;
|
||||
|
||||
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;
|
||||
Balance = balance;
|
||||
}
|
||||
@@ -44,24 +40,18 @@ public sealed class StoreInitializeState : BoundUserInterfaceState
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class StoreRequestUpdateInterfaceMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public EntityUid CurrentBuyer;
|
||||
|
||||
public StoreRequestUpdateInterfaceMessage(EntityUid currentBuyer)
|
||||
public StoreRequestUpdateInterfaceMessage()
|
||||
{
|
||||
CurrentBuyer = currentBuyer;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class StoreBuyListingMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public EntityUid Buyer;
|
||||
|
||||
public ListingData Listing;
|
||||
|
||||
public StoreBuyListingMessage(EntityUid buyer, ListingData listing)
|
||||
public StoreBuyListingMessage(ListingData listing)
|
||||
{
|
||||
Buyer = buyer;
|
||||
Listing = listing;
|
||||
}
|
||||
}
|
||||
@@ -69,15 +59,12 @@ public sealed class StoreBuyListingMessage : BoundUserInterfaceMessage
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class StoreRequestWithdrawMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public EntityUid Buyer;
|
||||
|
||||
public string Currency;
|
||||
|
||||
public int Amount;
|
||||
|
||||
public StoreRequestWithdrawMessage(EntityUid buyer, string currency, int amount)
|
||||
public StoreRequestWithdrawMessage(string currency, int amount)
|
||||
{
|
||||
Buyer = buyer;
|
||||
Currency = currency;
|
||||
Amount = amount;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user