Exemple #1
0
        protected override List <AOETargetNode> GetValidTargets(IAbilityCaster source, GameObject target, AbilityEffectContext abilityEffectInput, List <AbilityEffect> abilityEffectList)
        {
            //Debug.Log(MyName + ".RainEffect.GetValidTargets()");
            // we are intentionally not calling the base class

            // max targets determines how many objects to spawn

            Vector3 aoeSpawnCenter = Vector3.zero;

            if (prefabSpawnLocation == PrefabSpawnLocation.Target && target != null)
            {
                //Debug.Log("AOEEffect.Cast(): Setting AOE center to target");
                aoeSpawnCenter = target.transform.position;
            }
            else if (prefabSpawnLocation == PrefabSpawnLocation.Caster)
            {
                //Debug.Log("AOEEffect.Cast(): Setting AOE center to caster");
                aoeSpawnCenter = source.UnitGameObject.transform.position;
            }
            else if (prefabSpawnLocation == PrefabSpawnLocation.GroundTarget)
            {
                //Debug.Log("AOEEffect.Cast(): Setting AOE center to groundTarget at: " + abilityEffectInput.prefabLocation);
                aoeSpawnCenter = abilityEffectInput.groundTargetLocation;
            }
            else
            {
                //Debug.Log("AOEEffect.Cast(): Setting AOE center to vector3.zero!!! was prefab spawn location not set or target despawned?");
            }
            //aoeSpawnCenter += source.UnitGameObject.transform.TransformDirection(aoeCenter);

            //Debug.Log("AOEEffect.Cast(): Casting OverlapSphere with radius: " + aoeRadius);
            List <AOETargetNode> validTargets = new List <AOETargetNode>();

            // for loop max targets
            for (int i = 0; i < maxTargets; i++)
            {
                AOETargetNode validTargetNode = new AOETargetNode();
                validTargetNode.targetGameObject = null;
                //abilityEffectInput.prefabLocation = new Vector3(aoeSpawnCenter.x + Random.Range(-aoeRadius, aoeRadius), aoeSpawnCenter.y + aoeCenter.y, aoeSpawnCenter.z + Random.Range(-aoeRadius, aoeRadius));
                validTargetNode.abilityEffectInput = new AbilityEffectContext();

                foreach (ResourceInputAmountNode resourceInputAmountNode in abilityEffectInput.resourceAmounts)
                {
                    validTargetNode.abilityEffectInput.AddResourceAmount(resourceInputAmountNode.resourceName, (int)resourceInputAmountNode.amount);
                }

                validTargetNode.abilityEffectInput.overrideDuration      = abilityEffectInput.overrideDuration;
                validTargetNode.abilityEffectInput.savedEffect           = abilityEffectInput.savedEffect;
                validTargetNode.abilityEffectInput.castTimeMultiplier    = abilityEffectInput.castTimeMultiplier;
                validTargetNode.abilityEffectInput.spellDamageMultiplier = abilityEffectInput.spellDamageMultiplier;
                //validTargetNode.abilityEffectInput.prefabLocation = abilityEffectInput.prefabLocation;
                //validTargetNode.abilityEffectInput = abilityEffectInput;
                validTargetNode.abilityEffectInput.groundTargetLocation = new Vector3(aoeSpawnCenter.x + Random.Range(-aoeRadius, aoeRadius), aoeSpawnCenter.y + aoeCenter.y, aoeSpawnCenter.z + Random.Range(-aoeRadius, aoeRadius));
                //Debug.Log(MyName + ".RainEffect.GetValidTargets(). prefabLocation: " + validTargetNode.abilityEffectInput.prefabLocation);
                validTargets.Add(validTargetNode);
            }

            //Debug.Log(MyName + ".RainEffect.GetValidTargets(). Valid targets count: " + validTargets.Count);
            return(validTargets);
        }
Exemple #2
0
        protected virtual List <AOETargetNode> GetValidTargets()
        {
            //Debug.Log(gameObject.name + ".EnvironmentalEffectArea.GetValidTargets()");

            Vector3 aoeSpawnCenter = transform.position;

            Collider[] colliders     = new Collider[0];
            int        playerMask    = 1 << LayerMask.NameToLayer("Player");
            int        characterMask = 1 << LayerMask.NameToLayer("CharacterUnit");
            int        validMask     = (playerMask | characterMask);

            //Debug.Log(MyName + ".AOEEffect.GetValidTargets(): using aoeSpawnCenter: " + aoeSpawnCenter + ", extents: " + aoeExtents);
            colliders = Physics.OverlapBox(aoeSpawnCenter, boxCollider.bounds.extents, Quaternion.identity, validMask);

            //Debug.Log("AOEEffect.Cast(): Casting OverlapSphere with radius: " + aoeRadius);
            List <AOETargetNode> validTargets = new List <AOETargetNode>();

            foreach (Collider collider in colliders)
            {
                //Debug.Log(gameObject.name + ".EnvironmentalEffectArea.GetValidTargets() hit: " + collider.gameObject.name + "; layer: " + collider.gameObject.layer);

                bool canAdd = true;
                if (collider.gameObject.GetComponent <CharacterUnit>() == null)
                {
                    canAdd = false;
                }

                /*
                 * foreach (AbilityEffect abilityEffect in abilityEffects) {
                 *  if (abilityEffect.CanUseOn(collider.gameObject, source) == false) {
                 *      canAdd = false;
                 *  }
                 * }
                 */
                //Debug.Log(MyName + "performing AOE ability  on " + collider.gameObject);
                if (canAdd)
                {
                    AOETargetNode validTargetNode = new AOETargetNode();
                    validTargetNode.targetGameObject = collider.gameObject;
                    validTargets.Add(validTargetNode);
                }
            }
            //Debug.Log(gameObject.name + ".EnvironmentalEffectArea.GetValidTargets(). Valid targets count: " + validTargets.Count);
            return(validTargets);
        }
Exemple #3
0
        protected virtual List <AOETargetNode> GetValidTargets(IAbilityCaster source, Interactable target, AbilityEffectContext abilityEffectContext, List <AbilityEffect> abilityEffectList)
        {
            //Debug.Log(DisplayName + ".AOEEffect.GetValidTargets()");

            Vector3 aoeSpawnCenter = Vector3.zero;

            if (prefabSpawnLocation == PrefabSpawnLocation.Target && target != null)
            {
                //Debug.Log("AOEEffect.Cast(): Setting AOE center to target");
                aoeSpawnCenter = target.transform.position;
            }
            else if (prefabSpawnLocation == PrefabSpawnLocation.Caster)
            {
                //Debug.Log("AOEEffect.Cast(): Setting AOE center to caster");
                aoeSpawnCenter  = source.AbilityManager.UnitGameObject.transform.position;
                aoeSpawnCenter += source.AbilityManager.UnitGameObject.transform.TransformDirection(aoeCenter);
            }
            else if (prefabSpawnLocation == PrefabSpawnLocation.GroundTarget)
            {
                //Debug.Log("AOEEffect.Cast(): Setting AOE center to groundTarget at: " + abilityEffectInput.prefabLocation);
                aoeSpawnCenter  = abilityEffectContext.groundTargetLocation;
                aoeSpawnCenter += aoeCenter;
            }
            else
            {
                //Debug.Log("AOEEffect.Cast(): Setting AOE center to vector3.zero!!! was prefab spawn location not set or target despawned?");
            }
            //aoeSpawnCenter += source.AbilityManager.UnitGameObject.transform.TransformDirection(aoeCenter);
            Collider[] colliders     = new Collider[0];
            int        playerMask    = 1 << LayerMask.NameToLayer("Player");
            int        characterMask = 1 << LayerMask.NameToLayer("CharacterUnit");
            int        validMask     = (playerMask | characterMask);

            if (useRadius)
            {
                colliders = Physics.OverlapSphere(aoeSpawnCenter, aoeRadius, validMask);
            }
            if (useExtents)
            {
                //Debug.Log(MyName + ".AOEEffect.GetValidTargets(): using aoeSpawnCenter: " + aoeSpawnCenter + ", extents: " + aoeExtents);
                colliders = Physics.OverlapBox(aoeSpawnCenter, aoeExtents / 2f, source.AbilityManager.UnitGameObject.transform.rotation, validMask);
            }
            //Debug.Log("AOEEffect.Cast(): Casting OverlapSphere with radius: " + aoeRadius);
            List <AOETargetNode> validTargets = new List <AOETargetNode>();

            foreach (Collider collider in colliders)
            {
                //Debug.Log(DisplayName + ".AOEEffect.Cast() hit: " + collider.gameObject.name + "; layer: " + collider.gameObject.layer);
                bool         canAdd             = true;
                Interactable targetInteractable = collider.gameObject.GetComponent <Interactable>();
                foreach (AbilityEffect abilityEffect in abilityEffectList)
                {
                    if (abilityEffect.CanUseOn(targetInteractable, source, abilityEffectContext) == false)
                    {
                        canAdd = false;
                    }
                }
                //if (CanUseOn(collider.gameObject, source)) {
                // next line was preventing aoe from hitting current target
                //if (collider.gameObject != target && CanUseOn(collider.gameObject, source)) {
                //Debug.Log(MyName + "performing AOE ability  on " + collider.gameObject);
                if (canAdd)
                {
                    AOETargetNode validTargetNode = new AOETargetNode();
                    validTargetNode.targetGameObject   = targetInteractable;
                    validTargetNode.abilityEffectInput = abilityEffectContext;
                    validTargets.Add(validTargetNode);
                }
                //Debug.Log(MyName + "AOEEffect.GetValidTargets(). maxTargets: " + maxTargets + "; validTargets.Count: " + validTargets.Count);
                if (maxTargets > 0)
                {
                    //Debug.Log(MyName + "AOEEffect.GetValidTargets(). maxTargets: " + maxTargets + "; validTargets.Count: " + validTargets.Count);
                    while (validTargets.Count > maxTargets)
                    {
                        int removeNumber = 0;
                        if (preferClosestTargets == true)
                        {
                            int counter = 0;
                            foreach (AOETargetNode validTarget in validTargets)
                            {
                                if (Vector3.Distance(validTarget.targetGameObject.transform.position, source.AbilityManager.UnitGameObject.transform.position) > Vector3.Distance(validTargets[removeNumber].targetGameObject.transform.position, source.AbilityManager.UnitGameObject.transform.position))
                                {
                                    removeNumber = counter;
                                }
                                counter++;
                            }
                        }
                        else
                        {
                            removeNumber = Random.Range(0, validTargets.Count);
                        }
                        //Debug.Log("AOEEffect.GetValidTargets(). maxTargets: " + maxTargets + "; validTargets.Count: " + validTargets.Count + "; randomNumber: " + randomNumber);
                        validTargets.RemoveAt(removeNumber);
                    }
                }
                //}
            }
            //Debug.Log(abilityEffectName + ".AOEEffect.Cast(). Valid targets count: " + validTargets.Count);
            return(validTargets);
        }