Example #1
0
    public override IEnumerator StartMyActivationCoroutine()
    {
        Ability move       = mySpellBook.GetAbilityByName("Move");
        Ability siphonLife = mySpellBook.GetAbilityByName("Siphon Life");
        Ability twinStrike = mySpellBook.GetAbilityByName("Twin Strike");
        Ability teleport   = mySpellBook.GetAbilityByName("Teleport");
        Ability fireBall   = mySpellBook.GetAbilityByName("Fire Ball");

        ChooseRandomTargetingLogic();

ActionStart:


        if (myCurrentTarget.currentHealth <= 0 || myCurrentTarget == null)
        {
            ChooseRandomTargetingLogic();
        }

        if (IsAbleToTakeActions() == false)
        {
            EndMyActivation();
        }

        // Siphon Life
        else if (IsAbilityOffCooldown(siphonLife.abilityCurrentCooldownTime) &&
                 IsTargetInRange(myCurrentTarget, siphonLife.abilityRange) &&
                 HasEnoughAP(currentAP, siphonLife.abilityAPCost)
                 )
        {
            //SetTargetDefender(GetClosestDefender());
            StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Siphon Life", false));
            yield return(new WaitForSeconds(0.5f));

            AbilityLogic.Instance.PerformSiphonLife(this, myCurrentTarget);
            // brief delay between actions
            yield return(new WaitForSeconds(1f));

            goto ActionStart;
        }

        // If unable to siphon life the ideal target, siphon the closest valid target
        else if (IsAbilityOffCooldown(siphonLife.abilityCurrentCooldownTime) &&
                 IsTargetInRange(GetClosestDefender(), siphonLife.abilityRange) &&
                 HasEnoughAP(currentAP, siphonLife.abilityAPCost)
                 )
        {
            SetTargetDefender(GetClosestDefender());
            StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Siphon Life", false));
            yield return(new WaitForSeconds(0.5f));

            AbilityLogic.Instance.PerformSiphonLife(this, myCurrentTarget);
            // brief delay between actions
            yield return(new WaitForSeconds(1f));

            goto ActionStart;
        }

        // Twin Strike
        else if (IsTargetInRange(myCurrentTarget, currentMeleeRange) &&
                 HasEnoughAP(currentAP, twinStrike.abilityAPCost) &&
                 IsAbilityOffCooldown(twinStrike.abilityCurrentCooldownTime))
        {
            //SetTargetDefender(GetDefenderWithLowestCurrentHP());
            StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Twin Strike", false));
            yield return(new WaitForSeconds(0.5f));

            AbilityLogic.Instance.PerformTwinStrike(this, myCurrentTarget);
            yield return(new WaitForSeconds(1f));

            goto ActionStart;
        }

        // Fireball
        else if (IsTargetInRange(myCurrentTarget, fireBall.abilityRange) &&
                 HasEnoughAP(currentAP, fireBall.abilityAPCost) &&
                 IsAbilityOffCooldown(fireBall.abilityCurrentCooldownTime))
        {
            //SetTargetDefender(GetMostVulnerableDefender());
            StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Fire Ball", false));
            yield return(new WaitForSeconds(0.5f));

            AbilityLogic.Instance.PerformFireBall(this, myCurrentTarget);
            yield return(new WaitForSeconds(1f));

            goto ActionStart;
        }


        // Move
        else if (IsTargetInRange(myCurrentTarget, fireBall.abilityRange) == false &&
                 IsAbleToMove() &&
                 HasEnoughAP(currentAP, move.abilityAPCost) &&
                 IsAbilityOffCooldown(move.abilityCurrentCooldownTime)
                 )
        {
            StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Move", false));
            yield return(new WaitForSeconds(0.5f));

            TileScript destination = AILogic.GetBestValidMoveLocationBetweenMeAndTarget(this, myCurrentTarget, fireBall.abilityRange, currentMobility);
            AbilityLogic.Instance.PerformMove(this, destination);

            // small delay here in order to seperate the two actions a bit.
            yield return(new WaitForSeconds(1f));

            goto ActionStart;
        }

        else if (AILogic.IsEngagedInMelee(this) &&
                 IsAbilityOffCooldown(teleport.abilityCurrentCooldownTime) &&
                 HasEnoughAP(currentAP, teleport.abilityAPCost)
                 )
        {
            StartCoroutine(VisualEffectManager.Instance.CreateStatusEffect(transform.position, "Teleport", false));
            yield return(new WaitForSeconds(0.5f));

            AbilityLogic.Instance.PerformTeleport(this, GetBestTeleportLocation(myCurrentTarget.TileCurrentlyOn));

            yield return(new WaitForSeconds(1f));

            goto ActionStart;
        }

        EndMyActivation();
    }