Exemple #1
0
        public static Impact GetImpact(LethalEntity entity, GameObject target, bool friendlyFire, Vector3 hitPoint, Vector3 hitNormal)
        {
            Impact imp = new Impact();

            imp.owner     = entity.owner;
            imp.target    = target;
            imp.hitPoint  = hitPoint;
            imp.hitNormal = hitNormal;

            imp.damageType   = entity.damageType;
            imp.faction      = entity.faction;
            imp.damageNature = entity.damageNature;

            if (entity.randomDamagePoint)
            {
                imp.damagePoint = Random.Range(entity.damagePoint, entity.damagePointMax);
            }
            else
            {
                imp.damagePoint = entity.damagePoint;
            }

            imp.damageRadius = entity.damageRadius;

            imp.isPhysic  = entity.isPhysic;
            imp.force     = entity.force;
            imp.forceMode = entity.forceMode;

            return(imp);
        }
Exemple #2
0
        protected void DoAreaDamage(Vector3 position, bool perSecond = false)
        {
            Collider[] hitColliders = Physics.OverlapSphere(position, damageRadius, layerMask, QueryTriggerInteraction.Ignore);

            bool isFriendlyFire = GameManager.instance.friendlyFire;

            for (int i = 0; i < hitColliders.Length; i++)
            {
                GameEntity entity = hitColliders[i].GetComponentInParent <GameEntity>();

                if (entity && (isFriendlyFire || !isFriendlyFire && faction && faction.GetAlignement(entity.faction) < 1 && entity.gameObject.activeInHierarchy))
                {
                    Vector3 closestPoint = hitColliders[i].ClosestPointOnBounds(position);
                    float   distance     = Vector3.Distance(closestPoint, position);
                    float   damage       = 1f - Mathf.Clamp01(distance / damageRadius);

                    Impact imp = Impact.GetImpact(this, hitColliders[i].gameObject, isFriendlyFire, closestPoint, Vector3.zero);
                    imp.damagePoint *= damage;
                    if (perSecond)
                    {
                        imp.damagePoint *= Time.deltaTime;
                    }

                    entity.ReceiveDamage(imp);
                }
            }
        }
Exemple #3
0
        protected void DoDamage(GameObject target, Vector3 hitPosition, Vector3 hitNormal, bool perSecond = false)
        {
            if (target)
            {
                bool isFriendlyFire = GameManager.Instance.friendlyFire;

                switch (damageType)
                {
                case DamageType.Simple:
                    GameEntity entity = target.GetComponentInParent <GameEntity>();

                    if (entity && entity.gameObject.activeInHierarchy && (isFriendlyFire || ((!isFriendlyFire && faction && faction.GetAlignement(entity.faction) < 1) || (!isFriendlyFire && faction == null))))
                    {
                        Impact imp = Impact.GetImpact(this, target, isFriendlyFire, hitPosition, hitNormal);
                        if (perSecond)
                        {
                            imp.damagePoint *= Time.deltaTime;
                        }
                        entity.ReceiveDamage(imp);
                    }
                    break;

                case DamageType.Area:

                    DoAreaDamage(hitPosition, perSecond);
                    break;
                }
            }
        }
Exemple #4
0
 private void DamageMitigation(Impact impact)
 {
     if (mitigation > 0)
     {
         impact.damagePoint *= (1 - mitigation);
         impact.target       = protectedEntity.gameObject;
         protectedEntity.ReceiveDamage(impact);
     }
 }
Exemple #5
0
        public void InitHitEffect(Impact impact)
        {
            owner = impact.target.transform;

            if (useObjectPivot)
            {
                if (!localOffset)
                {
                    cachedTransform.position = owner.position + offset;
                }
                else
                {
                    cachedTransform.position = owner.TransformPoint(offset);
                }
            }

            SetDamageValue(impact.damagePoint);
        }
Exemple #6
0
        public void ReceiveDamage(Impact impact)
        {
            if (!isInvulnerable && !isOnDespawn)
            {
                impact.damagePoint = impact.damagePoint * damagesSensitivity[impact.damageNature];


                life        -= impact.damagePoint;
                damageStack += impact.damagePoint;

                onHit.Invoke(impact);

                // Life is over
                if (life <= 0 && !isOnDespawn)
                {
                    // Hit
                    if (hitEffects.Length > 0)
                    {
                        for (int i = 0; i < hitEffects.Length; i++)
                        {
                            GameObject tmpObj = PoolManager.Spawn(hitEffects[i], impact.hitPoint + hitEffectOffset, Quaternion.identity);
                            IHitEffect effect = tmpObj.GetComponent <IHitEffect>();
                            if (effect != null)
                            {
                                effect.InitHitEffect(impact);
                            }
                        }
                        onHit.Invoke(impact);
                    }

                    Kill();

                    // Score management
                    if (impact.owner && impact.owner.CompareTag("Player"))
                    {
                        GameEntity playerEntity = impact.owner.GetComponent <GameEntity>();
                        if ((playerEntity && playerEntity.life > 0) || playerEntity == null)
                        {
                            GameManager.instance.Add2Score(scorePoint);
                        }
                    }
                }
                else
                {
                    // Force
                    if (impact.isPhysic && cachedRigidbody && addForceFromImpact)
                    {
                        if (impact.damageType == DamageType.Simple)
                        {
                            cachedRigidbody.AddForceAtPosition(impact.hitNormal * impact.force * -1 * damagesSensitivity[impact.damageNature], impact.hitPoint, impact.forceMode);
                        }
                        else
                        {
                            cachedRigidbody.AddExplosionForce(impact.force, impact.hitPoint, impact.damageRadius, 2f, impact.forceMode);
                        }
                    }

                    // Hit Effect
                    if (hitEffects.Length > 0 && damageStack >= damageThreshold)
                    {
                        for (int i = 0; i < hitEffects.Length; i++)
                        {
                            impact.damagePoint = damageStack;
                            GameObject tmpObj = PoolManager.Spawn(hitEffects[i], impact.hitPoint + hitEffectOffset, Quaternion.identity);
                            IHitEffect effect = tmpObj.GetComponent <IHitEffect>();
                            if (effect != null)
                            {
                                effect.InitHitEffect(impact);
                            }
                        }

                        damageStack = 0;
                    }
                }
            }
        }