DragonInfo.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. using System.Drawing;
  2. using Server.MirEnvir;
  3. namespace Server.MirDatabase
  4. {
  5. public class DragonInfo
  6. {
  7. protected static Envir Envir
  8. {
  9. get { return Envir.Main; }
  10. }
  11. protected static MessageQueue MessageQueue
  12. {
  13. get { return MessageQueue.Instance; }
  14. }
  15. public bool Enabled;
  16. public string MapFileName, MonsterName, BodyName;
  17. public Point Location, DropAreaTop, DropAreaBottom;
  18. public List<DropInfo>[] Drops = new List<DropInfo>[Globals.MaxDragonLevel];
  19. public long[] Exps = new long[Globals.MaxDragonLevel - 1];
  20. public byte Level;
  21. public long Experience;
  22. public DragonInfo()
  23. {
  24. //Default values
  25. Enabled = false;
  26. MapFileName = "D2083";
  27. MonsterName = "Evil Mir";
  28. BodyName = "00";
  29. Location = new Point(82, 44);
  30. DropAreaTop = new Point(75, 45);
  31. DropAreaBottom = new Point(86, 57);
  32. Level = 1;
  33. for (int i = 0; i < Exps.Length; i++)
  34. {
  35. Exps[i] = (i + 1) * 10000;
  36. }
  37. for (int i = 0; i < Drops.Length; i++)
  38. {
  39. Drops[i] = new List<DropInfo>();
  40. }
  41. }
  42. public DragonInfo(BinaryReader reader)
  43. {
  44. Enabled = reader.ReadBoolean();
  45. MapFileName = reader.ReadString();
  46. MonsterName = reader.ReadString();
  47. BodyName = reader.ReadString();
  48. Location = new Point(reader.ReadInt32(), reader.ReadInt32());
  49. DropAreaTop = new Point(reader.ReadInt32(), reader.ReadInt32());
  50. DropAreaBottom = new Point(reader.ReadInt32(), reader.ReadInt32());
  51. Level = 1;
  52. for (int i = 0; i < Exps.Length; i++)
  53. {
  54. Exps[i] = reader.ReadInt64();
  55. }
  56. for (int i = 0; i < Drops.Length; i++)
  57. {
  58. Drops[i] = new List<DropInfo>();
  59. }
  60. }
  61. public void Save(BinaryWriter writer)
  62. {
  63. writer.Write(Enabled);
  64. writer.Write(MapFileName);
  65. writer.Write(MonsterName);
  66. writer.Write(BodyName);
  67. writer.Write(Location.X);
  68. writer.Write(Location.Y);
  69. writer.Write(DropAreaTop.X);
  70. writer.Write(DropAreaTop.Y);
  71. writer.Write(DropAreaBottom.X);
  72. writer.Write(DropAreaBottom.Y);
  73. for (int i = 0; i < Exps.Length; i++)
  74. {
  75. writer.Write(Exps[i]);
  76. }
  77. }
  78. public void LoadDrops()
  79. {
  80. for (int i = 0; i < Globals.MaxDragonLevel; i++) Drops[i].Clear();
  81. string path = Path.Combine(Settings.DropPath, "DragonItem.txt");
  82. if (!File.Exists(path))
  83. {
  84. string[] contents = new[]
  85. {
  86. ";Pots + Other", string.Empty, string.Empty,
  87. ";Weapons", string.Empty, string.Empty,
  88. ";Armour", string.Empty, string.Empty,
  89. ";Helmets", string.Empty, string.Empty,
  90. ";Necklace", string.Empty, string.Empty,
  91. ";Bracelets", string.Empty, string.Empty,
  92. ";Rings", string.Empty, string.Empty,
  93. ";Shoes", string.Empty, string.Empty,
  94. ";Belts", string.Empty, string.Empty,
  95. ";Stone",
  96. };
  97. File.WriteAllLines(path, contents);
  98. return;
  99. }
  100. string[] lines = File.ReadAllLines(path);
  101. for (int i = 0; i < lines.Length; i++)
  102. {
  103. if (lines[i].StartsWith(";") || string.IsNullOrWhiteSpace(lines[i])) continue;
  104. DropInfo drop = DropInfo.FromLine(lines[i]);
  105. if (drop == null)
  106. {
  107. MessageQueue.Enqueue(GameLanguage.ServerTextMap.GetLocalization((ServerTextKeys.CouldNotLoadDropDragonItem), lines[i]));
  108. continue;
  109. }
  110. if (drop.level <= 0 || drop.level > Globals.MaxDragonLevel) return;
  111. Drops[drop.level - 1].Add(drop);
  112. }
  113. for (int i = 0; i < Globals.MaxDragonLevel; i++)
  114. {
  115. Drops[i].Sort((drop1, drop2) =>
  116. {
  117. if (drop1.Gold > 0 && drop2.Gold == 0)
  118. return 1;
  119. if (drop1.Gold == 0 && drop2.Gold > 0)
  120. return -1;
  121. return drop1.Item.Type.CompareTo(drop2.Item.Type);
  122. });
  123. }
  124. }
  125. public class DropInfo
  126. {
  127. public int Chance;
  128. public ItemInfo Item;
  129. public uint Gold;
  130. public byte level;
  131. public static DropInfo FromLine(string s)
  132. {
  133. string[] parts = s.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
  134. DropInfo info = new DropInfo();
  135. if (!int.TryParse(parts[0].Substring(2), out info.Chance)) return null;
  136. if (string.Compare(parts[1], "Gold", StringComparison.OrdinalIgnoreCase) == 0)
  137. {
  138. if (parts.Length < 4) return null;
  139. if (!uint.TryParse(parts[2], out info.Gold) || info.Gold == 0) return null;
  140. if (!byte.TryParse(parts[3], out info.level)) return null;
  141. }
  142. else
  143. {
  144. if (parts.Length < 3) return null;
  145. info.Item = Envir.GetItemInfo(parts[1]);
  146. if (info.Item == null) return null;
  147. if (!byte.TryParse(parts[2], out info.level)) return null;
  148. }
  149. return info;
  150. }
  151. }
  152. }
  153. }