Пример #1
0
    /// <summary>
    /// Deals damage to a given target combatant based on the stats of a given
    /// source combatant.
    /// </summary>
    /// <param name="source">The attacking combatant.</param>
    /// <param name="target">The combatant being attacked.</param>
    private IEnumerator DoAttack(CombatantController source, CombatantController target)
    {
        // If these combatants are animating, wait for them to finish
        while (currentlyAnimatingCombatants.Contains(source.BattleID) ||
               currentlyAnimatingCombatants.Contains(target.BattleID))
        {
            Debug.Log("Waiting for combatants to finish animating!");
            yield return(null);
        }

        // These combatants are ready to animate, so remove them from the anim
        // queue
        combatantsQueuedForAnim.Remove(source.BattleID);
        combatantsQueuedForAnim.Remove(target.BattleID);

        // Add the combatant IDs to the list of currently animating ones
        // so they don't get involved in any future animations throughout this
        // one
        currentlyAnimatingCombatants.Add(source.BattleID);
        currentlyAnimatingCombatants.Add(target.BattleID);

        Vector3 moveTarget = target.transform.position;

        if (target.Allegiance == Allegiance.PLAYER)
        {
            moveTarget += new Vector3(0.3f, 0f);
        }
        else
        {
            moveTarget += new Vector3(-0.3f, 0f);
        }
        Vector3 startPos = source.transform.position;

        // Move the combatant to "attack range" of its target
        yield return(MoveCombatantToPos(source, moveTarget, 0.5f));

        source.SetAnimBool("attacking", true);

        yield return(new WaitForSeconds(source.GetAnimDuration("attacking")));

        // Simply use the attack ability
        DoAbility(attackAbility, source, new List <CombatantController>()
        {
            target
        });

        source.SetAnimBool("attacking", false);

        yield return(MoveCombatantToPos(source, startPos, 0.5f));

        // These combatants are no longer animating, so remove them from the
        // list so they can be involved in future animations
        currentlyAnimatingCombatants.Remove(source.BattleID);
        currentlyAnimatingCombatants.Remove(target.BattleID);
    }
Пример #2
0
    /// <summary>
    /// Smoothly moves a combatant's sprite to the given location in world space
    /// over the given duration.
    /// </summary>
    /// <param name="source">The combatant moving.</param>
    /// <param name="target">The location being moved to.</param>
    /// <param name="duration">How long the combatant should be in motion for</param>
    /// <returns></returns>
    private IEnumerator MoveCombatantToPos(CombatantController source, Vector3 target, float duration)
    {
        source.SetAnimBool("moving", true);

        Vector3 startPos = source.transform.position;
        float   dt       = 0f;

        while (dt < duration)
        {
            dt += Time.smoothDeltaTime;
            source.transform.position = Vector3.Lerp(startPos, target, dt / duration);
            yield return(null);
        }
        source.transform.position = target;

        source.SetAnimBool("moving", false);
    }
Пример #3
0
    private void KillCombatant(CombatantController target)
    {
        // Set their animation
        target.SetAnimBool("dead", true);

        // If all enemies or heroes are dead, end the battle
        int numDeadHeroes  = 0;
        int numDeadEnemies = 0;

        for (int i = 0; i < GetNumHeroes(); ++i)
        {
            if (Combatants[i].HP <= 0)
            {
                numDeadHeroes++;
            }
        }
        for (int i = GetNumHeroes(); i < GetNumCombatants(); ++i)
        {
            if (Combatants[i].HP <= 0)
            {
                numDeadEnemies++;
            }
        }

        // Check if the battle is over
        if (numDeadHeroes == GetNumHeroes())
        {
            State = BattleState.ENEMYWON;
            EndBattle();
        }
        else if (numDeadEnemies == GetNumEnemies())
        {
            State = BattleState.PLAYERWON;
            EndBattle();
        }
        else
        {
            // Refresh turn order
            RefreshTurnOrder();
            turnController.ForceRefreshTurnOrder();
        }
    }