public void Execute(MySqlConnection connection, MySqlTransaction transaction) { string stmt = "SELECT i.id, i.name, i.rarity, i.series, i.type, i.subtype, " + " s.base_atk, s.base_mag, s.base_acc, s.base_def, s.base_res, s.base_eva, s.base_mnd, " + " s.max_atk, s.max_mag, s.max_acc, s.max_def, s.max_res, s.max_eva, s.max_mnd " + "FROM items i LEFT OUTER JOIN equipment_stats s ON s.equipment_id = i.id"; using (MySqlCommand command = new MySqlCommand(stmt, connection, transaction)) { using (MySqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { DataCache.Items.Key key = new DataCache.Items.Key(); DataCache.Items.Data data = new DataCache.Items.Data(); key.ItemId = (uint)reader["id"]; data.Name = (string)reader["name"]; data.Rarity = (byte)reader["rarity"]; data.Series = reader.GetValueOrNull <uint>("series"); data.Type = (byte)reader["type"]; data.Subtype = (byte)reader["subtype"]; data.BaseStats = new GameData.EquipStats(); data.BaseStats.Atk = reader.GetValueOrNull <short>("base_atk"); data.BaseStats.Mag = reader.GetValueOrNull <short>("base_mag"); data.BaseStats.Acc = reader.GetValueOrNull <short>("base_acc"); data.BaseStats.Def = reader.GetValueOrNull <short>("base_def"); data.BaseStats.Res = reader.GetValueOrNull <short>("base_res"); data.BaseStats.Eva = reader.GetValueOrNull <short>("base_eva"); data.BaseStats.Mnd = reader.GetValueOrNull <short>("base_mnd"); data.MaxStats = new GameData.EquipStats(); data.MaxStats.Atk = reader.GetValueOrNull <short>("max_atk"); data.MaxStats.Mag = reader.GetValueOrNull <short>("max_mag"); data.MaxStats.Acc = reader.GetValueOrNull <short>("max_acc"); data.MaxStats.Def = reader.GetValueOrNull <short>("max_def"); data.MaxStats.Res = reader.GetValueOrNull <short>("max_res"); data.MaxStats.Eva = reader.GetValueOrNull <short>("max_eva"); data.MaxStats.Mnd = reader.GetValueOrNull <short>("max_mnd"); mItems.Update(key, data); } } } }
public void Execute(MySqlConnection connection, MySqlTransaction transaction) { string stmt = "SELECT i.id, i.name, i.rarity, i.series, i.type, i.subtype, " + " s.base_atk, s.base_mag, s.base_acc, s.base_def, s.base_res, s.base_eva, s.base_mnd, " + " s.max_atk, s.max_mag, s.max_acc, s.max_def, s.max_res, s.max_eva, s.max_mnd " + "FROM items i LEFT OUTER JOIN equipment_stats s ON s.equipment_id = i.id"; using (MySqlCommand command = new MySqlCommand(stmt, connection, transaction)) { using (MySqlDataReader reader = command.ExecuteReader()) { while (reader.Read()) { DataCache.Items.Key key = new DataCache.Items.Key(); DataCache.Items.Data data = new DataCache.Items.Data(); key.ItemId = (uint)reader["id"]; data.Name = (string)reader["name"]; data.Rarity = (byte)reader["rarity"]; data.Series = reader.GetValueOrNull<uint>("series"); data.Type = (byte)reader["type"]; data.Subtype = (byte)reader["subtype"]; data.BaseStats = new GameData.EquipStats(); data.BaseStats.Atk = reader.GetValueOrNull<short>("base_atk"); data.BaseStats.Mag = reader.GetValueOrNull<short>("base_mag"); data.BaseStats.Acc = reader.GetValueOrNull<short>("base_acc"); data.BaseStats.Def = reader.GetValueOrNull<short>("base_def"); data.BaseStats.Res = reader.GetValueOrNull<short>("base_res"); data.BaseStats.Eva = reader.GetValueOrNull<short>("base_eva"); data.BaseStats.Mnd = reader.GetValueOrNull<short>("base_mnd"); data.MaxStats = new GameData.EquipStats(); data.MaxStats.Atk = reader.GetValueOrNull<short>("max_atk"); data.MaxStats.Mag = reader.GetValueOrNull<short>("max_mag"); data.MaxStats.Acc = reader.GetValueOrNull<short>("max_acc"); data.MaxStats.Def = reader.GetValueOrNull<short>("max_def"); data.MaxStats.Res = reader.GetValueOrNull<short>("max_res"); data.MaxStats.Eva = reader.GetValueOrNull<short>("max_eva"); data.MaxStats.Mnd = reader.GetValueOrNull<short>("max_mnd"); mItems.Update(key, data); } } } }
private void PopulateActiveBattleListView(EventBattleInitiated battle) { listViewActiveBattle.Items.Clear(); if (battle == null) { labelActiveBattleNotice.Visible = true; labelNoDrops.Visible = false; return; } listViewActiveBattle.View = View.Details; List<DropEvent> drops = battle.Battle.Drops.ToList(); labelActiveBattleNotice.Visible = false; if (drops.Count == 0) { labelNoDrops.Visible = true; return; } lock(FFRKProxy.Instance.Cache.SyncRoot) { foreach (DropEvent drop in battle.Battle.Drops) { string Item; DataCache.Items.Key ItemKey = new DataCache.Items.Key { ItemId = drop.ItemId }; DataCache.Items.Data ItemData = null; if (drop.ItemType == DataEnemyDropItem.DropItemType.Gold) Item = String.Format("{0} gold", drop.GoldAmount); else if (FFRKProxy.Instance.Cache.Items.TryGetValue(ItemKey, out ItemData)) Item = ItemData.Name; else Item = drop.ItemId.ToString(); if (drop.NumberOfItems > 1) Item += String.Format(" x{0}", drop.NumberOfItems); string[] row = { Item, drop.Rarity.ToString(), drop.Round.ToString(), drop.EnemyName, "", "" }; listViewActiveBattle.Items.Add(new ListViewItem(row)); } } }
private void PopulateDropInfoListView(EventBattleInitiated battle) { listViewDropInfo.Items.Clear(); if (battle == null) { return; } else { listViewDropInfo.View = View.Details; List<DropEvent> drops = battle.Battle.Drops.ToList(); //labelActiveBattleNotice.Visible = false; if (drops.Count == 0) { return; } else { lock (FFRKProxy.Instance.Cache.SyncRoot) { foreach (DropEvent drop in battle.Battle.Drops) { string Item; DataCache.Items.Key ItemKey = new DataCache.Items.Key { ItemId = drop.ItemId }; DataCache.Items.Data ItemData = null; if (drop.ItemType == DataEnemyDropItem.DropItemType.Gold) Item = String.Format("{0} gold", drop.GoldAmount); else if (drop.ItemType == DataEnemyDropItem.DropItemType.Materia) Item = drop.MateriaName; else if (drop.ItemType == DataEnemyDropItem.DropItemType.Potion) Item = drop.PotionName; else if (FFRKProxy.Instance.Cache.Items.TryGetValue(ItemKey, out ItemData)) Item = ItemData.Name; else Item = drop.ItemId.ToString(); if (drop.NumberOfItems > 1) Item += String.Format(" x{0}", drop.NumberOfItems); string[] row = { Item, drop.Rarity.ToString(), drop.Round.ToString(), drop.EnemyName }; listViewDropInfo.Items.Add(new ListViewItem(row)); } } } foreach (ColumnHeader column in listViewDropInfo.Columns) { column.Width = -2; } } }
private GridEquipStats ComputeDisplayStats(DataEquipmentInformation equip) { ViewUpgradeModeComboIndex upgrade_type = (ViewUpgradeModeComboIndex)comboBoxUpgradeMode.SelectedIndex; RealmSynergy.SynergyValue synergy = RealmSynergy.Values.ElementAt(comboBoxSynergy.SelectedIndex); bool has_synergy = equip.SeriesId == synergy.GameSeries; DataCache.Items.Key cache_key = new DataCache.Items.Key { ItemId = equip.EquipmentId }; DataCache.Items.Data cache_value; bool in_cache = FFRKProxy.Instance.Cache.Items.TryGetValue(cache_key, out cache_value); GridEquipStats result = new GridEquipStats(); if (upgrade_type == ViewUpgradeModeComboIndex.CurrentUpgradeCurrentLevel) { result.Stats.Atk = (has_synergy) ? equip.SeriesAtk : equip.Atk; result.Stats.Mag = (has_synergy) ? equip.SeriesMag : equip.Mag; result.Stats.Acc = (has_synergy) ? equip.SeriesAcc : equip.Acc; result.Stats.Def = (has_synergy) ? equip.SeriesDef : equip.Def; result.Stats.Res = (has_synergy) ? equip.SeriesRes : equip.Res; result.Stats.Eva = (has_synergy) ? equip.SeriesEva : equip.Eva; result.Stats.Mnd = (has_synergy) ? equip.SeriesMnd : equip.Mnd; result.Level = equip.Level; result.MaxLevel = equip.LevelMax; if (equip.SeriesId == synergy.GameSeries) { result.Level = StatCalculator.EffectiveLevelWithSynergy(result.Level); } } else { if (upgrade_type == ViewUpgradeModeComboIndex.CurrentUpgradeMaxLevel) { result.MaxLevel = StatCalculator.MaxLevel(equip.Rarity); } else if (upgrade_type == ViewUpgradeModeComboIndex.MaxLevelThroughExistingCombine) { // Valid candidates for combining items into this are only those items with matching // equipment id and rarity LESS THAN OR EQUAL TO current item's rarity int candidates = mEquipments.Count(x => x.EquipmentId == equip.EquipmentId && x.InstanceId != equip.InstanceId && x.Rarity <= equip.Rarity); result.MaxLevel = StatCalculator.MaxLevel(StatCalculator.EvolveAsMuchAsPossible(equip.BaseRarity, equip.Rarity, candidates)); } else { result.MaxLevel = StatCalculator.MaxLevel(StatCalculator.Evolve(equip.BaseRarity, SchemaConstants.EvolutionLevel.PlusPlus)); } result.Level = result.MaxLevel; if (has_synergy) { result.Level = StatCalculator.EffectiveLevelWithSynergy(result.Level); } if (in_cache && cache_value.AreStatsValid) { // Try to get the equipment stats from the database result.Stats.Atk = StatCalculator.ComputeStatForLevel(equip.BaseRarity, cache_value.BaseStats.Atk, cache_value.MaxStats.Atk, result.Level); result.Stats.Mag = StatCalculator.ComputeStatForLevel(equip.BaseRarity, cache_value.BaseStats.Mag, cache_value.MaxStats.Mag, result.Level); result.Stats.Acc = StatCalculator.ComputeStatForLevel(equip.BaseRarity, cache_value.BaseStats.Acc, cache_value.MaxStats.Acc, result.Level); result.Stats.Def = StatCalculator.ComputeStatForLevel(equip.BaseRarity, cache_value.BaseStats.Def, cache_value.MaxStats.Def, result.Level); result.Stats.Res = StatCalculator.ComputeStatForLevel(equip.BaseRarity, cache_value.BaseStats.Res, cache_value.MaxStats.Res, result.Level); result.Stats.Eva = StatCalculator.ComputeStatForLevel(equip.BaseRarity, cache_value.BaseStats.Eva, cache_value.MaxStats.Eva, result.Level); result.Stats.Mnd = StatCalculator.ComputeStatForLevel(equip.BaseRarity, cache_value.BaseStats.Mnd, cache_value.MaxStats.Mnd, result.Level); } else { // If they aren't there, fall back to trying to compute effective stats from the ifnormation in the JSON. This will lead to some // rounding error due to the fact that the values for Atk and SeriesAtk etc are all rounded, so the division will be less precise // than doing it over the entire range of Max stats and base stats, but it's the best we can do in this case. byte series_effective_level = StatCalculator.EffectiveLevelWithSynergy(equip.Level); result.Stats.Atk = (result.MaxLevel == equip.Level) ? ((has_synergy) ? equip.SeriesAtk : equip.Atk) : StatCalculator.ComputeStatForLevel2(equip.Atk, equip.Level, equip.SeriesAtk, series_effective_level, result.Level); result.Stats.Mag = (result.MaxLevel == equip.Level) ? ((has_synergy) ? equip.SeriesMag : equip.Mag) : StatCalculator.ComputeStatForLevel2(equip.Mag, equip.Level, equip.SeriesMag, series_effective_level, result.Level); result.Stats.Acc = (result.MaxLevel == equip.Level) ? ((has_synergy) ? equip.SeriesAcc : equip.Acc) : StatCalculator.ComputeStatForLevel2(equip.Acc, equip.Level, equip.SeriesAcc, series_effective_level, result.Level); result.Stats.Def = (result.MaxLevel == equip.Level) ? ((has_synergy) ? equip.SeriesDef : equip.Def) : StatCalculator.ComputeStatForLevel2(equip.Def, equip.Level, equip.SeriesDef, series_effective_level, result.Level); result.Stats.Res = (result.MaxLevel == equip.Level) ? ((has_synergy) ? equip.SeriesRes : equip.Res) : StatCalculator.ComputeStatForLevel2(equip.Res, equip.Level, equip.SeriesRes, series_effective_level, result.Level); result.Stats.Eva = (result.MaxLevel == equip.Level) ? ((has_synergy) ? equip.SeriesEva : equip.Eva) : StatCalculator.ComputeStatForLevel2(equip.Eva, equip.Level, equip.SeriesEva, series_effective_level, result.Level); result.Stats.Mnd = (result.MaxLevel == equip.Level) ? ((has_synergy) ? equip.SeriesMnd : equip.Mnd) : StatCalculator.ComputeStatForLevel2(equip.Mnd, equip.Level, equip.SeriesMnd, series_effective_level, result.Level); } } if (equip.AugmentStat != null && equip.Augment > 0) { double bonus = (has_synergy) ? equip.Augment * 1.5 : (double)equip.Augment; System.Reflection.FieldInfo augmentField = typeof(EquipStats).GetField(equip.AugmentStat); short val = (short)augmentField.GetValue(result.Stats); augmentField.SetValue(result.Stats, (short)Math.Ceiling(val + bonus)); } return(result); }
private void PopulateActiveBattleListView(EventBattleInitiated battle) { listViewActiveBattle.Items.Clear(); if (battle == null) { labelActiveBattleNotice.Visible = true; labelNoDrops.Visible = false; return; } listViewActiveBattle.View = View.Details; List <DropEvent> drops = battle.Battle.Drops.ToList(); labelActiveBattleNotice.Visible = false; if (drops.Count == 0) { labelNoDrops.Visible = true; return; } lock (FFRKProxy.Instance.Cache.SyncRoot) { foreach (DropEvent drop in battle.Battle.Drops) { string Item; DataCache.Items.Key ItemKey = new DataCache.Items.Key { ItemId = drop.ItemId }; DataCache.Items.Data ItemData = null; if (drop.ItemType == DataEnemyDropItem.DropItemType.Gold) { Item = String.Format("{0} gold", drop.GoldAmount); } else if (drop.ItemType == DataEnemyDropItem.DropItemType.Materia) { Item = drop.MateriaName; } else if (drop.ItemType == DataEnemyDropItem.DropItemType.Potion) { Item = drop.PotionName; } else if (FFRKProxy.Instance.Cache.Items.TryGetValue(ItemKey, out ItemData)) { Item = ItemData.Name; } else { Item = drop.ItemId.ToString(); } if (drop.NumberOfItems > 1) { Item += String.Format(" x{0}", drop.NumberOfItems); } string[] row = { Item, drop.Rarity.ToString(), drop.Round.ToString(), drop.EnemyName, "", "" }; listViewActiveBattle.Items.Add(new ListViewItem(row)); } } }