Пример #1
0
    /// <summary>
    /// Gets the nearest enemy.
    /// </summary>
    /// <returns>The nearest enemy.</returns>
    protected Unit GetNearestEnemy()
    {
        TurnOrderController turnOrderController = GameManager.Instance.GetTurnOrderController();
        float currentDistance = Mathf.Infinity;
        Unit  nearestEnemy    = null;

        foreach (Unit unit in turnOrderController.GetAllUnits())
        {
            if (!_self.IsFriendlyUnit(unit))
            {
                float distance = Vector3.Distance(unit.Tile, _self.Tile);
                if (distance < currentDistance)
                {
                    currentDistance = distance;
                    nearestEnemy    = unit;
                }
            }
        }
        //Debug.Log (string.Format("Nearest Enemy - {0}: {1}", nearestEnemy, currentDistance));
        return(nearestEnemy);
    }
Пример #2
0
    private IEnumerator Init()
    {
        _tileMap = controller.TileMap;

        controller.ShowCursorAndTileSelector(false);
        controller.SelectionIndicator.ClearIndicators();
        controller.MissionObjectivesPanel.SetActive(false);

        // Setup turn order
        TurnOrderController turnOrderController = controller.TurnOrderController;
        Unit unit = controller.TurnOrderController.GetNextUp();

        StartCoroutine(controller.CameraController.MoveToPosition(unit.transform.position));
        controller.HighlightCharacter(unit);

        // Determine if music needs to be transitioned higher/lower
        MusicController musicController = controller.MusicController;

        if (IsEnemyNearby(turnOrderController.GetAllUnits()))
        {
            musicController.TransitionMusic(false);
        }
        else
        {
            musicController.TransitionMusic(true);
        }

        // Incremental Effects
        List <Effect> effects = unit.GetEffects();

        if (effects != null && effects.Count > 0)
        {
            // Lower music so you can hear ability SFX
            yield return(StartCoroutine(controller.MusicController.LowerCombatMusic()));

            int index = 0;
            do
            {
                Effect effect = effects [index];

                // Only run this logic with over time effects
                if (effect.GetEffectType() == EffectType.OVER_TIME)
                {
                    bool showedEffectPopupText = false;
                    effect.ApplyIncrementalEffect(unit);

                    List <GameObject> vfxGameObjects = ApplyVFXToTargets(effect.GetVFXPath(), new List <Unit>()
                    {
                        unit
                    });
                    if (effect.GetDisplayString() != "")
                    {
                        showedEffectPopupText = true;
                        PopupTextController.CreatePopupText(effect.GetIncrementalDisplayString(), unit.transform.position, effect.GetColor());
                    }

                    // If unit is killed after application of effect, handle death
                    unit.UpdateHealthbar();

                    // If pop up text was shown, wait x seconds so it doesn't stack with other potential ones
                    if (showedEffectPopupText)
                    {
                        yield return(new WaitForSeconds(2.0f));
                    }

                    if (unit.IsDead())
                    {
                        HandleDeath(unit);
                    }

                    DestroyVFX(vfxGameObjects);
                }

                index++;
            } while (index < effects.Count && unit != null);

            // Bring music back up to normal volume
            yield return(StartCoroutine(controller.MusicController.RaiseCombatMusic()));
        }

        // Decrement Effect Turns
        if (unit != null)
        {
            unit.DecrementEffectTurns();
        }

        yield return(null);

        // If unit is not available at this point, switch state to next unit in the turn order
        if (unit == null)
        {
            controller.ChangeState <TurnOverState> ();
        }
        else
        {
            if (unit.IsPlayerControlled)
            {
                controller.ChangeState <PlayerTurnState> ();
            }
            else
            {
                controller.ChangeState <CPUTurnState> ();
            }
        }
    }