Exemple #1
0
 void OnAttackButtonClicked()
 {
     tilesInRange = TileMapTools.GetTilesWithinMovementRange(map, currentlySelectedCharacter.occupyingTile
                                                             , currentlySelectedCharacter.GetAttackRange());
     foreach (var tile in tilesInRange)
     {
         if (IsEnemyCharacterOnTile(tile))
         {
             tile.EnableMovementRangeHighlight(currentlySelectedCharacter.tileHighlightColor);
         }
     }
 }
Exemple #2
0
 void OnMoveButtonClicked()
 {
     tilesInRange = TileMapTools.GetTilesWithinMovementRange(map, currentlySelectedCharacter.occupyingTile
                                                             , currentlySelectedCharacter.GetMovementPerAction());
     foreach (var tile in tilesInRange)
     {
         if (!IsAnyCharacterOnTile(tile))
         {
             tile.EnableMovementRangeHighlight(currentlySelectedCharacter.tileHighlightColor);
         }
     }
 }
Exemple #3
0
    void TakeActionForCharacter(CCharacter character)
    {
        Debug.Log("Determining course of action for character " + character.name);

        if (character.CanTakeAction(ECharacterAction.ATTACK))
        {
            var tilesInRange = TileMapTools.GetTilesWithinMovementRange(map,
                                                                        character.occupyingTile, character.GetAttackRange());

            foreach (var tile in tilesInRange)
            {
                if (actionController.IsEnemyCharacterOnTile(tile))
                {
                    var characterToAttack = actionController.GetCharacterOnTile(tile);
                    character.Attack(characterToAttack);
                    CharacterEvents.aiActionTakenEvent.Invoke(character, ECharacterAction.ATTACK);
                    return;
                }
            }
        }

        if (character.CanTakeAction(ECharacterAction.MOVE))
        {
            var tilesInRange = TileMapTools.GetTilesWithinMovementRange(map,
                                                                        character.occupyingTile, character.GetMovementPerAction());
            int randomlySelectedIndex = UnityEngine.Random.Range(0, tilesInRange.Count);
            while (actionController.IsAnyCharacterOnTile(tilesInRange[randomlySelectedIndex]))
            {
                if (tilesInRange.Count == 0)
                {
                    Debug.LogWarning("Character could not find a tile to MOVE to! Weird!");
                    character.ExhaustActionPoints();
                    return;
                }

                tilesInRange.RemoveAt(randomlySelectedIndex);
                randomlySelectedIndex = UnityEngine.Random.Range(0, tilesInRange.Count);
            }
            character.MoveTo(tilesInRange[randomlySelectedIndex]);
            CharacterEvents.aiActionTakenEvent.Invoke(character, ECharacterAction.MOVE);
            return;
        }
    }