Fix the server not checking uplink purchase prices (#1917)
This commit is contained in:
@@ -69,7 +69,7 @@ namespace Content.Client.GameObjects.Components.PDA
|
||||
};
|
||||
}
|
||||
|
||||
SendMessage(new PDAUplinkBuyListingMessage(listing));
|
||||
SendMessage(new PDAUplinkBuyListingMessage(listing.ItemId));
|
||||
};
|
||||
|
||||
_menu.OnCategoryButtonPressed += (args, category) =>
|
||||
|
||||
@@ -102,7 +102,7 @@ namespace Content.Server.GameObjects.Components.PDA
|
||||
|
||||
case PDAUplinkBuyListingMessage buyMsg:
|
||||
{
|
||||
if (!_uplinkManager.TryPurchaseItem(_syndicateUplinkAccount, buyMsg.ListingToBuy))
|
||||
if (!_uplinkManager.TryPurchaseItem(_syndicateUplinkAccount, buyMsg.ItemId))
|
||||
{
|
||||
SendNetworkMessage(new PDAUplinkInsufficientFundsMessage(), message.Session.ConnectedClient);
|
||||
break;
|
||||
@@ -128,7 +128,7 @@ namespace Content.Server.GameObjects.Components.PDA
|
||||
{
|
||||
var accData = new UplinkAccountData(_syndicateUplinkAccount.AccountHolder,
|
||||
_syndicateUplinkAccount.Balance);
|
||||
var listings = _uplinkManager.FetchListings.ToArray();
|
||||
var listings = _uplinkManager.FetchListings.Values.ToArray();
|
||||
UserInterface?.SetState(new PDAUpdateState(_lightOn, ownerInfo, accData, listings));
|
||||
}
|
||||
else
|
||||
|
||||
@@ -5,13 +5,15 @@ namespace Content.Server.Interfaces.PDA
|
||||
{
|
||||
public interface IPDAUplinkManager
|
||||
{
|
||||
public IReadOnlyList<UplinkListingData> FetchListings => null;
|
||||
public IReadOnlyDictionary<string, UplinkListingData> FetchListings => null;
|
||||
|
||||
void Initialize();
|
||||
|
||||
public bool AddNewAccount(UplinkAccount acc);
|
||||
|
||||
public bool ChangeBalance(UplinkAccount acc, int amt);
|
||||
|
||||
public bool TryPurchaseItem(UplinkAccount acc, UplinkListingData listing);
|
||||
public bool TryPurchaseItem(UplinkAccount acc, string itemId);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,13 +18,13 @@ namespace Content.Server.PDA
|
||||
[Dependency] private readonly IEntityManager _entityManager = default!;
|
||||
|
||||
private List<UplinkAccount> _accounts;
|
||||
private List<UplinkListingData> _listings;
|
||||
private Dictionary<string, UplinkListingData> _listings;
|
||||
|
||||
public IReadOnlyList<UplinkListingData> FetchListings => _listings;
|
||||
public IReadOnlyDictionary<string, UplinkListingData> FetchListings => _listings;
|
||||
|
||||
public void Initialize()
|
||||
{
|
||||
_listings = new List<UplinkListingData>();
|
||||
_listings = new Dictionary<string, UplinkListingData>();
|
||||
foreach (var item in _prototypeManager.EnumeratePrototypes<UplinkStoreListingPrototype>())
|
||||
{
|
||||
var newListing = new UplinkListingData(item.ListingName, item.ItemId, item.Price, item.Category,
|
||||
@@ -40,26 +40,32 @@ namespace Content.Server.PDA
|
||||
{
|
||||
if (!ContainsListing(listing))
|
||||
{
|
||||
_listings.Add(listing);
|
||||
_listings.Add(listing.ItemId, listing);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private bool ContainsListing(UplinkListingData listing)
|
||||
{
|
||||
return _listings.Any(otherListing => listing.Equals(otherListing));
|
||||
return _listings.ContainsKey(listing.ItemId);
|
||||
}
|
||||
|
||||
public bool AddNewAccount(UplinkAccount acc)
|
||||
{
|
||||
var entity = _entityManager.GetEntity(acc.AccountHolder);
|
||||
|
||||
if (entity.TryGetComponent(out MindComponent mindComponent))
|
||||
{
|
||||
if (mindComponent.Mind.AllRoles.Any(role => !role.Antagonist))
|
||||
if (!mindComponent.HasMind)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (mindComponent.Mind!.AllRoles.Any(role => !role.Antagonist))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (_accounts.Contains(acc))
|
||||
{
|
||||
return false;
|
||||
@@ -72,21 +78,35 @@ namespace Content.Server.PDA
|
||||
public bool ChangeBalance(UplinkAccount acc, int amt)
|
||||
{
|
||||
var account = _accounts.Find(uplinkAccount => uplinkAccount.AccountHolder == acc.AccountHolder);
|
||||
if (account != null && account.Balance + amt < 0)
|
||||
|
||||
if (account == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (account.Balance + amt < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
account.ModifyAccountBalance(account.Balance + amt);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryPurchaseItem(UplinkAccount acc, UplinkListingData listing)
|
||||
public bool TryPurchaseItem(UplinkAccount acc, string itemId)
|
||||
{
|
||||
if (acc == null || listing == null)
|
||||
if (acc == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!ContainsListing(listing) || acc.Balance < listing.Price)
|
||||
|
||||
if (!_listings.TryGetValue(itemId, out var listing))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (acc.Balance < listing.Price)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -95,14 +115,12 @@ namespace Content.Server.PDA
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var player = _entityManager.GetEntity(acc.AccountHolder);
|
||||
var hands = player.GetComponent<HandsComponent>();
|
||||
hands.PutInHandOrDrop(_entityManager.SpawnEntity(listing.ItemId,
|
||||
player.Transform.GridPosition).GetComponent<ItemComponent>());
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ namespace Content.Shared.GameObjects.Components.PDA
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public class PDAUBoundUserInterfaceState : BoundUserInterfaceState
|
||||
{
|
||||
@@ -70,10 +69,11 @@ namespace Content.Shared.GameObjects.Components.PDA
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class PDAUplinkBuyListingMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public UplinkListingData ListingToBuy;
|
||||
public PDAUplinkBuyListingMessage(UplinkListingData itemToBuy)
|
||||
public string ItemId;
|
||||
|
||||
public PDAUplinkBuyListingMessage(string itemId)
|
||||
{
|
||||
ListingToBuy = itemToBuy;
|
||||
ItemId = itemId;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,8 +96,7 @@ namespace Content.Shared.GameObjects.Components.PDA
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[NetSerializable, Serializable]
|
||||
[Serializable, NetSerializable]
|
||||
public struct PDAIdInfoText
|
||||
{
|
||||
public string ActualOwnerName;
|
||||
@@ -105,13 +104,13 @@ namespace Content.Shared.GameObjects.Components.PDA
|
||||
public string JobTitle;
|
||||
}
|
||||
|
||||
[NetSerializable, Serializable]
|
||||
[Serializable, NetSerializable]
|
||||
public enum PDAVisuals
|
||||
{
|
||||
FlashlightLit,
|
||||
}
|
||||
|
||||
[NetSerializable, Serializable]
|
||||
[Serializable, NetSerializable]
|
||||
public enum PDAUiKey
|
||||
{
|
||||
Key
|
||||
@@ -142,7 +141,7 @@ namespace Content.Shared.GameObjects.Components.PDA
|
||||
}
|
||||
}
|
||||
|
||||
[NetSerializable, Serializable]
|
||||
[Serializable, NetSerializable]
|
||||
public class UplinkAccountData
|
||||
{
|
||||
public EntityUid DataAccountHolder;
|
||||
@@ -155,7 +154,7 @@ namespace Content.Shared.GameObjects.Components.PDA
|
||||
}
|
||||
}
|
||||
|
||||
[NetSerializable, Serializable]
|
||||
[Serializable, NetSerializable]
|
||||
public class UplinkListingData : ComponentState, IEquatable<UplinkListingData>
|
||||
{
|
||||
public string ItemId;
|
||||
@@ -185,5 +184,4 @@ namespace Content.Shared.GameObjects.Components.PDA
|
||||
return ItemId == other.ItemId;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user