Exemple #1
0
        //a method that deals damage to a target:
        private void DealDamage(FactionEntity target)
        {
            if (canDealDamage == false || target == null) //can't deal damage then stop here
            {
                return;
            }

            if (dotEnabled == true) //is damage over time enabled?
            {
                DamageOverTime dot = null;

                foreach (DamageOverTime potentialDoT in target.EntityHealthComp.DotComps) //go through the potential damage over time components on the target
                {
                    if (potentialDoT.IsActive == false)                                   //if it's not active, we can activate and use it
                    {
                        dot = potentialDoT;
                        break;
                    }
                }

                if (dot == null)                                             //if no free DoT component has been found
                {
                    dot = target.gameObject.AddComponent <DamageOverTime>(); //create new instance of the Damage Over Time component on the target
                    target.EntityHealthComp.DotComps.Add(dot);
                }

                dot.Init(currDamage, dotAttributes, (source != null) ? source.FactionEntity : null, target.EntityHealthComp); //assign the DoT attributes.
            }
            else
            {
                target.EntityHealthComp.AddHealth(-currDamage, source.FactionEntity);
            }

            //spawn damage and effect objects:
            gameMgr.EffectPool.SpawnEffectObj(target.EntityHealthComp.GetDamageEffect(), target.transform.position, Quaternion.identity, target.transform);
            gameMgr.EffectPool.SpawnEffectObj(effect, target.transform.position, Quaternion.identity, target.transform, true, false, effectLifeTime);

            //if there's a valid source:
            if (source != null)
            {
                source.AddDamageDealt(currDamage);
            }

            //trigger attack damage dealt event
            source.InvokeAttackDamageDealtEvent();
            CustomEvents.OnAttackDamageDealt(source, target, currDamage);
        }