Пример #1
0
        public void Cmd_RequestSwapOrMerge(RequestSwapOrMergeMessage data)
        {
            logger.LogVerbose($"[Server] Client requested to SwapOrMerge an item from {data.fromIndex} to {data.toIndex}. slot from collection {data.collectionGuid} to {data.toCollectionGuid}", bridge);

            ICollection fromCol, toCol;
            var         error = inputValidator.ValidateSwapOrMerge(bridge.identity, data, out fromCol, out toCol).error;

            if (error == null)
            {
                error = fromCol.SwapOrMerge(data.fromIndex, toCol, data.toIndex, data.amount).error;
            }

            HandleError(error);
        }
Пример #2
0
        public Result <bool> ValidateSwapOrMerge(NetworkIdentity identity, RequestSwapOrMergeMessage data, out ICollection fromOut, out ICollection toOut)
        {
            fromOut = null;
            toOut   = null;
            if (CheckGuidBytes(data.collectionGuid.bytes) == false ||
                CheckGuidBytes(data.toCollectionGuid.bytes) == false)
            {
                return(Failed());
            }

            if (CheckCollectionPermission(identity, data.collectionGuid, data.toCollectionGuid, out fromOut, out toOut) == false)
            {
                return(Failed());
            }

            if (CheckClamped(data.fromIndex, 0, fromOut.slotCount - 1) == false ||
                CheckClamped(data.toIndex, 0, toOut.slotCount - 1) == false ||
                CheckClamped(data.amount, 1, fromOut.GetAmount(data.fromIndex)) == false)
            {
                return(Failed());
            }

            return(true);
        }