-SSC now saves player hair, hair color, hair dye, cloth colors and accessory visibility.
-Fixed hair changes now showing up to other players ingame.
This commit is contained in:
parent
2a62bf84df
commit
39a81cfa66
5 changed files with 132 additions and 5 deletions
|
|
@ -19,6 +19,7 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
using System;
|
||||
using System.Data;
|
||||
using MySql.Data.MySqlClient;
|
||||
using Terraria;
|
||||
|
||||
namespace TShockAPI.DB
|
||||
{
|
||||
|
|
@ -38,7 +39,15 @@ namespace TShockAPI.DB
|
|||
new SqlColumn("MaxMana", MySqlDbType.Int32),
|
||||
new SqlColumn("Inventory", MySqlDbType.Text),
|
||||
new SqlColumn("spawnX", MySqlDbType.Int32),
|
||||
new SqlColumn("spawnY", MySqlDbType.Int32)
|
||||
new SqlColumn("spawnY", MySqlDbType.Int32),
|
||||
new SqlColumn("hair", MySqlDbType.Int32),
|
||||
new SqlColumn("hairDye", MySqlDbType.Int32),
|
||||
new SqlColumn("hairColor", MySqlDbType.Int32),
|
||||
new SqlColumn("pantsColor", MySqlDbType.Int32),
|
||||
new SqlColumn("shirtColor", MySqlDbType.Int32),
|
||||
new SqlColumn("underShirtColor", MySqlDbType.Int32),
|
||||
new SqlColumn("shoeColor", MySqlDbType.Int32),
|
||||
new SqlColumn("hideVisuals", MySqlDbType.Int32)
|
||||
);
|
||||
var creator = new SqlTableCreator(db,
|
||||
db.GetSqlType() == SqlType.Sqlite
|
||||
|
|
@ -65,6 +74,14 @@ namespace TShockAPI.DB
|
|||
playerData.inventory = NetItem.Parse(reader.Get<string>("Inventory"));
|
||||
playerData.spawnX = reader.Get<int>("spawnX");
|
||||
playerData.spawnY = reader.Get<int>("spawnY");
|
||||
playerData.hair = reader.Get<int?>("hair");
|
||||
playerData.hairDye = (byte)reader.Get<int>("hairDye");
|
||||
playerData.hairColor = TShock.Utils.DecodeColor(reader.Get<int?>("hairColor"));
|
||||
playerData.pantsColor = TShock.Utils.DecodeColor(reader.Get<int?>("pantsColor"));
|
||||
playerData.shirtColor = TShock.Utils.DecodeColor(reader.Get<int?>("shirtColor"));
|
||||
playerData.underShirtColor = TShock.Utils.DecodeColor(reader.Get<int?>("underShirtColor"));
|
||||
playerData.shoeColor = TShock.Utils.DecodeColor(reader.Get<int?>("shoeColor"));
|
||||
playerData.hideVisuals = TShock.Utils.DecodeBitsByte(reader.Get<int?>("hideVisuals"));
|
||||
return playerData;
|
||||
}
|
||||
}
|
||||
|
|
@ -106,8 +123,8 @@ namespace TShockAPI.DB
|
|||
{
|
||||
try
|
||||
{
|
||||
database.Query("INSERT INTO tsCharacter (Account, Health, MaxHealth, Mana, MaxMana, Inventory, spawnX, spawnY) VALUES (@0, @1, @2, @3, @4, @5, @6, @7);", player.UserID,
|
||||
playerData.health, playerData.maxHealth, playerData.mana, playerData.maxMana, NetItem.ToString(playerData.inventory), player.TPlayer.SpawnX, player.TPlayer.SpawnY);
|
||||
database.Query("INSERT INTO tsCharacter (Account, Health, MaxHealth, Mana, MaxMana, Inventory, spawnX, spawnY, hair, hairDye, hairColor, pantsColor, shirtColor, underShirtColor, shoeColor, hideVisuals) VALUES (@0, @1, @2, @3, @4, @5, @6, @7, @8, @9, @10, @11, @12, @13, @14);", player.UserID,
|
||||
playerData.health, playerData.maxHealth, playerData.mana, playerData.maxMana, NetItem.ToString(playerData.inventory), player.TPlayer.SpawnX, player.TPlayer.SpawnY, player.TPlayer.hair, player.TPlayer.hairDye, TShock.Utils.EncodeColor(player.TPlayer.hairColor), TShock.Utils.EncodeColor(player.TPlayer.pantsColor), TShock.Utils.EncodeColor(player.TPlayer.shirtColor), TShock.Utils.EncodeColor(player.TPlayer.underShirtColor), TShock.Utils.EncodeColor(player.TPlayer.shoeColor), TShock.Utils.EncodeBitsByte(player.TPlayer.hideVisual));
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -119,8 +136,8 @@ namespace TShockAPI.DB
|
|||
{
|
||||
try
|
||||
{
|
||||
database.Query("UPDATE tsCharacter SET Health = @0, MaxHealth = @1, Mana = @2, MaxMana = @3, Inventory = @4, spawnX = @6, spawnY = @7 WHERE Account = @5;", playerData.health, playerData.maxHealth,
|
||||
playerData.mana, playerData.maxMana, NetItem.ToString(playerData.inventory), player.UserID, player.TPlayer.SpawnX, player.TPlayer.SpawnY);
|
||||
database.Query("UPDATE tsCharacter SET Health = @0, MaxHealth = @1, Mana = @2, MaxMana = @3, Inventory = @4, spawnX = @6, spawnY = @7, hair = @8, hairDye = @9, hairColor = @10, pantsColor = @11, shirtColor = @12, underShirtColor = @13, shoeColor = @14, hideVisuals = @15 WHERE Account = @5;", playerData.health, playerData.maxHealth,
|
||||
playerData.mana, playerData.maxMana, NetItem.ToString(playerData.inventory), player.UserID, player.TPlayer.SpawnX, player.TPlayer.SpawnY, player.TPlayer.hair, player.TPlayer.hairDye, TShock.Utils.EncodeColor(player.TPlayer.hairColor), TShock.Utils.EncodeColor(player.TPlayer.pantsColor), TShock.Utils.EncodeColor(player.TPlayer.shirtColor), TShock.Utils.EncodeColor(player.TPlayer.underShirtColor), TShock.Utils.EncodeColor(player.TPlayer.shoeColor), TShock.Utils.EncodeBitsByte(player.TPlayer.hideVisual));
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
|||
|
|
@ -118,22 +118,42 @@ namespace TShockAPI.DB
|
|||
typeof (bool),
|
||||
(s, i) => s.GetBoolean(i)
|
||||
},
|
||||
{
|
||||
typeof (bool?),
|
||||
(s, i) => s.IsDBNull(i) ? null : (object)s.GetBoolean(i)
|
||||
},
|
||||
{
|
||||
typeof (byte),
|
||||
(s, i) => s.GetByte(i)
|
||||
},
|
||||
{
|
||||
typeof (byte?),
|
||||
(s, i) => s.IsDBNull(i) ? null : (object)s.GetByte(i)
|
||||
},
|
||||
{
|
||||
typeof (Int16),
|
||||
(s, i) => s.GetInt16(i)
|
||||
},
|
||||
{
|
||||
typeof (Int16?),
|
||||
(s, i) => s.IsDBNull(i) ? null : (object)s.GetInt16(i)
|
||||
},
|
||||
{
|
||||
typeof (Int32),
|
||||
(s, i) => s.GetInt32(i)
|
||||
},
|
||||
{
|
||||
typeof (Int32?),
|
||||
(s, i) => s.IsDBNull(i) ? null : (object)s.GetInt32(i)
|
||||
},
|
||||
{
|
||||
typeof (Int64),
|
||||
(s, i) => s.GetInt64(i)
|
||||
},
|
||||
{
|
||||
typeof (Int64?),
|
||||
(s, i) => s.IsDBNull(i) ? null : (object)s.GetInt64(i)
|
||||
},
|
||||
{
|
||||
typeof (string),
|
||||
(s, i) => s.GetString(i)
|
||||
|
|
@ -142,14 +162,26 @@ namespace TShockAPI.DB
|
|||
typeof (decimal),
|
||||
(s, i) => s.GetDecimal(i)
|
||||
},
|
||||
{
|
||||
typeof (decimal?),
|
||||
(s, i) => s.IsDBNull(i) ? null : (object)s.GetDecimal(i)
|
||||
},
|
||||
{
|
||||
typeof (float),
|
||||
(s, i) => s.GetFloat(i)
|
||||
},
|
||||
{
|
||||
typeof (float?),
|
||||
(s, i) => s.IsDBNull(i) ? null : (object)s.GetFloat(i)
|
||||
},
|
||||
{
|
||||
typeof (double),
|
||||
(s, i) => s.GetDouble(i)
|
||||
},
|
||||
{
|
||||
typeof (double?),
|
||||
(s, i) => s.IsDBNull(i) ? null : (object)s.GetDouble(i)
|
||||
},
|
||||
{
|
||||
typeof (object),
|
||||
(s, i) => s.GetValue(i)
|
||||
|
|
|
|||
|
|
@ -1405,6 +1405,7 @@ namespace TShockAPI
|
|||
if (args.Player.ReceivedInfo)
|
||||
{
|
||||
// Since Terraria 1.2.3 these character properties can change ingame.
|
||||
args.Player.TPlayer.hair = hair;
|
||||
args.Player.TPlayer.hairColor = hairColor;
|
||||
args.Player.TPlayer.hairDye = hairDye;
|
||||
args.Player.TPlayer.pantsColor = pantsColor;
|
||||
|
|
|
|||
|
|
@ -1274,6 +1274,14 @@ namespace TShockAPI
|
|||
public bool exists;
|
||||
public int spawnX= -1;
|
||||
public int spawnY= -1;
|
||||
public int? hair;
|
||||
public byte hairDye;
|
||||
public Color? hairColor;
|
||||
public Color? pantsColor;
|
||||
public Color? shirtColor;
|
||||
public Color? underShirtColor;
|
||||
public Color? shoeColor;
|
||||
public BitsByte? hideVisuals;
|
||||
|
||||
|
||||
public PlayerData(TSPlayer player)
|
||||
|
|
@ -1333,6 +1341,15 @@ namespace TShockAPI
|
|||
this.spawnX = player.TPlayer.SpawnX;
|
||||
this.spawnY = player.TPlayer.SpawnY;
|
||||
}
|
||||
this.hair = player.TPlayer.hair;
|
||||
this.hairDye = player.TPlayer.hairDye;
|
||||
this.hairColor = player.TPlayer.hairColor;
|
||||
this.pantsColor = player.TPlayer.pantsColor;
|
||||
this.shirtColor = player.TPlayer.shirtColor;
|
||||
this.underShirtColor = player.TPlayer.underShirtColor;
|
||||
this.shoeColor = player.TPlayer.shoeColor;
|
||||
this.hideVisuals = player.TPlayer.hideVisual;
|
||||
|
||||
Item[] inventory = player.TPlayer.inventory;
|
||||
Item[] armor = player.TPlayer.armor;
|
||||
Item[] dye = player.TPlayer.dye;
|
||||
|
|
@ -1419,6 +1436,24 @@ namespace TShockAPI
|
|||
player.TPlayer.SpawnY = this.spawnY;
|
||||
player.sX = this.spawnX;
|
||||
player.sY = this.spawnY;
|
||||
player.TPlayer.hairDye = this.hairDye;
|
||||
|
||||
if (this.hair != null)
|
||||
player.TPlayer.hair = this.hair.Value;
|
||||
if (this.hairColor != null)
|
||||
player.TPlayer.hairColor = this.hairColor.Value;
|
||||
if (this.pantsColor != null)
|
||||
player.TPlayer.pantsColor = this.pantsColor.Value;
|
||||
if (this.shirtColor != null)
|
||||
player.TPlayer.shirtColor = this.shirtColor.Value;
|
||||
if (this.underShirtColor != null)
|
||||
player.TPlayer.underShirtColor = this.underShirtColor.Value;
|
||||
if (this.shoeColor != null)
|
||||
player.TPlayer.shoeColor = this.shoeColor.Value;
|
||||
if (this.hideVisuals != null)
|
||||
player.TPlayer.hideVisual = this.hideVisuals.Value;
|
||||
else
|
||||
player.TPlayer.hideVisual.ClearAll();
|
||||
|
||||
for (int i = 0; i < NetItem.maxNetInventory; i++)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -975,5 +975,47 @@ namespace TShockAPI
|
|||
yield return new Point(regionArea.Right, regionArea.Top + y);
|
||||
}
|
||||
}
|
||||
|
||||
public int? EncodeColor(Color? color)
|
||||
{
|
||||
if (color == null)
|
||||
return null;
|
||||
|
||||
return BitConverter.ToInt32(new[] { color.Value.R, color.Value.G, color.Value.B, color.Value.A }, 0);
|
||||
}
|
||||
|
||||
public Color? DecodeColor(int? encodedColor)
|
||||
{
|
||||
if (encodedColor == null)
|
||||
return null;
|
||||
|
||||
byte[] data = BitConverter.GetBytes(encodedColor.Value);
|
||||
return new Color(data[0], data[1], data[2], data[3]);
|
||||
}
|
||||
|
||||
public byte? EncodeBitsByte(BitsByte? bitsByte)
|
||||
{
|
||||
if (bitsByte == null)
|
||||
return null;
|
||||
|
||||
byte result = 0;
|
||||
for (int i = 0; i < 8; i++)
|
||||
if (bitsByte.Value[i])
|
||||
result |= (byte)(1 << i);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public BitsByte? DecodeBitsByte(int? encodedBitsByte)
|
||||
{
|
||||
if (encodedBitsByte == null)
|
||||
return null;
|
||||
|
||||
BitsByte result = new BitsByte();
|
||||
for (int i = 0; i < 8; i++)
|
||||
result[i] = (encodedBitsByte & 1 << i) != 0;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue