54 lines
1.3 KiB
C#
54 lines
1.3 KiB
C#
using Unity.Mathematics;
|
|
|
|
namespace Backpack
|
|
{
|
|
public class BackpackItem : IBackpackItem
|
|
{
|
|
private int _id;
|
|
private string _name;
|
|
private string _description;
|
|
private ItemType _itemType;
|
|
private int _count;
|
|
private int _maxCount;
|
|
|
|
public int Id => _id;
|
|
|
|
public string Name => _name;
|
|
|
|
public string Description => _description;
|
|
|
|
public ItemType ItemType => _itemType;
|
|
|
|
public int Count => _count;
|
|
|
|
public int MaxCount => _maxCount;
|
|
|
|
public BackpackItem(int id, string name, string description, ItemType itemType, int count, int maxCount)
|
|
{
|
|
_id = id;
|
|
_name = name;
|
|
_description = description;
|
|
_itemType = itemType;
|
|
_count = count;
|
|
_maxCount = maxCount;
|
|
}
|
|
|
|
public bool Equals(IBackpackItem other)
|
|
{
|
|
return Id == other.Id;
|
|
}
|
|
|
|
public int AddCount(int count)
|
|
{
|
|
int tmp = _count + count;
|
|
_count = tmp > _maxCount ? _maxCount : _count;
|
|
return tmp > _maxCount ? tmp - _maxCount : 0;
|
|
}
|
|
|
|
public int RemoveCount(int count)
|
|
{
|
|
var tmp = count - _count;
|
|
return count > _maxCount ? math.abs(count - _maxCount) : 0;
|
|
}
|
|
}
|
|
} |