SharedItemComponent (#3513)
* StorableComponent refactor * ItemComponent refactor * conflict fixes * removes redundant null check * removes redundant item throwing code * fix conflicts * ExplosionLaunchedComponent Co-authored-by: metalgearsloth <comedian_vs_clown@hotmail.com>
This commit is contained in:
@@ -1,19 +1,23 @@
|
||||
using Content.Client.GameObjects.Components.HUD.Inventory;
|
||||
#nullable enable
|
||||
using Content.Client.GameObjects.Components.HUD.Inventory;
|
||||
using Content.Client.GameObjects.Components.Items;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.GameObjects.Components.Inventory;
|
||||
using Content.Shared.GameObjects.Components.Items;
|
||||
using Content.Shared.GameObjects.Components.Storage;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Clothing
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(SharedItemComponent))]
|
||||
[ComponentReference(typeof(ItemComponent))]
|
||||
[ComponentReference(typeof(IItemComponent))]
|
||||
public class ClothingComponent : ItemComponent
|
||||
{
|
||||
[DataField("femaleMask")]
|
||||
@@ -64,17 +68,9 @@ namespace Content.Client.GameObjects.Components.Clothing
|
||||
public (RSI rsi, RSI.StateId stateId)? GetEquippedStateInfo(EquipmentSlotDefines.SlotFlags slot, string? speciesId=null)
|
||||
{
|
||||
if (RsiPath == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var rsi = GetRSI();
|
||||
|
||||
if (rsi == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var rsi = IoCManager.Resolve<IResourceCache>().GetResource<RSIResource>(SharedSpriteComponent.TextureRoot / RsiPath).RSI;
|
||||
var prefix = ClothingEquippedPrefix ?? EquippedPrefix;
|
||||
var stateId = prefix != null ? $"{prefix}-equipped-{slot}" : $"equipped-{slot}";
|
||||
if (speciesId != null)
|
||||
|
||||
@@ -4,7 +4,9 @@ using System.Linq;
|
||||
using Content.Client.Animations;
|
||||
using Content.Client.UserInterface;
|
||||
using Content.Shared.GameObjects.Components.Items;
|
||||
using Content.Shared.GameObjects.Components.Storage;
|
||||
using Robust.Client.GameObjects;
|
||||
using Robust.Client.ResourceManagement;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Network;
|
||||
@@ -161,20 +163,26 @@ namespace Content.Client.GameObjects.Components.Items
|
||||
return;
|
||||
}
|
||||
|
||||
if (!entity.TryGetComponent(out ItemComponent? item)) return;
|
||||
if (!entity.TryGetComponent(out SharedItemComponent? item))
|
||||
return;
|
||||
|
||||
var maybeInHands = item.GetInHandStateInfo(hand.Location);
|
||||
|
||||
if (!maybeInHands.HasValue)
|
||||
if (item.RsiPath == null)
|
||||
{
|
||||
_sprite.LayerSetVisible($"hand-{name}", false);
|
||||
}
|
||||
else
|
||||
{
|
||||
var (rsi, state, color) = maybeInHands.Value;
|
||||
var rsi = IoCManager.Resolve<IResourceCache>().GetResource<RSIResource>(SharedSpriteComponent.TextureRoot / item.RsiPath).RSI;
|
||||
|
||||
var handName = hand.Location.ToString().ToLowerInvariant();
|
||||
var prefix = item.EquippedPrefix;
|
||||
var state = prefix != null ? $"{prefix}-inhand-{handName}" : $"inhand-{handName}";
|
||||
|
||||
var color = item.Color;
|
||||
|
||||
_sprite.LayerSetColor($"hand-{name}", color);
|
||||
_sprite.LayerSetVisible($"hand-{name}", true);
|
||||
_sprite.LayerSetState($"hand-{name}", state, rsi);
|
||||
_sprite.LayerSetState($"hand-{name}", state, rsi);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,102 +1,26 @@
|
||||
using Content.Client.GameObjects.Components.Disposal;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.GameObjects.Components.Items;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Robust.Client.Graphics;
|
||||
using Robust.Client.ResourceManagement;
|
||||
#nullable enable
|
||||
using Content.Shared.GameObjects.Components.Storage;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.IoC;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.Utility;
|
||||
using Robust.Shared.ViewVariables;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Items
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(IItemComponent))]
|
||||
public class ItemComponent : Component, IItemComponent, IDraggable
|
||||
[ComponentReference(typeof(SharedItemComponent))]
|
||||
public class ItemComponent : SharedItemComponent
|
||||
{
|
||||
[Dependency] private readonly IResourceCache _resourceCache = default!;
|
||||
|
||||
public override string Name => "Item";
|
||||
public override uint? NetID => ContentNetIDs.ITEM;
|
||||
|
||||
[ViewVariables]
|
||||
[DataField("sprite")]
|
||||
protected ResourcePath? RsiPath;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
[DataField("color")]
|
||||
protected Color Color = Color.White;
|
||||
|
||||
[DataField("HeldPrefix")]
|
||||
private string? _equippedPrefix;
|
||||
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public string? EquippedPrefix
|
||||
public override bool TryPutInHand(IEntity user)
|
||||
{
|
||||
get => _equippedPrefix;
|
||||
set
|
||||
{
|
||||
_equippedPrefix = value;
|
||||
|
||||
if (!Owner.TryGetContainer(out var container))
|
||||
return;
|
||||
|
||||
if (container.Owner.TryGetComponent(out HandsComponent? hands))
|
||||
hands.RefreshInHands();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public (RSI rsi, RSI.StateId stateId, Color color)? GetInHandStateInfo(HandLocation hand)
|
||||
protected override void OnEquippedPrefixChange()
|
||||
{
|
||||
var rsi = GetRSI();
|
||||
|
||||
if (rsi == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var handName = hand.ToString().ToLowerInvariant();
|
||||
var stateId = EquippedPrefix != null ? $"{EquippedPrefix}-inhand-{handName}" : $"inhand-{handName}";
|
||||
|
||||
if (rsi.TryGetState(stateId, out _))
|
||||
{
|
||||
return (rsi, stateId, Color);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected RSI? GetRSI()
|
||||
{
|
||||
if (RsiPath == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return _resourceCache.GetResource<RSIResource>(SharedSpriteComponent.TextureRoot / RsiPath).RSI;
|
||||
}
|
||||
|
||||
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||
{
|
||||
if (curState is not ItemComponentState state)
|
||||
if (!Owner.TryGetContainer(out var container))
|
||||
return;
|
||||
|
||||
EquippedPrefix = state.EquippedPrefix;
|
||||
}
|
||||
|
||||
bool IDraggable.CanDrop(CanDropEventArgs args)
|
||||
{
|
||||
return args.Target.HasComponent<DisposalUnitComponent>();
|
||||
}
|
||||
|
||||
bool IDraggable.Drop(DragDropEventArgs args)
|
||||
{
|
||||
// TODO: Shared item class
|
||||
return false;
|
||||
if (container.Owner.TryGetComponent(out HandsComponent? hands))
|
||||
hands.RefreshInHands();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
using Content.Shared.GameObjects.Components.Storage;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Client.GameObjects.Components.Storage
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(SharedStorableComponent))]
|
||||
public class StorableComponent : SharedStorableComponent
|
||||
{
|
||||
private int _size;
|
||||
|
||||
public override int Size
|
||||
{
|
||||
get => _size;
|
||||
set
|
||||
{
|
||||
if (_size == value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_size = value;
|
||||
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||
{
|
||||
base.HandleComponentState(curState, nextState);
|
||||
|
||||
if (curState is not StorableComponentState state)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_size = state.Size;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -252,6 +252,7 @@ namespace Content.Client
|
||||
"RandomSpawner",
|
||||
"SpawnAfterInteract",
|
||||
"DisassembleOnActivate",
|
||||
"ExplosionLaunched",
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
using Content.Server.GameObjects.Components.Items;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Explosion
|
||||
{
|
||||
[RegisterComponent]
|
||||
public class ExplosionLaunchedComponent : Component, IExAct
|
||||
{
|
||||
public override string Name => "ExplosionLaunched";
|
||||
|
||||
void IExAct.OnExplosion(ExplosionEventArgs eventArgs)
|
||||
{
|
||||
if (Owner.Deleted)
|
||||
return;
|
||||
|
||||
var sourceLocation = eventArgs.Source;
|
||||
var targetLocation = eventArgs.Target.Transform.Coordinates;
|
||||
var direction = (targetLocation.ToMapPos(Owner.EntityManager) - sourceLocation.ToMapPos(Owner.EntityManager)).Normalized;
|
||||
|
||||
var throwForce = eventArgs.Severity switch
|
||||
{
|
||||
ExplosionSeverity.Heavy => 30,
|
||||
ExplosionSeverity.Light => 20,
|
||||
_ => 0,
|
||||
};
|
||||
Owner.TryThrow(direction * throwForce);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Server.GameObjects.Components.Items.Storage;
|
||||
using Content.Shared.GameObjects.Components.Storage;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using Content.Server.GameObjects.Components.GUI;
|
||||
using Content.Server.GameObjects.Components.GUI;
|
||||
using Content.Server.GameObjects.Components.Items.Storage;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.GameObjects.Components.Items;
|
||||
@@ -14,10 +14,8 @@ using static Content.Shared.GameObjects.Components.Inventory.EquipmentSlotDefine
|
||||
namespace Content.Server.GameObjects.Components.Items.Clothing
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(SharedItemComponent))]
|
||||
[ComponentReference(typeof(ItemComponent))]
|
||||
[ComponentReference(typeof(StorableComponent))]
|
||||
[ComponentReference(typeof(SharedStorableComponent))]
|
||||
[ComponentReference(typeof(IItemComponent))]
|
||||
public class ClothingComponent : ItemComponent, IUse
|
||||
{
|
||||
public override string Name => "Clothing";
|
||||
|
||||
@@ -209,7 +209,7 @@ namespace Content.Server.GameObjects.Components.Items.Storage
|
||||
continue;
|
||||
|
||||
// only items that can be stored in an inventory, or a mob, can be eaten by a locker
|
||||
if (!entity.HasComponent<StorableComponent>() &&
|
||||
if (!entity.HasComponent<SharedItemComponent>() &&
|
||||
!entity.HasComponent<IBody>())
|
||||
continue;
|
||||
|
||||
|
||||
@@ -1,46 +1,23 @@
|
||||
#nullable enable
|
||||
using Content.Server.GameObjects.Components.GUI;
|
||||
using Content.Server.Interfaces.GameObjects.Components.Items;
|
||||
using Content.Shared.GameObjects;
|
||||
using Content.Shared.GameObjects.Components.Items;
|
||||
using Content.Shared.GameObjects.Components.Storage;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects.EntitySystems.ActionBlocker;
|
||||
using Content.Shared.GameObjects.Verbs;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Content.Shared.Utility;
|
||||
using Robust.Server.GameObjects;
|
||||
using Robust.Shared.Containers;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Localization;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Items.Storage
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(StorableComponent))]
|
||||
[ComponentReference(typeof(SharedStorableComponent))]
|
||||
[ComponentReference(typeof(IItemComponent))]
|
||||
public class ItemComponent : StorableComponent, IInteractHand, IExAct, IEquipped, IUnequipped, IItemComponent
|
||||
[ComponentReference(typeof(SharedItemComponent))]
|
||||
public class ItemComponent : SharedItemComponent
|
||||
{
|
||||
public override string Name => "Item";
|
||||
public override uint? NetID => ContentNetIDs.ITEM;
|
||||
|
||||
[DataField("HeldPrefix")]
|
||||
private string? _equippedPrefix;
|
||||
|
||||
public string? EquippedPrefix
|
||||
{
|
||||
get => _equippedPrefix;
|
||||
set
|
||||
{
|
||||
_equippedPrefix = value;
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
public void RemovedFromSlot()
|
||||
public override void RemovedFromSlot()
|
||||
{
|
||||
foreach (var component in Owner.GetAllComponents<ISpriteRenderableComponent>())
|
||||
{
|
||||
@@ -48,7 +25,7 @@ namespace Content.Server.GameObjects.Components.Items.Storage
|
||||
}
|
||||
}
|
||||
|
||||
public void EquippedToSlot()
|
||||
public override void EquippedToSlot()
|
||||
{
|
||||
foreach (var component in Owner.GetAllComponents<ISpriteRenderableComponent>())
|
||||
{
|
||||
@@ -56,44 +33,20 @@ namespace Content.Server.GameObjects.Components.Items.Storage
|
||||
}
|
||||
}
|
||||
|
||||
public virtual void Equipped(EquippedEventArgs eventArgs)
|
||||
public override bool TryPutInHand(IEntity user)
|
||||
{
|
||||
EquippedToSlot();
|
||||
}
|
||||
|
||||
public virtual void Unequipped(UnequippedEventArgs eventArgs)
|
||||
{
|
||||
RemovedFromSlot();
|
||||
}
|
||||
|
||||
public bool CanPickup(IEntity user)
|
||||
{
|
||||
if (!ActionBlockerSystem.CanPickup(user))
|
||||
{
|
||||
if (!CanPickup(user))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (user.Transform.MapID != Owner.Transform.MapID)
|
||||
{
|
||||
if (!user.TryGetComponent(out IHandsComponent? hands))
|
||||
return false;
|
||||
}
|
||||
|
||||
if (Owner.TryGetComponent(out IPhysBody? physics) &&
|
||||
physics.BodyType == BodyType.Static)
|
||||
{
|
||||
var activeHand = hands.ActiveHand;
|
||||
|
||||
if (activeHand == null)
|
||||
return false;
|
||||
}
|
||||
|
||||
return user.InRangeUnobstructed(Owner, ignoreInsideBlocker: true, popup: true);
|
||||
}
|
||||
|
||||
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
|
||||
{
|
||||
if (!CanPickup(eventArgs.User) ||
|
||||
!eventArgs.User.TryGetComponent(out IHandsComponent? hands) ||
|
||||
hands.ActiveHand == null) return false;
|
||||
|
||||
hands.PutInHand(this, hands.ActiveHand, false);
|
||||
hands.PutInHand(this, activeHand, false);
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -110,7 +63,7 @@ namespace Content.Server.GameObjects.Components.Items.Storage
|
||||
return;
|
||||
}
|
||||
|
||||
data.Text = Loc.GetString("Pick up");
|
||||
data.Text = Loc.GetString("Pick Up");
|
||||
}
|
||||
|
||||
protected override void Activate(IEntity user, ItemComponent component)
|
||||
@@ -121,34 +74,5 @@ namespace Content.Server.GameObjects.Components.Items.Storage
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState(ICommonSession session)
|
||||
{
|
||||
return new ItemComponentState(EquippedPrefix);
|
||||
}
|
||||
|
||||
public void OnExplosion(ExplosionEventArgs eventArgs)
|
||||
{
|
||||
var sourceLocation = eventArgs.Source;
|
||||
var targetLocation = eventArgs.Target.Transform.Coordinates;
|
||||
var dirVec = (targetLocation.ToMapPos(Owner.EntityManager) - sourceLocation.ToMapPos(Owner.EntityManager)).Normalized;
|
||||
|
||||
float throwForce;
|
||||
|
||||
switch (eventArgs.Severity)
|
||||
{
|
||||
case ExplosionSeverity.Destruction:
|
||||
throwForce = 30.0f;
|
||||
break;
|
||||
case ExplosionSeverity.Heavy:
|
||||
throwForce = 20.0f;
|
||||
break;
|
||||
default:
|
||||
throwForce = 10.0f;
|
||||
break;
|
||||
}
|
||||
|
||||
Owner.TryThrow(dirVec * throwForce);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#nullable enable
|
||||
using Content.Server.GameObjects.Components.GUI;
|
||||
using Content.Server.Interfaces.GameObjects.Components.Items;
|
||||
using Content.Shared.GameObjects.Components.Storage;
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.Interfaces;
|
||||
using Robust.Shared.Containers;
|
||||
|
||||
@@ -94,7 +94,7 @@ namespace Content.Server.GameObjects.Components.Items.Storage
|
||||
|
||||
foreach (var entity in _storage.ContainedEntities)
|
||||
{
|
||||
var item = entity.GetComponent<StorableComponent>();
|
||||
var item = entity.GetComponent<SharedItemComponent>();
|
||||
_storageUsed += item.Size;
|
||||
}
|
||||
}
|
||||
@@ -114,7 +114,7 @@ namespace Content.Server.GameObjects.Components.Items.Storage
|
||||
return false;
|
||||
}
|
||||
|
||||
if (entity.TryGetComponent(out StorableComponent? store) &&
|
||||
if (entity.TryGetComponent(out SharedItemComponent? store) &&
|
||||
store.Size > _storageCapacityMax - _storageUsed)
|
||||
{
|
||||
return false;
|
||||
@@ -152,7 +152,7 @@ namespace Content.Server.GameObjects.Components.Items.Storage
|
||||
Logger.DebugS(LoggerName, $"Storage (UID {Owner.Uid}) had entity (UID {message.Entity.Uid}) inserted into it.");
|
||||
|
||||
var size = 0;
|
||||
if (message.Entity.TryGetComponent(out StorableComponent? storable))
|
||||
if (message.Entity.TryGetComponent(out SharedItemComponent? storable))
|
||||
size = storable.Size;
|
||||
|
||||
_storageUsed += size;
|
||||
@@ -495,14 +495,14 @@ namespace Content.Server.GameObjects.Components.Items.Storage
|
||||
|
||||
// Pick up all entities in a radius around the clicked location.
|
||||
// The last half of the if is because carpets exist and this is terrible
|
||||
if(_areaInsert && (eventArgs.Target == null || !eventArgs.Target.HasComponent<StorableComponent>()))
|
||||
if(_areaInsert && (eventArgs.Target == null || !eventArgs.Target.HasComponent<SharedItemComponent>()))
|
||||
{
|
||||
var validStorables = new List<IEntity>();
|
||||
foreach (var entity in Owner.EntityManager.GetEntitiesInRange(eventArgs.ClickLocation, 1))
|
||||
{
|
||||
if (!entity.Transform.IsMapTransform
|
||||
|| entity == eventArgs.User
|
||||
|| !entity.HasComponent<StorableComponent>())
|
||||
|| !entity.HasComponent<SharedItemComponent>())
|
||||
continue;
|
||||
validStorables.Add(entity);
|
||||
}
|
||||
@@ -529,7 +529,7 @@ namespace Content.Server.GameObjects.Components.Items.Storage
|
||||
// Check again, situation may have changed for some entities, but we'll still pick up any that are valid
|
||||
if (!entity.Transform.IsMapTransform
|
||||
|| entity == eventArgs.User
|
||||
|| !entity.HasComponent<StorableComponent>())
|
||||
|| !entity.HasComponent<SharedItemComponent>())
|
||||
continue;
|
||||
var coords = entity.Transform.Coordinates;
|
||||
if (PlayerInsertEntityInWorld(eventArgs.User, entity))
|
||||
@@ -558,7 +558,7 @@ namespace Content.Server.GameObjects.Components.Items.Storage
|
||||
if (eventArgs.Target == null
|
||||
|| !eventArgs.Target.Transform.IsMapTransform
|
||||
|| eventArgs.Target == eventArgs.User
|
||||
|| !eventArgs.Target.HasComponent<StorableComponent>())
|
||||
|| !eventArgs.Target.HasComponent<SharedItemComponent>())
|
||||
return false;
|
||||
var position = eventArgs.Target.Transform.Coordinates;
|
||||
if(PlayerInsertEntityInWorld(eventArgs.User, eventArgs.Target))
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
using Content.Shared.GameObjects.Components.Storage;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Players;
|
||||
|
||||
namespace Content.Server.GameObjects.Components.Items.Storage
|
||||
{
|
||||
[RegisterComponent]
|
||||
[ComponentReference(typeof(SharedStorableComponent))]
|
||||
public class StorableComponent : SharedStorableComponent
|
||||
{
|
||||
private int _size;
|
||||
|
||||
public override int Size
|
||||
{
|
||||
get => _size;
|
||||
set
|
||||
{
|
||||
if (_size == value)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_size = value;
|
||||
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
|
||||
public override ComponentState GetComponentState(ICommonSession player)
|
||||
{
|
||||
return new StorableComponentState(_size);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Enum for the storage capacity of various containers
|
||||
/// </summary>
|
||||
public enum ReferenceSizes
|
||||
{
|
||||
Wallet = 4,
|
||||
Pocket = 12,
|
||||
Box = 24,
|
||||
Belt = 30,
|
||||
Toolbox = 60,
|
||||
Backpack = 100,
|
||||
NoStoring = 9999
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Content.Shared.GameObjects.Components.Body;
|
||||
@@ -168,7 +168,7 @@ namespace Content.Shared.GameObjects.Components.Disposal
|
||||
return false;
|
||||
|
||||
// TODO: Probably just need a disposable tag.
|
||||
if (!entity.TryGetComponent(out SharedStorableComponent? storable) &&
|
||||
if (!entity.TryGetComponent(out SharedItemComponent? storable) &&
|
||||
!entity.HasComponent<IBody>())
|
||||
{
|
||||
return false;
|
||||
@@ -182,7 +182,6 @@ namespace Content.Shared.GameObjects.Components.Disposal
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,17 +1,21 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
using System;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.Items
|
||||
{
|
||||
[Serializable, NetSerializable]
|
||||
public class ClothingComponentState : ItemComponentState
|
||||
public class ClothingComponentState : ComponentState
|
||||
{
|
||||
public string? ClothingEquippedPrefix { get; set; }
|
||||
public string? ClothingEquippedPrefix { get; }
|
||||
|
||||
public ClothingComponentState(string? clothingEquippedPrefix, string? equippedPrefix) : base(equippedPrefix, ContentNetIDs.CLOTHING)
|
||||
public string? EquippedPrefix { get; }
|
||||
|
||||
public ClothingComponentState(string? clothingEquippedPrefix, string? equippedPrefix) : base(ContentNetIDs.CLOTHING)
|
||||
{
|
||||
ClothingEquippedPrefix = clothingEquippedPrefix;
|
||||
EquippedPrefix = equippedPrefix;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
#nullable enable
|
||||
using Robust.Shared.GameObjects;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.Items
|
||||
{
|
||||
public interface IItemComponent : IComponent
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Serialization;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.Items
|
||||
{
|
||||
[Serializable, NetSerializable]
|
||||
public class ItemComponentState : ComponentState
|
||||
{
|
||||
public string? EquippedPrefix { get; set; }
|
||||
|
||||
public ItemComponentState(string? equippedPrefix) : base(ContentNetIDs.ITEM)
|
||||
{
|
||||
EquippedPrefix = equippedPrefix;
|
||||
}
|
||||
|
||||
protected ItemComponentState(string? equippedPrefix, uint netId) : base(netId)
|
||||
{
|
||||
EquippedPrefix = equippedPrefix;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,184 @@
|
||||
#nullable enable
|
||||
using Content.Shared.GameObjects.EntitySystems;
|
||||
using Content.Shared.GameObjects.EntitySystems.ActionBlocker;
|
||||
using Content.Shared.Interfaces.GameObjects.Components;
|
||||
using Content.Shared.Utility;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Maths;
|
||||
using Robust.Shared.Physics;
|
||||
using Robust.Shared.Players;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
using Robust.Shared.ViewVariables;
|
||||
using System;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.Storage
|
||||
{
|
||||
/// <summary>
|
||||
/// Players can pick up, drop, and put items in bags, and they can be seen in player's hands.
|
||||
/// </summary>
|
||||
public abstract class SharedItemComponent : Component, IEquipped, IUnequipped, IInteractHand
|
||||
{
|
||||
public override string Name => "Item";
|
||||
|
||||
public override uint? NetID => ContentNetIDs.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>
|
||||
[ViewVariables(VVAccess.ReadWrite)]
|
||||
public string? EquippedPrefix
|
||||
{
|
||||
get => _equippedPrefix;
|
||||
set
|
||||
{
|
||||
_equippedPrefix = value;
|
||||
OnEquippedPrefixChange();
|
||||
Dirty();
|
||||
}
|
||||
}
|
||||
[DataField("HeldPrefix")]
|
||||
private string? _equippedPrefix;
|
||||
|
||||
/// <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;
|
||||
protected 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;
|
||||
|
||||
public override ComponentState GetComponentState(ICommonSession player)
|
||||
{
|
||||
return new ItemComponentState(Size, EquippedPrefix, Color, RsiPath);
|
||||
}
|
||||
|
||||
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
||||
{
|
||||
base.HandleComponentState(curState, nextState);
|
||||
|
||||
if (curState is not ItemComponentState state)
|
||||
return;
|
||||
|
||||
Size = state.Size;
|
||||
EquippedPrefix = state.EquippedPrefix;
|
||||
Color = state.Color;
|
||||
RsiPath = state.RsiPath;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// If a player can pick up this item.
|
||||
/// </summary>
|
||||
public bool CanPickup(IEntity user)
|
||||
{
|
||||
if (!ActionBlockerSystem.CanPickup(user))
|
||||
return false;
|
||||
|
||||
if (user.Transform.MapID != Owner.Transform.MapID)
|
||||
return false;
|
||||
|
||||
if (!Owner.TryGetComponent(out IPhysBody? physics) || physics.BodyType == BodyType.Static)
|
||||
return false;
|
||||
|
||||
return user.InRangeUnobstructed(Owner, ignoreInsideBlocker: true, popup: true);
|
||||
}
|
||||
|
||||
void IEquipped.Equipped(EquippedEventArgs eventArgs)
|
||||
{
|
||||
EquippedToSlot();
|
||||
}
|
||||
|
||||
void IUnequipped.Unequipped(UnequippedEventArgs eventArgs)
|
||||
{
|
||||
RemovedFromSlot();
|
||||
}
|
||||
|
||||
bool IInteractHand.InteractHand(InteractHandEventArgs eventArgs)
|
||||
{
|
||||
return TryPutInHand(eventArgs.User);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Tries to put this item in a player's hands.
|
||||
/// TODO: Move server implementation here once hands are in shared.
|
||||
/// </summary>
|
||||
public abstract bool TryPutInHand(IEntity user);
|
||||
|
||||
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) : base(ContentNetIDs.ITEM)
|
||||
{
|
||||
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
|
||||
}
|
||||
}
|
||||
@@ -1,28 +0,0 @@
|
||||
#nullable enable
|
||||
using System;
|
||||
using Robust.Shared.GameObjects;
|
||||
using Robust.Shared.Prototypes;
|
||||
using Robust.Shared.Serialization;
|
||||
using Robust.Shared.Serialization.Manager.Attributes;
|
||||
|
||||
namespace Content.Shared.GameObjects.Components.Storage
|
||||
{
|
||||
public abstract class SharedStorableComponent : Component
|
||||
{
|
||||
public override string Name => "Storable";
|
||||
public override uint? NetID => ContentNetIDs.STORABLE;
|
||||
|
||||
[DataField("size")] public virtual int Size { get; set; } = 1;
|
||||
}
|
||||
|
||||
[Serializable, NetSerializable]
|
||||
public class StorableComponentState : ComponentState
|
||||
{
|
||||
public readonly int Size;
|
||||
|
||||
public StorableComponentState(int size) : base(ContentNetIDs.STORABLE)
|
||||
{
|
||||
Size = size;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,8 @@
|
||||
#nullable enable
|
||||
#nullable enable
|
||||
using System.Diagnostics.CodeAnalysis;
|
||||
using Content.Shared.GameObjects.Components.Mobs.State;
|
||||
using Content.Shared.GameObjects.Components.Movement;
|
||||
using Content.Shared.GameObjects.Components.Storage;
|
||||
using Content.Shared.GameObjects.EntitySystems.ActionBlocker;
|
||||
using Content.Shared.Physics;
|
||||
using Content.Shared.Physics.Pull;
|
||||
|
||||
@@ -31,3 +31,4 @@
|
||||
drawdepth: Items
|
||||
noRot: false
|
||||
- type: Pullable
|
||||
- type: ExplosionLaunched
|
||||
|
||||
Reference in New Issue
Block a user