public void LoadGlyphs() { List <ComparisonCalculationBase> glyphCalculations = new List <ComparisonCalculationBase>(); Character baseChar = Character.Clone(); Character newChar = Character.Clone(); CharacterCalculationsBase currentCalc; CharacterCalculationsBase newCalc; ComparisonCalculationBase compare; bool orig; List <string> relevant = Calculations.GetModel(Character.CurrentModel).GetRelevantGlyphs(); currentCalc = Calculations.GetCharacterCalculations(baseChar, null, false, true, false); foreach (PropertyInfo pi in baseChar.CurrentTalents.GetType().GetProperties()) { GlyphDataAttribute[] glyphDatas = pi.GetCustomAttributes(typeof(GlyphDataAttribute), true) as GlyphDataAttribute[]; if (glyphDatas.Length > 0) { GlyphDataAttribute glyphData = glyphDatas[0]; if (relevant == null || relevant.Contains(glyphData.Name)) { orig = baseChar.CurrentTalents.GlyphData[glyphData.Index]; if (orig) { newChar.CurrentTalents.GlyphData[glyphData.Index] = false; newCalc = Calculations.GetCharacterCalculations(newChar, null, false, true, false); compare = Calculations.GetCharacterComparisonCalculations(newCalc, currentCalc, glyphData.Name, orig, false); } else { newChar.CurrentTalents.GlyphData[glyphData.Index] = true; newCalc = Calculations.GetCharacterCalculations(newChar, null, false, true, false); compare = Calculations.GetCharacterComparisonCalculations(currentCalc, newCalc, glyphData.Name, orig, false); } compare.Description = glyphData.Description; // JOTHAY: WTB Tooltips that show info on these charts compare.Item = null; glyphCalculations.Add(compare); newChar.CurrentTalents.GlyphData[glyphData.Index] = orig; } } } comparisonGraph1.RoundValues = true; comparisonGraph1.CustomRendered = false; comparisonGraph1.ItemCalculations = glyphCalculations.ToArray(); comparisonGraph1.EquipSlot = CharacterSlot.None; _characterSlot = CharacterSlot.None; }
private void ParseGlyphsIntoTalents(List <int> glyphsList, Character character) { foreach (int glyphId in glyphsList) { foreach (PropertyInfo pi in character.CurrentTalents.GetType().GetProperties()) { GlyphDataAttribute[] glyphDatas = pi.GetCustomAttributes(typeof(GlyphDataAttribute), true) as GlyphDataAttribute[]; if (glyphDatas.Length > 0) { GlyphDataAttribute glyphData = glyphDatas[0]; if (glyphData.EffectID == glyphId) { character.CurrentTalents.GlyphData[glyphData.Index] = true; } } } } }
private void UpdateTrees() { ClearTalentPickerItems(); if (Talents != null) { _treeNames = new List <string>((string[])Talents.GetType().GetField("TreeNames").GetValue(Talents)); talentTree1.CharacterClass = _character.Class; talentTree1.TreeName = _treeNames[0]; tabPageTree1.Text = _treeNames[0]; talentTree2.CharacterClass = _character.Class; talentTree2.TreeName = _treeNames[1]; tabPageTree2.Text = _treeNames[1]; talentTree3.CharacterClass = _character.Class; talentTree3.TreeName = _treeNames[2]; tabPageTree3.Text = _treeNames[2]; TalentTree currentTree; List <GlyphDataAttribute> majors = new List <GlyphDataAttribute>(); List <GlyphDataAttribute> minors = new List <GlyphDataAttribute>(); List <string> relevant = Calculations.GetModel(Character.CurrentModel).GetRelevantGlyphs(); foreach (PropertyInfo pi in Talents.GetType().GetProperties()) { TalentDataAttribute[] talentDatas = pi.GetCustomAttributes(typeof(TalentDataAttribute), true) as TalentDataAttribute[]; if (talentDatas.Length > 0) { TalentDataAttribute talentData = talentDatas[0]; switch (talentData.Tree) { case 0: currentTree = talentTree1; break; case 1: currentTree = talentTree2; break; default: currentTree = talentTree3; break; } TalentItem item = new TalentItem(currentTree, talentData.Name, talentData.Row - 1, talentData.Column - 1, talentData.Index, LineWrapDescription(talentData.Description), talentData.Icon, (int)pi.GetValue(Talents, null), talentData.MaxPoints, talentData.Prerequisite >= 0 ? _talentPickerItems[talentData.Prerequisite] : null); _talentPickerItems[talentData.Index] = item; currentTree.AddTalent(item); item.CurrentRankChanged += new EventHandler(item_CurrentRankChanged); } GlyphDataAttribute[] glyphDatas = pi.GetCustomAttributes(typeof(GlyphDataAttribute), true) as GlyphDataAttribute[]; if (glyphDatas.Length > 0) { GlyphDataAttribute glyphData = glyphDatas[0]; if (glyphData.Major) { majors.Add(glyphData); } else { minors.Add(glyphData); } } } tabPageGlyphs.SuspendLayout(); foreach (Control c in grpMajorGlyph.Controls) { c.Dispose(); } grpMajorGlyph.Controls.Clear(); int count = 0; foreach (GlyphDataAttribute glyph in majors) { if (relevant == null || relevant.Contains(glyph.Name)) { CheckBox cb = new CheckBox(); grpMajorGlyph.Controls.Add(cb); cb.AutoSize = true; cb.Text = glyph.Name; cb.Tag = glyph.Index; cb.Checked = Talents.GlyphData[glyph.Index]; cb.UseVisualStyleBackColor = true; cb.Location = new Point(8, 17 + 21 * count); cb.CheckedChanged += new EventHandler(this.glyph_ValueChanged); tooltipGlyph.SetToolTip(cb, glyph.Description); count++; } } if (count == 0) { grpMajorGlyph.Hide(); } else { grpMajorGlyph.Show(); } count = 0; foreach (Control c in grpMinorGlyph.Controls) { c.Dispose(); } grpMinorGlyph.Controls.Clear(); foreach (GlyphDataAttribute glyph in minors) { if (relevant == null || relevant.Contains(glyph.Name)) { CheckBox cb = new CheckBox(); grpMinorGlyph.Controls.Add(cb); cb.AutoSize = true; cb.Text = glyph.Name; cb.Tag = glyph.Index; cb.Checked = Talents.GlyphData[glyph.Index]; cb.UseVisualStyleBackColor = true; cb.Location = new Point(6, 19 + 23 * count); cb.CheckedChanged += new EventHandler(this.glyph_ValueChanged); tooltipGlyph.SetToolTip(cb, glyph.Description); count++; } } if (count == 0) { grpMinorGlyph.Hide(); } else { grpMinorGlyph.Show(); } tabPageGlyphs.ResumeLayout(); talentTree1.Redraw(); talentTree2.Redraw(); talentTree3.Redraw(); item_CurrentRankChanged(null, null); } }
private Character ConvertBattleNetJsonToCharacter(string json, string region) { Character character = new Character(); // TODO consider replacing with DataContractJsonSerializer var dict = JsonParser.Parse(json, false); { character.Name = (string)dict["name"]; character.Realm = (string)dict["realm"]; character.Region = (CharacterRegion)Enum.Parse(typeof(CharacterRegion), region.ToUpperInvariant()); } //Race { character.Race = (CharacterRace)dict["race"]; } //Class { character.Class = (CharacterClass)dict["class"]; } //Talents { var talent = (Dictionary <string, object>)((object[])dict["talents"]).FirstOrDefault(t => { object selected; return(((Dictionary <string, object>)t).TryGetValue("selected", out selected) && (bool)selected); }); string spec = character.Class.ToString() + "." + talent["name"]; string talents = (string)talent["build"]; var glyphs = (Dictionary <string, object>)talent["glyphs"]; List <int> glyphIds = new List <int>(); foreach (var group in glyphs) { foreach (Dictionary <string, object> glyph in (object[])group.Value) { glyphIds.Add((int)glyph["item"]); } } switch (character.Class) { case CharacterClass.Warrior: character.WarriorTalents = new WarriorTalents(talents); character.CurrentModel = "DPSWarr"; break; case CharacterClass.Paladin: character.PaladinTalents = new PaladinTalents(talents); character.CurrentModel = "ProtPaladin"; break; case CharacterClass.Hunter: character.HunterTalents = new HunterTalents(talents); character.CurrentModel = "Hunter"; break; case CharacterClass.Rogue: character.RogueTalents = new RogueTalents(talents); character.CurrentModel = "Rogue"; break; case CharacterClass.Priest: character.PriestTalents = new PriestTalents(talents); character.CurrentModel = "ShadowPriest"; break; case CharacterClass.DeathKnight: character.DeathKnightTalents = new DeathKnightTalents(talents); character.CurrentModel = "DPSDK"; break; case CharacterClass.Shaman: character.ShamanTalents = new ShamanTalents(talents); character.CurrentModel = "Elemental"; break; case CharacterClass.Mage: character.MageTalents = new MageTalents(talents); character.CurrentModel = "Mage"; break; case CharacterClass.Warlock: character.WarlockTalents = new WarlockTalents(talents); character.CurrentModel = "Warlock"; break; case CharacterClass.Druid: character.DruidTalents = new DruidTalents(talents); character.CurrentModel = "Bear"; break; } switch (spec) { case "Warrior.Arms": character.CurrentModel = "DPSWarr"; break; case "Warrior.Fury": character.CurrentModel = "DPSWarr"; break; case "Warrior.Protection": character.CurrentModel = "ProtWarr"; break; case "Paladin.Holy": character.CurrentModel = "Healadin"; break; case "Paladin.Protection": character.CurrentModel = "ProtPaladin"; break; case "Paladin.Retribution": character.CurrentModel = "Retribution"; break; case "Hunter.Beast Mastery": character.CurrentModel = "Hunter"; break; case "Hunter.Marksmanship": character.CurrentModel = "Hunter"; break; case "Hunter.Survival": character.CurrentModel = "Hunter"; break; case "Rogue.Assassination": character.CurrentModel = "Rogue"; break; case "Rogue.Combat": character.CurrentModel = "Rogue"; break; case "Rogue.Subtlety": character.CurrentModel = "Rogue"; break; case "Priest.Discipline": character.CurrentModel = "HealPriest"; break; case "Priest.Holy": character.CurrentModel = "HealPriest"; break; case "Priest.Shadow": character.CurrentModel = "ShadowPriest"; break; case "DeathKnight.Blood": character.CurrentModel = "TankDK"; break; case "DeathKnight.Frost": character.CurrentModel = "DPSDK"; break; case "DeathKnight.Unholy": character.CurrentModel = "DPSDK"; break; case "Shaman.Elemental": character.CurrentModel = "Elemental"; break; case "Shaman.Enhancement": character.CurrentModel = "Enhance"; break; case "Shaman.Restoration": character.CurrentModel = "RestoSham"; break; case "Mage.Arcane": character.CurrentModel = "Mage"; break; case "Mage.Fire": character.CurrentModel = "Mage"; break; case "Mage.Frost": character.CurrentModel = "Mage"; break; case "Warlock.Affliction": character.CurrentModel = "Warlock"; break; case "Warlock.Demonology": character.CurrentModel = "Warlock"; break; case "Warlock.Destruction": character.CurrentModel = "Warlock"; break; case "Druid.Balance": character.CurrentModel = "Moonkin"; break; case "Druid.Feral Combat": character.CurrentModel = character.DruidTalents.ThickHide > 0 ? "Bear" : "Cat"; break; case "Druid.Restoration": character.CurrentModel = "Tree"; break; } Dictionary <int, PropertyInfo> glyphProperty = new Dictionary <int, PropertyInfo>(); foreach (PropertyInfo pi in character.CurrentTalents.GetType().GetProperties()) { GlyphDataAttribute[] glyphDatas = pi.GetCustomAttributes(typeof(GlyphDataAttribute), true) as GlyphDataAttribute[]; if (glyphDatas.Length > 0) { GlyphDataAttribute glyphData = glyphDatas[0]; glyphProperty[glyphData.SpellID] = pi; } } foreach (int glyph in glyphIds) { PropertyInfo pi; if (glyphProperty.TryGetValue(glyph, out pi)) { pi.SetValue(character.CurrentTalents, true, null); } } } //Professions try { var professions = (object[])((Dictionary <string, object>)dict["professions"])["primary"]; string profession1 = professions.Length >= 1 ? (string)((Dictionary <string, object>)professions[0])["name"] : null; string profession2 = professions.Length >= 2 ? (string)((Dictionary <string, object>)professions[1])["name"]: null; if (profession1 != null) { character.PrimaryProfession = (Profession)Enum.Parse(typeof(Profession), profession1); } if (profession2 != null) { character.SecondaryProfession = (Profession)Enum.Parse(typeof(Profession), profession2); } } catch { } //Items { var items = (Dictionary <string, object>)dict["items"]; if (items.ContainsKey("head")) { character._head = ParseItemJson(items["head"]); } if (items.ContainsKey("neck")) { character._neck = ParseItemJson(items["neck"]); } if (items.ContainsKey("shoulder")) { character._shoulders = ParseItemJson(items["shoulder"]); } if (items.ContainsKey("back")) { character._back = ParseItemJson(items["back"]); } if (items.ContainsKey("chest")) { character._chest = ParseItemJson(items["chest"]); } if (items.ContainsKey("shirt")) { character._shirt = ParseItemJson(items["shirt"]); } if (items.ContainsKey("tabard")) { character._tabard = ParseItemJson(items["tabard"]); } if (items.ContainsKey("wrist")) { character._wrist = ParseItemJson(items["wrist"]); } if (items.ContainsKey("hands")) { character._hands = ParseItemJson(items["hands"]); } if (items.ContainsKey("waist")) { character._waist = ParseItemJson(items["waist"]); } if (items.ContainsKey("legs")) { character._legs = ParseItemJson(items["legs"]); } if (items.ContainsKey("feet")) { character._feet = ParseItemJson(items["feet"]); } if (items.ContainsKey("finger1")) { character._finger1 = ParseItemJson(items["finger1"]); } if (items.ContainsKey("finger2")) { character._finger2 = ParseItemJson(items["finger2"]); } if (items.ContainsKey("trinket1")) { character._trinket1 = ParseItemJson(items["trinket1"]); } if (items.ContainsKey("trinket2")) { character._trinket2 = ParseItemJson(items["trinket2"]); } if (items.ContainsKey("mainHand")) { character._mainHand = ParseItemJson(items["mainHand"]); } if (items.ContainsKey("offHand")) { character._offHand = ParseItemJson(items["offHand"]); } if (items.ContainsKey("ranged")) { character._ranged = ParseItemJson(items["ranged"]); } var i = ((Dictionary <string, object>)((Dictionary <string, object>)items["wrist"])["tooltipParams"]); if (i.ContainsKey("extraSocket")) { character.WristBlacksmithingSocketEnabled = (bool)i["extraSocket"]; } i = ((Dictionary <string, object>)((Dictionary <string, object>)items["hands"])["tooltipParams"]); if (i.ContainsKey("extraSocket")) { character.HandsBlacksmithingSocketEnabled = (bool)i["extraSocket"]; } i = ((Dictionary <string, object>)((Dictionary <string, object>)items["waist"])["tooltipParams"]); if (i.ContainsKey("extraSocket")) { character.WaistBlacksmithingSocketEnabled = (bool)i["extraSocket"]; } } #region Pets try { object opets; if (dict.TryGetValue("pets", out opets)) { var pets = (object[])opets; character.ArmoryPets = new List <ArmoryPet>(); foreach (Dictionary <string, object> pet in pets) { ArmoryPet p = new ArmoryPet(); p.Name = (string)pet["name"]; p.CreatureID = (int)pet["creature"]; p.SlotID = (int)pet["slot"]; if (pet.ContainsKey("selected")) { p.Selected = true; } character.ArmoryPets.Add(p); } } } catch { } #endregion return(character); }