Пример #1
0
 /// <summary>
 /// A helper method for null checking actions
 /// </summary>
 /// <param name="action">Action to be done</param>
 /// <param name="info">The HealthChangeInfo to be passed to the Action</param>
 protected void SafelyDoAction(Action <HealthChangeInfo> action, HealthChangeInfo info)
 {
     if (action != null)
     {
         action(info);
     }
 }
Пример #2
0
        /// <summary>
        /// Use the alignment to see if taking damage is a valid action
        /// </summary>
        /// <param name="damage">
        /// The damage to take
        /// </param>
        /// <param name="damageAlignment">
        /// The alignment of the other combatant
        /// </param>
        /// <param name="output">
        /// The output data if there is damage taken
        /// </param>
        /// <returns>
        /// <value>true if this instance took damage</value>
        /// <value>false if this instance was already dead, or the alignment did not allow the damage</value>
        /// </returns>
        public bool TakeDamage(float damage, IAlignmentProvider damageAlignment, out HealthChangeInfo output)
        {
            output = new HealthChangeInfo
            {
                damageAlignment = damageAlignment,
                damageable      = this,
                newHealth       = currentHealth,
                oldHealth       = currentHealth
            };

            bool canDamage = damageAlignment == null || alignmentProvider == null ||
                             damageAlignment.CanHarm(alignmentProvider);

            if (isDead || !canDamage)
            {
                return(false);
            }

            ChangeHealth(-damage, output);
            SafelyDoAction(damaged, output);
            if (isDead)
            {
                SafelyDoAction(died, output);
            }
            return(true);
        }
Пример #3
0
        /// <summary>
        /// Changes the health.
        /// </summary>
        /// <param name="healthIncrement">Health increment.</param>
        /// <param name="info">HealthChangeInfo for this change</param>
        protected void ChangeHealth(float healthIncrement, HealthChangeInfo info)
        {
            info.oldHealth = currentHealth;
            currentHealth += healthIncrement;
            currentHealth  = Mathf.Clamp(currentHealth, 0f, maxHealth);
            info.newHealth = currentHealth;

            if (healthChanged != null)
            {
                healthChanged(info);
            }
        }
Пример #4
0
        /// <summary>
        /// Instantiate a death particle system
        /// </summary>
        void OnDied(HealthChangeInfo healthChangeInfo)
        {
            if (deathParticleSystemPrefab == null)
            {
                return;
            }

            var pfx = Poolable.TryGetPoolable <ParticleSystem>(deathParticleSystemPrefab.gameObject);

            pfx.transform.position = transform.position + deathEffectOffset;
            pfx.Play();
        }
Пример #5
0
        /// <summary>
        /// Changes the health.
        /// </summary>
        /// <param name="healthIncrement">Health increment.</param>
        /// <param name="info">HealthChangeInfo for this change</param>
        protected void ChangeHealth(float healthIncrement, HealthChangeInfo info)
        {
            Debug.LogFormat("<b>Taking damage</b>: {0} {1}", alignment.unityObjectReference, healthIncrement);

            info.oldHealth = currentHealth;
            currentHealth += healthIncrement;
            currentHealth  = Mathf.Clamp(currentHealth, 0f, maxHealth);
            info.newHealth = currentHealth;

            if (healthChanged != null)
            {
                healthChanged(info);
            }
        }
Пример #6
0
        /// <summary>
        /// Logic for increasing the health.
        /// </summary>
        /// <param name="health">Health.</param>
        public HealthChangeInfo IncreaseHealth(float health)
        {
            var info = new HealthChangeInfo {
                damageable = this
            };

            ChangeHealth(health, info);
            SafelyDoAction(healed, info);
            if (isAtMaxHealth)
            {
                SafelyDoAction(reachedMaxHealth);
            }

            return(info);
        }
Пример #7
0
        /// <summary>
        /// Instantiate a death particle system
        /// </summary>
        void OnDied(HealthChangeInfo healthChangeInfo)
        {
            if (deathParticleSystemPrefab == null)
            {
                return;
            }

            //WWiseEventPlayer myEventPlayer = gameObject.AddComponent(typeof(WWiseEventPlayer)) as WWiseEventPlayer;
            //myEventPlayer.PlayWwiseEvent("ui_objectDeath");

            var pfx = Poolable.TryGetPoolable <ParticleSystem>(deathParticleSystemPrefab.gameObject);

            pfx.transform.position = transform.position + deathEffectOffset;
            pfx.Play();
        }
Пример #8
0
        /// <summary>
        /// 赋值当前生命值
        /// </summary>
        /// <param name="health">
        /// The value to set <see cref="currentHealth"/> to
        /// </param>
        public void SetHealth(float health)
        {
            var info = new HealthChangeInfo
            {
                damageable = this,
                newHealth  = health,
                oldHealth  = currentHealth
            };

            currentHealth = health;

            if (healthChanged != null)
            {
                healthChanged(info);
            }
        }
 /// <summary>
 /// Event fired when Damageable takes critical damage
 /// </summary>
 void OnConfigurationDied(HealthChangeInfo changeInfo)
 {
     OnDeath();
     Remove();
 }
Пример #10
0
 void OnHealthChanged(HealthChangeInfo healthChangeInfo)
 {
     UpdateHealth(m_Damageable.normalisedHealth);
 }
Пример #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="HitInfo" /> struct.
 /// </summary>
 /// <param name="info">The health change info</param>
 /// <param name="damageLocation">Damage point.</param>
 public HitInfo(HealthChangeInfo info, Vector3 damageLocation)
 {
     m_DamagePoint      = damageLocation;
     m_HealthChangeInfo = info;
 }
Пример #12
0
 /// <summary>
 /// Raises the death UnityEvent.
 /// </summary>
 protected virtual void OnDeath(HealthChangeInfo info)
 {
     died.Invoke();
 }
Пример #13
0
 /// <summary>
 /// Raises the healthChanged UnityEvent.
 /// </summary>
 /// <param name="info">Info.</param>
 protected virtual void OnHealthChanged(HealthChangeInfo info)
 {
     healthChanged.Invoke(info);
 }
Пример #14
0
 /// <summary>
 /// Raises the damage UnityEvent.
 /// </summary>
 /// <param name="info">Info.</param>
 protected virtual void OnDamaged(HealthChangeInfo info)
 {
     damaged.Invoke(info);
 }