Exemple #1
0
        /// <summary>
        ///     Tries to set the damage value for the given <see cref="DamageType"/>.
        /// </summary>
        /// <param name="type">The type of damage to set.</param>
        /// <param name="newValue">The value to set it to.</param>
        /// <param name="quiet">
        ///     Whether or not to suppress the health changed event.
        /// </param>
        /// <returns>True if successful, false otherwise.</returns>
        public bool SetDamageValue(DamageType type, int newValue, bool quiet = false)
        {
            if (newValue < 0)
            {
                return(false);
            }

            if (!_damageList.ContainsKey(type))
            {
                return(false);
            }

            var old = _damageList[type];

            _damageList[type] = newValue;

            if (!quiet)
            {
                var delta = newValue - old;
                var datum = new HealthChangeData(type, 0, delta);
                var data  = new List <HealthChangeData> {
                    datum
                };

                OnHealthChanged(data);
            }

            return(true);
        }
Exemple #2
0
        /// <summary>
        ///     Attempts to set the damage value for the given <see cref="DamageType"/>.
        /// </summary>
        /// <returns>
        ///     True if successful, false if this container does not support that type.
        /// </returns>
        public bool TrySetDamageValue(DamageType type, int newValue)
        {
            if (newValue < 0)
            {
                return(false);
            }

            var damageClass = type.ToClass();

            if (SupportedClasses.Contains(damageClass))
            {
                var old = _damageList[type] = newValue;
                _damageList[type] = newValue;

                var delta = newValue - old;
                var datum = new HealthChangeData(type, newValue, delta);
                var data  = new List <HealthChangeData> {
                    datum
                };

                OnHealthChanged(data);

                return(true);
            }

            return(false);
        }
Exemple #3
0
        /// <summary>
        ///     Changes the damage value for the given <see cref="DamageType"/>.
        /// </summary>
        /// <param name="type">The type of damage to change.</param>
        /// <param name="delta">The amount to change it by.</param>
        /// <param name="quiet">
        ///     Whether or not to suppress the health change event.
        /// </param>
        /// <returns>
        ///     True if successful, false if this container does not support that type.
        /// </returns>
        public bool ChangeDamageValue(DamageType type, int delta, bool quiet = false)
        {
            if (!_damageList.TryGetValue(type, out var current))
            {
                return(false);
            }

            _damageList[type] = current + delta;

            if (_damageList[type] < 0)
            {
                _damageList[type] = 0;
                delta             = -current;
            }

            current = _damageList[type];

            var datum = new HealthChangeData(type, current, delta);
            var data  = new List <HealthChangeData> {
                datum
            };

            OnHealthChanged(data);

            return(true);
        }
Exemple #4
0
        /// <summary>
        ///     Attempts to change the damage value for the given
        ///     <see cref="DamageType"/>
        /// </summary>
        /// <returns>
        ///     True if successful, false if this container does not support that type.
        /// </returns>
        public bool TryChangeDamageValue(DamageType type, int delta)
        {
            var damageClass = type.ToClass();

            if (SupportsDamageClass(damageClass))
            {
                var current = _damageList[type];
                current = _damageList[type] = current + delta;

                if (_damageList[type] < 0)
                {
                    _damageList[type] = 0;
                    delta             = -current;
                    current           = 0;
                }

                var datum = new HealthChangeData(type, current, delta);
                var data  = new List <HealthChangeData> {
                    datum
                };

                OnHealthChanged(data);

                return(true);
            }

            return(false);
        }
        public HealthChangedEventArgs(IDamageableComponent damageable, DamageType type, int newValue, int delta)
        {
            Damageable = damageable;

            var datum = new HealthChangeData(type, newValue, delta);
            var data  = new List <HealthChangeData> {
                datum
            };

            Data = data;
        }
Exemple #6
0
        public void Heal()
        {
            var data = new List <HealthChangeData>();

            foreach (var type in SupportedTypes)
            {
                var delta = -GetDamageValue(type);
                var datum = new HealthChangeData(type, 0, delta);

                data.Add(datum);
                SetDamageValue(type, 0, true);
            }

            OnHealthChanged(data);
        }