static void ReadPrototypes(FileInfo[] files) { prototypes.Clear(); for (int i = 0; i < files.Length; i++) { using (Parser parser = new Parser(files[i].OpenRead())) { while (parser.SkipTillLineStartsWith("PROTOTYPE")) { string codeName = parser.ReadTill("("); if (codeName == null) { continue; } string type = parser.ReadTill(")"); if (type == null) { continue; } string nextWord = parser.ReadWord(); if (nextWord != "{") { continue; } type = type.Trim(); DDLInstance instance; if (string.Compare(type, "C_NPC", true) == 0) { instance = new DDLNpc(); } else if (string.Compare(type, "C_ITEM", true) == 0) { instance = new DDLItem(); } else { parser.SkipTill("};"); continue; } instance.HandleTextBody(parser.ReadTill("};")); prototypes.Add(codeName.Trim(), instance); } } } }
static void AddNPC(string codeName, DDLNpc instance) { DDLString str; if (!instance.TryGetValue("visual", out str)) { return; } string modelName = Path.GetFileNameWithoutExtension(str.Value); ModelDef model; if (!ModelDef.TryGetModel(modelName, out model)) { model = new ModelDef(modelName, str.Value); model.Create(); } NPCDef npc = NPCDef.Get(codeName); if (npc == null) { npc = new NPCDef(codeName); } else { npc.Delete(); } npc.Model = model; if (instance.TryGetValue("name", out str)) { npc.Name = str.Value; } if (string.IsNullOrWhiteSpace(npc.Name)) { npc.Name = "no name (" + codeName + ")"; } if (instance.TryGetValue("bodymesh", out str)) { npc.BodyMesh = str.Value; } if (instance.TryGetValue("headmesh", out str)) { npc.HeadMesh = str.Value; } DDLInt dint; if (instance.TryGetValue("bodytex", out dint)) { npc.BodyTex = dint.Value; } if (instance.TryGetValue("headtex", out dint)) { npc.HeadTex = dint.Value; } npc.Create(); }
static void ReadInstances(FileInfo[] files) { instances.Clear(); for (int i = 0; i < files.Length; i++) { using (Parser parser = new Parser(files[i].OpenRead())) { while (parser.SkipTillLineStartsWith("INSTANCE")) { string codeName = parser.ReadTill("("); if (string.IsNullOrWhiteSpace(codeName)) { continue; } string type = parser.ReadTill(")"); if (string.IsNullOrWhiteSpace(type)) { continue; } string nextWord = parser.ReadWord(); if (nextWord != "{") { continue; } type = type.Trim(); codeName = codeName.Trim(); DDLInstance instance; if (string.Compare(type, "C_NPC", true) == 0) { instance = new DDLNpc(); } else if (string.Compare(type, "C_ITEM", true) == 0) { instance = new DDLItem(); } else if (PrototypeParser.TryGetPrototype(type, out instance)) { if (instance is DDLNpc) { instance = new DDLNpc((DDLNpc)instance); } else if (instance is DDLItem) { instance = new DDLItem((DDLItem)instance); } else { parser.SkipTill("};"); continue; } } else { parser.SkipTill("};"); continue; } instance.HandleTextBody(parser.ReadTill("};")); instances.Add(codeName, instance); } } } }
public DDLNpc(DDLNpc prototype) : base(prototype) { this.equipment = new List <string>(prototype.equipment); }