Пример #1
0
        public async UniTask <PieceMoveResult> MovePiece(PublicDataType.IntegerVector2 startPosition,
                                                         PublicDataType.IntegerVector2 viaPosition,
                                                         PublicDataType.IntegerVector2 endPosition,
                                                         IPlayer player, IValueInputProvider <int> valueProvider)
        {
            if (isLocked)
            {
                return(new PieceMoveResult(false, false, null));
            }

            var verifiedMove = moveVerifier.VerifyMove(player, startPosition, viaPosition, endPosition);

            if (verifiedMove == VerifiedMove.InvalidMove)
            {
                return(new PieceMoveResult(false, false, null));
            }


            //1ターンに複数回動作する駒のためのロジック
            //ターン管理をここでするな!
            var movingPiece = verifiedMove.MovingPiece;

            if (movingPiece == operationStatus.PreviousPiece)
            {
                operationStatus.AddCount();
            }
            else
            {
                if (operationStatus.PreviousPiece != null)
                {
                    return(new PieceMoveResult(false, false, null));
                }
                else
                {
                    operationStatus.Reset(movingPiece);
                }
            }
            bool isTurnEnd = operationStatus.Count >= movingPiece.NumberOfMoves;

            if (isTurnEnd)
            {
                operationStatus.Reset(null);
            }

            isLocked = true;
            IPieceMoveTransaction pieceMoveAction = pieceMoveActionFactory.Create(player, verifiedMove, pieces, fieldEffectChecker, valueProvider, isTurnEnd);

            PieceMoveResult result = await pieceMoveAction.StartMove();

            if (result.isSuccess)
            {
                onEveryValueChanged.OnNext(Unit.Default);
            }
            isLocked = false;

            return(result);
        }