Untitled


SUBMITTED BY: Guest

DATE: Aug. 20, 2017, 10:24 p.m.

FORMAT: Text only

SIZE: 6.9 kB

HITS: 535

  1. public static bool CreateEntity(Network.GamePackets.EnitityCreate eC, Client.GameState client, ref string message)
  2. {
  3. if (eC.Name.Length > 16)
  4. eC.Name = eC.Name.Substring(0, 16);
  5. if (eC.Name == "")
  6. return false;
  7. if (eC.Name == "ChestDemon") // Golden Secret
  8. {
  9. message = "Invalid characters inside the name.";
  10. return false;
  11. }
  12. if (InvalidCharacters(eC.Name))
  13. {
  14. message = "Invalid characters inside the name.";
  15. return false;
  16. }
  17. using (var rdr = new MySqlReader(new MySqlCommand(MySqlCommandType.SELECT).Select("entities").Where("name", eC.Name)))
  18. {
  19. if (rdr.Read())
  20. {
  21. message = "The chosen name is already in use.";
  22. return false;
  23. }
  24. }
  25. client.Entity = new Game.Entity(Game.EntityFlag.Player, false);
  26. client.Entity.Name = eC.Name;
  27. switch (eC.Class)
  28. {
  29. case 0:
  30. case 1: eC.Class = 100; break;
  31. case 2:
  32. case 3: eC.Class = 10; break;
  33. case 4:
  34. case 5: eC.Class = 40; break;
  35. case 6:
  36. case 7: eC.Class = 20; break;
  37. case 8:
  38. case 9: eC.Class = 50; break;
  39. case 10:
  40. case 11: eC.Class = 60; break;
  41. case 12:
  42. case 13: eC.Class = 70; break;
  43. case 14:
  44. case 15: eC.Class = 80; break;
  45. default: { Console.WriteLine("Error Class = " + eC.Class); } break;
  46. }
  47. DataHolder.GetStats(eC.Class, 1, client);
  48. client.CalculateStatBonus();
  49. client.CalculateHPBonus();
  50. client.Entity.Hitpoints = client.Entity.MaxHitpoints;
  51. client.Entity.Mana = (ushort)(client.Entity.Spirit * 5);
  52. client.Entity.Class = eC.Class;
  53. client.Entity.Body = eC.Body;
  54. #region LookFace Dragon-Warrior
  55. if (eC.Body == 1003 || eC.Body == 1004 && eC.Class >= 80 && eC.Class <= 85)
  56. {
  57. client.Entity.Face = (ushort)Kernel.Random.Next(164, 168);
  58. }
  59. if (eC.Body == 2001 || eC.Body == 2002 && eC.Class >= 80 && eC.Class <= 85)
  60. {
  61. client.Entity.Face = (ushort)Kernel.Random.Next(355, 359);
  62. }
  63. #endregion
  64. #region LookFace Monk
  65. if (eC.Body == 1003 || eC.Body == 1004 && eC.Class >= 60 && eC.Class <= 65)
  66. {
  67. client.Entity.Face = (ushort)Kernel.Random.Next(109, 113);
  68. }
  69. if (eC.Body == 2001 || eC.Body == 2002 && eC.Class >= 60 && eC.Class <= 65)
  70. {
  71. client.Entity.Face = (ushort)Kernel.Random.Next(300, 304);
  72. }
  73. #endregion
  74. #region LookFace Ninja
  75. if (eC.Body == 1003 || eC.Body == 1004 && eC.Class >= 50 && eC.Class <= 55)
  76. {
  77. client.Entity.Face = (ushort)Kernel.Random.Next(103, 107);
  78. }
  79. if (eC.Body == 2001 || eC.Body == 2002 && eC.Class >= 50 && eC.Class <= 55)
  80. {
  81. client.Entity.Face = (ushort)Kernel.Random.Next(291, 295);
  82. }
  83. #endregion
  84. #region LookFace Pirate
  85. if (eC.Body == 1003 || eC.Body == 1004 && eC.Class >= 70 && eC.Class <= 75)
  86. {
  87. client.Entity.Face = (ushort)Kernel.Random.Next(154, 158);
  88. }
  89. if (eC.Body == 2001 || eC.Body == 2002 && eC.Class >= 70 && eC.Class <= 75)
  90. {
  91. client.Entity.Face = (ushort)Kernel.Random.Next(345, 349);
  92. }
  93. #endregion
  94. #region LookFace WindWalker
  95. if (eC.Body == 1003 || eC.Body == 1004 && eC.Class >= 160 && eC.Class <= 165)
  96. {
  97. client.Entity.Face = (ushort)Kernel.Random.Next(174, 178);
  98. }
  99. if (eC.Body == 2001 || eC.Body == 2002 && eC.Class >= 160 && eC.Class <= 165)
  100. {
  101. client.Entity.Face = (ushort)Kernel.Random.Next(365, 369);
  102. }
  103. #endregion
  104. //if (eC.Body == 1003 || eC.Body == 1004)
  105. // client.Entity.Face = (ushort)Kernel.Random.Next(1, 50);
  106. //else
  107. // client.Entity.Face = (ushort)Kernel.Random.Next(201, 250);
  108. byte Color = (byte)Kernel.Random.Next(4, 8);
  109. client.Entity.HairStyle = (ushort)(Color * 100 + 10 + (byte)Kernel.Random.Next(4, 9));
  110. client.Entity.UID = Server.EntityUID.Next;
  111. client.Entity.JustCreated = true;
  112. while (true)
  113. {
  114. using (var cmd = new MySqlCommand(MySqlCommandType.SELECT).Select("entities").Where("uid", client.Entity.UID))
  115. using (var reader = cmd.CreateReader())
  116. {
  117. if (reader.Read())
  118. client.Entity.UID = Server.EntityUID.Next;
  119. else
  120. break;
  121. }
  122. }
  123. while (true)
  124. {
  125. try
  126. {
  127. using (var cmd = new MySqlCommand(MySqlCommandType.INSERT))
  128. cmd.Insert("entities").Insert("Name", eC.Name).Insert("Owner", client.Account.Username).Insert("Class", eC.Class).Insert("UID", client.Entity.UID)
  129. .Insert("Hitpoints", client.Entity.Hitpoints).Insert("Mana", client.Entity.Mana).Insert("Body", client.Entity.Body)
  130. .Insert("Face", client.Entity.Face).Insert("HairStyle", client.Entity.HairStyle).Insert("Strength", client.Entity.Strength)
  131. .Insert("WarehousePW", "").Insert("Agility", client.Entity.Agility).Insert("Vitality", client.Entity.Vitality).Insert("Spirit", client.Entity.Spirit)
  132. .Insert("Windwalker", client.Entity.Windwalker)
  133. .Execute();
  134. message = "ANSWER_OK";
  135. break;
  136. }
  137. catch
  138. {
  139. client.Entity.UID = Server.EntityUID.Next;
  140. }
  141. }
  142. using (var cmd = new MySqlCommand(MySqlCommandType.UPDATE).Update("configuration").Set("EntityID", client.Entity.UID).Where("Server", Constants.ServerName))
  143. cmd.Execute();
  144. client.Account.EntityID = client.Entity.UID;
  145. client.Account.Save();
  146. return true;
  147. }

comments powered by Disqus