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
        }
Пример #2
0
        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.InvokeError(new ResponseSwapOrMergeStorageItemMessage()
                {
                    message = UITextKeys.UI_ERROR_NOT_LOGGED_IN,
                });
                return;
            }
            if (!storageUsers.Add(playerCharacter.Id))
            {
                result.InvokeError(new ResponseSwapOrMergeStorageItemMessage()
                {
                    message = UITextKeys.UI_ERROR_CONTENT_NOT_AVAILABLE,
                });
                return;
            }
            if (!GameInstance.ServerStorageHandlers.CanAccessStorage(playerCharacter, storageId))
            {
                storageUsers.Remove(playerCharacter.Id);
                result.InvokeError(new ResponseSwapOrMergeStorageItemMessage()
                {
                    message = UITextKeys.UI_ERROR_CANNOT_ACCESS_STORAGE,
                });
                return;
            }
            Storage storage = GameInstance.ServerStorageHandlers.GetStorage(storageId, out _);
            AsyncResponseData <SwapOrMergeStorageItemResp> resp = await DbServiceClient.SwapOrMergeStorageItemAsync(new SwapOrMergeStorageItemReq()
            {
                StorageType    = request.storageType,
                StorageOwnerId = request.storageOwnerId,
                CharacterId    = playerCharacter.Id,
                WeightLimit    = storage.weightLimit,
                SlotLimit      = storage.slotLimit,
                FromIndex      = request.fromIndex,
                ToIndex        = request.toIndex,
            });

            if (!resp.IsSuccess)
            {
                result.InvokeError(new ResponseSwapOrMergeStorageItemMessage()
                {
                    message = UITextKeys.UI_ERROR_INTERNAL_SERVER_ERROR,
                });
                return;
            }
            UITextKeys message = resp.Response.Error;
            if (message != UITextKeys.NONE)
            {
                storageUsers.Remove(playerCharacter.Id);
                result.InvokeError(new ResponseSwapOrMergeStorageItemMessage()
                {
                    message = message,
                });
                return;
            }
            GameInstance.ServerStorageHandlers.SetStorageItems(storageId, resp.Response.StorageCharacterItems);
            GameInstance.ServerStorageHandlers.NotifyStorageItemsUpdated(request.storageType, request.storageOwnerId);
            // Success
            storageUsers.Remove(playerCharacter.Id);
            result.InvokeSuccess(new ResponseSwapOrMergeStorageItemMessage());
#endif
        }