Exemplo n.º 1
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;
            }
        }
    }
    // 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;
            }
        }
    }
    public override void UpdateCombatControls()
    {
        if (GameController.state == GameState.Combat)
        {
            if (character.isIdle)
            {
                if (obstacle.enabled)
                {
                    obstacle.enabled = false;
                    return;
                }

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

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

                        if (target != null)
                        {
                            NeverdawnCamera.AddTargetLerped(target.transform);
                            hasFallback = false;

                            float distance = Vector3.Distance(character.position, target.position);

                            if (distance > rangedAttack.weapon.estimatedRange + character.remainingSteps)
                            {
                                if (character.remainingSteps > 0.0f)
                                {
                                    character.PushAction(new CharacterNavigateToAction(target.position, character.remainingSteps, false,
                                                                                       rangedAttack.weapon.estimatedRange - 0.1f));
                                }
                                else
                                {
                                    GameController.instance.combatController.EndTurn(this);
                                    return;
                                }
                            }
                            else
                            {
                                // Get positions and sort by strategic value (furthest away from target!)
                                List <Vector3> positions = sampleSurroundings(20, character.remainingSteps);
                                positions = positions.OrderByDescending(p => Vector3.Distance(p, target.position)).ToList();

                                // No position found yet!
                                bool    hasPosition    = false;
                                Vector3 targetPosition = Vector3.negativeInfinity;
                                Vector3 targetVelocity = Vector3.negativeInfinity;
                                Vector3 force;

                                foreach (Vector3 position in positions)
                                {
                                    Vector3 direction = target.position - position;
                                    direction.y = 0.0f;
                                    direction.Normalize();

                                    launchTransform.position = position;
                                    launchTransform.forward  = direction;

                                    Vector3 launchPosition = launchTransform.TransformPoint(rangedAttack.weapon.projectileSpawn);

                                    if (tryHitTarget(rangedAttack, launchPosition, target.frame, out force, 5))
                                    {
                                        targetPosition = position;
                                        targetVelocity = force;
                                        hasPosition    = true;
                                        break;
                                    }
                                }

                                if (hasPosition)
                                {
                                    rangedAttack.targetVelocity = targetVelocity;
                                    rangedAttack.caster         = character;

                                    character.PushAction(new CharacterNavigateToAction(targetPosition, character.remainingSteps, false));
                                    character.PushAction(rangedAttack.Prepare());
                                    character.PushAction(rangedAttack.Cast());
                                }
                                else
                                {
                                    if (hasFallback)
                                    {
                                        rangedAttack.targetVelocity = fallBackVelocity;
                                        rangedAttack.caster         = character;

                                        character.PushAction(new CharacterNavigateToAction(fallbackPosition, character.remainingSteps, false));
                                        character.PushAction(rangedAttack.Prepare());
                                        character.PushAction(rangedAttack.Cast());
                                    }
                                    else
                                    {
                                        GameController.instance.combatController.EndTurn(this);
                                    }
                                }
                            }
                        }
                        else
                        {
                            GameController.instance.combatController.EndTurn(this);
                        }
                    }
                    else
                    {
                        EndCombatTurn();
                    }
                }
                else
                {
                    if (target)
                    {
                        NeverdawnCamera.RemoveTargetLerped(target.transform);
                    }

                    EndCombatTurn();
                }
            }
        }


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