예제 #1
0
    void HighlightSelectedEntityStates(EntityData selectedEntity, ScenarioState currentGameState, List <ProjectedGameState> upcomingStates)
    {
        Clear();
        EntityData lastActiveEntity = null;

        for (int i = 0; i < upcomingStates.Count; i++)
        {
            ProjectedGameState projectedState = upcomingStates[i];

            if (projectedState.IsDummyState)
            {
                continue;
            }

            ProjectedGameState nextState = i == upcomingStates.Count - 1 ?
                                           null :
                                           upcomingStates[i + 1];

            bool isEntityDeadThisState = !projectedState.scenarioState.HasEntityWhere(e => e == selectedEntity);
            bool didEntityDieThisState = projectedState.scenarioState.lastGameState.HasEntityWhere(e => selectedEntity == e);

            if (isEntityDeadThisState)
            {
                if (!didEntityDieThisState)
                {
                    drawingSelectedEntity = false;
                    DrawState(projectedState, nextState, lastActiveEntity);
                    lastActiveEntity = projectedState.activeEntity;
                    continue;
                }
                else
                {
                    drawingSelectedEntity = true;
                    DrawState(projectedState, nextState, lastActiveEntity);
                    lastActiveEntity = projectedState.activeEntity;
                    Vector2Int entityPositionLastState = projectedState.scenarioState
                                                         .lastGameState
                                                         .GetEntityWhere(e => e == selectedEntity)
                                                         .Position;
                    if (!projectedState.scenarioState.HasEntityWhere(e => e.Position == selectedEntity.Position) && selectedEntity.Position != entityPositionLastState)
                    {
                        GenerateAndPositionCellImage(entityPositionLastState, 0f, selectedEntity.entitySprite, translucent);
                    }
                    GenerateAndPositionCellImage(entityPositionLastState, 0f, deadEntitySprite, Color.white);
                    continue;
                }
            }

            Vector2Int selectedEntityPositionThisState = projectedState
                                                         .scenarioState
                                                         .GetEntityWhere(e => e == selectedEntity)
                                                         .Position;

            bool isSelectedEntityState    = projectedState.activeEntity == selectedEntity;
            bool isSelectedEntityBumped   = projectedState.IsEntityBumped(selectedEntity);
            bool isSelectedEntityAttacked = projectedState.attackedPositions.Contains(selectedEntityPositionThisState);

            if (isSelectedEntityState || isSelectedEntityBumped || isSelectedEntityAttacked)
            {
                drawingSelectedEntity = true;

                // Draw entity under attack targeting reticule if
                // (A) selected entity is hit OR
                // (B) selected entity is attacking & hits someone.
                projectedState
                .attackedPositions
                .Select(position => projectedState
                        .scenarioState
                        .GetTileOccupant(position))
                .Where(attackTarget => attackTarget != null && isSelectedEntityState || attackTarget == selectedEntity)
                .ToList()
                .ForEach(entity => boardController.DrawEntityAtPosition(entity, translucent));

                // Draw entities killed this turn.
                projectedState
                .scenarioState
                .lastGameState
                .GetAllEntities()
                .ForEach(e =>
                {
                    if (!projectedState.scenarioState.HasEntityWhere(projectedEntity => e == projectedEntity))
                    {
                        if (!currentGameState.HasEntityWhere(currentEntity => currentEntity.Position == e.Position))
                        {
                            GenerateAndPositionCellImage(e.Position, 0f, e.entitySprite, translucent);
                        }
                        GenerateAndPositionCellImage(e.Position, 0f, deadEntitySprite, Color.white);
                    }
                });
            }
            else
            {
                drawingSelectedEntity = false;
            }
            DrawState(projectedState, nextState, lastActiveEntity);
            lastActiveEntity = projectedState.activeEntity;
        }

        DrawEntityHealth(selectedEntity);
        DrawItemDurations(currentGameState.items);
    }
예제 #2
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);
    }