public static bool CreateEntity(Network.GamePackets.EnitityCreate eC, Client.GameState client, ref string message)
{
if (eC.Name.Length > 16)
eC.Name = eC.Name.Substring(0, 16);
if (eC.Name == "")
return false;
if (eC.Name == "ChestDemon") // Golden Secret
{
message = "Invalid characters inside the name.";
return false;
}
if (InvalidCharacters(eC.Name))
{
message = "Invalid characters inside the name.";
return false;
}
using (var rdr = new MySqlReader(new MySqlCommand(MySqlCommandType.SELECT).Select("entities").Where("name", eC.Name)))
{
if (rdr.Read())
{
message = "The chosen name is already in use.";
return false;
}
}
client.Entity = new Game.Entity(Game.EntityFlag.Player, false);
client.Entity.Name = eC.Name;
switch (eC.Class)
{
case 0:
case 1: eC.Class = 100; break;
case 2:
case 3: eC.Class = 10; break;
case 4:
case 5: eC.Class = 40; break;
case 6:
case 7: eC.Class = 20; break;
case 8:
case 9: eC.Class = 50; break;
case 10:
case 11: eC.Class = 60; break;
case 12:
case 13: eC.Class = 70; break;
case 14:
case 15: eC.Class = 80; break;
default: { Console.WriteLine("Error Class = " + eC.Class); } break;
}
DataHolder.GetStats(eC.Class, 1, client);
client.CalculateStatBonus();
client.CalculateHPBonus();
client.Entity.Hitpoints = client.Entity.MaxHitpoints;
client.Entity.Mana = (ushort)(client.Entity.Spirit * 5);
client.Entity.Class = eC.Class;
client.Entity.Body = eC.Body;
#region LookFace Dragon-Warrior
if (eC.Body == 1003 || eC.Body == 1004 && eC.Class >= 80 && eC.Class <= 85)
{
client.Entity.Face = (ushort)Kernel.Random.Next(164, 168);
}
if (eC.Body == 2001 || eC.Body == 2002 && eC.Class >= 80 && eC.Class <= 85)
{
client.Entity.Face = (ushort)Kernel.Random.Next(355, 359);
}
#endregion
#region LookFace Monk
if (eC.Body == 1003 || eC.Body == 1004 && eC.Class >= 60 && eC.Class <= 65)
{
client.Entity.Face = (ushort)Kernel.Random.Next(109, 113);
}
if (eC.Body == 2001 || eC.Body == 2002 && eC.Class >= 60 && eC.Class <= 65)
{
client.Entity.Face = (ushort)Kernel.Random.Next(300, 304);
}
#endregion
#region LookFace Ninja
if (eC.Body == 1003 || eC.Body == 1004 && eC.Class >= 50 && eC.Class <= 55)
{
client.Entity.Face = (ushort)Kernel.Random.Next(103, 107);
}
if (eC.Body == 2001 || eC.Body == 2002 && eC.Class >= 50 && eC.Class <= 55)
{
client.Entity.Face = (ushort)Kernel.Random.Next(291, 295);
}
#endregion
#region LookFace Pirate
if (eC.Body == 1003 || eC.Body == 1004 && eC.Class >= 70 && eC.Class <= 75)
{
client.Entity.Face = (ushort)Kernel.Random.Next(154, 158);
}
if (eC.Body == 2001 || eC.Body == 2002 && eC.Class >= 70 && eC.Class <= 75)
{
client.Entity.Face = (ushort)Kernel.Random.Next(345, 349);
}
#endregion
#region LookFace WindWalker
if (eC.Body == 1003 || eC.Body == 1004 && eC.Class >= 160 && eC.Class <= 165)
{
client.Entity.Face = (ushort)Kernel.Random.Next(174, 178);
}
if (eC.Body == 2001 || eC.Body == 2002 && eC.Class >= 160 && eC.Class <= 165)
{
client.Entity.Face = (ushort)Kernel.Random.Next(365, 369);
}
#endregion
//if (eC.Body == 1003 || eC.Body == 1004)
// client.Entity.Face = (ushort)Kernel.Random.Next(1, 50);
//else
// client.Entity.Face = (ushort)Kernel.Random.Next(201, 250);
byte Color = (byte)Kernel.Random.Next(4, 8);
client.Entity.HairStyle = (ushort)(Color * 100 + 10 + (byte)Kernel.Random.Next(4, 9));
client.Entity.UID = Server.EntityUID.Next;
client.Entity.JustCreated = true;
while (true)
{
using (var cmd = new MySqlCommand(MySqlCommandType.SELECT).Select("entities").Where("uid", client.Entity.UID))
using (var reader = cmd.CreateReader())
{
if (reader.Read())
client.Entity.UID = Server.EntityUID.Next;
else
break;
}
}
while (true)
{
try
{
using (var cmd = new MySqlCommand(MySqlCommandType.INSERT))
cmd.Insert("entities").Insert("Name", eC.Name).Insert("Owner", client.Account.Username).Insert("Class", eC.Class).Insert("UID", client.Entity.UID)
.Insert("Hitpoints", client.Entity.Hitpoints).Insert("Mana", client.Entity.Mana).Insert("Body", client.Entity.Body)
.Insert("Face", client.Entity.Face).Insert("HairStyle", client.Entity.HairStyle).Insert("Strength", client.Entity.Strength)
.Insert("WarehousePW", "").Insert("Agility", client.Entity.Agility).Insert("Vitality", client.Entity.Vitality).Insert("Spirit", client.Entity.Spirit)
.Insert("Windwalker", client.Entity.Windwalker)
.Execute();
message = "ANSWER_OK";
break;
}
catch
{
client.Entity.UID = Server.EntityUID.Next;
}
}
using (var cmd = new MySqlCommand(MySqlCommandType.UPDATE).Update("configuration").Set("EntityID", client.Entity.UID).Where("Server", Constants.ServerName))
cmd.Execute();
client.Account.EntityID = client.Entity.UID;
client.Account.Save();
return true;
}