Пример #1
0
        internal static DamageScalar Parse(IniParser parser)
        {
            var result = new DamageScalar
            {
                Scalar = parser.ParsePercentage()
            };
            var token = parser.PeekNextTokenOptional();

            if (token.HasValue)
            {
                result.Targets = ObjectFilter.Parse(parser);
            }
            return(result);
        }
Пример #2
0
        internal static ObjectFilter Parse(IniParser parser)
        {
            var result = new ObjectFilter();

            IniToken?token;
            var      stringToValueMap = IniParser.GetEnumMap <ObjectKinds>();

            var includeThings = new List <string>();
            var excludeThings = new List <string>();

            while ((token = parser.GetNextTokenOptional()) != null)
            {
                var stringValue = token.Value.Text.ToUpperInvariant();

                switch (stringValue)
                {
                case "ALL":
                    result.Rules.Set(ObjectFilterRule.All, true);
                    continue;

                case "NONE":
                    result.Rules.Set(ObjectFilterRule.None, true);
                    continue;

                case "ANY":
                    result.Rules.Set(ObjectFilterRule.Any, true);
                    continue;

                case "ALLIES":
                    result.Rules.Set(ObjectFilterRule.Allies, true);
                    continue;

                case "ENEMIES":
                    result.Rules.Set(ObjectFilterRule.Enemies, true);
                    continue;

                case "NEUTRAL":
                    result.Rules.Set(ObjectFilterRule.Neutrals, true);
                    continue;

                case "NEUTRALS":
                    result.Rules.Set(ObjectFilterRule.Neutrals, true);
                    continue;

                case "NOT_SIMILAR":
                    result.Rules.Set(ObjectFilterRule.NotSimilar, true);
                    continue;

                case "SELF":
                    result.Rules.Set(ObjectFilterRule.Self, true);
                    continue;

                case "SUICIDE":
                    result.Rules.Set(ObjectFilterRule.Suicide, true);
                    continue;

                case "NOT_AIRBORNE":
                    result.Rules.Set(ObjectFilterRule.NotAirborne, true);
                    continue;

                case "SAME_HEIGHT_ONLY":
                    result.Rules.Set(ObjectFilterRule.SameHeightOnly, true);
                    continue;

                case "MINES":
                    result.Rules.Set(ObjectFilterRule.Mines, true);
                    continue;

                case "SAME_PLAYER":
                    result.Rules.Set(ObjectFilterRule.SamePlayer, true);
                    continue;
                }

                bool isInclude;
                switch (stringValue[0])
                {
                case '+':
                    isInclude = true;
                    break;

                case '-':
                    isInclude = false;
                    break;

                default:
                    throw new IniParseException($"Expected {stringValue} to have a + or - prefix", token.Value.Position);
                }

                stringValue = stringValue.Substring(1);

                if (stringToValueMap.TryGetValue(stringValue, out var enumValue))
                {
                    var bitArray = isInclude ? result.Include : result.Exclude;
                    bitArray.Set((ObjectKinds)enumValue, true);
                }
                else
                {
                    var list = isInclude ? includeThings : excludeThings;
                    list.Add(stringValue);
                }
            }

            result.IncludeThings = includeThings;
            result.ExcludeThings = excludeThings;

            return(result);
        }
Пример #3
0
        internal static ObjectFilter Parse(IniParser parser)
        {
            var result = new ObjectFilter();

            IniToken?token;

            if ((token = parser.GetNextTokenOptional()) != null)
            {
                var stringValue = token.Value.Text.ToUpperInvariant();
                switch (stringValue)
                {
                case "ALL":
                    result.Rule = ObjectFilterRule.All;
                    break;

                case "NONE":
                    result.Rule = ObjectFilterRule.None;
                    break;

                case "ANY":
                    result.Rule = ObjectFilterRule.Any;
                    break;

                default:
                    throw new IniParseException($"Expected one of ALL, NONE, or ANY", token.Value.Position);
                }
            }

            var stringToValueMap = IniParser.GetEnumMap <ObjectKinds>();

            var includeThings = new List <string>();
            var excludeThings = new List <string>();

            while ((token = parser.GetNextTokenOptional()) != null)
            {
                var stringValue = token.Value.Text.ToUpperInvariant();

                switch (stringValue)
                {
                case "ALLIES":
                    result.Targets.Set(ObjectFilterTargets.Allies, true);
                    continue;

                case "ENEMIES":
                    result.Targets.Set(ObjectFilterTargets.Enemies, true);
                    continue;

                case "NEUTRAL":
                    result.Targets.Set(ObjectFilterTargets.Neutral, true);
                    continue;

                case "SAME_PLAYER":
                    result.Targets.Set(ObjectFilterTargets.SamePlayer, true);
                    continue;
                }

                bool isInclude;
                switch (stringValue[0])
                {
                case '+':
                    isInclude = true;
                    break;

                case '-':
                    isInclude = false;
                    break;

                default:
                    throw new IniParseException($"Expected value to have a + or - prefix", token.Value.Position);
                }

                stringValue = stringValue.Substring(1);

                if (stringToValueMap.TryGetValue(stringValue, out var enumValue))
                {
                    var bitArray = isInclude ? result.Include : result.Exclude;
                    bitArray.Set((ObjectKinds)enumValue, true);
                }
                else
                {
                    var list = isInclude ? includeThings : excludeThings;
                    list.Add(stringValue);
                }
            }

            result.IncludeThings = includeThings;
            result.ExcludeThings = excludeThings;

            return(result);
        }