Exemple #1
0
        public async UniTask <MoveItemToStorageResp> MoveItemToStorageAsync(MoveItemToStorageReq request)
        {
            var result = await Client.SendRequestAsync <MoveItemToStorageReq, MoveItemToStorageResp>(DatabaseRequestTypes.RequestMoveItemToStorage, request);

            if (result.ResponseCode != AckResponseCode.Success)
            {
                return(new MoveItemToStorageResp());
            }
            return(result.Response);
        }
        public async UniTaskVoid HandleRequestMoveItemToStorage(RequestHandlerData requestHandler, RequestMoveItemToStorageMessage request, RequestProceedResultDelegate <ResponseMoveItemToStorageMessage> 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 ResponseMoveItemToStorageMessage()
                {
                    message = UITextKeys.UI_ERROR_NOT_LOGGED_IN,
                });
                return;
            }
            if (!GameInstance.ServerStorageHandlers.CanAccessStorage(playerCharacter, storageId))
            {
                result.Invoke(AckResponseCode.Error, new ResponseMoveItemToStorageMessage()
                {
                    message = UITextKeys.UI_ERROR_CANNOT_ACCESS_STORAGE,
                });
                return;
            }
            Storage storage          = GameInstance.ServerStorageHandlers.GetStorage(storageId, out _);
            MoveItemToStorageReq req = new MoveItemToStorageReq();
            req.StorageType         = request.storageType;
            req.StorageOwnerId      = request.storageOwnerId;
            req.CharacterId         = playerCharacter.Id;
            req.WeightLimit         = storage.weightLimit;
            req.SlotLimit           = storage.slotLimit;
            req.InventoryItemIndex  = request.inventoryItemIndex;
            req.InventoryItemAmount = request.inventoryItemAmount;
            req.StorageItemIndex    = request.storageItemIndex;
            MoveItemToStorageResp resp = await DbServiceClient.MoveItemToStorageAsync(req);

            UITextKeys message = (UITextKeys)resp.Error;
            if (message != UITextKeys.NONE)
            {
                result.Invoke(AckResponseCode.Error, new ResponseMoveItemToStorageMessage()
                {
                    message = message,
                });
                return;
            }
            playerCharacter.NonEquipItems = resp.InventoryItemItems;
            GameInstance.ServerStorageHandlers.SetStorageItems(storageId, resp.StorageCharacterItems);
            GameInstance.ServerStorageHandlers.NotifyStorageItemsUpdated(request.storageType, request.storageOwnerId);
            // Success
            result.Invoke(AckResponseCode.Success, new ResponseMoveItemToStorageMessage());
#endif
        }
        public async UniTask <AsyncResponseData <MoveItemToStorageResp> > MoveItemToStorageAsync(MoveItemToStorageReq request)
        {
            var resp = await Client.SendRequestAsync <MoveItemToStorageReq, MoveItemToStorageResp>(DatabaseRequestTypes.RequestMoveItemToStorage, request);

            if (!resp.IsSuccess)
            {
                Logging.LogError(nameof(DatabaseNetworkManager), $"Cannot {nameof(MoveItemToStorageAsync)} status: {resp.ResponseCode}");
            }
            return(resp);
        }