Moving PDA to ECS (#4538)
* 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>
This commit is contained in:
23
Content.Shared/Containers/ItemSlot/ItemSlotEvents.cs
Normal file
23
Content.Shared/Containers/ItemSlot/ItemSlotEvents.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Shared.Containers.ItemSlots
|
||||
{
|
||||
/// <summary>
|
||||
/// Item was placed in or removed from one of the slots in <see cref="SharedItemSlotsComponent"/>
|
||||
/// </summary>
|
||||
public class ItemSlotChanged : EntityEventArgs
|
||||
{
|
||||
public SharedItemSlotsComponent SlotsComponent;
|
||||
public string SlotName;
|
||||
public ItemSlot Slot;
|
||||
public readonly EntityUid? ContainedItem;
|
||||
|
||||
public ItemSlotChanged(SharedItemSlotsComponent slotsComponent, string slotName, ItemSlot slot)
|
||||
{
|
||||
SlotsComponent = slotsComponent;
|
||||
SlotName = slotName;
|
||||
Slot = slot;
|
||||
ContainedItem = slot.ContainerSlot.ContainedEntity?.Uid;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
using Content.Shared.Sound;
|
||||
using Content.Shared.Whitelist;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Serialization.TypeSerializers.Implementations.Custom.Prototype;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace Content.Shared.Containers.ItemSlots
|
||||
{
|
||||
/// <summary>
|
||||
/// Used for entities that can hold items in different slots
|
||||
/// Allows basic insert/eject interaction
|
||||
/// </summary>
|
||||
[RegisterComponent]
|
||||
public class SharedItemSlotsComponent : Component
|
||||
{
|
||||
public override string Name => "ItemSlots";
|
||||
|
||||
[ViewVariables] [DataField("slots")] public Dictionary<string, ItemSlot> Slots = new();
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
[DataDefinition]
|
||||
public class ItemSlot
|
||||
{
|
||||
[ViewVariables] [DataField("whitelist")] public EntityWhitelist? Whitelist;
|
||||
[ViewVariables] [DataField("insertSound")] public SoundSpecifier? InsertSound;
|
||||
[ViewVariables] [DataField("ejectSound")] public SoundSpecifier? EjectSound;
|
||||
|
||||
[DataField("item", customTypeSerializer: typeof(PrototypeIdSerializer<EntityPrototype>))]
|
||||
[ViewVariables] public string? StartingItem;
|
||||
|
||||
[ViewVariables] public ContainerSlot ContainerSlot = default!;
|
||||
}
|
||||
}
|
||||
187
Content.Shared/Containers/ItemSlot/SharedItemSlotsSystem.cs
Normal file
187
Content.Shared/Containers/ItemSlot/SharedItemSlotsSystem.cs
Normal file
@@ -0,0 +1,187 @@
|
||||
using Content.Shared.Hands.Components;
|
||||
using Content.Shared.Interaction;
|
||||
using Content.Shared.Item;
|
||||
using Content.Shared.Popups;
|
||||
using Robust.Shared.Audio;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Player;
|
||||
|
||||
namespace Content.Shared.Containers.ItemSlots
|
||||
{
|
||||
public class SharedItemSlotsSystem : EntitySystem
|
||||
{
|
||||
public override void Initialize()
|
||||
{
|
||||
base.Initialize();
|
||||
|
||||
SubscribeLocalEvent<SharedItemSlotsComponent, ComponentInit>(OnComponentInit);
|
||||
SubscribeLocalEvent<SharedItemSlotsComponent, MapInitEvent>(OnMapInit);
|
||||
SubscribeLocalEvent<SharedItemSlotsComponent, InteractUsingEvent>(OnInteractUsing);
|
||||
}
|
||||
|
||||
private void OnComponentInit(EntityUid uid, SharedItemSlotsComponent itemSlots, ComponentInit args)
|
||||
{
|
||||
// create container for each slot
|
||||
foreach (var pair in itemSlots.Slots)
|
||||
{
|
||||
var slotName = pair.Key;
|
||||
var slot = pair.Value;
|
||||
|
||||
slot.ContainerSlot = ContainerHelpers.EnsureContainer<ContainerSlot>(itemSlots.Owner, slotName);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnMapInit(EntityUid uid, SharedItemSlotsComponent itemSlots, MapInitEvent args)
|
||||
{
|
||||
foreach (var pair in itemSlots.Slots)
|
||||
{
|
||||
var slot = pair.Value;
|
||||
var slotName = pair.Key;
|
||||
|
||||
// Check if someone already put item inside container
|
||||
if (slot.ContainerSlot.ContainedEntity != null)
|
||||
continue;
|
||||
|
||||
// Try to spawn item inside each slot
|
||||
if (!string.IsNullOrEmpty(slot.StartingItem))
|
||||
{
|
||||
var item = EntityManager.SpawnEntity(slot.StartingItem, itemSlots.Owner.Transform.Coordinates);
|
||||
slot.ContainerSlot.Insert(item);
|
||||
|
||||
RaiseLocalEvent(uid, new ItemSlotChanged(itemSlots, slotName, slot));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnInteractUsing(EntityUid uid, SharedItemSlotsComponent itemSlots, InteractUsingEvent args)
|
||||
{
|
||||
if (args.Handled)
|
||||
return;
|
||||
|
||||
args.Handled = TryInsertContent(itemSlots, args.Used, args.User);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to insert item in any fitting item slot from users hand
|
||||
/// </summary>
|
||||
/// <returns>False if failed to insert item</returns>
|
||||
public bool TryInsertContent(SharedItemSlotsComponent itemSlots, IEntity item, IEntity user)
|
||||
{
|
||||
foreach (var pair in itemSlots.Slots)
|
||||
{
|
||||
var slotName = pair.Key;
|
||||
var slot = pair.Value;
|
||||
|
||||
// check if item allowed in whitelist
|
||||
if (slot.Whitelist != null && !slot.Whitelist.IsValid(item))
|
||||
continue;
|
||||
|
||||
// check if slot is empty
|
||||
if (slot.ContainerSlot.Contains(item))
|
||||
continue;
|
||||
|
||||
if (!user.TryGetComponent(out SharedHandsComponent? hands))
|
||||
{
|
||||
itemSlots.Owner.PopupMessage(user, Loc.GetString("item-slots-try-insert-no-hands"));
|
||||
return true;
|
||||
}
|
||||
|
||||
// get item inside container
|
||||
IEntity? swap = null;
|
||||
if (slot.ContainerSlot.ContainedEntity != null)
|
||||
swap = slot.ContainerSlot.ContainedEntity;
|
||||
|
||||
// return if user can't drop active item in hand
|
||||
if (!hands.TryDropEntityToFloor(item))
|
||||
return true;
|
||||
|
||||
// swap item in hand and item in slot
|
||||
if (swap != null)
|
||||
hands.TryPutInAnyHand(swap);
|
||||
|
||||
// insert item
|
||||
slot.ContainerSlot.Insert(item);
|
||||
RaiseLocalEvent(itemSlots.Owner.Uid, new ItemSlotChanged(itemSlots, slotName, slot));
|
||||
|
||||
// play sound
|
||||
if (slot.InsertSound != null)
|
||||
SoundSystem.Play(Filter.Pvs(itemSlots.Owner), slot.InsertSound.GetSound(), itemSlots.Owner);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to insert item in known slot. Doesn't interact with user
|
||||
/// </summary>
|
||||
/// <returns>False if failed to insert item</returns>
|
||||
public bool TryInsertContent(SharedItemSlotsComponent itemSlots, IEntity item, string slotName)
|
||||
{
|
||||
if (!itemSlots.Slots.TryGetValue(slotName, out var slot))
|
||||
return false;
|
||||
|
||||
if (slot.ContainerSlot.ContainedEntity != null)
|
||||
return false;
|
||||
|
||||
// check if item allowed in whitelist
|
||||
if (slot.Whitelist != null && !slot.Whitelist.IsValid(item))
|
||||
return false;
|
||||
|
||||
slot.ContainerSlot.Insert(item);
|
||||
RaiseLocalEvent(itemSlots.Owner.Uid, new ItemSlotChanged(itemSlots, slotName, slot));
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Check if slot has some content in it (without ejecting item)
|
||||
/// </summary>
|
||||
/// <returns>Null if doesn't have any content</returns>
|
||||
public IEntity? PeekItemInSlot(SharedItemSlotsComponent itemSlots, string slotName)
|
||||
{
|
||||
if (!itemSlots.Slots.TryGetValue(slotName, out var slot))
|
||||
return null;
|
||||
|
||||
var item = slot.ContainerSlot.ContainedEntity;
|
||||
return item;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Try to eject item from slot to users hands
|
||||
/// </summary>
|
||||
public bool TryEjectContent(SharedItemSlotsComponent itemSlots, string slotName, IEntity? user)
|
||||
{
|
||||
if (!itemSlots.Slots.TryGetValue(slotName, out var slot))
|
||||
return false;
|
||||
|
||||
if (slot.ContainerSlot.ContainedEntity == null)
|
||||
return false;
|
||||
|
||||
var item = slot.ContainerSlot.ContainedEntity;
|
||||
if (!slot.ContainerSlot.Remove(item))
|
||||
return false;
|
||||
|
||||
// try eject item to users hand
|
||||
if (user != null)
|
||||
{
|
||||
if (user.TryGetComponent(out SharedHandsComponent? hands))
|
||||
{
|
||||
hands.TryPutInAnyHand(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
itemSlots.Owner.PopupMessage(user, Loc.GetString("item-slots-try-insert-no-hands"));
|
||||
}
|
||||
}
|
||||
|
||||
if (slot.EjectSound != null)
|
||||
SoundSystem.Play(Filter.Pvs(itemSlots.Owner), slot.EjectSound.GetSound(), itemSlots.Owner);
|
||||
|
||||
RaiseLocalEvent(itemSlots.Owner.Uid, new ItemSlotChanged(itemSlots, slotName, slot));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Content.Shared/Light/SharedUnpoweredFlashlightVisuals.cs
Normal file
11
Content.Shared/Light/SharedUnpoweredFlashlightVisuals.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Robust.Shared.Serialization;
|
||||
using System;
|
||||
|
||||
namespace Content.Shared.Light
|
||||
{
|
||||
[Serializable, NetSerializable]
|
||||
public enum UnpoweredFlashlightVisuals : byte
|
||||
{
|
||||
LightOn
|
||||
}
|
||||
}
|
||||
52
Content.Shared/PDA/PDAMessagesUI.cs
Normal file
52
Content.Shared/PDA/PDAMessagesUI.cs
Normal file
@@ -0,0 +1,52 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
using System;
|
||||
|
||||
namespace Content.Shared.PDA
|
||||
{
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class PDAToggleFlashlightMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public PDAToggleFlashlightMessage()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class PDAEjectIDMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public PDAEjectIDMessage()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class PDAEjectPenMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public PDAEjectPenMessage()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class PDAShowUplinkMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public PDAShowUplinkMessage()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class PDARequestUpdateInterfaceMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public PDARequestUpdateInterfaceMessage()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
33
Content.Shared/PDA/PDAUpdateState.cs
Normal file
33
Content.Shared/PDA/PDAUpdateState.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using Content.Shared.Traitor.Uplink;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
using System;
|
||||
|
||||
|
||||
namespace Content.Shared.PDA
|
||||
{
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class PDAUpdateState : BoundUserInterfaceState
|
||||
{
|
||||
public bool FlashlightEnabled;
|
||||
public bool HasPen;
|
||||
public PDAIdInfoText PDAOwnerInfo;
|
||||
public bool HasUplink;
|
||||
|
||||
public PDAUpdateState(bool flashlightEnabled, bool hasPen, PDAIdInfoText pDAOwnerInfo, bool hasUplink = false)
|
||||
{
|
||||
FlashlightEnabled = flashlightEnabled;
|
||||
HasPen = hasPen;
|
||||
PDAOwnerInfo = pDAOwnerInfo;
|
||||
HasUplink = hasUplink;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public struct PDAIdInfoText
|
||||
{
|
||||
public string? ActualOwnerName;
|
||||
public string? IdOwner;
|
||||
public string? JobTitle;
|
||||
}
|
||||
}
|
||||
18
Content.Shared/PDA/PDAVisuals.cs
Normal file
18
Content.Shared/PDA/PDAVisuals.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.PDA
|
||||
{
|
||||
[Serializable, NetSerializable]
|
||||
public enum PDAVisuals
|
||||
{
|
||||
IDCardInserted
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum PDAUiKey
|
||||
{
|
||||
Key
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,197 +0,0 @@
|
||||
using System;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.GameStates;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Shared.PDA
|
||||
{
|
||||
[NetworkedComponent()]
|
||||
public class SharedPDAComponent : Component
|
||||
{
|
||||
public override string Name => "PDA";
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class PDAToggleFlashlightMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public PDAToggleFlashlightMessage()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class PDAEjectIDMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public PDAEjectIDMessage()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class PDAEjectPenMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public PDAEjectPenMessage()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public class PDAUBoundUserInterfaceState : BoundUserInterfaceState
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class PDAUpdateState : PDAUBoundUserInterfaceState
|
||||
{
|
||||
public bool FlashlightEnabled;
|
||||
public bool HasPen;
|
||||
public PDAIdInfoText PDAOwnerInfo;
|
||||
public UplinkAccountData Account = default!;
|
||||
public UplinkListingData[] Listings = default!;
|
||||
|
||||
public PDAUpdateState(bool isFlashlightOn, bool hasPen, PDAIdInfoText ownerInfo)
|
||||
{
|
||||
FlashlightEnabled = isFlashlightOn;
|
||||
HasPen = hasPen;
|
||||
PDAOwnerInfo = ownerInfo;
|
||||
}
|
||||
|
||||
public PDAUpdateState(bool isFlashlightOn, bool hasPen, PDAIdInfoText ownerInfo, UplinkAccountData accountData)
|
||||
: this(isFlashlightOn, hasPen, ownerInfo)
|
||||
{
|
||||
Account = accountData;
|
||||
}
|
||||
|
||||
public PDAUpdateState(bool isFlashlightOn, bool hasPen, PDAIdInfoText ownerInfo, UplinkAccountData accountData, UplinkListingData[] listings)
|
||||
: this(isFlashlightOn, hasPen, ownerInfo, accountData)
|
||||
{
|
||||
Listings = listings;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class PDAUplinkBuyListingMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public string ItemId;
|
||||
|
||||
public PDAUplinkBuyListingMessage(string itemId)
|
||||
{
|
||||
ItemId = itemId;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class PDAUplinkBuySuccessMessage : ComponentMessage
|
||||
{
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class PDAUplinkInsufficientFundsMessage : ComponentMessage
|
||||
{
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class PDARequestUpdateInterfaceMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public PDARequestUpdateInterfaceMessage()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public struct PDAIdInfoText
|
||||
{
|
||||
public string? ActualOwnerName;
|
||||
public string? IdOwner;
|
||||
public string? JobTitle;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum PDAVisuals
|
||||
{
|
||||
FlashlightLit,
|
||||
IDCardInserted
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public enum PDAUiKey
|
||||
{
|
||||
Key
|
||||
}
|
||||
|
||||
public class UplinkAccount
|
||||
{
|
||||
public event Action<UplinkAccount>? BalanceChanged;
|
||||
public EntityUid AccountHolder;
|
||||
private int _balance;
|
||||
[ViewVariables]
|
||||
public int Balance => _balance;
|
||||
|
||||
public UplinkAccount(EntityUid uid, int startingBalance)
|
||||
{
|
||||
AccountHolder = uid;
|
||||
_balance = startingBalance;
|
||||
}
|
||||
|
||||
public bool ModifyAccountBalance(int newBalance)
|
||||
{
|
||||
if (newBalance < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_balance = newBalance;
|
||||
BalanceChanged?.Invoke(this);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public class UplinkAccountData
|
||||
{
|
||||
public EntityUid DataAccountHolder;
|
||||
public int DataBalance;
|
||||
|
||||
public UplinkAccountData(EntityUid dataAccountHolder, int dataBalance)
|
||||
{
|
||||
DataAccountHolder = dataAccountHolder;
|
||||
DataBalance = dataBalance;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public class UplinkListingData : ComponentState, IEquatable<UplinkListingData>
|
||||
{
|
||||
public string ItemId;
|
||||
public int Price;
|
||||
public UplinkCategory Category;
|
||||
public string Description;
|
||||
public string ListingName;
|
||||
|
||||
public UplinkListingData(string listingName,string itemId,
|
||||
int price, UplinkCategory category,
|
||||
string description)
|
||||
{
|
||||
ListingName = listingName;
|
||||
Price = price;
|
||||
Category = category;
|
||||
Description = description;
|
||||
ItemId = itemId;
|
||||
}
|
||||
|
||||
public bool Equals(UplinkListingData? other)
|
||||
{
|
||||
if (other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return ItemId == other.ItemId;
|
||||
}
|
||||
}
|
||||
}
|
||||
32
Content.Shared/Traitor/Uplink/UplinkAccount.cs
Normal file
32
Content.Shared/Traitor/Uplink/UplinkAccount.cs
Normal file
@@ -0,0 +1,32 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using System;
|
||||
|
||||
namespace Content.Shared.Traitor.Uplink
|
||||
{
|
||||
public class UplinkAccount
|
||||
{
|
||||
public event Action<UplinkAccount>? BalanceChanged;
|
||||
public EntityUid AccountHolder;
|
||||
private int _balance;
|
||||
[ViewVariables]
|
||||
public int Balance => _balance;
|
||||
|
||||
public UplinkAccount(EntityUid uid, int startingBalance)
|
||||
{
|
||||
AccountHolder = uid;
|
||||
_balance = startingBalance;
|
||||
}
|
||||
|
||||
public bool ModifyAccountBalance(int newBalance)
|
||||
{
|
||||
if (newBalance < 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
_balance = newBalance;
|
||||
BalanceChanged?.Invoke(this);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
19
Content.Shared/Traitor/Uplink/UplinkAccountData.cs
Normal file
19
Content.Shared/Traitor/Uplink/UplinkAccountData.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
using System;
|
||||
|
||||
namespace Content.Shared.Traitor.Uplink
|
||||
{
|
||||
[Serializable, NetSerializable]
|
||||
public class UplinkAccountData
|
||||
{
|
||||
public EntityUid? DataAccountHolder;
|
||||
public int DataBalance;
|
||||
|
||||
public UplinkAccountData(EntityUid? dataAccountHolder, int dataBalance)
|
||||
{
|
||||
DataAccountHolder = dataAccountHolder;
|
||||
DataBalance = dataBalance;
|
||||
}
|
||||
}
|
||||
}
|
||||
38
Content.Shared/Traitor/Uplink/UplinkListingData.cs
Normal file
38
Content.Shared/Traitor/Uplink/UplinkListingData.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
using Content.Shared.PDA;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
using System;
|
||||
|
||||
namespace Content.Shared.Traitor.Uplink
|
||||
{
|
||||
[Serializable, NetSerializable]
|
||||
public class UplinkListingData : ComponentState, IEquatable<UplinkListingData>
|
||||
{
|
||||
public string ItemId;
|
||||
public int Price;
|
||||
public UplinkCategory Category;
|
||||
public string Description;
|
||||
public string ListingName;
|
||||
|
||||
public UplinkListingData(string listingName, string itemId,
|
||||
int price, UplinkCategory category,
|
||||
string description)
|
||||
{
|
||||
ListingName = listingName;
|
||||
Price = price;
|
||||
Category = category;
|
||||
Description = description;
|
||||
ItemId = itemId;
|
||||
}
|
||||
|
||||
public bool Equals(UplinkListingData? other)
|
||||
{
|
||||
if (other == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return ItemId == other.ItemId;
|
||||
}
|
||||
}
|
||||
}
|
||||
26
Content.Shared/Traitor/Uplink/UplinkMessagesUI.cs
Normal file
26
Content.Shared/Traitor/Uplink/UplinkMessagesUI.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
using System;
|
||||
|
||||
namespace Content.Shared.Traitor.Uplink
|
||||
{
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class UplinkBuyListingMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public string ItemId;
|
||||
|
||||
public UplinkBuyListingMessage(string itemId)
|
||||
{
|
||||
ItemId = itemId;
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class UplinkRequestUpdateInterfaceMessage : BoundUserInterfaceMessage
|
||||
{
|
||||
public UplinkRequestUpdateInterfaceMessage()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
16
Content.Shared/Traitor/Uplink/UplinkNetworkEvents.cs
Normal file
16
Content.Shared/Traitor/Uplink/UplinkNetworkEvents.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
using System;
|
||||
|
||||
namespace Content.Shared.Traitor.Uplink
|
||||
{
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class UplinkBuySuccessMessage : EntityEventArgs
|
||||
{
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public sealed class UplinkInsufficientFundsMessage : EntityEventArgs
|
||||
{
|
||||
}
|
||||
}
|
||||
19
Content.Shared/Traitor/Uplink/UplinkUpdateState.cs
Normal file
19
Content.Shared/Traitor/Uplink/UplinkUpdateState.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
using System;
|
||||
|
||||
namespace Content.Shared.Traitor.Uplink
|
||||
{
|
||||
[Serializable, NetSerializable]
|
||||
public class UplinkUpdateState : BoundUserInterfaceState
|
||||
{
|
||||
public UplinkAccountData Account;
|
||||
public UplinkListingData[] Listings;
|
||||
|
||||
public UplinkUpdateState(UplinkAccountData account, UplinkListingData[] listings)
|
||||
{
|
||||
Account = account;
|
||||
Listings = listings;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
Content.Shared/Traitor/Uplink/UplinkVisuals.cs
Normal file
11
Content.Shared/Traitor/Uplink/UplinkVisuals.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
using Robust.Shared.Serialization;
|
||||
using System;
|
||||
|
||||
namespace Content.Shared.Traitor.Uplink
|
||||
{
|
||||
[Serializable, NetSerializable]
|
||||
public enum UplinkUiKey : byte
|
||||
{
|
||||
Key
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user