Esempio n. 1
0
        private IEnumerator MoveItemFromStorageRoutine(BasePlayerCharacterEntity playerCharacterEntity, StorageId storageId, short storageItemIndex, short amount, short nonEquipIndex)
        {
            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 (storageItemIndex < 0 || storageItemIndex >= storageItemList.Count)
            {
                // Don't do anything, if storage item index is invalid
            }
            else
            {
                // Prepare storage data
                Storage storage     = GetStorage(storageId);
                bool    isLimitSlot = storage.slotLimit > 0;
                short   slotLimit   = storage.slotLimit;
                // Prepare item data
                CharacterItem movingItem = storageItemList[storageItemIndex].Clone();
                movingItem.amount = amount;
                if (nonEquipIndex < 0 ||
                    nonEquipIndex >= playerCharacterEntity.NonEquipItems.Count ||
                    playerCharacterEntity.NonEquipItems[nonEquipIndex].IsEmptySlot() ||
                    playerCharacterEntity.NonEquipItems[nonEquipIndex].dataId == movingItem.dataId)
                {
                    // Add to inventory or merge
                    bool isOverwhelming = playerCharacterEntity.IncreasingItemsWillOverwhelming(movingItem.dataId, movingItem.amount);
                    if (!isOverwhelming && playerCharacterEntity.IncreaseItems(movingItem))
                    {
                        // Remove from storage
                        storageItemList.DecreaseItemsByIndex(storageItemIndex, amount);
                    }
                }
                else
                {
                    // Swapping
                    CharacterItem storageItem  = storageItemList[storageItemIndex];
                    CharacterItem nonEquipItem = playerCharacterEntity.NonEquipItems[nonEquipIndex];

                    storageItemList[storageItemIndex] = nonEquipItem;
                    playerCharacterEntity.NonEquipItems[nonEquipIndex] = storageItem;
                }
                storageItemList.FillEmptySlots(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);
        }
Esempio n. 2
0
        private IEnumerator SaveCharacterRoutine(IPlayerCharacterData playerCharacterData, string userId)
        {
            if (playerCharacterData != null && !savingCharacters.Contains(playerCharacterData.Id))
            {
                savingCharacters.Add(playerCharacterData.Id);
                UpdateCharacterJob job = new UpdateCharacterJob(Database, playerCharacterData);
                job.Start();
                yield return(StartCoroutine(job.WaitFor()));

                StorageId storageId = new StorageId(StorageType.Player, userId);
                if (storageItems.ContainsKey(storageId))
                {
                    UpdateStorageItemsJob updateStorageItemsJob = new UpdateStorageItemsJob(Database, storageId.storageType, storageId.storageOwnerId, storageItems[storageId]);
                    updateStorageItemsJob.Start();
                    yield return(StartCoroutine(updateStorageItemsJob.WaitFor()));
                }
                savingCharacters.Remove(playerCharacterData.Id);
                if (LogInfo)
                {
                    Debug.Log("Character [" + playerCharacterData.Id + "] Saved");
                }
            }
        }
Esempio n. 3
0
        private IEnumerator SaveBuildingRoutine(IBuildingSaveData buildingSaveData)
        {
            if (buildingSaveData != null && !savingBuildings.Contains(buildingSaveData.Id))
            {
                savingBuildings.Add(buildingSaveData.Id);
                UpdateBuildingJob job = new UpdateBuildingJob(Database, Assets.onlineScene.SceneName, buildingSaveData);
                job.Start();
                yield return(StartCoroutine(job.WaitFor()));

                StorageId storageId = new StorageId(StorageType.Building, buildingSaveData.Id);
                if (storageItems.ContainsKey(storageId))
                {
                    UpdateStorageItemsJob updateStorageItemsJob = new UpdateStorageItemsJob(Database, storageId.storageType, storageId.storageOwnerId, storageItems[storageId]);
                    updateStorageItemsJob.Start();
                    yield return(StartCoroutine(updateStorageItemsJob.WaitFor()));
                }
                savingBuildings.Remove(buildingSaveData.Id);
                if (LogInfo)
                {
                    Debug.Log("Building [" + buildingSaveData.Id + "] Saved");
                }
            }
        }