RespawnInfo.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. using System.Drawing;
  2. using Server.MirEnvir;
  3. namespace Server.MirDatabase
  4. {
  5. public class RespawnInfo
  6. {
  7. protected static Envir Envir
  8. {
  9. get { return Envir.Main; }
  10. }
  11. public int MonsterIndex;
  12. public Point Location;
  13. public ushort Count, Spread, Delay, RandomDelay;
  14. public byte Direction;
  15. public string RoutePath = string.Empty;
  16. public int RespawnIndex;
  17. public bool SaveRespawnTime = false;
  18. public ushort RespawnTicks; //leave 0 if not using this system!
  19. public RespawnInfo()
  20. {
  21. }
  22. public RespawnInfo(BinaryReader reader, int Version, int Customversion)
  23. {
  24. MonsterIndex = reader.ReadInt32();
  25. Location = new Point(reader.ReadInt32(), reader.ReadInt32());
  26. Count = reader.ReadUInt16();
  27. Spread = reader.ReadUInt16();
  28. Delay = reader.ReadUInt16();
  29. Direction = reader.ReadByte();
  30. RoutePath = reader.ReadString();
  31. if (Version > 67)
  32. {
  33. RandomDelay = reader.ReadUInt16();
  34. RespawnIndex = reader.ReadInt32();
  35. SaveRespawnTime = reader.ReadBoolean();
  36. RespawnTicks = reader.ReadUInt16();
  37. }
  38. else
  39. {
  40. RespawnIndex = ++Envir.RespawnIndex;
  41. }
  42. }
  43. public static RespawnInfo FromText(string text)
  44. {
  45. string[] data = text.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries);
  46. if (data.Length < 7) return null;
  47. RespawnInfo info = new RespawnInfo();
  48. int x,y ;
  49. if (!int.TryParse(data[0], out info.MonsterIndex)) return null;
  50. if (!int.TryParse(data[1], out x)) return null;
  51. if (!int.TryParse(data[2], out y)) return null;
  52. info.Location = new Point(x, y);
  53. if (!ushort.TryParse(data[3], out info.Count)) return null;
  54. if (!ushort.TryParse(data[4], out info.Spread)) return null;
  55. if (!ushort.TryParse(data[5], out info.Delay)) return null;
  56. if (!byte.TryParse(data[6], out info.Direction)) return null;
  57. if (!ushort.TryParse(data[7], out info.RandomDelay)) return null;
  58. if (!int.TryParse(data[8], out info.RespawnIndex)) return null;
  59. if (!bool.TryParse(data[9], out info.SaveRespawnTime)) return null;
  60. if (!ushort.TryParse(data[10], out info.RespawnTicks)) return null;
  61. return info;
  62. }
  63. public void Save(BinaryWriter writer)
  64. {
  65. writer.Write(MonsterIndex);
  66. writer.Write(Location.X);
  67. writer.Write(Location.Y);
  68. writer.Write(Count);
  69. writer.Write(Spread);
  70. writer.Write(Delay);
  71. writer.Write(Direction);
  72. writer.Write(RoutePath);
  73. writer.Write(RandomDelay);
  74. writer.Write(RespawnIndex);
  75. writer.Write(SaveRespawnTime);
  76. writer.Write(RespawnTicks);
  77. }
  78. public override string ToString()
  79. {
  80. var monsterName = Envir.MonsterInfoList.Find(o => o.Index == MonsterIndex)?.Name ?? "Unknown";
  81. return string.Format("Monster: {0} - {1} - {2} - {3} - {4} - {5} - {6} - {7} - {8} - {9} - {10}",
  82. MonsterIndex,
  83. monsterName,
  84. Functions.PointToString(Location),
  85. Count,
  86. Spread,
  87. Delay,
  88. Direction,
  89. RandomDelay,
  90. RespawnIndex,
  91. SaveRespawnTime,
  92. RespawnTicks);
  93. }
  94. }
  95. public class RouteInfo
  96. {
  97. public Point Location;
  98. public int Delay;
  99. public static RouteInfo FromText(string text)
  100. {
  101. string[] data = text.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  102. if (data.Length < 2) return null;
  103. RouteInfo info = new RouteInfo();
  104. int x, y;
  105. if (!int.TryParse(data[0], out x)) return null;
  106. if (!int.TryParse(data[1], out y)) return null;
  107. info.Location = new Point(x, y);
  108. if (data.Length <= 2) return info;
  109. return !int.TryParse(data[2], out info.Delay) ? info : info;
  110. }
  111. }
  112. }