Ejemplo n.º 1
0
        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);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        static void AddItem(string codeName, DDLItem 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();
            }

            ItemDef item = ItemDef.Get(codeName);

            if (item == null)
            {
                item = new ItemDef(codeName);
            }
            else
            {
                item.Delete();
            }

            item.Model = model;

            if (instance.TryGetValue("name", out str))
            {
                item.Name = str.Value;
            }
            if (string.IsNullOrWhiteSpace(item.Name))
            {
                item.Name = "no name (" + codeName + ")";
            }

            if (instance.TryGetValue("effect", out str))
            {
                item.Effect = str.Value;
            }

            item.Create();
        }
Ejemplo n.º 3
0
        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);
                    }
                }
            }
        }
Ejemplo n.º 4
0
 public DDLItem(DDLItem prototype) : base(prototype)
 {
 }