Files
OldThink/Content.Shared/GameObjects/Components/SharedStackComponent.cs

147 lines
3.7 KiB
C#
Raw Normal View History

2020-05-24 16:56:19 +00:00
using System;
using Robust.Shared.Containers;
2020-01-09 00:27:52 +01:00
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.Reflection;
using Robust.Shared.IoC;
2020-01-09 00:27:52 +01:00
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
2020-01-09 00:27:52 +01:00
namespace Content.Shared.GameObjects.Components
{
public abstract class SharedStackComponent : Component
{
private const string SerializationCache = "stack";
2020-01-09 00:27:52 +01:00
public sealed override string Name => "Stack";
public sealed override uint? NetID => ContentNetIDs.STACK;
private int _count;
private int _maxCount;
[ViewVariables(VVAccess.ReadWrite)]
public virtual int Count
{
get => _count;
set
{
_count = value;
if (_count <= 0)
{
if (Owner.TryGetContainerMan(out var containerManager))
{
containerManager.Remove(Owner);
}
Owner.Delete();
}
Dirty();
}
}
[ViewVariables]
public int MaxCount
{
get => _maxCount;
private set
{
_maxCount = value;
Dirty();
}
}
[ViewVariables] public int AvailableSpace => MaxCount - Count;
[ViewVariables] public object StackType { get; private set; }
public override void ExposeData(ObjectSerializer serializer)
{
serializer.DataFieldCached(ref _maxCount, "max", 50);
serializer.DataFieldCached(ref _count, "count", MaxCount);
if (serializer.Writing)
{
return;
}
if (serializer.TryGetCacheData(SerializationCache, out object stackType))
{
StackType = stackType;
return;
}
if (serializer.TryReadDataFieldCached("stacktype", out string raw))
{
var refl = IoCManager.Resolve<IReflectionManager>();
if (refl.TryParseEnumReference(raw, out var @enum))
{
stackType = @enum;
}
else
{
stackType = raw;
}
}
else
{
stackType = Owner.Prototype.ID;
}
serializer.SetCacheData(SerializationCache, stackType);
StackType = stackType;
}
public override ComponentState GetComponentState()
{
return new StackComponentState(Count, MaxCount);
}
public override void HandleComponentState(ComponentState curState, ComponentState nextState)
{
if (curState is not StackComponentState cast)
{
return;
}
Count = cast.Count;
MaxCount = cast.MaxCount;
}
2020-01-09 00:27:52 +01:00
[Serializable, NetSerializable]
private sealed class StackComponentState : ComponentState
2020-01-09 00:27:52 +01:00
{
public int Count { get; }
public int MaxCount { get; }
public StackComponentState(int count, int maxCount) : base(ContentNetIDs.STACK)
2020-01-09 00:27:52 +01:00
{
Count = count;
MaxCount = maxCount;
}
}
}
public enum StackType
{
Metal,
Glass,
(Smaller) Construction PR - (IC Construction) (#2575) * Disable Pulling When Buckling an entity * Projectile Improvements If you shoot at a person that is critted now it will only hit if you aim at that person otherwise go "above" him and hit other targets. - Dead people are still unhitable * Update Content.Server/GameObjects/Components/Buckle/BuckleComponent.cs Co-authored-by: Víctor Aguilera Puerto <6766154+Zumorica@users.noreply.github.com> * Firelock In Progress * Revert "Projectile Improvements" This reverts commit 5821afc798e49e530d4086d7a9ddbe097805fdc4. * Firelock Graph * Revert "Merge branch 'master' into test2" This reverts commit c69661cc7d9dcdc6d8c0dd45770f9eb94b231463, reversing changes made to 5f1de8b8d24cd52190addb3df5617cb1012fd52c. * Bunch of stuff - Metal Rods - Reinforced Glass - SetStackCount Condition - Tables - Lattice * Output2 to FloorTileItemComponent * Plating, Underplating and Tiles (+FloorTile Improvements) * Turf Fixes + APC Electronics * Reinforced Glass In-hand textures * All the fixes * Final Changes * (Hopefully) Last commit * Update Resources/Prototypes/Entities/Constructible/Doors/firelock_frame.yml Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com> * Update Content.Server/GameObjects/Components/Atmos/FirelockComponent.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * A Few more things * Edit FirelockComponent.cs Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> Co-authored-by: Víctor Aguilera Puerto <6766154+Zumorica@users.noreply.github.com> Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
2020-11-20 16:58:06 +02:00
ReinforcedGlass,
Plasteel,
Cable,
Wood,
MVCable,
HVCable,
2020-05-24 16:56:19 +00:00
Gold,
Phoron,
Ointment,
Gauze,
Brutepack,
2020-04-22 17:49:42 +02:00
FloorTileSteel,
FloorTileCarpet,
FloorTileWhite,
FloorTileDark,
(Smaller) Construction PR - (IC Construction) (#2575) * Disable Pulling When Buckling an entity * Projectile Improvements If you shoot at a person that is critted now it will only hit if you aim at that person otherwise go "above" him and hit other targets. - Dead people are still unhitable * Update Content.Server/GameObjects/Components/Buckle/BuckleComponent.cs Co-authored-by: Víctor Aguilera Puerto <6766154+Zumorica@users.noreply.github.com> * Firelock In Progress * Revert "Projectile Improvements" This reverts commit 5821afc798e49e530d4086d7a9ddbe097805fdc4. * Firelock Graph * Revert "Merge branch 'master' into test2" This reverts commit c69661cc7d9dcdc6d8c0dd45770f9eb94b231463, reversing changes made to 5f1de8b8d24cd52190addb3df5617cb1012fd52c. * Bunch of stuff - Metal Rods - Reinforced Glass - SetStackCount Condition - Tables - Lattice * Output2 to FloorTileItemComponent * Plating, Underplating and Tiles (+FloorTile Improvements) * Turf Fixes + APC Electronics * Reinforced Glass In-hand textures * All the fixes * Final Changes * (Hopefully) Last commit * Update Resources/Prototypes/Entities/Constructible/Doors/firelock_frame.yml Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com> * Update Content.Server/GameObjects/Components/Atmos/FirelockComponent.cs Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com> * A Few more things * Edit FirelockComponent.cs Co-authored-by: DrSmugleaf <DrSmugleaf@users.noreply.github.com> Co-authored-by: Víctor Aguilera Puerto <6766154+Zumorica@users.noreply.github.com> Co-authored-by: Paul Ritter <ritter.paul1@googlemail.com> Co-authored-by: metalgearsloth <31366439+metalgearsloth@users.noreply.github.com>
2020-11-20 16:58:06 +02:00
FloorTileWood,
MetalRod
}
2020-01-09 00:27:52 +01:00
}