Files
tbd-station-14/Content.Shared/GameObjects/Components/SharedStackComponent.cs
Git-Nivrak 6d2882c7cf (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 15:58:06 +01:00

147 lines
3.7 KiB
C#

using System;
using Robust.Shared.Containers;
using Robust.Shared.GameObjects;
using Robust.Shared.Interfaces.Reflection;
using Robust.Shared.IoC;
using Robust.Shared.Serialization;
using Robust.Shared.ViewVariables;
namespace Content.Shared.GameObjects.Components
{
public abstract class SharedStackComponent : Component
{
private const string SerializationCache = "stack";
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 StackComponentState cast))
{
return;
}
Count = cast.Count;
MaxCount = cast.MaxCount;
}
[Serializable, NetSerializable]
private sealed class StackComponentState : ComponentState
{
public int Count { get; }
public int MaxCount { get; }
public StackComponentState(int count, int maxCount) : base(ContentNetIDs.STACK)
{
Count = count;
MaxCount = maxCount;
}
}
}
public enum StackType
{
Metal,
Glass,
ReinforcedGlass,
Plasteel,
Cable,
Wood,
MVCable,
HVCable,
Gold,
Phoron,
Ointment,
Gauze,
Brutepack,
FloorTileSteel,
FloorTileCarpet,
FloorTileWhite,
FloorTileDark,
FloorTileWood,
MetalRod
}
}