using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Newtonsoft.Json;
using Terraria;
namespace TShockAPI
{
///
/// Represents an item.
///
[JsonObject(MemberSerialization.OptIn)]
public struct NetItem
{
///
/// 40 - The number of slots in a piggy bank
///
public static readonly int PiggySlots = 40;
///
/// 40 - The number of slots in a safe
///
public static readonly int SafeSlots = PiggySlots;
///
/// 59 - The size of the player's inventory (inventory, coins, ammo)
///
public static readonly int InventorySlots = 59;
///
/// 20 - The number of armor slots.
///
public static readonly int ArmorSlots = 20;
///
/// 5 - The number of other equippable items
///
public static readonly int MiscEquipSlots = 5;
///
/// 10 - The number of dye slots.
///
public static readonly int DyeSlots = 10;
///
/// 5 - The number of other dye slots (for )
///
public static readonly int MiscDyeSlots = MiscEquipSlots;
///
/// 179 - The inventory size (including armour, dies, coins, ammo, piggy, safe, and trash)
///
public static readonly int MaxInventory = InventorySlots + ArmorSlots + DyeSlots + MiscEquipSlots + MiscDyeSlots + PiggySlots + SafeSlots + 1;
[JsonProperty("netID")]
private int _netId;
[JsonProperty("prefix")]
private byte _prefixId;
[JsonProperty("stack")]
private int _stack;
///
/// Gets the net ID.
///
public int NetId
{
get { return _netId; }
}
///
/// Gets the prefix.
///
public byte PrefixId
{
get { return _prefixId; }
}
///
/// Gets the stack.
///
public int Stack
{
get { return _stack; }
}
///
/// Creates a new .
///
/// The net ID.
/// The stack.
/// The prefix ID.
public NetItem(int netId, int stack, byte prefixId)
{
_netId = netId;
_stack = stack;
_prefixId = prefixId;
}
///
/// Converts the to a string.
///
///
public override string ToString()
{
return String.Format("{0},{1},{2}", _netId, _stack, _prefixId);
}
///
/// Converts a string into a .
///
/// The string.
///
///
///
public static NetItem Parse(string str)
{
if (str == null)
throw new ArgumentNullException("str");
string[] comp = str.Split(',');
if (comp.Length != 3)
throw new FormatException("String does not contain three sections.");
int netId = Int32.Parse(comp[0]);
int stack = Int32.Parse(comp[1]);
byte prefixId = Byte.Parse(comp[2]);
return new NetItem(netId, stack, prefixId);
}
///
/// Converts an into a .
///
/// The .
///
public static explicit operator NetItem(Item item)
{
return item == null
? new NetItem()
: new NetItem(item.netID, item.stack, item.prefix);
}
}
}