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
        }
Example #2
0
        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.InvokeError(new ResponseMoveItemFromStorageMessage()
                {
                    message = UITextKeys.UI_ERROR_NOT_LOGGED_IN,
                });
                return;
            }
            if (!storageUsers.Add(playerCharacter.Id))
            {
                result.InvokeError(new ResponseMoveItemFromStorageMessage()
                {
                    message = UITextKeys.UI_ERROR_CONTENT_NOT_AVAILABLE,
                });
                return;
            }
            if (!GameInstance.ServerStorageHandlers.CanAccessStorage(playerCharacter, storageId))
            {
                storageUsers.Remove(playerCharacter.Id);
                result.InvokeError(new ResponseMoveItemFromStorageMessage()
                {
                    message = UITextKeys.UI_ERROR_CANNOT_ACCESS_STORAGE,
                });
                return;
            }
            Storage storage = GameInstance.ServerStorageHandlers.GetStorage(storageId, out _);
            AsyncResponseData <MoveItemFromStorageResp> resp = await DbServiceClient.MoveItemFromStorageAsync(new MoveItemFromStorageReq()
            {
                StorageType        = request.storageType,
                StorageOwnerId     = request.storageOwnerId,
                CharacterId        = playerCharacter.Id,
                WeightLimit        = storage.weightLimit,
                SlotLimit          = storage.slotLimit,
                StorageItemIndex   = request.storageItemIndex,
                StorageItemAmount  = request.storageItemAmount,
                InventoryItemIndex = request.inventoryItemIndex,
                Inventory          = new List <CharacterItem>(playerCharacter.NonEquipItems),
            });

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