Backwards compatibility for databases with pre-existing SSC entries
This commit is contained in:
parent
58c4637021
commit
e5cbee82e9
2 changed files with 24 additions and 1 deletions
|
|
@ -77,7 +77,12 @@ namespace TShockAPI.DB
|
||||||
playerData.maxHealth = reader.Get<int>("MaxHealth");
|
playerData.maxHealth = reader.Get<int>("MaxHealth");
|
||||||
playerData.mana = reader.Get<int>("Mana");
|
playerData.mana = reader.Get<int>("Mana");
|
||||||
playerData.maxMana = reader.Get<int>("MaxMana");
|
playerData.maxMana = reader.Get<int>("MaxMana");
|
||||||
playerData.inventory = reader.Get<string>("Inventory").Split('~').Select(NetItem.Parse).ToArray();
|
List<NetItem> inventory = reader.Get<string>("Inventory").Split('~').Select(NetItem.Parse).ToList();
|
||||||
|
if (inventory.Count < NetItem.MaxInventory)
|
||||||
|
{
|
||||||
|
inventory.AddRange(new NetItem[NetItem.MaxInventory - inventory.Count]);
|
||||||
|
}
|
||||||
|
playerData.inventory = inventory.ToArray();
|
||||||
playerData.spawnX = reader.Get<int>("spawnX");
|
playerData.spawnX = reader.Get<int>("spawnX");
|
||||||
playerData.spawnY = reader.Get<int>("spawnY");
|
playerData.spawnY = reader.Get<int>("spawnY");
|
||||||
playerData.hair = reader.Get<int?>("hair");
|
playerData.hair = reader.Get<int?>("hair");
|
||||||
|
|
|
||||||
|
|
@ -1106,6 +1106,13 @@ namespace TShockAPI
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Stores an item at the specific storage slot
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="slot"></param>
|
||||||
|
/// <param name="netID"></param>
|
||||||
|
/// <param name="prefix"></param>
|
||||||
|
/// <param name="stack"></param>
|
||||||
public void StoreSlot(int slot, int netID, byte prefix, int stack)
|
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
|
if (slot > (this.inventory.Length - 1)) //if the slot is out of range then dont save
|
||||||
|
|
@ -1116,6 +1123,10 @@ namespace TShockAPI
|
||||||
this.inventory[slot] = new NetItem(netID, stack, prefix);
|
this.inventory[slot] = new NetItem(netID, stack, prefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Copies a characters data to this object
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="player"></param>
|
||||||
public void CopyCharacter(TSPlayer player)
|
public void CopyCharacter(TSPlayer player)
|
||||||
{
|
{
|
||||||
this.health = player.TPlayer.statLife > 0 ? player.TPlayer.statLife : 1;
|
this.health = player.TPlayer.statLife > 0 ? player.TPlayer.statLife : 1;
|
||||||
|
|
@ -1192,6 +1203,7 @@ namespace TShockAPI
|
||||||
NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots +
|
NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots +
|
||||||
NetItem.MiscDyeSlots + NetItem.PiggySlots)
|
NetItem.MiscDyeSlots + NetItem.PiggySlots)
|
||||||
{
|
{
|
||||||
|
//98-138
|
||||||
var index = i - (NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots
|
var index = i - (NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots
|
||||||
+ NetItem.MiscEquipSlots + NetItem.MiscDyeSlots);
|
+ NetItem.MiscEquipSlots + NetItem.MiscDyeSlots);
|
||||||
this.inventory[i] = (NetItem)piggy[index];
|
this.inventory[i] = (NetItem)piggy[index];
|
||||||
|
|
@ -1200,17 +1212,23 @@ namespace TShockAPI
|
||||||
NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots +
|
NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots + NetItem.MiscEquipSlots +
|
||||||
NetItem.MiscDyeSlots + NetItem.PiggySlots + NetItem.SafeSlots)
|
NetItem.MiscDyeSlots + NetItem.PiggySlots + NetItem.SafeSlots)
|
||||||
{
|
{
|
||||||
|
//138-178
|
||||||
var index = i - (NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots
|
var index = i - (NetItem.InventorySlots + NetItem.ArmorSlots + NetItem.DyeSlots
|
||||||
+ NetItem.MiscEquipSlots + NetItem.MiscDyeSlots + NetItem.PiggySlots);
|
+ NetItem.MiscEquipSlots + NetItem.MiscDyeSlots + NetItem.PiggySlots);
|
||||||
this.inventory[i] = (NetItem)safe[index];
|
this.inventory[i] = (NetItem)safe[index];
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
//179
|
||||||
this.inventory[i] = (NetItem)trash;
|
this.inventory[i] = (NetItem)trash;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Restores a player's character to the state stored in the database
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="player"></param>
|
||||||
public void RestoreCharacter(TSPlayer player)
|
public void RestoreCharacter(TSPlayer player)
|
||||||
{
|
{
|
||||||
// Start ignoring SSC-related packets! This is critical so that we don't send or receive dirty data!
|
// Start ignoring SSC-related packets! This is critical so that we don't send or receive dirty data!
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue