Ejemplo n.º 1
0
        public async UniTaskVoid OpenStorage(long connectionId, IPlayerCharacterData playerCharacter, StorageId storageId)
        {
#if UNITY_STANDALONE && !CLIENT_BUILD
            if (!CanAccessStorage(playerCharacter, storageId))
            {
                GameInstance.ServerGameMessageHandlers.SendGameMessage(connectionId, UITextKeys.UI_ERROR_CANNOT_ACCESS_STORAGE);
                return;
            }
            // Store storage usage states
            if (!usingStorageClients.ContainsKey(storageId))
            {
                usingStorageClients.TryAdd(storageId, new HashSet <long>());
            }
            usingStorageClients[storageId].Add(connectionId);
            usingStorageIds.TryRemove(connectionId, out _);
            usingStorageIds.TryAdd(connectionId, storageId);
            // Load storage items from database
            ReadStorageItemsReq req = new ReadStorageItemsReq();
            req.StorageType    = (EStorageType)storageId.storageType;
            req.StorageOwnerId = storageId.storageOwnerId;
            ReadStorageItemsResp resp = await DbServiceClient.ReadStorageItemsAsync(req);

            List <CharacterItem> storageItems = DatabaseServiceUtils.MakeListFromRepeatedByteString <CharacterItem>(resp.StorageCharacterItems);
            SetStorageItems(storageId, storageItems);
            // Notify storage items to client
            uint    storageObjectId;
            Storage storage = GetStorage(storageId, out storageObjectId);
            GameInstance.ServerGameMessageHandlers.NotifyStorageOpened(connectionId, storageId.storageType, storageId.storageOwnerId, storageObjectId, storage.weightLimit, storage.slotLimit);
            storageItems.FillEmptySlots(storage.slotLimit > 0, storage.slotLimit);
            GameInstance.ServerGameMessageHandlers.NotifyStorageItems(connectionId, storageItems);
#endif
        }
        /// <summary>
        /// Adds the loot bag items to the specified loot bag storage.
        /// </summary>
        /// <param name="storageId">loot bag storage ID</param>
        /// <param name="addingItems">items to add to loot bag</param>
        /// <returns>true if successful, false otherwise</returns>
        public async UniTask <bool> AddLootBagItems(StorageId storageId, List <CharacterItem> lootItems)
        {
#if UNITY_STANDALONE && !CLIENT_BUILD
            // Attempt to read from storage first. This registers it and adds it to cache.
            ReadStorageItemsReq rsir = new ReadStorageItemsReq();
            rsir.StorageType    = storageId.storageType;
            rsir.StorageOwnerId = storageId.storageOwnerId;
            ReadStorageItemsResp rsiresp = await DbServiceClient.ReadStorageItemsAsync(rsir);

            foreach (CharacterItem lootItem in lootItems)
            {
                Storage storge = GetStorage(storageId, out _);
                IncreaseStorageItemsReq req = new IncreaseStorageItemsReq();
                req.StorageType    = storageId.storageType;
                req.StorageOwnerId = storageId.storageOwnerId;
                req.WeightLimit    = storge.weightLimit;
                req.SlotLimit      = storge.slotLimit;
                req.Item           = lootItem;
                IncreaseStorageItemsResp resp = await DbServiceClient.IncreaseStorageItemsAsync(req);

                if (UITextKeys.NONE != resp.Error)
                {
                    return(false);
                }
                SetStorageItems(storageId, resp.StorageCharacterItems);
            }
            return(true);
#else
            return(false);
#endif
        }
        private async UniTask LoadStorageRoutine(StorageId storageId)
        {
            if (!loadingStorageIds.Contains(storageId))
            {
                loadingStorageIds.Add(storageId);
                ReadStorageItemsResp readStorageItemsResp = await DbServiceClient.ReadStorageItemsAsync(new ReadStorageItemsReq()
                {
                    StorageType    = (EStorageType)storageId.storageType,
                    StorageOwnerId = storageId.storageOwnerId
                });

                allStorageItems[storageId] = readStorageItemsResp.StorageCharacterItems.MakeListFromRepeatedByteString <CharacterItem>();
                loadingStorageIds.Remove(storageId);
            }
        }
Ejemplo n.º 4
0
        private async UniTask LoadStorageRoutine(StorageId storageId)
        {
            if (!loadingStorageIds.Contains(storageId))
            {
                loadingStorageIds.Add(storageId);
                ReadStorageItemsResp readStorageItemsResp = await DbServiceClient.ReadStorageItemsAsync(new ReadStorageItemsReq()
                {
                    StorageType    = storageId.storageType,
                    StorageOwnerId = storageId.storageOwnerId,
                });

                ServerStorageHandlers.SetStorageItems(storageId, readStorageItemsResp.StorageCharacterItems);
                loadingStorageIds.Remove(storageId);
            }
        }