Esempio n. 1
0
        public void AddModifier(StatModifier modifier)
        {
            Handlers.InvokeBeforeChanged();

            switch (modifier.Phase)
            {
            case StatModificationPhase.Base:
                switch (modifier.Type)
                {
                case StatModificationType.Additive:
                    if (BaseAdditiveModifiers == null)
                    {
                        BaseAdditiveModifiers = new List <StatModifier> ();
                    }
                    BaseAdditiveModifiers.Add(modifier);
                    break;

                case StatModificationType.SimpleMultiplicative:
                    if (BaseSimpleModifiers == null)
                    {
                        BaseSimpleModifiers = new List <StatModifier> ();
                    }
                    BaseSimpleModifiers.Add(modifier);
                    break;

                case StatModificationType.CompoundMultiplicative:
                    if (BaseCompoundModifiers == null)
                    {
                        BaseCompoundModifiers = new List <StatModifier> ();
                    }
                    BaseCompoundModifiers.Add(modifier);
                    break;

                case StatModificationType.None:
                    throw new InvalidOperationException($"\"{modifier.Type}\" is not a valid stat modification type.");
                }
                break;

            case StatModificationPhase.Typical:
                switch (modifier.Type)
                {
                case StatModificationType.Additive:
                    if (AdditiveModifiers == null)
                    {
                        AdditiveModifiers = new List <StatModifier> ();
                    }
                    AdditiveModifiers.Add(modifier);
                    break;

                case StatModificationType.SimpleMultiplicative:
                    if (SimpleModifiers == null)
                    {
                        SimpleModifiers = new List <StatModifier> ();
                    }
                    SimpleModifiers.Add(modifier);
                    break;

                case StatModificationType.CompoundMultiplicative:
                    if (CompoundModifiers == null)
                    {
                        CompoundModifiers = new List <StatModifier> ();
                    }
                    CompoundModifiers.Add(modifier);
                    break;

                case StatModificationType.None:
                    throw new InvalidOperationException($"\"{modifier.Type}\" is not a valid stat modification type.");
                }
                break;

            case StatModificationPhase.None:
                throw new InvalidOperationException($"\"{modifier.Phase}\" is not a valid stat modification phase.");
            }
            Handlers.InvokeAfterChanged();

            modifier.CurrentValue.Handlers[this].Add(this);

            Value = CalculateValue();
        }
Esempio n. 2
0
        public bool RemoveModifier(StatModifier modifier)
        {
            Handlers.InvokeBeforeChanged();

            bool result;

            switch (modifier.Phase)
            {
            case StatModificationPhase.Base:
                switch (modifier.Type)
                {
                case StatModificationType.Additive:
                    if (BaseAdditiveModifiers == null)
                    {
                        BaseAdditiveModifiers = new List <StatModifier> ();
                    }
                    result = BaseAdditiveModifiers.Remove(modifier);
                    break;

                case StatModificationType.SimpleMultiplicative:
                    if (BaseSimpleModifiers == null)
                    {
                        BaseSimpleModifiers = new List <StatModifier> ();
                    }
                    result = BaseSimpleModifiers.Remove(modifier);
                    break;

                case StatModificationType.CompoundMultiplicative:
                    if (BaseCompoundModifiers == null)
                    {
                        BaseCompoundModifiers = new List <StatModifier> ();
                    }
                    result = BaseCompoundModifiers.Remove(modifier);
                    break;

                default:
                case StatModificationType.None:
                    throw new InvalidOperationException($"\"{modifier.Type}\" is not a valid stat modification type.");
                }
                break;

            case StatModificationPhase.Typical:
                switch (modifier.Type)
                {
                case StatModificationType.Additive:
                    if (AdditiveModifiers == null)
                    {
                        AdditiveModifiers = new List <StatModifier> ();
                    }
                    result = AdditiveModifiers.Remove(modifier);
                    break;

                case StatModificationType.SimpleMultiplicative:
                    if (SimpleModifiers == null)
                    {
                        SimpleModifiers = new List <StatModifier> ();
                    }
                    result = SimpleModifiers.Remove(modifier);
                    break;

                case StatModificationType.CompoundMultiplicative:
                    if (CompoundModifiers == null)
                    {
                        CompoundModifiers = new List <StatModifier> ();
                    }
                    result = CompoundModifiers.Remove(modifier);
                    break;

                default:
                case StatModificationType.None:
                    throw new InvalidOperationException($"\"{modifier.Type}\" is not a valid stat modification type.");
                }
                break;

            default:
            case StatModificationPhase.None:
                throw new InvalidOperationException($"\"{modifier.Phase}\" is not a valid stat modification phase.");
            }

            Handlers.InvokeAfterChanged();

            Value = CalculateValue();

            return(result);
        }