Esempio n. 1
0
    private IEnumerator PerformAttackAction(Vector3Int clickedPos, Unit clickedUnit)
    {
        SkillConfig skillConfig = CurrentUnit.GetSkillConfig(AttackMode);

        Unit actingUnit      = CurrentUnit;
        bool isAttackClicked = actingUnit.skillHandler.Contains(skillConfig, clickedPos);

        if (isAttackClicked)
        {
            LevelTile clickedTile = TilemapNavigator.Instance.GetTile(clickedPos);
            bool      canAttack   = skillConfig.CanPerformAttack(actingUnit, clickedUnit, clickedTile);
            if (canAttack)
            {
                bool usedAnActionPoint = turnManager.UseActionPoint(CurrentUnit);
                if (usedAnActionPoint)
                {
                    UpdateDisabledUnits();
                    SelectUnit(null);
                    yield return(StartCoroutine(actingUnit.Attack(skillConfig, clickedPos, clickedUnit)));

                    if (turnManager.CanPerformMovement(actingUnit) || turnManager.CanPerformAction(actingUnit))
                    {
                        SelectUnit(actingUnit);
                    }
                }
            }
        }

        ChangeAttackMode(AttackModes.None);
        AvailableActionsChanged.Invoke();
    }
Esempio n. 2
0
    void RenderAvailableAttacks(Unit unit)
    {
        if (unit == null)
        {
            return;
        }

        SkillConfig skillConfig = unit.GetSkillConfig(unit == ActivePlayer.CurrentUnit
            ? ActivePlayer.AttackMode
            : AttackModes.Attack
                                                      );

        if (skillConfig == null)
        {
            return;
        }

        TilemapNavigator navigator = TilemapNavigator.Instance;
        SerializableDictionary <Vector3Int, AttackPatternField> pattern = unit.skillHandler.AttackArea(skillConfig);

        if (pattern != null)
        {
            foreach (KeyValuePair <Vector3Int, AttackPatternField> field in pattern)
            {
                LevelTile targetTile = navigator.GetTile(field.Key);
                bool      hasTile    = targetTile != null;
                Unit      targetUnit = navigator.GetUnit(field.Key);

                if (field.Value == AttackPatternField.On && hasTile)
                {
                    bool canAttack = skillConfig.CanPerformAttack(unit, targetUnit, targetTile);
                    TintMarker(attackAreaTilemap, field.Key, canAttack && unit != HoveredUnit ? MarkerTypes.Attack : MarkerTypes.AttackPreview);
                    availableAttacks.Add(field.Key);
                }
            }
        }
    }