Initial handling for saving/using beds with SSC
This commit is contained in:
parent
5b30cffaa7
commit
48a94b6247
4 changed files with 61 additions and 15 deletions
|
|
@ -36,7 +36,9 @@ namespace TShockAPI.DB
|
|||
new SqlColumn("MaxHealth", MySqlDbType.Int32),
|
||||
new SqlColumn("Mana", MySqlDbType.Int32),
|
||||
new SqlColumn("MaxMana", MySqlDbType.Int32),
|
||||
new SqlColumn("Inventory", MySqlDbType.Text)
|
||||
new SqlColumn("Inventory", MySqlDbType.Text),
|
||||
new SqlColumn("spawnX", MySqlDbType.Int32),
|
||||
new SqlColumn("spawnY", MySqlDbType.Int32)
|
||||
);
|
||||
var creator = new SqlTableCreator(db,
|
||||
db.GetSqlType() == SqlType.Sqlite
|
||||
|
|
@ -61,6 +63,8 @@ namespace TShockAPI.DB
|
|||
playerData.mana = reader.Get<int>("Mana");
|
||||
playerData.maxMana = reader.Get<int>("MaxMana");
|
||||
playerData.inventory = NetItem.Parse(reader.Get<string>("Inventory"));
|
||||
playerData.spawnX = reader.Get<int>("spawnX");
|
||||
playerData.spawnY = reader.Get<int>("spawnY");
|
||||
return playerData;
|
||||
}
|
||||
}
|
||||
|
|
@ -78,8 +82,8 @@ namespace TShockAPI.DB
|
|||
string initialItems = "-15,1,0~-13,1,0~-16,1,45~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0~0,0,0";
|
||||
try
|
||||
{
|
||||
database.Query("INSERT INTO tsCharacter (Account, Health, MaxHealth, Mana, MaxMana, Inventory) VALUES (@0, @1, @2, @3, @4, @5);", user.ID,
|
||||
100, 100, 20, 20, initialItems);
|
||||
database.Query("INSERT INTO tsCharacter (Account, Health, MaxHealth, Mana, MaxMana, Inventory, spawnX, spawnY) VALUES (@0, @1, @2, @3, @4, @5, @6, @7);", user.ID,
|
||||
100, 100, 20, 20, initialItems, -1, -1);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -93,16 +97,17 @@ namespace TShockAPI.DB
|
|||
public bool InsertPlayerData(TSPlayer player)
|
||||
{
|
||||
PlayerData playerData = player.PlayerData;
|
||||
|
||||
|
||||
if (!player.IsLoggedIn)
|
||||
return false;
|
||||
|
||||
|
||||
|
||||
if (!GetPlayerData(player, player.UserID).exists)
|
||||
{
|
||||
try
|
||||
{
|
||||
database.Query("INSERT INTO tsCharacter (Account, Health, MaxHealth, Mana, MaxMana, Inventory) VALUES (@0, @1, @2, @3, @4, @5);", player.UserID,
|
||||
playerData.health, playerData.maxHealth, playerData.mana, playerData.maxMana, NetItem.ToString(playerData.inventory));
|
||||
database.Query("INSERT INTO tsCharacter (Account, Health, MaxHealth, Mana, MaxMana, Inventory) 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);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
@ -114,8 +119,8 @@ namespace TShockAPI.DB
|
|||
{
|
||||
try
|
||||
{
|
||||
database.Query("UPDATE tsCharacter SET Health = @0, MaxHealth = @1, Mana = @2, MaxMana = @3, Inventory = @4 WHERE Account = @5;", playerData.health, playerData.maxHealth,
|
||||
playerData.mana, playerData.maxMana, NetItem.ToString(playerData.inventory), player.UserID);
|
||||
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);
|
||||
return true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
|
|
|
|||
|
|
@ -2704,6 +2704,11 @@ namespace TShockAPI
|
|||
else
|
||||
args.Player.InitSpawn = true;
|
||||
|
||||
if ((TShock.Config.ServerSideCharacter) && (args.Player.sX > 0) && (args.Player.sY > 0))
|
||||
{
|
||||
args.Player.Teleport(args.Player.sX * 16, (args.Player.sY * 16) -48);
|
||||
}
|
||||
|
||||
args.Player.Dead = false;
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,6 +69,10 @@ namespace TShockAPI
|
|||
|
||||
public int RPPending = 0;
|
||||
|
||||
public int sX = -1;
|
||||
public int sY = -1;
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// A queue of tiles destroyed by the player for reverting.
|
||||
/// </summary>
|
||||
|
|
@ -297,8 +301,8 @@ namespace TShockAPI
|
|||
/// Players controls are inverted if using SSC
|
||||
/// </summary>
|
||||
public bool Confused = false;
|
||||
|
||||
/// <summary>
|
||||
|
||||
/// <summary>
|
||||
/// Whether the player is a real, human, player on the server.
|
||||
/// </summary>
|
||||
public bool RealPlayer
|
||||
|
|
@ -590,9 +594,16 @@ namespace TShockAPI
|
|||
}
|
||||
|
||||
public void Spawn()
|
||||
{
|
||||
TPlayer.FindSpawn();
|
||||
Spawn(TPlayer.SpawnX, TPlayer.SpawnY);
|
||||
{
|
||||
// TPlayer.FindSpawn();
|
||||
if (this.sX > 0 && this.sY > 0)
|
||||
{
|
||||
Spawn(this.sX, this.sY);
|
||||
}
|
||||
else
|
||||
{
|
||||
Spawn(TPlayer.SpawnX, TPlayer.SpawnY);
|
||||
}
|
||||
}
|
||||
|
||||
public void Spawn(int tilex, int tiley)
|
||||
|
|
@ -1026,6 +1037,9 @@ namespace TShockAPI
|
|||
public int mana = 20;
|
||||
public int maxMana = 20;
|
||||
public bool exists;
|
||||
public int spawnX= -1;
|
||||
public int spawnY= -1;
|
||||
|
||||
|
||||
public PlayerData(TSPlayer player)
|
||||
{
|
||||
|
|
@ -1045,6 +1059,7 @@ namespace TShockAPI
|
|||
this.inventory[2].stack = 1;
|
||||
if (player.TPlayer.inventory[2] != null && player.TPlayer.inventory[2].netID == -16)
|
||||
this.inventory[2].prefix = player.TPlayer.inventory[2].prefix;
|
||||
|
||||
}
|
||||
|
||||
public void StoreSlot(int slot, int netID, int prefix, int stack)
|
||||
|
|
@ -1073,6 +1088,16 @@ namespace TShockAPI
|
|||
this.maxHealth = player.TPlayer.statLifeMax;
|
||||
this.mana = player.TPlayer.statMana;
|
||||
this.maxMana = player.TPlayer.statManaMax;
|
||||
if (player.sX > 0 && player.sY > 0)
|
||||
{
|
||||
this.spawnX = player.sX;
|
||||
this.spawnY = player.sY;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.spawnX = player.TPlayer.SpawnX;
|
||||
this.spawnY = player.TPlayer.SpawnY;
|
||||
}
|
||||
Item[] inventory = player.TPlayer.inventory;
|
||||
Item[] armor = player.TPlayer.armor;
|
||||
Item[] dye = player.TPlayer.dye;
|
||||
|
|
@ -1155,6 +1180,11 @@ namespace TShockAPI
|
|||
player.TPlayer.statLifeMax = this.maxHealth;
|
||||
player.TPlayer.statMana = this.maxMana;
|
||||
player.TPlayer.statManaMax = this.maxMana;
|
||||
player.TPlayer.SpawnX = this.spawnX;
|
||||
player.TPlayer.SpawnY = this.spawnY;
|
||||
player.sX = this.spawnX;
|
||||
player.sY = this.spawnY;
|
||||
|
||||
for (int i = 0; i < NetItem.maxNetInventory; i++)
|
||||
{
|
||||
if (i < NetItem.maxNetInventory - (NetItem.armorSlots + NetItem.dyeSlots))
|
||||
|
|
|
|||
|
|
@ -684,7 +684,13 @@ namespace TShockAPI
|
|||
|
||||
if (player.RecentFuse >0)
|
||||
player.RecentFuse--;
|
||||
|
||||
|
||||
if ((TShock.Config.ServerSideCharacter) && (player.sX > 0) && (player.sY > 0))
|
||||
{
|
||||
player.TPlayer.SpawnX=player.sX;
|
||||
player.TPlayer.SpawnY=player.sY;
|
||||
}
|
||||
|
||||
if (player.RPPending >0)
|
||||
{
|
||||
if (player.RPPending == 1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue