Exemple #1
0
        public virtual void Explode()
        {
            Collider[] colliders = Physics.OverlapSphere(transform.position, radius, Layer, triggerInteraction);             //Ignore Colliders

            foreach (var nearbyObj in colliders)
            {
                if (dontHitOwner && nearbyObj.transform.IsChildOf(Owner.transform))
                {
                    continue;                                                                                              //Don't hit yourself
                }
                nearbyObj.attachedRigidbody?.AddExplosionForce(Force, transform.position, radius, upwardsModifier, forceMode);

                var Distance = Vector3.Distance(transform.position, nearbyObj.transform.position);                              //Distance of the collider and the Explosion

                if (statModifier.ID != null)
                {
                    var modif = new StatModifier(statModifier)
                    {
                        Value = statModifier.Value * (1 - (Distance / radius))                                                   //Do Damage depending the distance from the explosion
                    };

                    TryDamage(nearbyObj.gameObject, modif);
                    TryInteract(nearbyObj.gameObject);

                    modif.ModifyStat(nearbyObj.GetComponentInParent <Stats>());                              //Use the Damageable comonent instead!!!!!!!!!!!!!!!!!!!!!!!!!!!
                }
            }
            Destroy(gameObject, life);
        }
Exemple #2
0
        public virtual void ReceiveDamage(Vector3 Direction, GameObject Damager, StatModifier modifier, bool isCritical, bool react, bool damageeMult)
        {
            Stat st = stats.Stat_Get(modifier.ID);

            if (st != null && !st.IsInmune)
            {
                SetDamageable(Direction, Damager);
                Root?.SetDamageable(Direction, Damager);                                 //Send the Direction and Damager to the Root

                if (isCritical)
                {
                    events.OnCriticalDamage.Invoke();
                    Root?.events.OnCriticalDamage.Invoke();
                }

                if (!damageeMult)
                {
                    modifier.Value *= multiplier;                                                         //Apply to the Stat modifier a new Modification
                }
                events.OnReceivingDamage.Invoke(modifier.Value);
                Root?.events.OnReceivingDamage.Invoke(modifier.Value);

                LastDamage = new DamageData(Damager, modifier);
                if (Root)
                {
                    Root.LastDamage = LastDamage;
                }

                modifier.ModifyStat(st);

                if (react)
                {
                    reaction?.React(character);            //Let the Damagee to apply a reaction
                }
                //Debug.Log("DamageReceived" + modifier.Value.Value);
                //Debug.Log("Damager" + Damager);
            }
        }