Пример #1
0
    void DrawPath_Between(EntityData entity, Vector2Int positionLastState, Vector2Int positionThisState, Vector2Int positionNextState)
    {
        PathType  pathType            = GetPathType(positionLastState, positionThisState, positionNextState);
        Sprite    pathSprite          = ScenarioImageManager.GetPathSprite(pathType);
        Direction directionOfEntrance = BoardHelperFunctions.GetDirectionFromPosition(positionThisState, positionLastState);

        GenerateAndPositionCellImage(positionThisState, GetImageRotation(directionOfEntrance), pathSprite, entity.IdentifyingColor);
    }
Пример #2
0
    void UpdatePlayerTurn_Action(CardData card, EntityData player, Vector2Int originPosition, Vector2Int targetPosition)
    {
        Tile playerTile = BoardController.CurrentBoard.GetTileAtPosition(originPosition);
        Tile targetTile = BoardController.CurrentBoard.GetTileAtPosition(targetPosition);

        GetPlayerTurn().action = new Action(card, player, BoardHelperFunctions.GetDirectionBetweenTiles(playerTile, targetTile), BoardHelperFunctions.GetLinearDistanceBetweenTiles(playerTile, targetTile));
        energyManager.UpdateProjectedEnergyCost(card.energyCost);
    }
Пример #3
0
    void DrawMove(ProjectedGameState projectedState, ProjectedGameState nextState, EntityData movingEntity, EntityData lastActiveEntity)
    {
        Vector2Int positionThisState = movingEntity.Position;
        Vector2Int positionLastState = projectedState
                                       .scenarioState
                                       .lastGameState
                                       .GetEntityWhere(e => e.ID == movingEntity.ID)
                                       .Position;
        Vector2Int positionTwoStatesAgo = projectedState
                                          .scenarioState
                                          .lastGameState
                                          .lastGameState
                                          .GetEntityWhere(e => e.ID == movingEntity.ID)
                                          .Position;

        bool isEntitysFirstMove = positionLastState == positionTwoStatesAgo || movingEntity != lastActiveEntity;
        bool isEntitysLastMove  = nextState == null ||
                                  !nextState.scenarioState.HasEntityWhere(e => e == movingEntity) ||
                                  nextState.scenarioState.GetEntityWhere(e => e == movingEntity).Position == movingEntity.Position;

        if (isEntitysLastMove)
        {
            DrawPath_Ending(movingEntity, positionLastState, positionThisState);
        }
        else
        {
            if (isEntitysFirstMove)
            {
                DrawPath_Beginning(movingEntity, positionLastState, positionThisState);
            }
            DrawPath_Between(movingEntity, positionLastState, positionThisState, nextState.scenarioState.GetEntityWhere(e => e == movingEntity).Position);
        }

        int distanceCovered = BoardHelperFunctions.GetLinearDistanceBetweenPositions(positionLastState, positionThisState);

        if (distanceCovered > 1)
        {
            Direction directionToDestination = BoardHelperFunctions.GetDirectionFromPosition(positionLastState, positionThisState);
            GameBoard currentBoard           = BoardController.CurrentBoard;

            Tile lastTile              = currentBoard.GetTileAtPosition(positionLastState);
            Tile currentTile           = lastTile.GetDirectionalNeighbor(directionToDestination);
            Tile nextTile              = currentTile.GetDirectionalNeighbor(directionToDestination);
            int  intermediaryPathCount = 0;

            while (intermediaryPathCount < distanceCovered - 1)
            {
                DrawPath_Between(movingEntity, lastTile.Position, currentTile.Position, nextTile.Position);
                lastTile    = currentTile;
                currentTile = nextTile;
                nextTile    = currentTile.GetDirectionalNeighbor(directionToDestination);

                intermediaryPathCount++;
            }
        }
    }
Пример #4
0
    // TODO: Very rudimentary AI rn, assumes all enemies rushing at player, need some
    // switch logic for different AI types.
    public void CalculateAndQueueEnemyTurns(ScenarioState gameState)
    {
        GameBoard         currentBoard = BoardController.CurrentBoard;
        List <EntityData> enemies      = gameState.enemies;

        upcomingEntityTargets.Clear();

        currentlyOccupiedTiles = enemies.Select(enemy => currentBoard.GetTileAtPosition(enemy.Position)).ToList <Tile>();

        foreach (EntityData enemy in enemies)
        {
            Tile enemyTile = currentBoard.GetTileAtPosition(enemy.Position);

            MovementCardData enemyMovementCard = enemy.movementCard;
            int enemyMoveRange = enemyMovementCard.range + enemy.GetMovementModifierValue();

            AttackCardData enemyAttackCard  = enemy.attackCard;
            int            enemyAttackRange = enemyAttackCard.range;

            List <EntityTurnTargets> possibleEntityTurns  = enemyTile.GetAllPossibleEntityTurns(enemyMoveRange, enemyAttackRange);
            List <EntityTurnTargets> sortedPotentialTurns = SortTurnTargetsByValue(enemyTile, possibleEntityTurns, gameState);
            int turnIndex = 0;
            EntityTurnTargets selectedTurnTargets       = sortedPotentialTurns[turnIndex];
            List <Direction>  movesToTargetMovementTile = BoardHelperFunctions.FindPathBetweenTiles(enemyTile, selectedTurnTargets.targetMovementTile);
            List <Tile>       tilesToTargetMovementTile = BoardHelperFunctions.GetTilesOnPath(enemyTile, movesToTargetMovementTile);

            // Enemies will not move through traps if they have any other moves available.
            while (turnIndex < sortedPotentialTurns.Count &&
                   tilesToTargetMovementTile.Any(tile => gameState.DoesPositionContainItemWhere(tile.Position, item => item.itemCategory == ItemCategory.Trap) ||
                                                 gameState.IsTileOccupied(tile)))
            {
                turnIndex++;
                selectedTurnTargets       = sortedPotentialTurns[turnIndex];
                movesToTargetMovementTile = BoardHelperFunctions.FindPathBetweenTiles(enemyTile, selectedTurnTargets.targetMovementTile);
                tilesToTargetMovementTile = BoardHelperFunctions.GetTilesOnPath(enemyTile, movesToTargetMovementTile);
            }

            if (turnIndex == sortedPotentialTurns.Count)
            {
                selectedTurnTargets = sortedPotentialTurns[0];
            }

            upcomingEntityTargets.Add(selectedTurnTargets);
            int       rangeOfProjectedAttack = BoardHelperFunctions.GetLinearDistanceBetweenTiles(selectedTurnTargets.targetMovementTile, selectedTurnTargets.targetAttackTile);
            Direction attackDirection        = BoardHelperFunctions.GetDirectionFromPosition(selectedTurnTargets.targetMovementTile.Position, selectedTurnTargets.targetAttackTile.Position);

            Action enemyAction = new Action(enemyAttackCard, enemy, attackDirection, rangeOfProjectedAttack);

            Turn enemyTurn = new Turn(enemy, movesToTargetMovementTile, enemyAction);

            turnStackController.AddNewTurn(enemyTurn);
        }
    }
Пример #5
0
    void DrawPath_Ending(EntityData entity, Vector2Int positionLastState, Vector2Int positionThisState)
    {
        if (positionThisState == positionLastState)
        {
            return;
        }

        Sprite    pathSprite          = ScenarioImageManager.GetPathSprite(PathType.Terminating);
        Direction directionOfEntrance = BoardHelperFunctions.GetDirectionFromPosition(positionThisState, positionLastState);

        GenerateAndPositionCellImage(positionThisState, GetImageRotation(directionOfEntrance), pathSprite, entity.IdentifyingColor);
    }
Пример #6
0
    void DrawBump(EntityData bumpingEntity, ProjectedGameState projectedState, ProjectedGameState nextState, Bump bump)
    {
        Vector2Int positionTwoStatesAgo = projectedState
                                          .scenarioState
                                          .lastGameState
                                          .lastGameState
                                          .GetEntityWhere(e => e.ID == bumpingEntity.ID)
                                          .Position;
        Vector2Int positionThisState = bumpingEntity.Position;
        Vector2Int positionLastState = projectedState
                                       .scenarioState
                                       .lastGameState
                                       .GetEntityWhere(e => e.ID == bumpingEntity.ID)
                                       .Position;
        bool isEntitysFirstMove = positionLastState == positionTwoStatesAgo;

        bool bumpSucceeds = bumpingEntity.Position != positionLastState;

        if (bumpSucceeds)
        {
            DrawPath_Ending(bumpingEntity, positionLastState, positionThisState);
            DrawSuccessfulBumpEffect(positionThisState, BoardHelperFunctions.GetDirectionFromPosition(positionThisState, positionLastState));

            DrawPath_Beginning(bump.bumpedEntity, positionThisState, bump.bumpedEntity.Position);
        }
        else if (isEntitysFirstMove)
        {
            Vector2Int bumpedEntityPosition = bump.bumpedEntity.Position;
            Sprite     pathSprite           = ScenarioImageManager.GetPathSprite(PathType.Beginning);
            Direction  directionOfEntrance  = BoardHelperFunctions.GetDirectionFromPosition(bumpedEntityPosition, positionThisState);
            GenerateAndPositionCellImage(positionThisState, GetImageRotation(directionOfEntrance), pathSprite, bumpingEntity.IdentifyingColor);

            DrawFailedBumpEffect(positionThisState,
                                 BoardHelperFunctions.GetDirectionFromPosition(positionThisState, bumpedEntityPosition));
        }
        else
        {
            PathType   pathType             = GetFailedBumpPathType(positionTwoStatesAgo, positionThisState, bump.bumpedEntity.Position);
            Sprite     pathSprite           = ScenarioImageManager.GetPathSprite(pathType);
            Vector2Int bumpedEntityPosition = bump.bumpedEntity.Position;
            Direction  directionOfEntrance  = BoardHelperFunctions.GetDirectionFromPosition(positionThisState, positionTwoStatesAgo);

            GenerateAndPositionCellImage(positionThisState, GetImageRotation(directionOfEntrance), pathSprite, bumpingEntity.IdentifyingColor);
            DrawFailedBumpEffect(positionThisState,
                                 BoardHelperFunctions.GetDirectionFromPosition(positionThisState, bumpedEntityPosition));
        }
    }
Пример #7
0
    static void ApplyModifierToAttack_PushPull(EntityData target, ModifierData modifier, EntityData attacker, ScenarioState gameState, ModifierCategory pushOrPull)
    {
        if (attacker.Position == target.Position)
        {
            return;
        }
        // Default to push, check for pull.
        Direction forceDirection = BoardHelperFunctions.GetDirectionFromPosition(attacker.Position, target.Position);

        if (pushOrPull == ModifierCategory.Pull)
        {
            forceDirection = BoardHelperFunctions.GetDirectionFromPosition(target.Position, attacker.Position);
        }
        int pushMagnitude = modifier.value;

        while (pushMagnitude > 0)
        {
            Tile currentTargetTile = BoardController
                                     .CurrentBoard
                                     .GetTileAtPosition(target.Position);
            bool canPushTarget = currentTargetTile
                                 .ConnectsToNeighbor(forceDirection);

            if (canPushTarget)
            {
                Tile nextTile           = currentTargetTile.GetDirectionalNeighbor(forceDirection);
                bool isNextTileOccupied = nextTile.IsOccupied(gameState);

                if (isNextTileOccupied)
                {
                    ResolveBump(target, gameState.GetTileOccupant(nextTile), forceDirection, gameState);
                    break;
                }
                else
                {
                    target.SetPosition(currentTargetTile.GetDirectionalNeighbor(forceDirection).Position, gameState);
                    pushMagnitude--;
                }
            }
            else
            {
                target.DealDamage(1, gameState);
                break;
            }
        }
    }
Пример #8
0
    PathType GetFailedBumpPathType(Vector2Int positionTwoStatesAgo, Vector2Int positionThisState, Vector2Int bumpeePosition)
    {
        if (BoardHelperFunctions.AreTwoPositionsLinear(positionTwoStatesAgo, bumpeePosition))
        {
            return(PathType.FailedBumpStraight);
        }

        Vector2Int localVectorToLastPosition = positionTwoStatesAgo - positionThisState;
        Vector2Int localVectorToNextPosition = bumpeePosition - positionThisState;

        float angleBetween = Vector2.SignedAngle(localVectorToLastPosition, localVectorToNextPosition);

        if (angleBetween - 90f == 0f)
        {
            return(PathType.FailedBumpLeft);
        }
        else
        {
            return(PathType.FailedBumpRight);
        }
    }
Пример #9
0
    PathType GetPathType(Vector2Int positionLastState, Vector2Int positionThisState, Vector2Int positionNextState)
    {
        if (BoardHelperFunctions.AreTwoPositionsLinear(positionLastState, positionNextState))
        {
            return(PathType.Straight);
        }

        Vector2Int localVectorToLastPosition = positionLastState - positionThisState;
        Vector2Int localVectorToNextPosition = positionNextState - positionThisState;

        float angleBetween = Vector2.SignedAngle(localVectorToLastPosition, localVectorToNextPosition);

        if (angleBetween - 90f == 0f)
        {
            return(PathType.LeftTurn);
        }
        else
        {
            return(PathType.RightTurn);
        }
    }
Пример #10
0
    public static Direction GetDirectionFromEntity(EntityData entity, Vector2Int targetPosition)
    {
        Vector2Int entityPosition = entity.Position;

        return(BoardHelperFunctions.GetDirectionFromPosition(entityPosition, targetPosition));
    }
Пример #11
0
    void UpdatePlayerTurn_Movement(Vector2Int originPosition, Vector2Int targetPosition)
    {
        List <Direction> pathToPosition = BoardHelperFunctions.FindPathBetweenTiles(BoardController.CurrentBoard.GetTileAtPosition(originPosition), BoardController.CurrentBoard.GetTileAtPosition(targetPosition));

        GetPlayerTurn().moves = pathToPosition;
    }