示例#1
0
        protected override bool DoesModifierApply(NoteOptionModifier modifier)
        {
            bool baseApplies = base.DoesModifierApply(modifier);
            bool match       = false;

            if (RootIdea?.GetType() == typeof(CharacterNote) &&
                modifier.GetType() == typeof(NoteOptionCharacterModifier))
            {
                CharacterNote host = (CharacterNote)RootIdea;
                NoteOptionCharacterModifier cModifier = (NoteOptionCharacterModifier)modifier;

                // Does not match if a gender is specified, but the character's gender (or its archetype) doesn't match
                if (cModifier.Genders.Count > 0 && (host.EffectiveGender == null ||
                                                    (!cModifier.Genders.Contains(host.EffectiveGender.Name) &&
                                                     !cModifier.Genders.Contains(host.EffectiveGender.Archetype))))
                {
                    return(false);
                }
                else
                {
                    match = true;
                }

                // Does not match if a race is specified, but the character's race doesn't match
                if (cModifier.Races.Count > 0)
                {
                    bool found = false;
                    foreach (var race in cModifier.Races)
                    {
                        if (host.Races.FindOption(race)?.IsChecked == true)
                        {
                            found = true;
                        }
                    }
                    if (!found)
                    {
                        return(false);
                    }
                    match = true;
                }

                // Does not match if an age range is specified, but the character's age is outside the range
                if (cModifier.MinAge.HasValue && host.AgeYears < cModifier.MinAge)
                {
                    return(false);
                }
                if (cModifier.MaxAge.HasValue && host.AgeYears > cModifier.MaxAge)
                {
                    return(false);
                }
                if (cModifier.MinAge.HasValue || cModifier.MaxAge.HasValue)
                {
                    match = true;
                }
            }

            // If the modifier had character-specific conditions which were met, and omits the usual target, it is considered a match
            if (string.IsNullOrEmpty(modifier.TargetPath) && match)
            {
                return(true);
            }

            // Otherwise, use the usual matching criteria only.
            return(baseApplies);
        }
示例#2
0
 public object GetUndoRoot() => RootIdea?.GetUndoRoot();