예제 #1
0
    public override IEnumerator StartMyActivationCoroutine()
    {
        Ability strike = mySpellBook.GetAbilityByName("Strike");
        Ability move   = mySpellBook.GetAbilityByName("Move");

ActionStart:
        while (EventManager.Instance.gameOverEventStarted)
        {
            yield return(null);
        }

        SetTargetDefender(EntityLogic.GetClosestValidEnemy(this));

        if (EntityLogic.IsAbleToTakeActions(this) == false)
        {
            LivingEntityManager.Instance.EndEntityActivation(this);
        }

        // Strike
        else if (EntityLogic.IsAbilityUseable(this, strike) &&
                 EntityLogic.IsTargetInRange(this, myCurrentTarget, currentMeleeRange))
        {
            Action action = AbilityLogic.Instance.PerformStrike(this, myCurrentTarget);
            yield return(new WaitUntil(() => action.ActionResolved() == true));

            yield return(new WaitForSeconds(1f));

            goto ActionStart;
        }

        // Move
        else if (EntityLogic.IsTargetInRange(this, myCurrentTarget, currentMeleeRange) == false &&
                 EntityLogic.IsAbleToMove(this) &&
                 EntityLogic.CanPerformAbilityTwoAfterAbilityOne(move, strike, this) &&
                 EntityLogic.IsAbilityUseable(this, move) &&
                 EntityLogic.GetBestValidMoveLocationBetweenMeAndTarget(this, myCurrentTarget, currentMeleeRange, EntityLogic.GetTotalMobility(this)) != null)
        {
            SetTargetDefender(EntityLogic.GetClosestEnemy(this));

            Tile   destination    = EntityLogic.GetBestValidMoveLocationBetweenMeAndTarget(this, myCurrentTarget, currentMeleeRange, EntityLogic.GetTotalMobility(this));
            Action movementAction = AbilityLogic.Instance.PerformMove(this, destination);
            yield return(new WaitUntil(() => movementAction.ActionResolved() == true));

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

            goto ActionStart;
        }

        // Can't do anything more, end activation
        else
        {
            LivingEntityManager.Instance.EndEntityActivation(this);
        }
    }