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