Exemplo n.º 1
0
        /// <summary>
        /// Reads a <see cref="IMonsterType"/> out of a monster file.
        /// </summary>
        /// <param name="monsterFileInfo">The information about the monster file.</param>
        /// <returns>The <see cref="IMonsterType"/> instance.</returns>
        private IMonsterType ReadMonsterFile(FileInfo monsterFileInfo)
        {
            monsterFileInfo.ThrowIfNull(nameof(monsterFileInfo));

            if (!monsterFileInfo.Exists)
            {
                return(null);
            }

            var monsterType = new MonsterType();

            foreach ((string name, string value) in this.ReadInDataTuples(File.ReadLines(monsterFileInfo.FullName), monsterFileInfo.FullName))
            {
                switch (name)
                {
                case "racenumber":
                    monsterType.SetId(Convert.ToUInt16(value));
                    break;

                case "name":
                    monsterType.SetName(value.Trim('\"'));
                    break;

                case "article":
                    monsterType.SetArticle(value.Trim('\"'));
                    break;

                case "outfit":
                    monsterType.SetOutfit(value.Trim('(', ')'));
                    break;

                case "corpse":
                    monsterType.SetCorpse(Convert.ToUInt16(value));
                    break;

                case "blood":
                    monsterType.SetBlood(value);
                    break;

                case "experience":
                    monsterType.SetExperience(Convert.ToUInt32(value));
                    break;

                case "summoncost":
                    monsterType.SetSummonCost(Convert.ToUInt16(value));
                    break;

                case "fleethreshold":
                    monsterType.SetFleeTreshold(Convert.ToUInt16(value));
                    break;

                case "attack":
                    monsterType.SetAttack(Convert.ToUInt16(value));
                    break;

                case "defend":
                    monsterType.SetDefense(Convert.ToUInt16(value));
                    break;

                case "armor":
                    monsterType.SetArmor(Convert.ToUInt16(value));
                    break;

                case "poison":
                    monsterType.SetConditionInfect(ConditionFlag.Posion, Convert.ToUInt16(value));
                    break;

                case "losetarget":
                    monsterType.SetLoseTarget(Convert.ToByte(value));
                    break;

                case "strategy":
                    monsterType.SetStrategy(CipFileParser.ParseMonsterStrategy(value));
                    break;

                case "flags":
                    monsterType.SetFlags(CipFileParser.Parse(value));
                    break;

                case "skills":
                    monsterType.SetSkills(CipFileParser.ParseMonsterSkills(value));
                    break;

                case "spells":
                    monsterType.SetSpells(CipFileParser.ParseMonsterSpells(value));
                    break;

                case "inventory":
                    monsterType.SetInventory(CipFileParser.ParseMonsterInventory(value));
                    break;

                case "talk":
                    monsterType.SetPhrases(CipFileParser.ParsePhrases(value));
                    break;
                }
            }

            monsterType.Lock();

            return(monsterType);
        }