Exemple #1
0
 public QA_AttributeModifier(QA_AttributeModifier template)
 {
     Name                 = template.Name;
     ModificationType     = template.ModificationType;
     Value                = template.Value;
     Duration             = template.Duration;
     Lifetime             = template.Lifetime;
     ModificationInterval = template.ModificationInterval;
     LifeTimer            = template.LifeTimer;
     ModificationTimer    = template.ModificationTimer;
 }
        /// <summary>
        /// Adds a modifier to the handler from the given template.
        /// </summary>
        /// <param name="template">The template modifier.</param>
        public void AddModifier(QA_AttributeModifier template)
        {
            if (template.Name.Length == 0)
            {
                return;
            }
            if (template.Duration == QA_AMDuration.Permanent)
            {
                foreach (var modifier in PermanentModifiers)
                {
                    if (modifier.Name == template.Name)
                    {
                        return;
                    }
                }

                PermanentModifiers.Add(new QA_AttributeModifier(template));
            }
            else
            {
                foreach (var modifier in TemporaryModifiers)
                {
                    if (modifier.Name == template.Name)
                    {
                        return;
                    }
                }
                QA_AttributeModifier newModifier = new QA_AttributeModifier(template);
                newModifier.LifeTimer         = newModifier.Lifetime;
                newModifier.ModificationTimer = newModifier.ModificationInterval;
                TemporaryModifiers.Add(newModifier);
            }

            if (template.Duration == QA_AMDuration.Permanent || Mathf.Approximately(template.ModificationInterval, 0))
            {
                if (template.ModificationType == QA_AMModificationType.RawValue)
                {
                    SetValue(Value + template.Value);
                }
                else if (template.ModificationType == QA_AMModificationType.Percent)
                {
                    SetValue(Value + template.Value / 100 * MaximumValue);
                }
            }
        }