/* TShock, a server mod for Terraria Copyright (C) 2011-2019 Pryaxis & TShock Contributors This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ 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; /// /// 40 - The number of slots in a forge /// public static readonly int ForgeSlots = SafeSlots; /// /// 40 - The number of slots in a void vault /// public static readonly int VoidSlots = ForgeSlots; /// /// 59 - The size of the player's inventory (inventory, coins, ammo, held item) /// 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; /// /// 1 - The number of trash can slots. /// public static readonly int TrashSlots = 1; /// /// The number of armor slots in a loadout. /// public static readonly int LoadoutArmorSlots = ArmorSlots; /// /// The number of dye slots in a loadout. /// public static readonly int LoadoutDyeSlots = DyeSlots; /// /// 180 - The inventory size (inventory, held item, armour, dies, coins, ammo, piggy, safe, and trash) /// public static readonly int MaxInventory = InventorySlots + ArmorSlots + DyeSlots + MiscEquipSlots + MiscDyeSlots + PiggySlots + SafeSlots + ForgeSlots + VoidSlots + TrashSlots + (LoadoutArmorSlots * 3) + (LoadoutDyeSlots * 3); public static readonly Tuple InventoryIndex = new Tuple(0, InventorySlots); public static readonly Tuple ArmorIndex = new Tuple(InventoryIndex.Item2, InventoryIndex.Item2 + ArmorSlots); public static readonly Tuple DyeIndex = new Tuple(ArmorIndex.Item2, ArmorIndex.Item2 + DyeSlots); public static readonly Tuple MiscEquipIndex = new Tuple(DyeIndex.Item2, DyeIndex.Item2 + MiscEquipSlots); public static readonly Tuple MiscDyeIndex = new Tuple(MiscEquipIndex.Item2, MiscEquipIndex.Item2 + MiscDyeSlots); public static readonly Tuple PiggyIndex = new Tuple(MiscDyeIndex.Item2, MiscDyeIndex.Item2 + PiggySlots); public static readonly Tuple SafeIndex = new Tuple(PiggyIndex.Item2, PiggyIndex.Item2 + SafeSlots); public static readonly Tuple TrashIndex = new Tuple(SafeIndex.Item2, SafeIndex.Item2 + TrashSlots); public static readonly Tuple ForgeIndex = new Tuple(TrashIndex.Item2, TrashIndex.Item2 + ForgeSlots); public static readonly Tuple VoidIndex = new Tuple(ForgeIndex.Item2, ForgeIndex.Item2 + VoidSlots); public static readonly Tuple Loadout1Armor = new Tuple(VoidIndex.Item2, VoidIndex.Item2 + LoadoutArmorSlots); public static readonly Tuple Loadout1Dye = new Tuple(Loadout1Armor.Item2, Loadout1Armor.Item2 + LoadoutDyeSlots); public static readonly Tuple Loadout2Armor = new Tuple(Loadout1Dye.Item2, Loadout1Dye.Item2 + LoadoutArmorSlots); public static readonly Tuple Loadout2Dye = new Tuple(Loadout2Armor.Item2, Loadout2Armor.Item2 + LoadoutDyeSlots); public static readonly Tuple Loadout3Armor = new Tuple(Loadout2Dye.Item2, Loadout2Dye.Item2 + LoadoutArmorSlots); public static readonly Tuple Loadout3Dye = new Tuple(Loadout3Armor.Item2, Loadout3Armor.Item2 + LoadoutDyeSlots); [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 = 1, byte prefixId = 0) { _netId = netId; _stack = stack; _prefixId = prefixId; } /// /// Creates a new . /// /// Item in the game. public NetItem(Item item) { _netId = item.netID; _stack = item.stack; _prefixId = item.prefix; } /// /// Creates based on data from this structure. /// /// A copy of the item. public Item ToItem() { Item item = new Item(); item.netDefaults(_netId); item.stack = _stack; item.prefix = _prefixId; return item; } /// /// 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); } } }