using Sandbox; using Sandbox.UI; namespace Sasalka; public class InventoryItem : Component { [Property] public BaseItemDefinition Definition { get; set; } [Sync, Property] public int Count { get; set; } = 1; [Sync] public bool Equipped { get; set; } = false; protected override void OnStart() { if ( GameObject.Components.TryGet( out var item ) ) { item.Label = Definition?.Name ?? "Unknown Item"; } } public bool CanStackWith( InventoryItem other ) { if ( other == null || Definition == null || other.Definition == null ) return false; return Definition == other.Definition && Definition.MaxCount > 1; } public bool CanAddCount( int amount ) { if ( Definition == null ) return false; return Count + amount <= Definition.MaxCount; } public bool TryAddCount( int amount ) { if ( !CanAddCount( amount ) ) return false; Count += amount; return true; } public bool TryRemoveCount( int amount ) { if ( Count < amount ) return false; Count -= amount; return true; } public InventoryItem Clone() { var clone = new InventoryItem { Definition = Definition, Count = Count, Equipped = false }; return clone; } public override string ToString() { return $"{Definition?.Name ?? "Unknown"} x{Count}"; } }