NPCInfo.cs 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  1. using System.Drawing;
  2. using Server.MirEnvir;
  3. namespace Server.MirDatabase
  4. {
  5. public class NPCInfo
  6. {
  7. protected static Envir EditEnvir
  8. {
  9. get { return Envir.Edit; }
  10. }
  11. public int Index;
  12. public string FileName = string.Empty, Name = string.Empty;
  13. public int MapIndex;
  14. public Point Location;
  15. public ushort Rate = 100;
  16. public ushort Image;
  17. public Color Colour;
  18. public bool TimeVisible = false;
  19. public byte HourStart = 0;
  20. public byte MinuteStart = 0;
  21. public byte HourEnd = 0;
  22. public byte MinuteEnd = 1;
  23. public short MinLev = 0;
  24. public short MaxLev = 0;
  25. public string DayofWeek = "";
  26. public string ClassRequired = "";
  27. public bool Sabuk = false;
  28. public int FlagNeeded = 0;
  29. public int Conquest;
  30. public bool ShowOnBigMap;
  31. public int BigMapIcon;
  32. public bool CanTeleportTo;
  33. public bool ConquestVisible = true;
  34. public List<int> CollectQuestIndexes = new List<int>();
  35. public List<int> FinishQuestIndexes = new List<int>();
  36. public NPCInfo() { }
  37. public NPCInfo(BinaryReader reader)
  38. {
  39. Index = reader.ReadInt32();
  40. MapIndex = reader.ReadInt32();
  41. int count = reader.ReadInt32();
  42. for (int i = 0; i < count; i++)
  43. CollectQuestIndexes.Add(reader.ReadInt32());
  44. count = reader.ReadInt32();
  45. for (int i = 0; i < count; i++)
  46. FinishQuestIndexes.Add(reader.ReadInt32());
  47. FileName = reader.ReadString();
  48. Name = reader.ReadString();
  49. Location = new Point(reader.ReadInt32(), reader.ReadInt32());
  50. if (Envir.LoadVersion >= 72)
  51. {
  52. Image = reader.ReadUInt16();
  53. }
  54. else
  55. {
  56. Image = reader.ReadByte();
  57. }
  58. Rate = reader.ReadUInt16();
  59. if (Envir.LoadVersion >= 64)
  60. {
  61. TimeVisible = reader.ReadBoolean();
  62. HourStart = reader.ReadByte();
  63. MinuteStart = reader.ReadByte();
  64. HourEnd = reader.ReadByte();
  65. MinuteEnd = reader.ReadByte();
  66. MinLev = reader.ReadInt16();
  67. MaxLev = reader.ReadInt16();
  68. DayofWeek = reader.ReadString();
  69. ClassRequired = reader.ReadString();
  70. if (Envir.LoadVersion >= 66)
  71. Conquest = reader.ReadInt32();
  72. else
  73. Sabuk = reader.ReadBoolean();
  74. FlagNeeded = reader.ReadInt32();
  75. }
  76. if (Envir.LoadVersion > 95)
  77. {
  78. ShowOnBigMap = reader.ReadBoolean();
  79. BigMapIcon = reader.ReadInt32();
  80. }
  81. if (Envir.LoadVersion > 96)
  82. CanTeleportTo = reader.ReadBoolean();
  83. if (Envir.LoadVersion >= 107)
  84. {
  85. ConquestVisible = reader.ReadBoolean();
  86. }
  87. }
  88. public void Save(BinaryWriter writer)
  89. {
  90. writer.Write(Index);
  91. writer.Write(MapIndex);
  92. writer.Write(CollectQuestIndexes.Count());
  93. for (int i = 0; i < CollectQuestIndexes.Count; i++)
  94. writer.Write(CollectQuestIndexes[i]);
  95. writer.Write(FinishQuestIndexes.Count());
  96. for (int i = 0; i < FinishQuestIndexes.Count; i++)
  97. writer.Write(FinishQuestIndexes[i]);
  98. writer.Write(FileName);
  99. writer.Write(Name);
  100. writer.Write(Location.X);
  101. writer.Write(Location.Y);
  102. writer.Write(Image);
  103. writer.Write(Rate);
  104. writer.Write(TimeVisible);
  105. writer.Write(HourStart);
  106. writer.Write(MinuteStart);
  107. writer.Write(HourEnd);
  108. writer.Write(MinuteEnd);
  109. writer.Write(MinLev);
  110. writer.Write(MaxLev);
  111. writer.Write(DayofWeek);
  112. writer.Write(ClassRequired);
  113. writer.Write(Conquest);
  114. writer.Write(FlagNeeded);
  115. writer.Write(ShowOnBigMap);
  116. writer.Write(BigMapIcon);
  117. writer.Write(CanTeleportTo);
  118. writer.Write(ConquestVisible);
  119. }
  120. public static void FromText(string text)
  121. {
  122. string[] data = text.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
  123. if (data.Length < 6) return;
  124. NPCInfo info;
  125. bool isNew = false;
  126. if (!int.TryParse(data[0], out var index))
  127. {
  128. index = -1;
  129. }
  130. if (index == -1 || (info = EditEnvir.NPCInfoList.FirstOrDefault(d => d.Index == index)) == null)
  131. {
  132. info = new NPCInfo() { Index = ++EditEnvir.NPCIndex };
  133. isNew = true;
  134. }
  135. info.FileName = data[1];
  136. info.MapIndex = EditEnvir.MapInfoList.Where(d => d.FileName == data[2]).FirstOrDefault().Index;
  137. if (!int.TryParse(data[3], out int x)) return;
  138. if (!int.TryParse(data[4], out int y)) return;
  139. info.Location = new Point(x, y);
  140. info.Name = data[5];
  141. if (!ushort.TryParse(data[6], out info.Image)) return;
  142. if (!ushort.TryParse(data[7], out info.Rate)) return;
  143. if (!bool.TryParse(data[8], out info.ShowOnBigMap)) return;
  144. if (!int.TryParse(data[9], out info.BigMapIcon)) return;
  145. if (!bool.TryParse(data[10], out info.CanTeleportTo)) return;
  146. if (!bool.TryParse(data[11], out info.ConquestVisible)) return;
  147. if (!short.TryParse(data[12], out info.MinLev)) return;
  148. if (!short.TryParse(data[13], out info.MaxLev)) return;
  149. if (!bool.TryParse(data[14], out info.TimeVisible)) return;
  150. if (!byte.TryParse(data[15], out info.HourStart)) return;
  151. if (!byte.TryParse(data[16], out info.MinuteStart)) return;
  152. if (!byte.TryParse(data[17], out info.HourEnd)) return;
  153. if (!byte.TryParse(data[18], out info.MinuteEnd)) return;
  154. if (isNew) EditEnvir.NPCInfoList.Add(info);
  155. }
  156. public string ToText()
  157. {
  158. return string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18}", Index,
  159. FileName, EditEnvir.MapInfoList.Where(d => d.Index == MapIndex).FirstOrDefault().FileName, Location.X, Location.Y, Name, Image, Rate, ShowOnBigMap, BigMapIcon, CanTeleportTo, ConquestVisible,
  160. MinLev, MaxLev, TimeVisible, HourStart, MinuteStart, HourEnd, MinuteEnd);
  161. }
  162. public override string ToString()
  163. {
  164. return $" [{Index}] {FileName}: {Name}, {Functions.PointToString(Location)}";
  165. }
  166. public string GameName
  167. {
  168. get
  169. {
  170. string s = Name;
  171. if (s.Contains("_"))
  172. {
  173. string[] splitName = s.Split('_');
  174. s = splitName[splitName.Length - 1];
  175. }
  176. return s;
  177. }
  178. }
  179. public ClientNPCInfo ClientInformation
  180. {
  181. get
  182. {
  183. return new ClientNPCInfo
  184. {
  185. ObjectID = 0,
  186. Index = Index,
  187. FileName = FileName,
  188. Name = Name,
  189. MapIndex = MapIndex,
  190. Location = Location,
  191. Image = Image,
  192. Rate = Rate,
  193. ShowOnBigMap = ShowOnBigMap,
  194. BigMapIcon = BigMapIcon,
  195. Icon = BigMapIcon,
  196. CanTeleportTo = CanTeleportTo
  197. };
  198. }
  199. }
  200. }
  201. }