diff --git a/TShockAPI/DB/CharacterManager.cs b/TShockAPI/DB/CharacterManager.cs index bd416ad4..20ec8b82 100755 --- a/TShockAPI/DB/CharacterManager.cs +++ b/TShockAPI/DB/CharacterManager.cs @@ -77,7 +77,20 @@ namespace TShockAPI.DB playerData.maxHealth = reader.Get("MaxHealth"); playerData.mana = reader.Get("Mana"); playerData.maxMana = reader.Get("MaxMana"); - playerData.inventory = reader.Get("Inventory").Split('~').Select(NetItem.Parse).ToArray(); + List inventory = reader.Get("Inventory").Split('~').Select(NetItem.Parse).ToList(); + if (inventory.Count < NetItem.MaxInventory) + { + //TODO: unhardcode this - stop using magic numbers and use NetItem numbers + //Set new armour slots empty + inventory.InsertRange(67, new NetItem[2]); + //Set new vanity slots empty + inventory.InsertRange(77, new NetItem[2]); + //Set new dye slots empty + inventory.InsertRange(87, new NetItem[2]); + //Set the rest of the new slots empty + inventory.AddRange(new NetItem[NetItem.MaxInventory - inventory.Count]); + } + playerData.inventory = inventory.ToArray(); playerData.spawnX = reader.Get("spawnX"); playerData.spawnY = reader.Get("spawnY"); playerData.hair = reader.Get("hair"); diff --git a/TShockAPI/NetItem.cs b/TShockAPI/NetItem.cs index 35fef45d..af2c8ac8 100644 --- a/TShockAPI/NetItem.cs +++ b/TShockAPI/NetItem.cs @@ -24,7 +24,7 @@ namespace TShockAPI public static readonly int SafeSlots = PiggySlots; /// - /// 59 - The size of the player's inventory (inventory, coins, ammo) + /// 59 - The size of the player's inventory (inventory, coins, ammo, held item) /// public static readonly int InventorySlots = 59; @@ -49,7 +49,7 @@ namespace TShockAPI public static readonly int MiscDyeSlots = MiscEquipSlots; /// - /// 179 - The inventory size (including armour, dies, coins, ammo, piggy, safe, and trash) + /// 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 + 1; diff --git a/TShockAPI/TSPlayer.cs b/TShockAPI/TSPlayer.cs index 1eeada48..eed65b90 100755 --- a/TShockAPI/TSPlayer.cs +++ b/TShockAPI/TSPlayer.cs @@ -1112,6 +1112,13 @@ namespace TShockAPI } } + /// + /// Stores an item at the specific storage slot + /// + /// + /// + /// + /// public void StoreSlot(int slot, int netID, byte prefix, int stack) { if (slot > (this.inventory.Length - 1)) //if the slot is out of range then dont save @@ -1122,6 +1129,10 @@ namespace TShockAPI this.inventory[slot] = new NetItem(netID, stack, prefix); } + /// + /// Copies a characters data to this object + /// + /// public void CopyCharacter(TSPlayer player) { this.health = player.TPlayer.statLife > 0 ? player.TPlayer.statLife : 1; @@ -1198,6 +1209,7 @@ namespace TShockAPI NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots + NetItem.MiscDyeSlots + NetItem.PiggySlots) { + //98-138 var index = i - (NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots + NetItem.MiscDyeSlots); this.inventory[i] = (NetItem)piggy[index]; @@ -1206,17 +1218,23 @@ namespace TShockAPI NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots + NetItem.MiscDyeSlots + NetItem.PiggySlots + NetItem.SafeSlots) { + //138-178 var index = i - (NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots + NetItem.MiscDyeSlots + NetItem.PiggySlots); this.inventory[i] = (NetItem)safe[index]; } else { + //179 this.inventory[i] = (NetItem)trash; } } } + /// + /// Restores a player's character to the state stored in the database + /// + /// public void RestoreCharacter(TSPlayer player) { // Start ignoring SSC-related packets! This is critical so that we don't send or receive dirty data!