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 }
public async UniTask <ReadStorageItemsResp> ReadStorageItemsAsync(ReadStorageItemsReq request) { var result = await Client.SendRequestAsync <ReadStorageItemsReq, ReadStorageItemsResp>(DatabaseRequestTypes.RequestReadStorageItems, request); if (result.ResponseCode != AckResponseCode.Success) { return(new ReadStorageItemsResp()); } return(result.Response); }
public async UniTask <AsyncResponseData <ReadStorageItemsResp> > ReadStorageItemsAsync(ReadStorageItemsReq request) { var resp = await Client.SendRequestAsync <ReadStorageItemsReq, ReadStorageItemsResp>(DatabaseRequestTypes.RequestReadStorageItems, request); if (!resp.IsSuccess) { Logging.LogError(nameof(DatabaseNetworkManager), $"Cannot {nameof(ReadStorageItemsAsync)} status: {resp.ResponseCode}"); } return(resp); }