* some work * equip: done unequip: todo * unequipping done & refactored events * workin * movin * reee namespaces * stun * mobstate * fixes * some work on events * removes serverside itemcomp & misc fixes * work * smol merge fix * ports template to prototype & finishes ui * moves relay & adds containerenumerator * actions & cuffs * my god what is actioncode * more fixes * im loosing my grasp on reality * more fixes * more work * explosions * yes * more work * more fixes * merge master & misc fixed because i forgot to commit before merging master * more fixes * fixes * moar * more work * moar fixes * suffixmap * more work on client * motivation low * no. no containers * mirroring client to server * fixes * move serverinvcomp * serverinventorycomponent is dead * gaming * only strippable & ai left... * only ai and richtext left * fixes ai * fixes * fixes sprite layers * more fixes * resolves optional * yes * stable™️ * fixes * moar fixes * moar * fix some tests * lmao * no comment * good to merge™️ * fixes build but for real * adresses some reviews * adresses some more reviews * nullables, yo * fixes lobbyscreen * timid refactor to differentiate actor & target * adresses more reviews * more * my god what a mess * removed the rest of duplicates * removed duplicate slotflags and renamed shoes to feet * removes another unused one * yes * fixes lobby & makes tryunequip return unequipped item * fixes * some funny renames * fixes * misc improvements to attemptevents * fixes * merge fixes Co-authored-by: Paul Ritter <ritter.paul1@gmail.com>
176 lines
5.0 KiB
C#
176 lines
5.0 KiB
C#
using System;
|
|
using Content.Shared.ActionBlocker;
|
|
using Content.Shared.Hands.Components;
|
|
using Content.Shared.Interaction;
|
|
using Content.Shared.Interaction.Helpers;
|
|
using Content.Shared.Inventory;
|
|
using Content.Shared.Sound;
|
|
using Robust.Shared.GameObjects;
|
|
using Robust.Shared.GameStates;
|
|
using Robust.Shared.IoC;
|
|
using Robust.Shared.Maths;
|
|
using Robust.Shared.Physics;
|
|
using Robust.Shared.Serialization;
|
|
using Robust.Shared.Serialization.Manager.Attributes;
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
namespace Content.Shared.Item
|
|
{
|
|
/// <summary>
|
|
/// Players can pick up, drop, and put items in bags, and they can be seen in player's hands.
|
|
/// </summary>
|
|
[NetworkedComponent()]
|
|
public class SharedItemComponent : Component, IInteractHand
|
|
{
|
|
[Dependency] private readonly IEntityManager _entMan = default!;
|
|
|
|
public override string Name => "Item";
|
|
|
|
/// <summary>
|
|
/// How much big this item is.
|
|
/// </summary>
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
public int Size
|
|
{
|
|
get => _size;
|
|
set
|
|
{
|
|
_size = value;
|
|
Dirty();
|
|
}
|
|
}
|
|
[DataField("size")]
|
|
private int _size;
|
|
|
|
/// <summary>
|
|
/// Part of the state of the sprite shown on the player when this item is in their hands.
|
|
/// </summary>
|
|
// todo paul make this update slotvisuals on client on change
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
public string? EquippedPrefix
|
|
{
|
|
get => _equippedPrefix;
|
|
set
|
|
{
|
|
_equippedPrefix = value;
|
|
OnEquippedPrefixChange();
|
|
Dirty();
|
|
}
|
|
}
|
|
[DataField("HeldPrefix")]
|
|
private string? _equippedPrefix;
|
|
|
|
[ViewVariables]
|
|
[DataField("Slots")]
|
|
public SlotFlags SlotFlags = SlotFlags.PREVENTEQUIP; //Different from None, NONE allows equips if no slot flags are required
|
|
|
|
[DataField("EquipSound")]
|
|
public SoundSpecifier? EquipSound { get; set; } = default!;
|
|
|
|
/// <summary>
|
|
/// Color of the sprite shown on the player when this item is in their hands.
|
|
/// </summary>
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
public Color Color
|
|
{
|
|
get => _color;
|
|
set
|
|
{
|
|
_color = value;
|
|
Dirty();
|
|
}
|
|
}
|
|
[DataField("color")]
|
|
private Color _color = Color.White;
|
|
|
|
/// <summary>
|
|
/// Rsi of the sprite shown on the player when this item is in their hands.
|
|
/// </summary>
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
|
public string? RsiPath
|
|
{
|
|
get => _rsiPath;
|
|
set
|
|
{
|
|
_rsiPath = value;
|
|
Dirty();
|
|
}
|
|
}
|
|
[DataField("sprite")]
|
|
private string? _rsiPath;
|
|
|
|
/// <summary>
|
|
/// If a player can pick up this item.
|
|
/// </summary>
|
|
public bool CanPickup(EntityUid user, bool popup = true)
|
|
{
|
|
if (!EntitySystem.Get<ActionBlockerSystem>().CanPickup(user))
|
|
return false;
|
|
|
|
if (_entMan.GetComponent<TransformComponent>(user).MapID != _entMan.GetComponent<TransformComponent>(Owner).MapID)
|
|
return false;
|
|
|
|
if (!_entMan.TryGetComponent(Owner, out IPhysBody? physics) || physics.BodyType == BodyType.Static)
|
|
return false;
|
|
|
|
return user.InRangeUnobstructed(Owner, ignoreInsideBlocker: true, popup: popup);
|
|
}
|
|
|
|
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
|
|
{
|
|
var user = eventArgs.User;
|
|
|
|
if (!CanPickup(user))
|
|
return false;
|
|
|
|
if (!_entMan.TryGetComponent(user, out SharedHandsComponent? hands))
|
|
return false;
|
|
|
|
var activeHand = hands.ActiveHand;
|
|
|
|
if (activeHand == null)
|
|
return false;
|
|
|
|
hands.TryPickupEntityToActiveHand(Owner);
|
|
return true;
|
|
}
|
|
|
|
protected virtual void OnEquippedPrefixChange() { }
|
|
|
|
public virtual void RemovedFromSlot() { }
|
|
|
|
public virtual void EquippedToSlot() { }
|
|
}
|
|
|
|
[Serializable, NetSerializable]
|
|
public class ItemComponentState : ComponentState
|
|
{
|
|
public int Size { get; }
|
|
public string? EquippedPrefix { get; }
|
|
public Color Color { get; }
|
|
public string? RsiPath { get; }
|
|
|
|
public ItemComponentState(int size, string? equippedPrefix, Color color, string? rsiPath)
|
|
{
|
|
Size = size;
|
|
EquippedPrefix = equippedPrefix;
|
|
Color = color;
|
|
RsiPath = rsiPath;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// Reference sizes for common containers and items.
|
|
/// </summary>
|
|
public enum ReferenceSizes
|
|
{
|
|
Wallet = 4,
|
|
Pocket = 12,
|
|
Box = 24,
|
|
Belt = 30,
|
|
Toolbox = 60,
|
|
Backpack = 100,
|
|
NoStoring = 9999
|
|
}
|
|
}
|