public override void MoveItemToStorage(BasePlayerCharacterEntity playerCharacterEntity, StorageId storageId, short nonEquipIndex, short amount, short storageItemIndex)
        {
            if (!CanAccessStorage(playerCharacterEntity, playerCharacterEntity.CurrentStorageId))
            {
                SendServerGameMessage(playerCharacterEntity.ConnectionId, GameMessage.Type.CannotAccessStorage);
                return;
            }
            if (!storageItems.ContainsKey(storageId))
            {
                storageItems[storageId] = new List <CharacterItem>();
            }
            List <CharacterItem> storageItemList = storageItems[storageId];

            if (nonEquipIndex < 0 || nonEquipIndex >= playerCharacterEntity.NonEquipItems.Count)
            {
                // Don't do anything, if non equip item index is invalid
                return;
            }
            // Prepare storage data
            Storage storage       = GetStorage(storageId);
            bool    isLimitWeight = storage.weightLimit > 0;
            bool    isLimitSlot   = storage.slotLimit > 0;
            short   weightLimit   = storage.weightLimit;
            short   slotLimit     = storage.slotLimit;
            // Prepare item data
            CharacterItem movingItem = playerCharacterEntity.NonEquipItems[nonEquipIndex].Clone();

            movingItem.amount = amount;
            if (storageItemIndex < 0 ||
                storageItemIndex >= storageItemList.Count ||
                !storageItemList[storageItemIndex].NotEmptySlot() ||
                storageItemList[storageItemIndex].dataId == movingItem.dataId)
            {
                // Add to storage or merge
                bool isOverwhelming = CharacterDataExtension.IncreasingItemsWillOverwhelming(
                    storageItemList, movingItem.dataId, movingItem.amount, isLimitWeight, weightLimit,
                    CharacterDataExtension.GetTotalItemWeight(storageItemList), isLimitSlot, slotLimit);
                if (!isOverwhelming && CharacterDataExtension.IncreaseItems(storageItemList, movingItem))
                {
                    // Decrease from inventory
                    playerCharacterEntity.DecreaseItemsByIndex(nonEquipIndex, amount);
                }
            }
            else
            {
                // Swapping
                CharacterItem storageItem  = storageItemList[storageItemIndex];
                CharacterItem nonEquipItem = playerCharacterEntity.NonEquipItems[nonEquipIndex];

                storageItemList[storageItemIndex] = nonEquipItem;
                playerCharacterEntity.NonEquipItems[nonEquipIndex] = storageItem;
            }
            CharacterDataExtension.FillEmptySlots(storageItemList, isLimitSlot, slotLimit);
            UpdateStorageItemsToCharacters(usingStorageCharacters[storageId], storageItemList);
        }
        private IEnumerator MoveItemToStorageRoutine(BasePlayerCharacterEntity playerCharacterEntity, StorageId storageId, short nonEquipIndex, short amount, short storageItemIndex)
        {
            List <CharacterItem> storageItemList     = new List <CharacterItem>();
            ReadStorageItemsJob  readStorageItemsJob = new ReadStorageItemsJob(Database, storageId.storageType, storageId.storageOwnerId);

            readStorageItemsJob.Start();
            yield return(StartCoroutine(readStorageItemsJob.WaitFor()));

            if (readStorageItemsJob.result != null)
            {
                // Set storage items
                storageItemList = readStorageItemsJob.result;
            }
            if (nonEquipIndex < 0 || nonEquipIndex >= playerCharacterEntity.NonEquipItems.Count)
            {
                // Don't do anything, if non equip item index is invalid
            }
            else
            {
                // Prepare storage data
                Storage storage       = GetStorage(storageId);
                bool    isLimitWeight = storage.weightLimit > 0;
                bool    isLimitSlot   = storage.slotLimit > 0;
                short   weightLimit   = storage.weightLimit;
                short   slotLimit     = storage.slotLimit;
                // Prepare item data
                CharacterItem movingItem = playerCharacterEntity.NonEquipItems[nonEquipIndex].Clone();
                movingItem.amount = amount;
                if (storageItemIndex < 0 ||
                    storageItemIndex >= storageItemList.Count ||
                    !storageItemList[storageItemIndex].NotEmptySlot() ||
                    storageItemList[storageItemIndex].dataId == movingItem.dataId)
                {
                    // Add to storage or merge
                    bool isOverwhelming = CharacterDataExtension.IncreasingItemsWillOverwhelming(
                        storageItemList, movingItem.dataId, movingItem.amount, isLimitWeight, weightLimit,
                        CharacterDataExtension.GetTotalItemWeight(storageItemList), isLimitSlot, slotLimit);
                    if (!isOverwhelming && CharacterDataExtension.IncreaseItems(storageItemList, movingItem))
                    {
                        // Remove from inventory
                        playerCharacterEntity.DecreaseItemsByIndex(nonEquipIndex, amount);
                    }
                }
                else
                {
                    // Swapping
                    CharacterItem storageItem  = storageItemList[storageItemIndex];
                    CharacterItem nonEquipItem = playerCharacterEntity.NonEquipItems[nonEquipIndex];

                    storageItemList[storageItemIndex] = nonEquipItem;
                    playerCharacterEntity.NonEquipItems[nonEquipIndex] = storageItem;
                }
                CharacterDataExtension.FillEmptySlots(storageItemList, isLimitSlot, slotLimit);
            }
            // Update storage list immediately
            // TODO: Have to test about race condition while running multiple-server
            UpdateStorageItemsJob updateStorageItemsJob = new UpdateStorageItemsJob(Database, storageId.storageType, storageId.storageOwnerId, storageItemList);

            updateStorageItemsJob.Start();
            yield return(StartCoroutine(updateStorageItemsJob.WaitFor()));

            // Update storage items to characters that open the storage
            UpdateStorageItemsToCharacters(usingStorageCharacters[storageId], storageItemList);
        }