* Moved pen slot to separate component * Moved it all to more generic item slot class * Add sounds * Item slots now supports many slots * Some clean-up * Refactored slots a bit * Moving ID card out * Moving pda to system * Moving PDA owner to ECS * Moved PDA flashlight to separate component * Toggle lights work through events * Fixing UI * Moving uplink to separate component * Continue moving uplink to separate component * More cleaning * Removing pda shared * Nuked shared pda component * Fixed flashlight * Pen slot now showed in UI * Light toggle now shows correctly in UI * Small refactoring of item slots * Added contained entity * Fixed tests * Finished with PDA * Moving PDA uplink to separate window * Adding-removing uplink should show new button * Working on a better debug * Debug command to add uplink * Uplink send state to UI * Almost working UI * Uplink correcty updates when you buy-sell items * Ups * Moved localization to separate file * Minor fixes * Removed item slots methods events * Removed PDA owner name * Removed one uplink event * Deleted all uplink events * Removed flashlight events * Update Content.Shared/Traitor/Uplink/UplinkVisuals.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/Containers/ItemSlot/ItemSlotsSystem.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/Containers/ItemSlot/ItemSlotsSystem.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Update Content.Server/GameTicking/Presets/PresetTraitorDeathMatch.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * Item slots system review * Flashlight review * PDA to XAML * Move UplinkMenu to seperate class, fix WeightedColors methods * Move UI to XAML * Moved events to entity id * Address review * Removed uplink extensions * Minor fix * Moved item slots to shared * My bad Robust... * Fixed pda sound * Fixed pda tests * Fixed pda test again Co-authored-by: Alexander Evgrashin <evgrashin.adl@gmail.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> Co-authored-by: Visne <vincefvanwijk@gmail.com>
118 lines
3.3 KiB
C#
118 lines
3.3 KiB
C#
using System.Collections.Generic;
|
|
using System.Diagnostics.CodeAnalysis;
|
|
using Content.Server.Mind.Components;
|
|
using Content.Shared.PDA;
|
|
using Content.Shared.Traitor.Uplink;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Map;
|
|
using Robust.Shared.Prototypes;
|
|
using System.Linq;
|
|
|
|
namespace Content.Server.PDA.Managers
|
|
{
|
|
public class UplinkManager : IUplinkManager
|
|
{
|
|
[Dependency] private readonly IPrototypeManager _prototypeManager = default!;
|
|
[Dependency] private readonly IEntityManager _entityManager = default!;
|
|
|
|
private readonly Dictionary<EntityUid, UplinkAccount> _accounts = new();
|
|
private readonly Dictionary<string, UplinkListingData> _listings = new();
|
|
|
|
public IReadOnlyDictionary<string, UplinkListingData> FetchListings => _listings;
|
|
|
|
public void Initialize()
|
|
{
|
|
foreach (var item in _prototypeManager.EnumeratePrototypes<UplinkStoreListingPrototype>())
|
|
{
|
|
var newListing = new UplinkListingData(item.ListingName, item.ItemId, item.Price, item.Category,
|
|
item.Description);
|
|
|
|
RegisterUplinkListing(newListing);
|
|
}
|
|
}
|
|
|
|
private void RegisterUplinkListing(UplinkListingData listing)
|
|
{
|
|
if (!ContainsListing(listing))
|
|
{
|
|
_listings.Add(listing.ItemId, listing);
|
|
}
|
|
}
|
|
|
|
private bool ContainsListing(UplinkListingData listing)
|
|
{
|
|
return _listings.ContainsKey(listing.ItemId);
|
|
}
|
|
|
|
public bool AddNewAccount(UplinkAccount acc)
|
|
{
|
|
var entity = _entityManager.GetEntity(acc.AccountHolder);
|
|
|
|
if (entity.TryGetComponent(out MindComponent? mindComponent) && !mindComponent.HasMind)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (_accounts.ContainsKey(acc.AccountHolder))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
_accounts.Add(acc.AccountHolder, acc);
|
|
return true;
|
|
}
|
|
|
|
public bool TryGetAccount(EntityUid owner, out UplinkAccount? acc)
|
|
{
|
|
return _accounts.TryGetValue(owner, out acc);
|
|
}
|
|
|
|
public bool ChangeBalance(UplinkAccount acc, int amt)
|
|
{
|
|
var account = _accounts.GetValueOrDefault(acc.AccountHolder);
|
|
|
|
if (account == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (account.Balance + amt < 0)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
account.ModifyAccountBalance(account.Balance + amt);
|
|
|
|
return true;
|
|
}
|
|
|
|
public bool TryPurchaseItem(UplinkAccount? acc, string itemId, EntityCoordinates spawnCoords, [NotNullWhen(true)] out IEntity? purchasedItem)
|
|
{
|
|
purchasedItem = null;
|
|
if (acc == null)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (!_listings.TryGetValue(itemId, out var listing))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (acc.Balance < listing.Price)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (!ChangeBalance(acc, -listing.Price))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
purchasedItem = _entityManager.SpawnEntity(listing.ItemId, spawnCoords);
|
|
return true;
|
|
}
|
|
}
|
|
}
|