public async UniTaskVoid HandleRequestSwapOrMergeStorageItem(RequestHandlerData requestHandler, RequestSwapOrMergeStorageItemMessage request, RequestProceedResultDelegate <ResponseSwapOrMergeStorageItemMessage> result)
        {
#if UNITY_STANDALONE && !CLIENT_BUILD
            StorageId            storageId = new StorageId(request.storageType, request.storageOwnerId);
            IPlayerCharacterData playerCharacter;
            if (!GameInstance.ServerUserHandlers.TryGetPlayerCharacter(requestHandler.ConnectionId, out playerCharacter))
            {
                result.Invoke(AckResponseCode.Error, new ResponseSwapOrMergeStorageItemMessage()
                {
                    message = UITextKeys.UI_ERROR_NOT_LOGGED_IN,
                });
                return;
            }
            if (!GameInstance.ServerStorageHandlers.CanAccessStorage(playerCharacter, storageId))
            {
                result.Invoke(AckResponseCode.Error, new ResponseSwapOrMergeStorageItemMessage()
                {
                    message = UITextKeys.UI_ERROR_CANNOT_ACCESS_STORAGE,
                });
                return;
            }
            Storage storage = GameInstance.ServerStorageHandlers.GetStorage(storageId, out _);
            SwapOrMergeStorageItemReq req = new SwapOrMergeStorageItemReq();
            req.StorageType    = request.storageType;
            req.StorageOwnerId = request.storageOwnerId;
            req.CharacterId    = playerCharacter.Id;
            req.WeightLimit    = storage.weightLimit;
            req.SlotLimit      = storage.slotLimit;
            req.FromIndex      = request.fromIndex;
            req.ToIndex        = request.toIndex;
            SwapOrMergeStorageItemResp resp = await DbServiceClient.SwapOrMergeStorageItemAsync(req);

            UITextKeys message = (UITextKeys)resp.Error;
            if (message != UITextKeys.NONE)
            {
                result.Invoke(AckResponseCode.Error, new ResponseSwapOrMergeStorageItemMessage()
                {
                    message = message,
                });
                return;
            }
            GameInstance.ServerStorageHandlers.SetStorageItems(storageId, resp.StorageCharacterItems);
            GameInstance.ServerStorageHandlers.NotifyStorageItemsUpdated(request.storageType, request.storageOwnerId);
            // Success
            result.Invoke(AckResponseCode.Success, new ResponseSwapOrMergeStorageItemMessage());
#endif
        }
        public async UniTask <AsyncResponseData <SwapOrMergeStorageItemResp> > SwapOrMergeStorageItemAsync(SwapOrMergeStorageItemReq request)
        {
            var resp = await Client.SendRequestAsync <SwapOrMergeStorageItemReq, SwapOrMergeStorageItemResp>(DatabaseRequestTypes.RequestSwapOrMergeStorageItem, request);

            if (!resp.IsSuccess)
            {
                Logging.LogError(nameof(DatabaseNetworkManager), $"Cannot {nameof(SwapOrMergeStorageItemAsync)} status: {resp.ResponseCode}");
            }
            return(resp);
        }
Exemplo n.º 3
0
        public async UniTask <SwapOrMergeStorageItemResp> SwapOrMergeStorageItemAsync(SwapOrMergeStorageItemReq request)
        {
            var result = await Client.SendRequestAsync <SwapOrMergeStorageItemReq, SwapOrMergeStorageItemResp>(DatabaseRequestTypes.RequestSwapOrMergeStorageItem, request);

            if (result.ResponseCode != AckResponseCode.Success)
            {
                return(new SwapOrMergeStorageItemResp());
            }
            return(result.Response);
        }