Exemple #1
0
    static ProjectedGameState GetNextGameStateFromAction(ScenarioState lastState, EntityData entity, Action action)
    {
        ScenarioState newState = lastState.DeepCopy();

        newState.lastGameState = lastState;
        EntityData entityCopy = newState.GetAllEntities().Find(e => entity.ID == e.ID);

        // TODO: This is pretty bare-bones right now because it isn't clear how other card categories will be
        // implemented--need to get it more set up once the basic structure of the state list is running.
        switch (action.card.category)
        {
        case CardCategory.Movement:
            return(GetNextGameStateFromMove(newState, entityCopy, action.direction));

        case CardCategory.Attack:
            return(GetNextStateFromAction_Attack(newState,
                                                 entityCopy,
                                                 action));

        case CardCategory.Self:
            return(GetNextStateFromAction_Self(newState,
                                               entityCopy,
                                               action));

        default:
            return(GetNextGameStateFromMove(newState, entityCopy, action.direction));
        }
    }
Exemple #2
0
    static ProjectedGameState GetNextGameStateFromMove(ScenarioState lastState, EntityData entity, Direction move)
    {
        ScenarioState newState = lastState.DeepCopy();

        newState.lastGameState = lastState;
        EntityData entityCopy        = newState.GetAllEntities().Find(e => entity.ID == e.ID);
        Tile       currentEntityTile = BoardController.CurrentBoard.GetTileAtPosition(entityCopy.Position);

        Action stateAction = new Action(GenericMovementCard, entity, move, 1);

        // If entity can't move that direction, return state as-is.
        if (!currentEntityTile.ConnectsToNeighbor(move))
        {
            return(new ProjectedGameState(entityCopy, newState, stateAction));
        }

        Tile nextTile = currentEntityTile.GetDirectionalNeighbor(move);

        // If tile is empty, move entity there and return.
        if (!newState.IsTileOccupied(nextTile))
        {
            entityCopy.SetPosition(nextTile.Position, newState);
            return(new ProjectedGameState(entityCopy, newState, stateAction));
        }

        EntityData tileOccupant = newState.GetTileOccupant(nextTile.Position);

        ResolveBump(entity, tileOccupant, move, newState);

        Bump bump = new Bump(entityCopy, tileOccupant);

        return(new ProjectedGameState(entityCopy, newState, stateAction, bump));
    }
Exemple #3
0
    public static List <ProjectedGameState> CalculateUpcomingStates(ScenarioState currentState, GameBoard board)
    {
        List <ProjectedGameState> projectedGameStates = new List <ProjectedGameState>();

        ScenarioState mostRecentState = currentState.DeepCopy();

        mostRecentState.lastGameState = currentState;

        Vector2Int lastPlayerPosition = currentState.player.Position;

        while (mostRecentState.turnStack.Count > 0)
        {
            Turn       turn   = mostRecentState.turnStack.Pop();
            EntityData entity = turn.Entity;

            foreach (Direction move in turn.moves)
            {
                bool entityIsAliveToMove = mostRecentState.HasEntityWhere(e => e == entity);

                if (!entityIsAliveToMove)
                {
                    break;
                }

                ProjectedGameState updatedState = GetNextGameStateFromMove(mostRecentState, entity, move);
                entity = updatedState.activeEntity;

                projectedGameStates.Add(updatedState);

                mostRecentState = updatedState.scenarioState;

                if (updatedState.bumps.Count > 0)
                {
                    break;
                }
            }

            if (projectedGameStates.Count > 0)
            {
                projectedGameStates.Last().scenarioState.CollectFinishMoveItems();
            }

            bool entityIsStillAlive = mostRecentState.HasEntityWhere(e => e == entity);

            if (!entityIsStillAlive)
            {
                continue;
            }

            if (turn.action.card != null)
            {
                ProjectedGameState updatedState = GetNextGameStateFromAction(mostRecentState, entity, turn.action);
                entity = updatedState.activeEntity;
                projectedGameStates.Add(updatedState);

                mostRecentState = updatedState.scenarioState;
            }

            UpdateEntityModifiers(entity, mostRecentState);
        }

        // TODO: As-is, this was causing a bunch of problems with state calculation. Gotta bugfix it.
        // If enemies dead, duplicate current gamestate, just for stagnation projection purposes.
        //if (projectedGameStates.Count == 0)
        //{
        //    ProjectedGameState fillerGameState = new ProjectedGameState(currentState.DeepCopy());
        //    projectedGameStates.Add(fillerGameState);
        //}

        //ScenarioState lastCalculatedState = projectedGameStates.Last().scenarioState;

        //lastCalculatedState.UpdateStagnation(board);
        //lastCalculatedState.stagnatedPositions.ForEach(p =>
        //{
        //    EntityData stagnatedEntity = lastCalculatedState.GetTileOccupant(p);
        //    if (stagnatedEntity != null)
        //    {
        //        stagnatedEntity.DealDamage(1, lastCalculatedState);
        //    }
        //});

        return(projectedGameStates);
    }