Beispiel #1
0
 public static void OnUnitSelected(TacticsCharacter unit)
 {
     if (onUnitSelectedEvent != null)
     {
         onUnitSelectedEvent(unit);
     }
 }
Beispiel #2
0
    private IEnumerator ShootUnitRoutine(TacticsCharacter targetUnit, Action onShootRoutineComplete)
    {
        // Time to wait for the initial rotation
        yield return(new WaitForSeconds(0.25f));

        for (int i = 0; i < m_ProjectilesPerAttack; i++)
        {
            if (targetUnit == null || targetUnit._health == null)
            {
                break;
            }

            LineRenderer lineRenderer = null;
            // Attack visual / Line Renderer
            if (m_LineRendererPrefab != null)
            {
                var startPosition    = m_GunBarrel != null ? m_GunBarrel.position : transform.position;
                var targetPosition   = targetUnit.transform.position + (Vector3.up * 0.5f);
                var relativePosition = targetPosition - startPosition;
                lineRenderer = Instantiate(m_LineRendererPrefab, startPosition, Quaternion.identity);
                Vector3[] pos = new Vector3[2] {
                    startPosition, targetPosition - (relativePosition.normalized * 0.2f)
                };
                lineRenderer.SetPositions(pos);
            }
            // Apply damage and create the popup text
            DamageHealth(targetUnit._health);
            PopupTextManager.Instance.CreatePopupText(targetUnit.transform.position, m_AttackDamage.ToString(), Vector3.down * 0.15f + UnityEngine.Random.insideUnitSphere * 0.25f);
            // Wait 1 frame
            yield return(null);

            // Camera Shake
            var cis = GetComponent <CinemachineImpulseSource>();
            if (cis != null)
            {
                cis.GenerateImpulse(Vector3.one);
            }
            // Wait time before deactivating the line renderere
            yield return(new WaitForSeconds(0.04f));

            // Destroy the line renderere
            if (lineRenderer != null)
            {
                lineRenderer.gameObject.SetActive(false);
                Destroy(lineRenderer.gameObject, 0.1f);
            }

            if (i + 1 < m_ProjectilesPerAttack)
            {
                yield return(new WaitForSeconds(0.18f));
            }
        }

        onShootRoutineComplete();
    }
Beispiel #3
0
 public void DeselectUnit()
 {
     // Clear the Unit's action ranges
     if (m_SelectedUnit != null)
     {
         m_SelectedUnit.ClearRanges();
         // Set the selected unit to null
         m_SelectedUnit = null;
         // Trigger the OnUnitDeSelect event
         OnUnitDeSelected();
     }
 }
    private void OnUnitSelected(TacticsCharacter unit)
    {
        // Attack Button

        /*
         * if (unit.CanAttack() && !m_AttackButton.IsActive())
         * {
         *  m_AttackButton.gameObject.SetActive(true);
         * }
         * else if (!unit.CanAttack() && m_AttackButton.IsActive() && m_AttackButton.interactable)
         * {
         *  m_AttackButton.interactable = false;
         * }
         */
    }
Beispiel #5
0
    public TacticsCharacter SelectNextUnit()
    {
        // Get the index
        var unitIndex = m_CurrentPlayerTurn.m_Units.IndexOf(m_SelectedUnit);

        unitIndex++;
        // Looped through all the player's units
        if (unitIndex >= m_CurrentPlayerTurn.m_Units.Count)
        {
            TriggerNewTurn();
            return(null);
        }

        m_SelectedUnit = m_CurrentPlayerTurn.m_Units[unitIndex];
        OnUnitSelected(m_SelectedUnit);
        return(m_SelectedUnit);
    }
 private void OnSelectedUnit(TacticsCharacter unit)
 {
     // Selectedunit state
     SetControllerState(TacticsPlayerControllerState.SelectedUnit);
     if (unit.CanMove())
     {
         unit.CalculateMovementRange(true);
         if (unit.CanAttack())
         {
             unit.CalculateAttackRangeWithVictimsOnly(true);
         }
     }
     else if (unit.CanAttack())
     {
         unit.CalculateAttackRange(true);
     }
     else
     {
         TacticsGameManager.Instance.SelectNextUnit();
     }
 }
Beispiel #7
0
    public TacticsCharacter TrySelectUnitAtTile(GridTile targetTile)
    {
        var unitAtTile = GridManager.Instance.GetGridObjectAtPosition(targetTile.m_GridPosition);

        if (unitAtTile != null)
        {
            var tacticsCharacterComponent = unitAtTile.GetComponent <TacticsCharacter>();
            if (tacticsCharacterComponent != null)
            {
                if (DoesUnitBelongToCurrentPlayer(tacticsCharacterComponent))
                {
                    m_SelectedUnit = tacticsCharacterComponent;
                    // Trigger the unit selected event
                    OnUnitSelected(m_SelectedUnit);
                    return(m_SelectedUnit);
                }
            }
        }

        return(null);
    }
Beispiel #8
0
 public void RemoveUnitFromGame(TacticsCharacter unit)
 {
     foreach (TacticsPlayer player in m_Players.ToList())
     {
         // Remove the unit from the player's units list
         if (player.m_Units.Contains(unit))
         {
             player.m_Units.Remove(unit);
         }
         // Check if the player has no more units
         if (!(player.m_Units.Count > 0))
         {
             // Remove the player from the players list
             m_Players.Remove(player);
             // If there is not more than 1 player do the GameOver
             if (!(m_Players.Count > 1))
             {
                 OnGameOver(m_Players[0]);
             }
         }
     }
 }
Beispiel #9
0
 public bool CanAttackUnit(TacticsCharacter targetUnit)
 {
     return(targetUnit._health.CanBeAttackedBy(_tacticsCharacter._gridObject) && !TacticsGameManager.Instance.DoesUnitBelongToCurrentPlayer(targetUnit));
 }
Beispiel #10
0
 protected void Awake()
 {
     _tacticsCharacter = GetComponent <TacticsCharacter>();
 }
Beispiel #11
0
 private void ShootUnit(TacticsCharacter targetUnit, Action onShootComplete)
 {
     StartCoroutine(ShootUnitRoutine(targetUnit, onShootComplete));
 }
Beispiel #12
0
 public void AttackUnit(TacticsCharacter targetUnit, Action onAttackEndCallback)
 {
     _tacticsCharacter._gridMovement.RotateTo(targetUnit._gridObject.m_GridPosition);
     ShootUnit(targetUnit, onAttackEndCallback);
 }
Beispiel #13
0
 private void OnUnitSelected(TacticsCharacter unit)
 {
     Enable(unit.transform);
 }
 public void EnterSelectedUnitState(TacticsCharacter unit)
 {
     // Unit selected event
     TacticsGameManager.OnUnitSelected(unit);
 }
Beispiel #15
0
 public bool DoesUnitBelongToCurrentPlayer(TacticsCharacter unit)
 {
     return(m_CurrentPlayerTurn.m_Units.Contains(unit));
 }