コード例 #1
0
ファイル: Bonus.cs プロジェクト: primordially/primordially
        public Bonus(TextSpan value)
        {
            AddPropertyDefinitions(() => new[]
            {
                IsEquipment?CommonProperties.ConditionForEquipment: CommonProperties.Conditions,
            });

            if (!value.TryRemoveInfix("|", out var category, out value))
            {
                throw new ParseFailedException(value, "Unable to parse bonus.");
            }
            if (!value.TryRemoveInfix("|", out var variableSpan, out value))
            {
                throw new ParseFailedException(value, "Unable to parse bonus.");
            }

            Category = category.Value;
            foreach (var part in value.Split('|'))
            {
                // This is fine, Provided that the only inheritor is EquipmentBonus
                // and it only overrides the IsEquipment property
                // ReSharper disable once VirtualMemberCallInConstructor
                AddField(part);
            }

            Formula ??= "%CHOICEVALUE";
            switch (Category)
            {
            case "ITEMCOST":
                Variables.Add("Cost");
                if (!variableSpan.TryRemovePrefix("TYPE.", out var types))
                {
                    throw new ParseFailedException(value, "Unable to parse bonus.");
                }
                var allTypes = types.Value.Split('.').Select(t => $"item.IsType(\"{t}\")").ToList();
                Properties.GetList <Condition>("Conditions")
                .Add(new EquipmentTypeCondition(false, allTypes.Count, allTypes));
                break;

            default:
                Variables.AddRange(variableSpan.Value.Split(','));
                break;
            }
        }
コード例 #2
0
        public override void AddField(TextSpan field)
        {
            if (field.TryRemovePrefix("CHOICE:", out field))
            {
                if (!field.TryRemoveInfix("|", out var k, out var v))
                {
                    throw new ParseFailedException(field, "Unable to parse CHOICE");
                }
                ChoiceKind  = k.Value;
                ChoiceValue = v.Value;
                return;
            }

            base.AddField(field);
        }
コード例 #3
0
        public ProhibitedSpell(TextSpan value)
        {
            AddPropertyDefinitions(() => new[]
            {
                CommonProperties.Conditions,
            });

            if (value.TryRemoveInfix("|", out var newValue, out var conditions))
            {
                foreach (var part in conditions.Split('|'))
                {
                    AddField(part);
                }

                value = newValue;
            }

            if (value.TryRemovePrefix("ALIGNMENT.", out value))
            {
                Alignments.AddRange(value.Value.Split('.'));
            }
            else if (value.TryRemovePrefix("DESCRIPTOR.", out value))
            {
                Descriptors.AddRange(value.Value.Split('.'));
            }
            else if (value.TryRemovePrefix("SCHOOL.", out value))
            {
                Schools.AddRange(value.Value.Split('.'));
            }
            else if (value.TryRemovePrefix("SUBSCHOOL.", out value))
            {
                SubSchools.AddRange(value.Value.Split('.'));
            }
            else if (value.TryRemovePrefix("SPELL.", out value))
            {
                Names.AddRange(value.Value.Split(','));
            }
            else
            {
                throw new ParseFailedException(value, "Unable to parse PROHIBITSPELL");
            }
        }