mirror of
https://github.com/DeltaV-Station/Delta-v.git
synced 2026-09-29 23:57:29 +00:00
* Reapply "Nubody Merge" (#5807) This reverts commitd62f7cef10. * Revert "Nubody Merge (#5670)" This reverts commitb465cfb3fd. * Revert "IPC fibers (#4968)" This reverts commitc2b42211f0. * Revert "IPC Polymorph fix (#4545)" This reverts commitfa03d8c655. * Revert "fix IPC not having humanoid emotes (#4445)" This reverts commit216fdf999f. * Revert "ipc heat/cold (#4306)" This reverts commitfafd5cf816. * Revert "ipc cables (#4283)" This reverts commit54958039a1. * Revert "feat: ipcs now have dynamic power draw based off movement speed (#3917)" This reverts commit71e8b7e64b. * Revert "fix ipcs not being able to disarm (#3374)" This reverts commit764c4dcf54. * Revert "make steel heal caustic for ipcs (#3206)" This reverts commit450ac82550. * Revert "add missing ipc survival boxes (#3065)" This reverts commit888c9cdb00. * Revert "make borgs use ipc repairing (#3064)" This reverts commitf77a49dd0b. * Revert "Update hud.yml to add ipcs to diagnostic hud (#3019)" This reverts commit7220643531. * Revert "Tweak IPCs (#2979)" This reverts commit98b47476de. * Revert "fix nukies ipc test fail (#2957)" This reverts commit4a1acbf863. * Revert "fix ipc nukies not getting comms (#2884)" This reverts commit8a2254770e. * Revert "fix ipc encryption key mispredict (#2879)" This reverts commitf08726efc1. * Revert "Merge pull request #2800 from Spielern/port-ipc" This reverts commit822fa4312c, reversing changes made tofe4c23c702. * Remove and Fix rest of IPC Hangons causing crashes * Integration test Errors * Expand migration file with removed IPC stuff * IPC Leg was found and migrated to naught * Revert "Merge pull request #2542 from deltanedas/shitmed-ops" This reverts commit83a8002922, reversing changes made tobaa89b0052. * Revert "Set up surgical augments infrastructure & add tool panel augments (#3059)" This reverts commita40f0be6fd. * Revert "Psionic Prosthetics (#4689)" This reverts commit2679bb238a. * Revert "Add surgical cleanliness and sanitation (#2847)" This reverts commit64565ba4f7. * Remove unremoved mentions * Revert "Add autoclave to easily sanitize large amounts of items and faster (#2933)" This reverts commitd0da90fa2e. * Shit Med Removed * Remove _ShitMed Folders and fix Errors in Console * Add OrganAnimalBrain into the mirgraiton file * Heads no Input Mover * Monke * Full migration file I guess * oops * shiv state fix * Restore accidental deleted recipe * Forgot one flt mention * Fix more issues * Comment out Damage Visual for motorkind for now * Motorkind... * Commenting stuff out for now * thought there'd be more of this to gut --------- Co-authored-by: Janet Blackquill <uhhadd@gmail.com>
326 lines
12 KiB
C#
326 lines
12 KiB
C#
using System.Linq;
|
|
using Content.Client.Clothing;
|
|
using Content.Client.Examine;
|
|
using Content.Client.Verbs.UI;
|
|
using Content.Shared.Interaction;
|
|
using Content.Shared.Inventory;
|
|
using Content.Shared.Inventory.Events;
|
|
using Content.Shared.Storage;
|
|
using JetBrains.Annotations;
|
|
using Robust.Client.Player;
|
|
using Robust.Client.UserInterface;
|
|
using Robust.Shared.Containers;
|
|
using Robust.Shared.Input.Binding;
|
|
using Robust.Shared.Player;
|
|
using Robust.Shared.Timing;
|
|
|
|
namespace Content.Client.Inventory
|
|
{
|
|
[UsedImplicitly]
|
|
public sealed class ClientInventorySystem : InventorySystem
|
|
{
|
|
[Dependency] private readonly IPlayerManager _playerManager = default!;
|
|
[Dependency] private readonly IUserInterfaceManager _ui = default!;
|
|
[Dependency] private readonly ClientClothingSystem _clothingVisualsSystem = default!;
|
|
[Dependency] private readonly ExamineSystem _examine = default!;
|
|
|
|
public Action<SlotData>? EntitySlotUpdate = null;
|
|
public Action<SlotData>? OnSlotAdded = null;
|
|
public Action<SlotData>? OnSlotRemoved = null;
|
|
public Action<EntityUid, InventorySlotsComponent>? OnLinkInventorySlots = null;
|
|
public Action? OnUnlinkInventory = null;
|
|
public Action<SlotSpriteUpdate>? OnSpriteUpdate = null;
|
|
|
|
private readonly Queue<(InventorySlotsComponent comp, EntityEventArgs args)> _equipEventsQueue = new();
|
|
|
|
public override void Initialize()
|
|
{
|
|
UpdatesOutsidePrediction = true;
|
|
base.Initialize();
|
|
|
|
SubscribeLocalEvent<InventorySlotsComponent, LocalPlayerAttachedEvent>(OnPlayerAttached);
|
|
SubscribeLocalEvent<InventorySlotsComponent, LocalPlayerDetachedEvent>(OnPlayerDetached);
|
|
|
|
SubscribeLocalEvent<InventoryComponent, ComponentShutdown>(OnShutdown);
|
|
|
|
SubscribeLocalEvent<InventorySlotsComponent, DidEquipEvent>((_, comp, args) =>
|
|
_equipEventsQueue.Enqueue((comp, args)));
|
|
SubscribeLocalEvent<InventorySlotsComponent, DidUnequipEvent>((_, comp, args) =>
|
|
_equipEventsQueue.Enqueue((comp, args)));
|
|
}
|
|
|
|
public override void Update(float frameTime)
|
|
{
|
|
base.Update(frameTime);
|
|
|
|
while (_equipEventsQueue.TryDequeue(out var tuple))
|
|
{
|
|
var (component, args) = tuple;
|
|
|
|
switch (args)
|
|
{
|
|
case DidEquipEvent equipped:
|
|
OnDidEquip(component, equipped);
|
|
break;
|
|
case DidUnequipEvent unequipped:
|
|
OnDidUnequip(component, unequipped);
|
|
break;
|
|
default:
|
|
throw new InvalidOperationException($"Received queued event of unknown type: {args.GetType()}");
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnDidUnequip(InventorySlotsComponent component, DidUnequipEvent args)
|
|
{
|
|
UpdateSlot(args.Equipee, component, args.Slot);
|
|
if (args.Equipee != _playerManager.LocalEntity)
|
|
return;
|
|
var update = new SlotSpriteUpdate(null, args.SlotGroup, args.Slot, false);
|
|
OnSpriteUpdate?.Invoke(update);
|
|
}
|
|
|
|
private void OnDidEquip(InventorySlotsComponent component, DidEquipEvent args)
|
|
{
|
|
UpdateSlot(args.Equipee, component, args.Slot);
|
|
if (args.Equipee != _playerManager.LocalEntity)
|
|
return;
|
|
var update = new SlotSpriteUpdate(args.Equipment, args.SlotGroup, args.Slot,
|
|
HasComp<StorageComponent>(args.Equipment));
|
|
OnSpriteUpdate?.Invoke(update);
|
|
}
|
|
|
|
private void OnShutdown(EntityUid uid, InventoryComponent component, ComponentShutdown args)
|
|
{
|
|
if (TryComp(uid, out InventorySlotsComponent? inventorySlots))
|
|
{
|
|
foreach (var slot in component.Slots)
|
|
{
|
|
TryRemoveSlotData((uid, inventorySlots), (SlotData)slot);
|
|
}
|
|
}
|
|
|
|
if (uid == _playerManager.LocalEntity)
|
|
OnUnlinkInventory?.Invoke();
|
|
}
|
|
|
|
private void OnPlayerDetached(EntityUid uid, InventorySlotsComponent component, LocalPlayerDetachedEvent args)
|
|
{
|
|
OnUnlinkInventory?.Invoke();
|
|
}
|
|
|
|
private void OnPlayerAttached(EntityUid uid, InventorySlotsComponent component, LocalPlayerAttachedEvent args)
|
|
{
|
|
OnLinkInventorySlots?.Invoke(uid, component);
|
|
}
|
|
|
|
protected override void OnInit(Entity<InventoryComponent> ent, ref ComponentInit args)
|
|
{
|
|
base.OnInit(ent, ref args);
|
|
|
|
_clothingVisualsSystem.InitClothing(ent.Owner, ent.Comp);
|
|
}
|
|
|
|
public override void Shutdown()
|
|
{
|
|
CommandBinds.Unregister<ClientInventorySystem>();
|
|
base.Shutdown();
|
|
}
|
|
|
|
public void ReloadInventory(InventorySlotsComponent? component = null)
|
|
{
|
|
var player = _playerManager.LocalEntity;
|
|
if (player == null || !Resolve(player.Value, ref component, false))
|
|
{
|
|
return;
|
|
}
|
|
|
|
OnUnlinkInventory?.Invoke();
|
|
OnLinkInventorySlots?.Invoke(player.Value, component);
|
|
}
|
|
|
|
public void SetSlotHighlight(EntityUid owner, InventorySlotsComponent component, string slotName, bool state)
|
|
{
|
|
var oldData = component.SlotData[slotName];
|
|
var newData = component.SlotData[slotName] = new SlotData(oldData, state);
|
|
if (owner == _playerManager.LocalEntity)
|
|
EntitySlotUpdate?.Invoke(newData);
|
|
}
|
|
|
|
public void UpdateSlot(EntityUid owner, InventorySlotsComponent component, string slotName,
|
|
bool? blocked = null, bool? highlight = null)
|
|
{
|
|
// The slot might have been removed when changing templates, which can cause items to be dropped.
|
|
if (!component.SlotData.TryGetValue(slotName, out var oldData))
|
|
return;
|
|
|
|
var newHighlight = oldData.Highlighted;
|
|
var newBlocked = oldData.Blocked;
|
|
|
|
if (blocked != null)
|
|
newBlocked = blocked.Value;
|
|
|
|
if (highlight != null)
|
|
newHighlight = highlight.Value;
|
|
|
|
var newData = component.SlotData[slotName] =
|
|
new SlotData(component.SlotData[slotName], newHighlight, newBlocked);
|
|
if (owner == _playerManager.LocalEntity)
|
|
EntitySlotUpdate?.Invoke(newData);
|
|
}
|
|
|
|
public bool TryAddSlotData(Entity<InventorySlotsComponent> ent, SlotData newSlotData)
|
|
{
|
|
if (!ent.Comp.SlotData.TryAdd(newSlotData.SlotName, newSlotData))
|
|
return false;
|
|
|
|
if (TryGetSlotContainer(ent.Owner, newSlotData.SlotName, out var newContainer, out _))
|
|
ent.Comp.SlotData[newSlotData.SlotName].Container = newContainer;
|
|
|
|
if (ent.Owner == _playerManager.LocalEntity)
|
|
OnSlotAdded?.Invoke(newSlotData);
|
|
|
|
return true;
|
|
}
|
|
|
|
public bool TryRemoveSlotData(Entity<InventorySlotsComponent> ent, SlotData removedSlotData)
|
|
{
|
|
if (!ent.Comp.SlotData.Remove(removedSlotData.SlotName))
|
|
return false;
|
|
|
|
if (ent.Owner == _playerManager.LocalEntity)
|
|
OnSlotRemoved?.Invoke(removedSlotData);
|
|
|
|
return true;
|
|
}
|
|
|
|
public void UIInventoryActivate(string slot)
|
|
{
|
|
RaisePredictiveEvent(new UseSlotNetworkMessage(slot));
|
|
}
|
|
|
|
public void UIInventoryStorageActivate(string slot)
|
|
{
|
|
RaisePredictiveEvent(new OpenSlotStorageNetworkMessage(slot));
|
|
}
|
|
|
|
public void UIInventoryExamine(string slot, EntityUid uid)
|
|
{
|
|
if (!TryGetSlotEntity(uid, slot, out var item))
|
|
return;
|
|
|
|
_examine.DoExamine(item.Value);
|
|
}
|
|
|
|
public void UIInventoryOpenContextMenu(string slot, EntityUid uid)
|
|
{
|
|
if (!TryGetSlotEntity(uid, slot, out var item))
|
|
return;
|
|
|
|
_ui.GetUIController<VerbMenuUIController>().OpenVerbMenu(item.Value);
|
|
}
|
|
|
|
public void UIInventoryActivateItem(string slot, EntityUid uid)
|
|
{
|
|
if (!TryGetSlotEntity(uid, slot, out var item))
|
|
return;
|
|
|
|
RaisePredictiveEvent(
|
|
new InteractInventorySlotEvent(GetNetEntity(item.Value), altInteract: false));
|
|
}
|
|
|
|
public void UIInventoryAltActivateItem(string slot, EntityUid uid)
|
|
{
|
|
if (!TryGetSlotEntity(uid, slot, out var item))
|
|
return;
|
|
|
|
RaisePredictiveEvent(new InteractInventorySlotEvent(GetNetEntity(item.Value), altInteract: true));
|
|
}
|
|
|
|
protected override void UpdateInventoryTemplate(Entity<InventoryComponent> ent)
|
|
{
|
|
base.UpdateInventoryTemplate(ent);
|
|
|
|
if (!TryComp<InventorySlotsComponent>(ent, out var inventorySlots))
|
|
return;
|
|
|
|
List<SlotData> slotDataToRemove = new(); // don't modify dict while iterating
|
|
|
|
foreach (var slotData in inventorySlots.SlotData.Values)
|
|
{
|
|
if (!ent.Comp.Slots.Any(s => s.Name == slotData.SlotName))
|
|
slotDataToRemove.Add(slotData);
|
|
}
|
|
|
|
// remove slots that are no longer in the new template
|
|
foreach (var slotData in slotDataToRemove)
|
|
{
|
|
TryRemoveSlotData((ent.Owner, inventorySlots), slotData);
|
|
}
|
|
|
|
// update existing slots or add them if they don't exist yet
|
|
foreach (var slot in ent.Comp.Slots)
|
|
{
|
|
if (inventorySlots.SlotData.TryGetValue(slot.Name, out var slotData))
|
|
slotData.SlotDef = slot;
|
|
else
|
|
TryAddSlotData((ent.Owner, inventorySlots), (SlotData)slot);
|
|
}
|
|
|
|
if (ent.Owner == _playerManager.LocalEntity)
|
|
ReloadInventory(inventorySlots);
|
|
}
|
|
|
|
public sealed class SlotData
|
|
{
|
|
[ViewVariables] public SlotDefinition SlotDef;
|
|
[ViewVariables] public EntityUid? HeldEntity => Container?.ContainedEntity;
|
|
[ViewVariables] public bool Blocked;
|
|
[ViewVariables] public bool Highlighted;
|
|
[ViewVariables] public ContainerSlot? Container;
|
|
[ViewVariables] public bool HasSlotGroup => SlotDef.SlotGroup != "Default";
|
|
[ViewVariables] public Vector2i ButtonOffset => SlotDef.UIWindowPosition;
|
|
[ViewVariables] public string SlotName => SlotDef.Name;
|
|
[ViewVariables] public bool ShowInWindow => SlotDef.ShowInWindow;
|
|
[ViewVariables] public string SlotGroup => SlotDef.SlotGroup;
|
|
[ViewVariables] public string SlotDisplayName => SlotDef.DisplayName;
|
|
[ViewVariables] public string TextureName => "Slots/" + SlotDef.TextureName;
|
|
[ViewVariables] public string FullTextureName => SlotDef.FullTextureName;
|
|
|
|
public SlotData(SlotDefinition slotDef, ContainerSlot? container = null, bool highlighted = false,
|
|
bool blocked = false)
|
|
{
|
|
SlotDef = slotDef;
|
|
Highlighted = highlighted;
|
|
Blocked = blocked;
|
|
Container = container;
|
|
}
|
|
|
|
public SlotData(SlotData oldData, bool highlighted = false, bool blocked = false)
|
|
{
|
|
SlotDef = oldData.SlotDef;
|
|
Highlighted = highlighted;
|
|
Container = oldData.Container;
|
|
Blocked = blocked;
|
|
}
|
|
|
|
public static implicit operator SlotData(SlotDefinition s)
|
|
{
|
|
return new SlotData(s);
|
|
}
|
|
|
|
public static implicit operator SlotDefinition(SlotData s)
|
|
{
|
|
return s.SlotDef;
|
|
}
|
|
}
|
|
|
|
public readonly record struct SlotSpriteUpdate(
|
|
EntityUid? Entity,
|
|
string Group,
|
|
string Name,
|
|
bool ShowStorage
|
|
);
|
|
}
|
|
}
|