public void Step(ref CheckmateModalStepState token, int condition)
        {
            ModalEV     modal            = modalService.FindModalEV(entitiesDB);
            TurnEV      currentTurn      = turnService.GetCurrentTurnEV(entitiesDB);
            PlayerColor victoriousPlayer = TurnService.CalcOtherTurnPlayer(currentTurn.TurnPlayer.PlayerColor);

            SetModalOptions(modal, victoriousPlayer);
            modalService.DisplayModal(modal);
        }
        public bool DoesForcedRearrangementResolveOrPreventCheck(
            PieceEV forcedRearrangementPiece, PieceEV commander, List <PieceEV> towerPieces, IEntitiesDB entitiesDB)
        {
            List <PieceEV> allPieces   = pieceFindService.FindAllBoardPieces(entitiesDB).ToList();
            List <PieceEV> enemyPieces = pieceFindService.FindPiecesByTeam(
                TurnService.CalcOtherTurnPlayer(commander.PlayerOwner.PlayerColor), entitiesDB).ToList();
            List <PieceEV> actualThreats = destinationTileService.FindActualEnemyThreats(
                commander, enemyPieces, allPieces, entitiesDB);

            return(destinationTileService.ForcedRearrangementCanResolveThreats(
                       commander, forcedRearrangementPiece, actualThreats, allPieces, entitiesDB));
        }
        private bool DropReleasesCheck(
            PieceEV pieceToDrop,
            Vector2 location,
            PlayerColor playerColor,
            PieceSide side,
            HandPieceEV handPiece,
            DropCheckmateLevel recursionLevel,
            IEntitiesDB entitiesDB)
        {
            bool returnValue;

            PieceEV?topPieceAtLocation = pieceFindService.FindTopPieceByLocation(location, entitiesDB);

            pieceSetService.SetTopOfTowerToFalse(topPieceAtLocation, entitiesDB);

            int tier = topPieceAtLocation.HasValue ? topPieceAtLocation.Value.Tier.Tier + 1 : 1;

            pieceSetService.SetPieceLocationAndTier(pieceToDrop, location, tier, entitiesDB);
            pieceSetService.SetPiecePlayerOwner(pieceToDrop, playerColor, entitiesDB);
            pieceSetService.SetPieceSide(pieceToDrop, side, entitiesDB);
            handService.DecrementHandPiece(ref handPiece);

            PlayerColor enemyPlayerColor = TurnService.CalcOtherTurnPlayer(playerColor);

            returnValue = DropCheckmateNotViolated(
                pieceToDrop,
                location,
                playerColor,
                side,
                handPiece,
                recursionLevel,
                entitiesDB);

            if (returnValue)
            {
                returnValue = !checkService.IsCommanderInCheck(playerColor, entitiesDB);
            }

            handService.IncrementHandPiece(ref handPiece);
            pieceSetService.SetPieceLocationToHandLocation(pieceToDrop, entitiesDB);

            if (topPieceAtLocation.HasValue)
            {
                pieceSetService.SetTopOfTower(topPieceAtLocation.Value, entitiesDB);
            }

            return(returnValue);
        }
        private void MoveCapturePieceToOtherPlayersHand(PieceEV pieceCaptured)
        {
            // Remove piece from player hand
            TurnEV      currentTurn = turnService.GetCurrentTurnEV(entitiesDB);
            HandPieceEV handPiece   = handService.FindHandPiece(
                pieceCaptured.Piece.Front,
                pieceCaptured.Piece.Back,
                currentTurn.TurnPlayer.PlayerColor,
                entitiesDB);

            handService.DecrementHandPiece(ref handPiece);

            // Add piece to other player's hand
            PlayerColor opponent = TurnService.CalcOtherTurnPlayer(currentTurn.TurnPlayer.PlayerColor);

            handService.AddPieceToHand(pieceCaptured, entitiesDB, opponent);
        }
示例#5
0
        private void SetModalOptions(TowerModalEV modal)
        {
            PieceEV        pieceTier1       = pieceFindService.FindPieceEVById(modal.Tier1.ReferencedPieceId, entitiesDB).Value;
            List <PieceEV> piecesAtLocation = pieceFindService.FindPiecesByLocation(pieceTier1.Location.Location, entitiesDB);

            TurnEV      currentTurnEV = turnService.GetCurrentTurnEV(entitiesDB);
            PlayerColor colorToEnable = TurnService.CalcOtherTurnPlayer(currentTurnEV.TurnPlayer.PlayerColor);

            PieceEV pieceTier2 = piecesAtLocation[1];
            PieceEV?pieceTier3 = piecesAtLocation.Count > 2 ? (PieceEV?)piecesAtLocation[2] : null;

            // TODO I think this logic is unnecessary, but I'm too scared to remove it now (all handled in TowerModalEngine).  Later refactor.
            bool noTier1CheckViolationsExist = immobileCaptureService.NoTier1CheckViolationsExist(piecesAtLocation, entitiesDB);
            bool noTier3BetrayalTwoFileMoveViolationsExist = immobileCaptureService.NoTier3BetrayalTwoFileMoveViolationsExist(piecesAtLocation, entitiesDB);

            entitiesDB.ExecuteOnEntity(
                modal.ID,
                (ref TowerModalEV modalToChange) =>
            {
                modalToChange.ImmobileCaptureState.ImmobileCaptureDesignated = true;

                modalToChange.Tier1.Enabled = noTier1CheckViolationsExist &&
                                              pieceTier1.PlayerOwner.PlayerColor == colorToEnable &&
                                              pieceTier1.PlayerOwner.PlayerColor != pieceTier2.PlayerOwner.PlayerColor;

                modalToChange.Tier2.Enabled = pieceTier2.PlayerOwner.PlayerColor == colorToEnable &&
                                              (pieceTier2.PlayerOwner.PlayerColor != pieceTier1.PlayerOwner.PlayerColor ||
                                               (pieceTier3.HasValue && pieceTier2.PlayerOwner.PlayerColor != pieceTier3.Value.PlayerOwner.PlayerColor));

                if (pieceTier3.HasValue)
                {
                    modalToChange.Tier3.Enabled = noTier3BetrayalTwoFileMoveViolationsExist &&
                                                  pieceTier3.Value.PlayerOwner.PlayerColor == colorToEnable &&
                                                  pieceTier3.Value.PlayerOwner.PlayerColor != pieceTier2.PlayerOwner.PlayerColor;
                }
                else
                {
                    modalToChange.Tier3.Enabled = false;
                }
            });
        }
        private bool DropCheckmateNotViolated(
            PieceEV pieceToDrop,
            Vector2 location,
            PlayerColor playerColor,
            PieceSide side,
            HandPieceEV handPiece,
            DropCheckmateLevel recursionLevel,
            IEntitiesDB entitiesDB)
        {
            bool        returnValue      = true;
            PlayerColor enemyPlayerColor = TurnService.CalcOtherTurnPlayer(playerColor);

            if (recursionLevel != DropCheckmateLevel.FINAL_TURN_PLAYER_CHECK && // Prevent infinite recursion
                AbilityToPiece.HasAbility(DropAbility.CANNOT_DROP_CHECKMATE, pieceToDrop.Piece.PieceType) &&
                checkService.IsCommanderInCheck(enemyPlayerColor, entitiesDB))
            {
                recursionLevel = recursionLevel == DropCheckmateLevel.FIRST_TURN_PLAYER_CHECK
                    ? DropCheckmateLevel.SECOND_ENEMY_PLAYER_CHECK : DropCheckmateLevel.FINAL_TURN_PLAYER_CHECK;
                returnValue = AnyValidMoves(enemyPlayerColor, entitiesDB, recursionLevel);
            }

            return(returnValue);
        }