Exemple #1
0
        internal void SetInventory(string v)
        {
            if (Locked)
            {
                throw new InvalidOperationException("This MonsterType is locked and cannot be altered.");
            }

            var enclosingChars = new Dictionary <char, char>
            {
                { CipParser.CloseCurly, CipParser.OpenCurly },
                { CipParser.CloseParenthesis, CipParser.OpenParenthesis }
            };

            var enclosures = CipParser.GetEnclosedButPreserveQuoted(v, enclosingChars);

            foreach (var enclosure in enclosures)
            {
                var inventoryParams = enclosure.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                if (!inventoryParams.Any())
                {
                    continue;
                }

                if (inventoryParams.Length != 3)
                {
                    throw new InvalidDataException($"Unexpected number of elements in inventory line {v} on monster type {Name}.");
                }

                InventoryComposition.Add(new Tuple <ushort, byte, ushort>(Convert.ToUInt16(inventoryParams[0]), Convert.ToByte(inventoryParams[1]), Convert.ToUInt16(inventoryParams[2])));
            }
        }
Exemple #2
0
        internal void SetSkills(string v)
        {
            if (Locked)
            {
                throw new InvalidOperationException("This MonsterType is locked and cannot be altered.");
            }

            var enclosingChars = new Dictionary <char, char>
            {
                { CipParser.CloseCurly, CipParser.OpenCurly },
                { CipParser.CloseParenthesis, CipParser.OpenParenthesis }
            };

            var enclosures = CipParser.GetEnclosedButPreserveQuoted(v, enclosingChars);

            foreach (var enclosure in enclosures)
            {
                var skillParams = enclosure.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries);

                if (!skillParams.Any())
                {
                    continue;
                }

                if (skillParams.Length != 7)
                {
                    throw new InvalidDataException($"Unexpected number of elements in skill line {v} on monster type {Name}.");
                }

                MonsterSkill mSkill;

                if (!Enum.TryParse(skillParams[0].ToUpper(), out mSkill))
                {
                    continue;
                }

                switch (mSkill)
                {
                case MonsterSkill.HITPOINTS:
                    MaxHitPoints = Convert.ToUInt32(skillParams[1]);
                    break;

                case MonsterSkill.GOSTRENGTH:
                    try
                    {
                        Speed = Convert.ToUInt16(skillParams[1]);
                    }
                    catch
                    {
                        // TODO: handle -1 here...
                    }

                    break;

                case MonsterSkill.CARRYSTRENGTH:
                    Capacity = Convert.ToUInt16(skillParams[1]);
                    break;

                case MonsterSkill.FISTFIGHTING:
                    var fistLevel = Convert.ToUInt16(skillParams[1]);
                    if (fistLevel > 0)
                    {
                        Skills[SkillType.Fist] = new Skill(SkillType.Fist, fistLevel, 1.00, 1, fistLevel, (ushort)(fistLevel * 2));
                    }

                    break;

                case MonsterSkill.AXEFIGHTING:
                    var axeLevel = Convert.ToUInt16(skillParams[1]);
                    if (axeLevel > 0)
                    {
                        Skills[SkillType.Fist] = new Skill(SkillType.Fist, axeLevel, 1.00, 1, axeLevel, (ushort)(axeLevel * 2));
                    }

                    break;

                case MonsterSkill.SWORDFIGHTING:
                    var swordLevel = Convert.ToUInt16(skillParams[1]);
                    if (swordLevel > 0)
                    {
                        Skills[SkillType.Fist] = new Skill(SkillType.Fist, swordLevel, 1.00, 1, swordLevel, (ushort)(swordLevel * 2));
                    }

                    break;

                case MonsterSkill.CLUBFIGHTING:
                    var clubLevel = Convert.ToUInt16(skillParams[1]);
                    if (clubLevel > 0)
                    {
                        Skills[SkillType.Fist] = new Skill(SkillType.Fist, clubLevel, 1.00, 1, clubLevel, (ushort)(clubLevel * 2));
                    }

                    break;
                }
            }
        }