Beispiel #1
0
 public bool RemovePerk(Type type)
 {
     if (type == typeof(PerkBase) || type == typeof(ConditionalPerk) || type.IsSubclassOf(typeof(ConditionalPerk)))
     {
         return(false);
     }
     if (perks.ContainsKey(type))
     {
         PerkBase removed = perks[type];
         removed.Deactivate();
         return(perks.Remove(type));
     }
     return(false);
 }
        protected internal override bool RemoveModifier(PerkBase perk)
        {
            Type type = perk.GetType();
            T    oldT = GetValue();

            if (valueModifiers.Remove(type))
            {
                if (CheckChanged(oldT))
                {
                    onChange?.Invoke(oldT);
                }
                return(true);
            }

            return(false);
        }
        protected internal override bool AddModifier(PerkBase perk, ValueModifierStore <T> valueModifier, bool overwriteExisting = false)
        {
            Type type = perk.GetType();

            if (valueModifiers.ContainsKey(type) && !overwriteExisting)
            {
                return(false);
            }
            else
            {
                T oldT = GetValue();
                valueModifiers[type] = valueModifier;
                if (CheckChanged(oldT))
                {
                    onChange?.Invoke(oldT);
                }
                return(true);
            }
        }
 bool IRemovableModifier.RemoveModifier(PerkBase perk) => RemoveModifier(perk);
 protected internal abstract bool HasModifier(PerkBase perk);
 protected internal abstract bool RemoveModifier(PerkBase perk);
        //these are internal. we expose these indirectly through PerkBase. this way, we can guarentee the perk modifiers are always up to date, and you don't
        //have to manually add and remove them all the time - simply tell the perk to do it, and it'll automatically add and remove when activated or deactivated, respectively.

        protected internal abstract bool AddModifier(PerkBase perk, T valueModifier, bool overwriteExisting = false);
 protected internal override bool HasModifier(PerkBase perk)
 {
     return(valueModifiers.ContainsKey(perk.GetType()));
 }