//apply effect to all active hostile unit void ApplyEffectAll() { //get all active hostile unit from UnitTracker List <Unit> unitList = UnitTracker.GetAllUnitList(); for (int i = 0; i < unitList.Count; i++) { //clone the attack stats so that the original value wont get modified when making further calculation AttackInstance aInstance = new AttackInstance(); aInstance.aStats = aStats.Clone(); unitList[i].ApplyAttack(aInstance); } }
//launch the ability, at the position given public void Activate(Vector3 pos = default(Vector3), bool useCostNCD = true) { if (useCostNCD) { currentCD = GetCooldown(); //set the cooldown GameControl.GetPlayer().energy -= GetCost(); //deduct player energy by the ability cost } AudioManager.PlaySound(launchSFX); //instantiate the launch object, if there's any if (launchObj != null) { GameObject obj = (GameObject)MonoBehaviour.Instantiate(launchObj, pos, Quaternion.identity); if (autoDestroyLaunchObj) { MonoBehaviour.Destroy(obj, launchObjActiveDuration); } } //for aoe ability if (type == _AbilityType.AOE || type == _AbilityType.AOESelf) { //get all the collider in range Collider[] cols = Physics.OverlapSphere(pos, GetAOERadius()); for (int i = 0; i < cols.Length; i++) { Unit unitInstance = cols[i].gameObject.GetComponent <Unit>(); //only continue if the collider is a unit and is not player if (unitInstance != null && unitInstance != GameControl.GetPlayer()) { //create an AttackInstance and mark it as AOE attack AttackInstance aInstance = new AttackInstance(GameControl.GetPlayer(), GetRuntimeAttackStats()); aInstance.isAOE = true; aInstance.aoeDistance = Vector3.Distance(pos, cols[i].transform.position); //apply the AttackInstance unitInstance.ApplyAttack(aInstance); } } //apply explosion force TDSPhysics.ApplyExplosionForce(pos, aStats); } //for ability that affects all hostile unit in game else if (type == _AbilityType.All) { //get all hostile unit for unit tracker List <Unit> unitList = new List <Unit>(UnitTracker.GetAllUnitList()); //loop through all unit, create an AttackInstance and apply the attack for (int i = 0; i < unitList.Count; i++) { AttackInstance aInstance = new AttackInstance(GameControl.GetPlayer(), GetRuntimeAttackStats()); unitList[i].ApplyAttack(aInstance); } } //for ability that meant to be cast on player unit else if (type == _AbilityType.Self) { //apply the attack on player AttackInstance aInstance = new AttackInstance(GameControl.GetPlayer(), GetRuntimeAttackStats()); GameControl.GetPlayer().ApplyAttack(aInstance); } //for ability that fires a shoot object else if (type == _AbilityType.Shoot) { //get the position and rotation to fire the shoot object from Transform srcT = GetShootObjectSrcTransform(); Vector3 shootPos = srcT.TransformPoint(shootPosOffset); pos.y = shootPos.y; Quaternion shootRot = Quaternion.LookRotation(pos - shootPos); //create the AttackInstance AttackInstance aInstance = new AttackInstance(GameControl.GetPlayer(), GetRuntimeAttackStats()); //Instantiate the shoot-object and fires it GameObject soObj = (GameObject)MonoBehaviour.Instantiate(shootObject, shootPos, shootRot); ShootObject soInstance = soObj.GetComponent <ShootObject>(); soInstance.Shoot(GameControl.GetPlayer().thisObj.layer, GetRange(), srcT, aInstance); } else if (type == _AbilityType.Movement) { if (moveType == _MoveType.Blink) { GameControl.GetPlayer().thisT.position += GameControl.GetPlayer().thisT.TransformVector(Vector3.forward * range); } else if (moveType == _MoveType.Dash) { //GameControl.GetPlayer().thisT.position+=GameControl.GetPlayer().thisT.TransformPoint(Vector3.z)*range; GameControl.GetPlayer().Dash(range, duration); } else if (moveType == _MoveType.Teleport) { Transform playerT = GameControl.GetPlayer().thisT; Vector3 tgtPos = new Vector3(pos.x, playerT.position.y, pos.z); if (Vector3.Distance(playerT.position, tgtPos) > range) { tgtPos = playerT.position + (tgtPos - playerT.position).normalized * range; } playerT.position = tgtPos; } } }