public void Execute(MySqlConnection connection, MySqlTransaction transaction) { SelectBuilder builder = new SelectBuilder(); builder.Table = "dungeon_drops"; builder.Columns.Add("*"); builder.Parameters.Add(mItemTypes); builder.Parameters.Add(mRarities); builder.Parameters.Add(mSynergies); builder.Parameters.Add(mWorlds); builder.Parameters.Add(mDungeons); builder.Parameters.Add(mBattles); builder.Parameters.Add(mName); // Since histogram bars will come in on different rows we need a way to look up the item // so we can modify its histogram on the fly. var keyed_lookup = new Dictionary <KeyValuePair <uint, uint>, BasicItemDropStats>(); string stmt = builder.ToString(); using (MySqlCommand command = new MySqlCommand(stmt, connection)) { builder.Bind(command); using (MySqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { uint battle_id = (uint)reader["battleid"]; uint item_id = (uint)reader["itemid"]; var key = new KeyValuePair <uint, uint>(battle_id, item_id); BasicItemDropStats stats = null; if (!keyed_lookup.TryGetValue(key, out stats)) { // This is a new entry. RealmSynergy.SynergyValue synergy = null; int series_ordinal = reader.GetOrdinal("item_series"); if (!reader.IsDBNull(series_ordinal)) { uint series = (uint)reader["item_series"]; synergy = RealmSynergy.FromSeries(series); } stats = new BasicItemDropStats { BattleId = battle_id, ItemId = item_id, DungeonId = (uint)reader["dungeon_id"], WorldId = (uint)reader["world_id"], WorldName = (string)reader["world_name"], DungeonName = (string)reader["dungeon_name"], DungeonType = (SchemaConstants.DungeonType)reader["dungeon_type"], Rarity = (SchemaConstants.Rarity)reader["item_rarity"], Type = (SchemaConstants.ItemType)reader["item_type"], TimesRun = (uint)reader["times_run"], TimesRunWithHistogram = (uint)reader["times_run_with_histogram"], Synergy = synergy, BattleName = (string)reader["battle_name"], BattleStamina = (ushort)reader["battle_stamina"], ItemName = (string)reader["item_name"], }; keyed_lookup.Add(key, stats); } // Modify its histogram entry. int bucket = (int)reader["histo_bucket"]; uint bucket_value = (uint)reader["histo_value"]; if (bucket < 0) { // The total drops is stored in bucket -1. This should always be present. stats.TotalDrops = bucket_value; } else if (bucket > 0) { // We should never have a bucket 0, because that would mean 0 of the item dropped, // in which case why would it even be in the drop list? System.Diagnostics.Debug.Assert(bucket != 0); stats.Histogram[bucket] = bucket_value; } } } } if (mOnlyRepeatable) { mDropList = keyed_lookup.Values.Where(x => x.IsBattleRepeatable).ToList(); } else { mDropList = keyed_lookup.Values.ToList(); } foreach (BasicItemDropStats stats in mDropList) { // Post process the list. None of the items will have a value set for Histogram[0] because that // means we didn't see anything. So we have to compute this by subtracting all the events where // we did see something from all the events total. stats.Histogram[0] = stats.TimesRunWithHistogram; for (int i = 1; i < stats.Histogram.BucketCount; ++i) { stats.Histogram[0] -= stats.Histogram[i]; } } }
private void UpdateAllDropsForLastBattle(EventBattleInitiated battle) { if (battle == null) { this.listViewAllDrops.VirtualListSize = 0; this.mAllItems.Clear(); this.mFilteredItems.Collection.Clear(); } else { foreach (BasicItemDropStats basicItemDropStats in this.mAllItems.Where <BasicItemDropStats>((Func <BasicItemDropStats, bool>)(x => (int)x.BattleId == (int)battle.Battle.BattleId))) { ++basicItemDropStats.TimesRun; ++basicItemDropStats.TimesRunWithHistogram; } lock (FFRKProxy.Instance.Cache.SyncRoot) { foreach (DropEvent drop1 in battle.Battle.Drops) { DropEvent drop = drop1; if (drop.ItemType != DataEnemyDropItem.DropItemType.Gold && drop.ItemType != DataEnemyDropItem.DropItemType.Materia && drop.ItemType != DataEnemyDropItem.DropItemType.Potion) { BasicItemDropStats basicItemDropStats = this.mAllItems.Find((Predicate <BasicItemDropStats>)(x => (int)x.BattleId == (int)battle.Battle.BattleId && (int)x.ItemId == (int)drop.ItemId)); if (basicItemDropStats != null) { ++basicItemDropStats.TotalDrops; } else { EventListBattles activeDungeon = FFRKProxy.Instance.GameState.ActiveDungeon; if (activeDungeon != null) { DataBattle dataBattle = activeDungeon.Battles.Find(x => (int)x.Id == (int)battle.Battle.BattleId); if (dataBattle != null) { uint num1 = 1; uint num2 = 1; string name = drop.ItemId.ToString(); FFRKInspector.DataCache.Items.Data data1; if (FFRKProxy.Instance.Cache.Items.TryGetValue(new FFRKInspector.DataCache.Items.Key() { ItemId = drop.ItemId }, out data1)) { name = data1.Name; } FFRKInspector.DataCache.Battles.Data data2; if (FFRKProxy.Instance.Cache.Battles.TryGetValue(new FFRKInspector.DataCache.Battles.Key() { BattleId = battle.Battle.BattleId }, out data2)) { num1 = data2.Samples; num2 = data2.HistoSamples; } this.mAllItems.Add(new BasicItemDropStats() { BattleId = battle.Battle.BattleId, BattleName = dataBattle.Name, BattleStamina = dataBattle.Stamina, ItemId = drop.ItemId, ItemName = name, TimesRun = num1, TotalDrops = 1U }); } } } } } } this.RebuildFilteredDropListAndInvalidate(); } }
void UpdateAllDropsForLastBattle(EventBattleInitiated battle) { if (battle == null) { listViewAllDrops.VirtualListSize = 0; mAllItems.Clear(); mFilteredItems.Collection.Clear(); return; } foreach (BasicItemDropStats stats in mAllItems.Where(x => x.BattleId == battle.Battle.BattleId)) { // Update the times_run field of every item that matches the last battle. If we don't do // this here in a separate loop, it will only happen for items that actually dropped in // the following loop. stats.TimesRun++; stats.TimesRunWithHistogram++; } lock (FFRKProxy.Instance.Cache.SyncRoot) { foreach (DropEvent drop in battle.Battle.Drops) { if (drop.ItemType == DataEnemyDropItem.DropItemType.Gold) { continue; } if (drop.ItemType == DataEnemyDropItem.DropItemType.Materia) { continue; } if (drop.ItemType == DataEnemyDropItem.DropItemType.Potion) { continue; } BasicItemDropStats match = mAllItems.Find(x => (x.BattleId == battle.Battle.BattleId) && (x.ItemId == drop.ItemId)); if (match != null) { ++match.TotalDrops; continue; } EventListBattles this_battle_list = FFRKProxy.Instance.GameState.ActiveDungeon; if (this_battle_list == null) { continue; } DataBattle this_battle = this_battle_list.Battles.Find(x => x.Id == battle.Battle.BattleId); if (this_battle == null) { continue; } uint times_run = 1; uint histo_times_run = 1; string item_name = drop.ItemId.ToString(); DataCache.Items.Data item_data; DataCache.Battles.Data battle_data; if (FFRKProxy.Instance.Cache.Items.TryGetValue(new DataCache.Items.Key { ItemId = drop.ItemId }, out item_data)) { item_name = item_data.Name; } if (FFRKProxy.Instance.Cache.Battles.TryGetValue(new DataCache.Battles.Key { BattleId = battle.Battle.BattleId }, out battle_data)) { // Get the times_run from the cache, and add 1 to it. times_run = battle_data.Samples; histo_times_run = battle_data.HistoSamples; } mAllItems.Add( new BasicItemDropStats { BattleId = battle.Battle.BattleId, BattleName = this_battle.Name, BattleStamina = this_battle.Stamina, ItemId = drop.ItemId, ItemName = item_name, TimesRun = times_run, TotalDrops = 1, }); } } RebuildFilteredDropListAndInvalidate(); }