| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236 |
- using System.Drawing;
- using Server.MirEnvir;
- namespace Server.MirDatabase
- {
- public class NPCInfo
- {
- protected static Envir EditEnvir
- {
- get { return Envir.Edit; }
- }
- public int Index;
- public string FileName = string.Empty, Name = string.Empty;
- public int MapIndex;
- public Point Location;
- public ushort Rate = 100;
- public ushort Image;
- public Color Colour;
- public bool TimeVisible = false;
- public byte HourStart = 0;
- public byte MinuteStart = 0;
- public byte HourEnd = 0;
- public byte MinuteEnd = 1;
- public short MinLev = 0;
- public short MaxLev = 0;
- public string DayofWeek = "";
- public string ClassRequired = "";
- public bool Sabuk = false;
- public int FlagNeeded = 0;
- public int Conquest;
- public bool ShowOnBigMap;
- public int BigMapIcon;
- public bool CanTeleportTo;
- public bool ConquestVisible = true;
- public List<int> CollectQuestIndexes = new List<int>();
- public List<int> FinishQuestIndexes = new List<int>();
- public NPCInfo() { }
- public NPCInfo(BinaryReader reader)
- {
- Index = reader.ReadInt32();
- MapIndex = reader.ReadInt32();
- int count = reader.ReadInt32();
- for (int i = 0; i < count; i++)
- CollectQuestIndexes.Add(reader.ReadInt32());
- count = reader.ReadInt32();
- for (int i = 0; i < count; i++)
- FinishQuestIndexes.Add(reader.ReadInt32());
- FileName = reader.ReadString();
- Name = reader.ReadString();
- Location = new Point(reader.ReadInt32(), reader.ReadInt32());
- if (Envir.LoadVersion >= 72)
- {
- Image = reader.ReadUInt16();
- }
- else
- {
- Image = reader.ReadByte();
- }
- Rate = reader.ReadUInt16();
- if (Envir.LoadVersion >= 64)
- {
- TimeVisible = reader.ReadBoolean();
- HourStart = reader.ReadByte();
- MinuteStart = reader.ReadByte();
- HourEnd = reader.ReadByte();
- MinuteEnd = reader.ReadByte();
- MinLev = reader.ReadInt16();
- MaxLev = reader.ReadInt16();
- DayofWeek = reader.ReadString();
- ClassRequired = reader.ReadString();
- if (Envir.LoadVersion >= 66)
- Conquest = reader.ReadInt32();
- else
- Sabuk = reader.ReadBoolean();
- FlagNeeded = reader.ReadInt32();
- }
- if (Envir.LoadVersion > 95)
- {
- ShowOnBigMap = reader.ReadBoolean();
- BigMapIcon = reader.ReadInt32();
- }
- if (Envir.LoadVersion > 96)
- CanTeleportTo = reader.ReadBoolean();
- if (Envir.LoadVersion >= 107)
- {
- ConquestVisible = reader.ReadBoolean();
- }
- }
- public void Save(BinaryWriter writer)
- {
- writer.Write(Index);
- writer.Write(MapIndex);
- writer.Write(CollectQuestIndexes.Count());
- for (int i = 0; i < CollectQuestIndexes.Count; i++)
- writer.Write(CollectQuestIndexes[i]);
- writer.Write(FinishQuestIndexes.Count());
- for (int i = 0; i < FinishQuestIndexes.Count; i++)
- writer.Write(FinishQuestIndexes[i]);
- writer.Write(FileName);
- writer.Write(Name);
- writer.Write(Location.X);
- writer.Write(Location.Y);
- writer.Write(Image);
- writer.Write(Rate);
- writer.Write(TimeVisible);
- writer.Write(HourStart);
- writer.Write(MinuteStart);
- writer.Write(HourEnd);
- writer.Write(MinuteEnd);
- writer.Write(MinLev);
- writer.Write(MaxLev);
- writer.Write(DayofWeek);
- writer.Write(ClassRequired);
- writer.Write(Conquest);
- writer.Write(FlagNeeded);
- writer.Write(ShowOnBigMap);
- writer.Write(BigMapIcon);
- writer.Write(CanTeleportTo);
- writer.Write(ConquestVisible);
- }
- public static void FromText(string text)
- {
- string[] data = text.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
- if (data.Length < 6) return;
- NPCInfo info;
- bool isNew = false;
- if (!int.TryParse(data[0], out var index))
- {
- index = -1;
- }
- if (index == -1 || (info = EditEnvir.NPCInfoList.FirstOrDefault(d => d.Index == index)) == null)
- {
- info = new NPCInfo() { Index = ++EditEnvir.NPCIndex };
- isNew = true;
- }
- info.FileName = data[1];
- info.MapIndex = EditEnvir.MapInfoList.Where(d => d.FileName == data[2]).FirstOrDefault().Index;
- if (!int.TryParse(data[3], out int x)) return;
- if (!int.TryParse(data[4], out int y)) return;
- info.Location = new Point(x, y);
- info.Name = data[5];
- if (!ushort.TryParse(data[6], out info.Image)) return;
- if (!ushort.TryParse(data[7], out info.Rate)) return;
- if (!bool.TryParse(data[8], out info.ShowOnBigMap)) return;
- if (!int.TryParse(data[9], out info.BigMapIcon)) return;
- if (!bool.TryParse(data[10], out info.CanTeleportTo)) return;
- if (!bool.TryParse(data[11], out info.ConquestVisible)) return;
- if (!short.TryParse(data[12], out info.MinLev)) return;
- if (!short.TryParse(data[13], out info.MaxLev)) return;
- if (!bool.TryParse(data[14], out info.TimeVisible)) return;
- if (!byte.TryParse(data[15], out info.HourStart)) return;
- if (!byte.TryParse(data[16], out info.MinuteStart)) return;
- if (!byte.TryParse(data[17], out info.HourEnd)) return;
- if (!byte.TryParse(data[18], out info.MinuteEnd)) return;
- if (isNew) EditEnvir.NPCInfoList.Add(info);
- }
- public string ToText()
- {
- return string.Format("{0},{1},{2},{3},{4},{5},{6},{7},{8},{9},{10},{11},{12},{13},{14},{15},{16},{17},{18}", Index,
- FileName, EditEnvir.MapInfoList.Where(d => d.Index == MapIndex).FirstOrDefault().FileName, Location.X, Location.Y, Name, Image, Rate, ShowOnBigMap, BigMapIcon, CanTeleportTo, ConquestVisible,
- MinLev, MaxLev, TimeVisible, HourStart, MinuteStart, HourEnd, MinuteEnd);
- }
- public override string ToString()
- {
- return $" [{Index}] {FileName}: {Name}, {Functions.PointToString(Location)}";
- }
- public string GameName
- {
- get
- {
- string s = Name;
- if (s.Contains("_"))
- {
- string[] splitName = s.Split('_');
- s = splitName[splitName.Length - 1];
- }
- return s;
- }
- }
- public ClientNPCInfo ClientInformation
- {
- get
- {
- return new ClientNPCInfo
- {
- ObjectID = 0,
- Index = Index,
- FileName = FileName,
- Name = Name,
- MapIndex = MapIndex,
- Location = Location,
- Image = Image,
- Rate = Rate,
- ShowOnBigMap = ShowOnBigMap,
- BigMapIcon = BigMapIcon,
- Icon = BigMapIcon,
- CanTeleportTo = CanTeleportTo
- };
- }
- }
- }
- }
|