コード例 #1
0
        /*public static string[] TreeBackgrounds = new string[] {
         *  "http://static.wowhead.com/images/wow/hunterpettalents/live/bg_3.jpg",
         *  "http://static.wowhead.com/images/wow/hunterpettalents/live/bg_1.jpg",
         *  "http://static.wowhead.com/images/wow/hunterpettalents/live/bg_2.jpg",
         * };*/

        public static PetTalents FromArmoryPet(ArmoryPet pet)
        {
            if (pet.Spec == "")
            {
                return(new PetTalents());                // send back a blank one
            }
            PetTalents retVal     = new PetTalents();
            string     armoryspec = pet.Spec;

            try
            {
                //retVal.Reset();
                switch (pet.SpecKey)
                {
                case "Ferocity":
                {
                    if (armoryspec.Length < 22)
                    {
                        break;
                    }
                    // Tier 1
                    retVal.SerpentSwiftness = int.Parse(armoryspec[00].ToString());
                    retVal.DiveDash         = int.Parse(armoryspec[01].ToString()) + int.Parse(armoryspec[02].ToString());
                    retVal.GreatStamina     = int.Parse(armoryspec[03].ToString());
                    retVal.NaturalArmor     = int.Parse(armoryspec[04].ToString());
                    // Tier 2
                    retVal.ImprovedCower = int.Parse(armoryspec[05].ToString());
                    retVal.Bloodthirsty  = int.Parse(armoryspec[06].ToString());
                    retVal.SpikedCollar  = int.Parse(armoryspec[07].ToString());
                    retVal.BoarsSpeed    = int.Parse(armoryspec[08].ToString());
                    // Tier 3
                    retVal.CullingTheHerd = int.Parse(armoryspec[09].ToString());
                    retVal.Lionhearted    = int.Parse(armoryspec[10].ToString());
                    retVal.ChargeSwoop    = int.Parse(armoryspec[11].ToString()) + int.Parse(armoryspec[12].ToString());
                    // Tier 4
                    retVal.HeartOfThePhoenix = int.Parse(armoryspec[13].ToString());
                    retVal.SpidersBite       = int.Parse(armoryspec[14].ToString());
                    retVal.GreatResistance   = int.Parse(armoryspec[15].ToString());
                    // Tier 5
                    retVal.Rabid          = int.Parse(armoryspec[16].ToString());
                    retVal.LickYourWounds = int.Parse(armoryspec[17].ToString());
                    retVal.CallOfTheWild  = int.Parse(armoryspec[18].ToString());
                    // Tier 6
                    retVal.SharkAttack = int.Parse(armoryspec[19].ToString());
                    retVal.WildHunt    = int.Parse(armoryspec[20].ToString());
                    break;
                }

                case "Cunning":
                {
                    if (armoryspec.Length < 22)
                    {
                        break;
                    }
                    // Tier 1
                    retVal.SerpentSwiftness = int.Parse(armoryspec[00].ToString());
                    //retVal.Unknown = int.Parse(armoryspec[01].ToString());
                    retVal.DiveDash     = int.Parse(armoryspec[02].ToString());
                    retVal.GreatStamina = int.Parse(armoryspec[03].ToString());
                    retVal.NaturalArmor = int.Parse(armoryspec[04].ToString());
                    // Tier 2
                    retVal.BoarsSpeed = int.Parse(armoryspec[05].ToString());
                    //retVal.Unknown = int.Parse(armoryspec[06].ToString());
                    retVal.Mobility     = int.Parse(armoryspec[07].ToString());
                    retVal.OwlsFocus    = int.Parse(armoryspec[08].ToString());
                    retVal.SpikedCollar = int.Parse(armoryspec[09].ToString());
                    // Tier 3
                    retVal.CullingTheHerd = int.Parse(armoryspec[10].ToString());
                    retVal.Lionhearted    = int.Parse(armoryspec[11].ToString());
                    retVal.CarrionFeeder  = int.Parse(armoryspec[12].ToString());
                    // Tier 4
                    retVal.GreatResistance = int.Parse(armoryspec[13].ToString());
                    retVal.Cornered        = int.Parse(armoryspec[14].ToString());
                    retVal.FeedingFrenzy   = int.Parse(armoryspec[15].ToString());
                    // Tier 5
                    retVal.WolverineBite    = int.Parse(armoryspec[16].ToString());
                    retVal.RoarOfRecovery   = int.Parse(armoryspec[17].ToString());
                    retVal.Bullheaded       = int.Parse(armoryspec[18].ToString());
                    retVal.GraceOfTheMantis = int.Parse(armoryspec[19].ToString());
                    // Tier 6
                    retVal.WildHunt        = int.Parse(armoryspec[20].ToString());
                    retVal.RoarOfSacrifice = int.Parse(armoryspec[21].ToString());
                    break;
                }

                case "Tenacity":
                {
                    if (armoryspec.Length < 22)
                    {
                        break;
                    }
                    // Tier 1
                    retVal.SerpentSwiftness = int.Parse(armoryspec[00].ToString());
                    retVal.ChargeSwoop      = int.Parse(armoryspec[01].ToString());
                    retVal.GreatStamina     = int.Parse(armoryspec[02].ToString());
                    retVal.NaturalArmor     = int.Parse(armoryspec[03].ToString());
                    // Tier 2
                    retVal.SpikedCollar    = int.Parse(armoryspec[04].ToString());
                    retVal.BoarsSpeed      = int.Parse(armoryspec[05].ToString());
                    retVal.BloodOfTheRhino = int.Parse(armoryspec[06].ToString());
                    retVal.PetBarding      = int.Parse(armoryspec[07].ToString());
                    // Tier 3
                    retVal.CullingTheHerd = int.Parse(armoryspec[08].ToString());
                    retVal.GuardDog       = int.Parse(armoryspec[09].ToString());
                    retVal.Lionhearted    = int.Parse(armoryspec[10].ToString());
                    retVal.Thunderstomp   = int.Parse(armoryspec[11].ToString());
                    // Tier 4
                    retVal.GraceOfTheMantis = int.Parse(armoryspec[12].ToString());
                    retVal.GreatResistance  = int.Parse(armoryspec[13].ToString());
                    // Tier 5
                    retVal.LastStand       = int.Parse(armoryspec[14].ToString());
                    retVal.Taunt           = int.Parse(armoryspec[15].ToString());
                    retVal.RoarOfSacrifice = int.Parse(armoryspec[16].ToString());
                    retVal.Intervene       = int.Parse(armoryspec[17].ToString());
                    // Tier 6
                    retVal.Silverback = int.Parse(armoryspec[18].ToString());
                    retVal.WildHunt   = int.Parse(armoryspec[19].ToString());
                    break;
                }

                default: { throw new Exception("Failed to determine armory pet spec key"); }
                }

                return(retVal);
            } catch (Exception ex) {
                new Base.ErrorBox()
                {
                    Title        = "Error converting Armory Pet Talents to PetTalents",
                    Function     = "FromArmoryPet(ArmoryPet pet)",
                    TheException = ex,
                }.Show();
            }
            return(null);
        }
コード例 #2
0
        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);
        }
コード例 #3
0
ファイル: PetTalents.cs プロジェクト: LucasPeacecraft/rawr
        /*public static string[] TreeBackgrounds = new string[] {
            "http://static.wowhead.com/images/wow/hunterpettalents/live/bg_3.jpg",
            "http://static.wowhead.com/images/wow/hunterpettalents/live/bg_1.jpg",
            "http://static.wowhead.com/images/wow/hunterpettalents/live/bg_2.jpg",
        };*/

        public static PetTalents FromArmoryPet(ArmoryPet pet)
        {
            if (pet.Spec == "") return new PetTalents(); // send back a blank one
            PetTalents retVal = new PetTalents();
            string armoryspec = pet.Spec;
            try
            {
                //retVal.Reset();
                switch (pet.SpecKey)
                {
                    case "Ferocity":
                        {
                            if (armoryspec.Length < 22) break;
                            // Tier 1
                            retVal.SerpentSwiftness = int.Parse(armoryspec[00].ToString());
                            retVal.DiveDash = int.Parse(armoryspec[01].ToString()) + int.Parse(armoryspec[02].ToString());
                            retVal.GreatStamina = int.Parse(armoryspec[03].ToString());
                            retVal.NaturalArmor = int.Parse(armoryspec[04].ToString());
                            // Tier 2
                            retVal.ImprovedCower = int.Parse(armoryspec[05].ToString());
                            retVal.Bloodthirsty = int.Parse(armoryspec[06].ToString());
                            retVal.SpikedCollar = int.Parse(armoryspec[07].ToString());
                            retVal.BoarsSpeed = int.Parse(armoryspec[08].ToString());
                            // Tier 3
                            retVal.CullingTheHerd = int.Parse(armoryspec[09].ToString());
                            retVal.Lionhearted = int.Parse(armoryspec[10].ToString());
                            retVal.ChargeSwoop = int.Parse(armoryspec[11].ToString()) + int.Parse(armoryspec[12].ToString());
                            // Tier 4
                            retVal.HeartOfThePhoenix = int.Parse(armoryspec[13].ToString());
                            retVal.SpidersBite = int.Parse(armoryspec[14].ToString());
                            retVal.GreatResistance = int.Parse(armoryspec[15].ToString());
                            // Tier 5
                            retVal.Rabid = int.Parse(armoryspec[16].ToString());
                            retVal.LickYourWounds = int.Parse(armoryspec[17].ToString());
                            retVal.CallOfTheWild = int.Parse(armoryspec[18].ToString());
                            // Tier 6
                            retVal.SharkAttack = int.Parse(armoryspec[19].ToString());
                            retVal.WildHunt = int.Parse(armoryspec[20].ToString());
                            break;
                        }
                    case "Cunning":
                        {
                            if (armoryspec.Length < 22) break;
                            // Tier 1
                            retVal.SerpentSwiftness = int.Parse(armoryspec[00].ToString());
                            //retVal.Unknown = int.Parse(armoryspec[01].ToString());
                            retVal.DiveDash = int.Parse(armoryspec[02].ToString());
                            retVal.GreatStamina = int.Parse(armoryspec[03].ToString());
                            retVal.NaturalArmor = int.Parse(armoryspec[04].ToString());
                            // Tier 2
                            retVal.BoarsSpeed = int.Parse(armoryspec[05].ToString());
                            //retVal.Unknown = int.Parse(armoryspec[06].ToString());
                            retVal.Mobility = int.Parse(armoryspec[07].ToString());
                            retVal.OwlsFocus = int.Parse(armoryspec[08].ToString());
                            retVal.SpikedCollar = int.Parse(armoryspec[09].ToString());
                            // Tier 3
                            retVal.CullingTheHerd = int.Parse(armoryspec[10].ToString());
                            retVal.Lionhearted = int.Parse(armoryspec[11].ToString());
                            retVal.CarrionFeeder = int.Parse(armoryspec[12].ToString());
                            // Tier 4
                            retVal.GreatResistance = int.Parse(armoryspec[13].ToString());
                            retVal.Cornered = int.Parse(armoryspec[14].ToString());
                            retVal.FeedingFrenzy = int.Parse(armoryspec[15].ToString());
                            // Tier 5
                            retVal.WolverineBite = int.Parse(armoryspec[16].ToString());
                            retVal.RoarOfRecovery = int.Parse(armoryspec[17].ToString());
                            retVal.Bullheaded = int.Parse(armoryspec[18].ToString());
                            retVal.GraceOfTheMantis = int.Parse(armoryspec[19].ToString());
                            // Tier 6
                            retVal.WildHunt = int.Parse(armoryspec[20].ToString());
                            retVal.RoarOfSacrifice = int.Parse(armoryspec[21].ToString());
                            break;
                        }
                    case "Tenacity":
                        {
                            if (armoryspec.Length < 22) break;
                            // Tier 1
                            retVal.SerpentSwiftness = int.Parse(armoryspec[00].ToString());
                            retVal.ChargeSwoop = int.Parse(armoryspec[01].ToString());
                            retVal.GreatStamina = int.Parse(armoryspec[02].ToString());
                            retVal.NaturalArmor = int.Parse(armoryspec[03].ToString());
                            // Tier 2
                            retVal.SpikedCollar = int.Parse(armoryspec[04].ToString());
                            retVal.BoarsSpeed = int.Parse(armoryspec[05].ToString());
                            retVal.BloodOfTheRhino = int.Parse(armoryspec[06].ToString());
                            retVal.PetBarding = int.Parse(armoryspec[07].ToString());
                            // Tier 3
                            retVal.CullingTheHerd = int.Parse(armoryspec[08].ToString());
                            retVal.GuardDog = int.Parse(armoryspec[09].ToString());
                            retVal.Lionhearted = int.Parse(armoryspec[10].ToString());
                            retVal.Thunderstomp = int.Parse(armoryspec[11].ToString());
                            // Tier 4
                            retVal.GraceOfTheMantis = int.Parse(armoryspec[12].ToString());
                            retVal.GreatResistance = int.Parse(armoryspec[13].ToString());
                            // Tier 5
                            retVal.LastStand = int.Parse(armoryspec[14].ToString());
                            retVal.Taunt = int.Parse(armoryspec[15].ToString());
                            retVal.RoarOfSacrifice = int.Parse(armoryspec[16].ToString());
                            retVal.Intervene = int.Parse(armoryspec[17].ToString());
                            // Tier 6
                            retVal.Silverback = int.Parse(armoryspec[18].ToString());
                            retVal.WildHunt = int.Parse(armoryspec[19].ToString());
                            break;
                        }
                    default: { throw new Exception("Failed to determine armory pet spec key"); }
                }

                return retVal;
            } catch (Exception ex) {
                new Base.ErrorBox()
                {
                    Title = "Error converting Armory Pet Talents to PetTalents",
                    Function = "FromArmoryPet(ArmoryPet pet)",
                    TheException = ex,
                }.Show();
            }
            return null;
        }