Exemplo n.º 1
0
        public async UniTask <MoveItemFromStorageResp> MoveItemFromStorageAsync(MoveItemFromStorageReq request)
        {
            var result = await Client.SendRequestAsync <MoveItemFromStorageReq, MoveItemFromStorageResp>(DatabaseRequestTypes.RequestMoveItemFromStorage, request);

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

            UITextKeys message = (UITextKeys)resp.Error;
            if (message != UITextKeys.NONE)
            {
                result.Invoke(AckResponseCode.Error, new ResponseMoveItemFromStorageMessage()
                {
                    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 ResponseMoveItemFromStorageMessage());
#endif
        }
        public async UniTask <AsyncResponseData <MoveItemFromStorageResp> > MoveItemFromStorageAsync(MoveItemFromStorageReq request)
        {
            var resp = await Client.SendRequestAsync <MoveItemFromStorageReq, MoveItemFromStorageResp>(DatabaseRequestTypes.RequestMoveItemFromStorage, request);

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