Fix the server not checking uplink purchase prices (#1917)
This commit is contained in:
@@ -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;
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user