internal void UpdateInventoryItems(InventoryDelta delta) { if (delta?.InventoryItems == null || delta.InventoryItems.All(i => i == null)) { return; } InventoryItems.AddRange(delta.InventoryItems.Where(i => i != null)); // Only keep the newest ones foreach (var deltaItem in delta.InventoryItems.Where(d => d?.InventoryItemData != null)) { var oldItems = new List <InventoryItem>(); if (deltaItem.InventoryItemData.PlayerStats != null) { oldItems.AddRange( InventoryItems.Where(i => i.InventoryItemData?.PlayerStats != null) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1)); } if (deltaItem.InventoryItemData.PlayerCurrency != null) { oldItems.AddRange( InventoryItems.Where(i => i.InventoryItemData?.PlayerCurrency != null) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1)); } if (deltaItem.InventoryItemData.PlayerCamera != null) { oldItems.AddRange( InventoryItems.Where(i => i.InventoryItemData?.PlayerCamera != null) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1)); } if (deltaItem.InventoryItemData.InventoryUpgrades != null) { oldItems.AddRange( InventoryItems.Where(i => i.InventoryItemData?.InventoryUpgrades != null) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1)); } if (deltaItem.InventoryItemData.PokedexEntry != null) { oldItems.AddRange( InventoryItems.Where( i => i.InventoryItemData?.PokedexEntry != null && i.InventoryItemData.PokedexEntry.PokemonId == deltaItem.InventoryItemData.PokedexEntry.PokemonId) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1)); } if (deltaItem.InventoryItemData.Candy != null) { oldItems.AddRange( InventoryItems.Where( i => i.InventoryItemData?.Candy != null && i.InventoryItemData.Candy.FamilyId == deltaItem.InventoryItemData.Candy.FamilyId) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1)); } if (deltaItem.InventoryItemData.Item != null) { oldItems.AddRange( InventoryItems.Where( i => i.InventoryItemData?.Item != null && i.InventoryItemData.Item.ItemId == deltaItem.InventoryItemData.Item.ItemId) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1)); } if (deltaItem.InventoryItemData.PokemonData != null) { oldItems.AddRange( InventoryItems.Where( i => i.InventoryItemData?.PokemonData != null && i.InventoryItemData.PokemonData.Id == deltaItem.InventoryItemData.PokemonData.Id) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1)); } if (deltaItem.InventoryItemData.AppliedItems != null) { oldItems.AddRange( InventoryItems.Where(i => i.InventoryItemData?.AppliedItems != null) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1)); } if (deltaItem.InventoryItemData.EggIncubators != null) { oldItems.AddRange( InventoryItems.Where(i => i.InventoryItemData?.EggIncubators != null) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1)); } foreach (var oldItem in oldItems) { InventoryItems.Remove(oldItem); } } var appliedItems = InventoryItems.Select(i => i.InventoryItemData?.AppliedItems) .Where(aItems => aItems?.Item != null) .SelectMany(aItems => aItems.Item).ToDictionary(item => item.ItemId, item => new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(item.ExpireMs)); DateTime expires = new DateTime(0); foreach (var item in InventoryItems.Select(i => i.InventoryItemData?.Item).Where(item => item != null)) { if (appliedItems.ContainsKey(item.ItemId)) { expires = appliedItems[item.ItemId]; var time = expires - DateTime.UtcNow; if (expires.Ticks == 0 || time.TotalSeconds < 0) { // check item if (item.ItemId == ItemId.ItemIncenseCool || item.ItemId == ItemId.ItemIncenseFloral || item.ItemId == ItemId.ItemIncenseOrdinary || item.ItemId == ItemId.ItemIncenseSpicy) { _session.IncenseUsed = false; } if (item.ItemId == ItemId.ItemLuckyEgg) { _session.LuckyEggsUsed = false; } } else { // check item if (item.ItemId == ItemId.ItemIncenseCool || item.ItemId == ItemId.ItemIncenseFloral || item.ItemId == ItemId.ItemIncenseOrdinary || item.ItemId == ItemId.ItemIncenseSpicy) { _session.IncenseUsed = true; _session.Logger.Info($"Session applied item: {item.ItemId.ToString().Replace("Item", "")} active for: {time.Minutes}m {Math.Abs(time.Seconds)}s."); } if (item.ItemId == ItemId.ItemLuckyEgg) { _session.LuckyEggsUsed = true; _session.Logger.Info($"Session applied item: {item.ItemId.ToString().Replace("Item", "")} active for: {time.Minutes}m {Math.Abs(time.Seconds)}s."); } } } } _session.OnInventoryUpdate(); }
internal void UpdateInventoryItems(InventoryDelta delta) { if (delta?.InventoryItems == null || delta.InventoryItems.All(i => i == null)) { return; } InventoryItems.AddRange(delta.InventoryItems.Where(i => i != null)); // Only keep the newest ones foreach (var deltaItem in delta.InventoryItems.Where(d => d?.InventoryItemData != null)) { var oldItems = new List <InventoryItem>(); if (deltaItem.InventoryItemData.PlayerStats != null) { oldItems.AddRange( InventoryItems.Where(i => i.InventoryItemData?.PlayerStats != null) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1)); } if (deltaItem.InventoryItemData.PlayerCurrency != null) { oldItems.AddRange( InventoryItems.Where(i => i.InventoryItemData?.PlayerCurrency != null) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1)); } if (deltaItem.InventoryItemData.PlayerCamera != null) { oldItems.AddRange( InventoryItems.Where(i => i.InventoryItemData?.PlayerCamera != null) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1)); } if (deltaItem.InventoryItemData.InventoryUpgrades != null) { oldItems.AddRange( InventoryItems.Where(i => i.InventoryItemData?.InventoryUpgrades != null) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1)); } if (deltaItem.InventoryItemData.PokedexEntry != null) { oldItems.AddRange( InventoryItems.Where( i => i.InventoryItemData?.PokedexEntry != null && i.InventoryItemData.PokedexEntry.PokemonId == deltaItem.InventoryItemData.PokedexEntry.PokemonId) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1)); } if (deltaItem.InventoryItemData.Candy != null) { oldItems.AddRange( InventoryItems.Where( i => i.InventoryItemData?.Candy != null && i.InventoryItemData.Candy.FamilyId == deltaItem.InventoryItemData.Candy.FamilyId) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1)); } if (deltaItem.InventoryItemData.Item != null) { oldItems.AddRange( InventoryItems.Where( i => i.InventoryItemData?.Item != null && i.InventoryItemData.Item.ItemId == deltaItem.InventoryItemData.Item.ItemId) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1)); } if (deltaItem.InventoryItemData.PokemonData != null) { oldItems.AddRange( InventoryItems.Where( i => i.InventoryItemData?.PokemonData != null && i.InventoryItemData.PokemonData.Id == deltaItem.InventoryItemData.PokemonData.Id) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1)); } if (deltaItem.InventoryItemData.AppliedItems != null) { oldItems.AddRange( InventoryItems.Where(i => i.InventoryItemData?.AppliedItems != null) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1)); } if (deltaItem.InventoryItemData.EggIncubators != null) { oldItems.AddRange( InventoryItems.Where(i => i.InventoryItemData?.EggIncubators != null) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1)); } foreach (var oldItem in oldItems) { InventoryItems.Remove(oldItem); } } Update?.Invoke(this, EventArgs.Empty); }
/// <summary> /// /// </summary> /// <param name="value"></param> /// <remarks>These might not stay here, we'll see how the pattern plays out.</remarks> public void RaiseInventoryDeltaReceived(InventoryDelta value) => InventoryDeltaReceived?.Invoke(this, value);
internal void UpdateInventoryItems(InventoryDelta delta) { if (CachedInventory == null) { CachedInventory = new GetInventoryResponse(); CachedInventory.InventoryDelta = delta; return; } var InventoryItems = CachedInventory.InventoryDelta.InventoryItems; if (delta?.InventoryItems == null || delta.InventoryItems.All(i => i == null)) { return; } InventoryItems.AddRange(delta.InventoryItems.Where(i => i != null)); // Only keep the newest ones foreach (var deltaItem in delta.InventoryItems.Where(d => d?.InventoryItemData != null)) { var oldItems = new List <InventoryItem>(); if (deltaItem.InventoryItemData.PlayerStats != null) { var oldValues = InventoryItems.Where(i => i.InventoryItemData?.PlayerStats != null) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1); if (oldValues != null) { oldItems.AddRange(oldValues); } } if (deltaItem.InventoryItemData.PlayerCurrency != null) { var oldValues = InventoryItems.Where(i => i.InventoryItemData?.PlayerCurrency != null) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1); if (oldValues != null) { oldItems.AddRange(oldValues); } } if (deltaItem.InventoryItemData.PlayerCamera != null) { var oldValues = InventoryItems.Where(i => i.InventoryItemData?.PlayerCamera != null) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1); if (oldValues != null) { oldItems.AddRange(oldValues); } } if (deltaItem.InventoryItemData.InventoryUpgrades != null) { var oldValues = InventoryItems.Where(i => i.InventoryItemData?.InventoryUpgrades != null) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1); if (oldValues != null) { oldItems.AddRange(oldValues); } } if (deltaItem.InventoryItemData.PokedexEntry != null) { var oldValues = InventoryItems.Where( i => i.InventoryItemData?.PokedexEntry != null && i.InventoryItemData.PokedexEntry.PokemonId == deltaItem.InventoryItemData.PokedexEntry.PokemonId) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1); if (oldValues != null) { oldItems.AddRange(oldValues); } } if (deltaItem.InventoryItemData.Candy != null) { var oldValues = InventoryItems.Where( i => i.InventoryItemData?.Candy != null && i.InventoryItemData.Candy.FamilyId == deltaItem.InventoryItemData.Candy.FamilyId) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1); if (oldValues != null) { oldItems.AddRange(oldValues); } } if (deltaItem.InventoryItemData.Item != null) { var oldValues = InventoryItems.Where( i => i.InventoryItemData?.Item != null && i.InventoryItemData.Item.ItemId == deltaItem.InventoryItemData.Item.ItemId) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1); if (oldValues != null) { oldItems.AddRange(oldValues); } } if (deltaItem.InventoryItemData.PokemonData != null) { var oldValues = InventoryItems.Where( i => i.InventoryItemData?.PokemonData != null && i.InventoryItemData.PokemonData.Id == deltaItem.InventoryItemData.PokemonData.Id) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1); if (oldValues != null) { oldItems.AddRange(oldValues); } } if (deltaItem.InventoryItemData.AppliedItems != null) { var oldValues = InventoryItems.Where(i => i.InventoryItemData?.AppliedItems != null) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1); if (oldValues != null) { oldItems.AddRange(oldValues); } } if (deltaItem.InventoryItemData.EggIncubators != null) { var oldValues = InventoryItems.Where(i => i.InventoryItemData?.EggIncubators != null) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1); if (oldValues != null) { oldItems.AddRange(oldValues); } } foreach (var oldItem in oldItems) { InventoryItems.Remove(oldItem); } var deletedPokemons = delta.InventoryItems.Select(i => i.DeletedItem).Where(x => x != null); foreach (var element in deletedPokemons) { var cachedElement = InventoryItems.FirstOrDefault(x => x.InventoryItemData.PokemonData != null && x.InventoryItemData.PokemonData.Id == element.PokemonId); if (cachedElement != null) { InventoryItems.Remove(cachedElement); } } } }
internal void UpdateInventoryItems(InventoryDelta delta) { if (delta?.InventoryItems == null || delta.InventoryItems.All(i => i == null)) { return; } InventoryItems.AddRange(delta.InventoryItems.Where(i => i != null)); // Only keep the newest ones foreach (var deltaItem in delta.InventoryItems.Where(d => d?.InventoryItemData != null)) { var oldItems = new List<InventoryItem>(); if (deltaItem.InventoryItemData.PlayerStats != null) { oldItems.AddRange( InventoryItems.Where(i => i.InventoryItemData?.PlayerStats != null) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1)); } if (deltaItem.InventoryItemData.PlayerCurrency != null) { oldItems.AddRange( InventoryItems.Where(i => i.InventoryItemData?.PlayerCurrency != null) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1)); } if (deltaItem.InventoryItemData.PlayerCamera != null) { oldItems.AddRange( InventoryItems.Where(i => i.InventoryItemData?.PlayerCamera != null) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1)); } if (deltaItem.InventoryItemData.InventoryUpgrades != null) { oldItems.AddRange( InventoryItems.Where(i => i.InventoryItemData?.InventoryUpgrades != null) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1)); } if (deltaItem.InventoryItemData.PokedexEntry != null) { oldItems.AddRange( InventoryItems.Where( i => i.InventoryItemData?.PokedexEntry != null && i.InventoryItemData.PokedexEntry.PokemonId == deltaItem.InventoryItemData.PokedexEntry.PokemonId) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1)); } if (deltaItem.InventoryItemData.Candy != null) { oldItems.AddRange( InventoryItems.Where( i => i.InventoryItemData?.Candy != null && i.InventoryItemData.Candy.FamilyId == deltaItem.InventoryItemData.Candy.FamilyId) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1)); } if (deltaItem.InventoryItemData.Item != null) { oldItems.AddRange( InventoryItems.Where( i => i.InventoryItemData?.Item != null && i.InventoryItemData.Item.ItemId == deltaItem.InventoryItemData.Item.ItemId) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1)); } if (deltaItem.InventoryItemData.PokemonData != null) { oldItems.AddRange( InventoryItems.Where( i => i.InventoryItemData?.PokemonData != null && i.InventoryItemData.PokemonData.Id == deltaItem.InventoryItemData.PokemonData.Id) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1)); } if (deltaItem.InventoryItemData.AppliedItems != null) { oldItems.AddRange( InventoryItems.Where(i => i.InventoryItemData?.AppliedItems != null) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1)); } if (deltaItem.InventoryItemData.EggIncubators != null) { oldItems.AddRange( InventoryItems.Where(i => i.InventoryItemData?.EggIncubators != null) .OrderByDescending(i => i.ModifiedTimestampMs) .Skip(1)); } foreach (var oldItem in oldItems) { InventoryItems.Remove(oldItem); } } Update?.Invoke(this, EventArgs.Empty); }