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,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
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user