Exemple #1
0
        //launch an area damage:
        public void LaunchAreaDamage(Vector3 center, int sourceFactionID)
        {
            Collider[] collidersInRange = Physics.OverlapSphere(center, attackRanges[attackRanges.Length - 1].GetRange());
            foreach (Collider c in collidersInRange)
            {
                SelectionEntity selection = c.gameObject.GetComponent <SelectionEntity>();
                if (selection == null || selection.FactionEntity == null) //if the collider doesn't belong to an object with a selection component or it does but it's linked to a resource
                {
                    continue;                                             //move to next one
                }
                //make sure the faction entity can be attacked
                if (selection.FactionEntity.FactionID == sourceFactionID || (source != null && (!source.CanAttackFaction(selection.FactionEntity.FactionID) || source.CanEngageTarget(selection.FactionEntity) != ErrorMessage.none)))
                {
                    continue;
                }

                float distance = Vector3.Distance(selection.Source.transform.position, center);
                //target can be attacked by this source, go through the attack ranges to deal the right damage
                for (int i = 0; i < attackRanges.Length; i++)
                {
                    if (distance > attackRanges[i].GetRange()) //as long as the right range for this faction entity isn't found
                    {
                        continue;                              //move to next one
                    }
                    //correct range is found, get either the unit or building damage value and apply damage
                    currDamage = (selection.FactionEntity.Type == EntityTypes.unit) ? attackRanges[i].GetUnitDamage() : attackRanges[i].GetBuildingDamage();
                    DealDamage(selection.FactionEntity); //deal damage
                }
            }
        }