// Update is called once per frame
    public override void UpdateCombatControls()
    {
        base.UpdateCombatControls();

        if (character.isIdle)
        {
            if (obstacle.enabled)
            {
                obstacle.enabled = false;
                return;
            }

            if (character.remainingActions > 0)
            {
                MeleeAttackAbility meleeAbility = character.GetCastableAbilities <MeleeAttackAbility>()
                                                  .Where(a => a.CharacterHasEnoughMana(character))
                                                  .OrderByDescending(m => m.threatRating).FirstOrDefault();

                if (meleeAbility != null)
                {
                    MeleeAttackAbility currentAbility = meleeAbility;

                    target = CharacterUtils.GetClosestCharacter(GameController.instance.party, character.position);

                    if (target != null)
                    {
                        if (character.currentTile.IsAdjacent(target.currentTile))
                        {
                            if (currentAbility.IsCastable(character))
                            {
                                currentAbility.caster = character;
                                currentAbility.target = target.frame;

                                character.PushAction(currentAbility.Prepare());
                                character.PushAction(currentAbility.Cast());
                            }
                        }
                        else
                        {
                            if (character.remainingSteps > 0)
                            {
                                character.PushAction(new CharacterNavigateToTileAction(target.currentTile, true));
                            }
                            else
                            {
                                EndCombatTurn();
                                return;
                            }
                        }
                    }
                    else
                    {
                        EndCombatTurn();
                    }
                }
                else
                {
                    EndCombatTurn();
                }
            }
            else
            {
                EndCombatTurn();
            }
        }

        if (character.isIdle && character.isAlive)
        {
            if (!obstacle.enabled)
            {
                obstacle.enabled = true;
            }
        }
    }
Exemplo n.º 2
0
    // Update is called once per frame
    public override void UpdateCombatControls()
    {
        base.UpdateCombatControls();

        if (character.isIdle)
        {
            if (obstacle.enabled)
            {
                obstacle.enabled = false;
                return;
            }

            if (character.remainingActions > 0)
            {
                MeleeAttackAbility meleeAbility = character.GetCastableAbilities <MeleeAttackAbility>()
                                                  .OrderByDescending(m => m.threatRating).FirstOrDefault();

                if (meleeAbility != null)
                {
                    target = CharacterUtils.GetClosestCharacter(GameController.instance.party, character.position);

                    if (target != null)
                    {
                        float distance = Vector3.Distance(character.position, target.position);

                        if (distance > meleeAbility.attackRange)
                        {
                            if (character.remainingSteps > 0.0f)
                            {
                                character.PushAction(new CharacterNavigateToAction(target.position, character.remainingSteps, false,
                                                                                   meleeAbility.attackRange - 0.1f));
                            }
                            else
                            {
                                EndCombatTurn();
                                return;
                            }
                        }
                        else
                        {
                            meleeAbility.caster = character;
                            meleeAbility.target = target.frame;

                            character.PushAction(meleeAbility.Prepare());
                            character.PushAction(meleeAbility.Cast());
                        }
                    }
                    else
                    {
                        EndCombatTurn();
                    }
                }
                else
                {
                    EndCombatTurn();
                }
            }
            else
            {
                EndCombatTurn();
            }
        }



        if (character.isIdle)
        {
            if (!obstacle.enabled)
            {
                obstacle.enabled = true;
            }
        }
    }