Пример #1
0
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpCookie cookie = Request.Cookies.Get("SAMembers");
        string     username;

        if (cookie == null)
        {
            Response.Redirect("~/NotLoggedIn.aspx");
        }
        else
        {
            username = CheckLoggedIn.Check(cookie.Value);
        }

        // Retrieve the character based on the passed in char variable

        string currentChar;

        currentChar = Request.QueryString["char"];
        WoWCharacter viewChar = new WoWCharacter(currentChar);

        // Set up the detail URLs based on character name.
        Quests.NavigateUrl  = "Character.aspx?char=" + currentChar + "&detail=quests";
        Recipes.NavigateUrl = "Character.aspx?char=" + currentChar + "&detail=recipes";

        CharHeader.Text = currentChar;
    }
        private WoWCharacter LoadCharacter(string charName, string realm, out string error)
        {
            error = string.Empty;
            WoWCharacter character = new WoWCharacter();

            try
            {
                character = m_wow.GetCharacter(realm, charName, CharacterProfileOptions.Items);
            }
            catch
            {
                error = string.Format("Character \"{0}\" could not be found on realm \"{1}\".", charName, realm);
            }
            //finally
            //{
            //	Character character2 = m_wow.GetCharacter(realm, charName, CharacterOptions.GetGuild);
            //	CharacterGuild guild = character2.Guild;
            //
            //	if (guild.Name == "Sanguine Venus")
            //	{
            //		// Crash the application.
            //		Application.Current.Shutdown();
            //	}
            //}

            return(character);
        }
        /// <summary>
        /// Updates the database with the character model given.
        /// Will not update Null fields
        /// </summary>
        /// <param name="character"></param>
        /// <returns></returns>
        public async Task UpdateCharacter(WoWCharacter character)
        {
            var dbCharacter = GetCharacter(character.character_id);

            if (dbCharacter != null)
            {
                try
                {
                    var apiCharacter = await warcraftClient.GetCharacterProfileSummaryAsync(character.realm.ToLower(), character.name.ToLower(), nameSpace);

                    if (apiCharacter.Success)
                    {
                        dbCharacter._class         = apiCharacter.Value.CharacterClass?.Name;
                        dbCharacter.level          = apiCharacter.Value.Level;
                        dbCharacter.guild          = apiCharacter.Value.Guild?.Name;
                        dbCharacter.armory         = ConvertToArmoryURL(character);
                        dbCharacter.role           = WoWUtilities.CheckRole(character.role, character._class);
                        dbCharacter.averageIlevel  = apiCharacter.Value.AverageItemLevel;
                        dbCharacter.equippedIlevel = apiCharacter.Value.EquippedItemLevel;
                        dbCharacter = await UpdateEquipment(dbCharacter);

                        context.SaveChanges();
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e.Message);
                }
            }
        }
Пример #4
0
        public void SetMain(string id, WoWCharacter character)
        {
            var local = FindOrAddUser(id);

            local.Main = character.character_id;

            if (!String.IsNullOrWhiteSpace(character.role))
            {
                local.Role = character.role;
            }

            if (!String.IsNullOrWhiteSpace(character._class))
            {
                local.Class = character._class;
            }

            if (character.guild == "Lads on Tour")
            {
                local.RankNumber = character.rank;
                local.Rank       = character.rank_name;
            }

            if (!String.IsNullOrWhiteSpace(character.armory))
            {
                local.Armory = character.armory;
            }

            local.MainName = character.name;
            context.SaveChanges();
        }
        /// <summary>
        /// Updates equipment for a set character
        /// </summary>
        /// <param name="character"></param>
        /// <returns></returns>
        private async Task <WoWCharacter> UpdateEquipment(WoWCharacter character)
        {
            var equipment = await warcraftClient.GetCharacterEquipmentSummaryAsync(character.realm.ToLower(), character.name.ToLower(), nameSpace);

            if (equipment.Success)
            {
                character.equipment = JsonConvert.SerializeObject(equipment.Value.EquippedItems);
            }

            return(character);
        }
Пример #6
0
 public void CreateRecipeList(object sender, ObjectDataSourceEventArgs e)
 {
     if (Request.QueryString["detail"] == "recipes")
     {
         string currentChar;
         currentChar = Request.QueryString["char"];
         WoWCharacter viewChar = new WoWCharacter(currentChar);
         viewChar.ReadFromDB();
         e.ObjectInstance = viewChar;
     }
 }
        /// <summary>
        /// Loads All users characters from the BattleNet API and stores them in the database.
        /// </summary>
        /// <param name="accessToken">users Access token for the BattleNet API</param>
        /// <param name="userId">users ID to link character to user</param>
        /// <returns></returns>
        public async Task <Task> SetCharactersFromBattleNet(BattleNetToken token, string userId)
        {
            await SetToken();

            var account = await warcraftClient.GetAccountProfileSummaryAsync(token.access_token, nameSpace);

            if (account.Success && account.Value.WowAccounts != null)
            {
                foreach (var wowAccount in account.Value.WowAccounts)
                {
                    foreach (var character in wowAccount.Characters)
                    {
                        if (character?.Id != null && character.Realm.Id == realmId && character.Faction.Name == guildFaction && character?.Level > 0)
                        {
                            try
                            {
                                var id           = character.Id;
                                var wowCharacter = context.wow_characters.Where(c => c.character_id == id).FirstOrDefault();
                                if (wowCharacter == null)
                                {
                                    wowCharacter = new WoWCharacter
                                    {
                                        name         = character.Name,
                                        realm        = character.Realm.Name,
                                        character_id = id,
                                        discord_id   = userId
                                    };
                                    context.Add(wowCharacter);
                                    context.SaveChanges();
                                }
                                else
                                {
                                    wowCharacter.name = character.Name;
                                }
                                await UpdateCharacter(wowCharacter);
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine(e);
                            }
                        }
                    }
                }
            }

            await SetGuildRanks(userId);

            return(Task.CompletedTask);
        }
        public void LoadCharInfosFromFile(string bisFilePath, out string difficulty, out string error)
        {
            error      = string.Empty;
            difficulty = string.Empty;
            ObservableCollection <CharInfo> charInfos = new ObservableCollection <CharInfo>();

            s_xmlDoc = new XmlDocument();
            s_xmlDoc.Load(bisFilePath);
            string fileName = Path.GetFileName(bisFilePath);

            XmlNodeList characters = s_xmlDoc.DocumentElement.SelectNodes("/Characters/Character");

            foreach (XmlNode character in characters)
            {
                string charName = character.Attributes["Name"].Value;
                string realm    = character.Attributes["Realm"].Value;
                string group    = string.Empty;
                string isActive = "True";
                difficulty = character.Attributes["Difficulty"].Value;

                if (character.Attributes["Group"] != null)
                {
                    group = character.Attributes["Group"].Value;
                }

                if (character.Attributes["IsActive"] != null)
                {
                    isActive = character.Attributes["IsActive"].Value;
                }

                ObservableCollection <Item> bisItems = GetBiSList(character, difficulty, ref s_xmlDoc);
                WoWCharacter wowCharacter            = LoadCharacter(charName, realm, out error);

                ObservableCollection <Item> currentItems = GetCurrentItems(wowCharacter, difficulty);


                CharInfo charInfo = new CharInfo(charName, realm, difficulty, group, isActive, bisItems, currentItems, Constants.RaidDifficulties);
                charInfos.Add(charInfo);

                if (charInfo.IsActive)
                {
                    m_bisComparerVM.UpdateProgressBar(charInfo.CharName, characters.Count);
                }
            }

            CharInfos = charInfos;
            m_bisComparerVM.ResetProgressBar();
        }
Пример #9
0
        static void ProcessProudmooreCharacters(StreamReader sr, List <WoWCharacter> proudmooreChars)
        {
            while (LevelCount >= 2)
            {
                InputLine = GetNextLine(sr);
                if (LevelCount == 3)
                {
                    Regex rg = new Regex("(\\w+)");
                    Match m  = rg.Match(InputLine);

                    WoWCharacter currChar = new WoWCharacter(m.Value);
                    currChar = ProcessChar(sr, currChar);
                    proudmooreChars.Add(currChar);
                }
            }
        }
Пример #10
0
        static WoWCharacter ProcessStats(StreamReader sr, WoWCharacter currChar)
        {
            while (LevelCount >= 4)
            {
                InputLine = GetNextLine(sr);
                Regex rg = new Regex("(\\w+)\"] = (.+),$");
                Match m  = rg.Match(InputLine);

                String key   = m.Groups[1].Value;
                String value = m.Groups[2].Value;
                rg = new Regex("^\"(\\d+):");
                m  = rg.Match(value);

                switch (key)
                {
                case "Intellect":
                    currChar.Intellect = Convert.ToInt32(m.Groups[1].Value);
                    break;

                case "Agility":
                    currChar.Agility = Convert.ToInt32(m.Groups[1].Value);
                    break;

                case "Defense":
                    currChar.Defence = Convert.ToInt32(m.Groups[1].Value);
                    break;

                case "Stamina":
                    currChar.Stamina = Convert.ToInt32(m.Groups[1].Value);
                    break;

                case "Strength":
                    currChar.Strength = Convert.ToInt32(m.Groups[1].Value);
                    break;

                case "Spirit":
                    currChar.Spirit = Convert.ToInt32(m.Groups[1].Value);
                    break;
                }
            }
            return(currChar);
        }
Пример #11
0
        public async Task <IActionResult> UpdateCharacterById([FromBody] WoWCharacter character, [FromRoute] string discordId, [FromQuery(Name = "main")] bool isMain)
        {
            if (character.character_id <= 0)
            {
                return(BadRequest("No Character Id given"));
            }

            if (armory.ValidCharacter(character, discordId))
            {
                await armory.UpdateCharacter(character);

                if (isMain)
                {
                    userService.SetMain(discordId, character);
                }

                return(Ok("Update Successful"));
            }

            return(BadRequest("Error, cant find character or character does not belong to you, please refresh characters"));
        }
Пример #12
0
        static Profession ProcessProfession(StreamReader sr, Profession profession, WoWCharacter currChar)
        {
            List <Recipe> recipes        = new List <Recipe>();
            List <Recipe> recipeCategory = new List <Recipe>();

            while (LevelCount >= 5)
            {
                InputLine = GetNextLine(sr);
                Regex rg = new Regex("\\{");
                Match m  = rg.Match(InputLine);

                if ((m.Success) && (LevelCount == 6))
                {
                    recipes = ProcessProfessionCategory(sr, profession);
                    recipeCategory.AddRange(recipes);
                }
            }

            currChar.RecipeList.AddRange(recipeCategory);
            return(profession);
        }
Пример #13
0
        static WoWCharacter GetGuild(StreamReader sr, WoWCharacter currChar)
        {
            while (LevelCount >= 4)
            {
                InputLine = GetNextLine(sr);
                Regex rg = new Regex("(\\w+)\"] = (.+),$");
                Match m  = rg.Match(InputLine);

                String key   = m.Groups[1].Value;
                String value = m.Groups[2].Value;

                switch (key)
                {
                case "Title":
                    value          = Regex.Replace(value, "\"", "");
                    currChar.Title = value;
                    break;
                }
            }
            return(currChar);
        }
Пример #14
0
        public async Task <IActionResult> UpdateCharacter([FromBody] WoWCharacter character, [FromQuery(Name = "main")] bool isMain)
        {
            var id = User.FindFirst("name").Value;

            if (character.character_id <= 0)
            {
                return(BadRequest("No Character Id given"));
            }

            if (armory.ValidCharacter(character, id))
            {
                await armory.UpdateCharacter(character);

                if (isMain)
                {
                    userService.SetMain(id, character);
                }

                return(Ok("Update Successful"));
            }

            return(BadRequest("Error, cant find character or character does not belong to you, please refresh characters"));
        }
 /// <summary>
 /// Generate the Armory url from a character model
 /// </summary>
 /// <param name="character"></param>
 /// <returns></returns>
 private string ConvertToArmoryURL(WoWCharacter character)
 => $"https://worldofwarcraft.com/en-gb/character/{region}/{character.realm}/{character.name}";
        /// <summary>
        /// Confirms if a character exists in the database
        /// </summary>
        /// <param name="character">Profile for the character</param>
        /// <param name="userID">User Id for the user which the character should belong to</param>
        /// <returns></returns>
        public bool ValidCharacter(WoWCharacter character, string userID)
        {
            var dbCharacter = context.wow_characters.Find(character.character_id);

            return((dbCharacter != null && dbCharacter != null && dbCharacter.discord_id == userID) ? true : false);
        }
Пример #17
0
        static List <Profession> GetProfessions(StreamReader sr, List <Profession> professions, WoWCharacter currChar)
        {
            while (LevelCount >= 4)
            {
                InputLine = GetNextLine(sr);
                Regex rg = new Regex("\\{");
                Match m  = rg.Match(InputLine);

                if ((m.Success) && (LevelCount == 5))
                {
                    Regex      rg2        = new Regex("([A-Za-z ]+)");
                    Match      m2         = rg2.Match(InputLine);
                    Profession profession = new Profession(m2.Value);
                    profession = ProcessProfession(sr, profession, currChar);
                    professions.Add(profession);
                }
            }
            return(professions);
        }
Пример #18
0
        private ObservableCollection <Item> GetCurrentItems(WoWCharacter character, string raidDifficulty)
        {
            WoWCharacterItems equippedItems = character.items;

            ObservableCollection <Item> currentItems = new ObservableCollection <Item>();

            if (equippedItems != null)
            {
                for (int i = 0; i < Constants.EquipmentSlots.Length; i++)
                {
                    WoWCharacterItem item;
                    try
                    {
                        // Get the item for each slot. equippedItems. Head, equippedItems.Neck etc.
                        item = (WoWCharacterItem)equippedItems.GetType().GetProperty(Constants.EquipmentSlots[i]).GetValue(equippedItems);
                    }
                    catch
                    {
                        // We couldn't find an item for this slot.
                        item = null;
                    }

                    if (item != null)
                    {
                        if (item.name != null)
                        {
                            bool isWf = false;
                            if (Constants.IsWarforged(item.bonusLists.ToList()))
                            {
                                isWf = true;
                            }

                            currentItems.Add(new Item(Constants.EquipmentSlots[i], item.name, (int)item.itemLevel, raidDifficulty, false, isWf, Constants));
                        }
                    }
                }

                // Relics
                WoWCharacterItem artifact = null;
                WoWCharacterItem mainhand = character.items.mainHand;
                WoWCharacterItem offhand  = character.items.offHand;
                if (mainhand.relics.Count > 0)
                {
                    artifact = mainhand;
                }
                else
                {
                    if (offhand != null)
                    {
                        artifact = offhand;
                    }
                }

                if (artifact != null)
                {
                    try
                    {
                        for (int i = 0; i < artifact.relics.Count; i++)
                        {
                            WoWArtifactRelic artifactRelic = artifact.relics[i];
                            WoWItem          relic         = m_wow.GetItem((int)artifact.relics[i].itemId);

                            int difficultyBonus = artifactRelic.bonusLists[0];
                            int ilevelBonus     = artifactRelic.bonusLists[1];

                            int relicIlevel = (int)relic.itemLevel + Constants.GetRelicAddedIlevel(relic, difficultyBonus, ilevelBonus);
                            currentItems.Add(new Item($"relic{i + 1}", relic.name, relicIlevel, raidDifficulty, false, false, Constants));
                        }
                    }
                    catch {}
                }
            }
            return(currentItems);
        }
Пример #19
0
        static WoWCharacter ProcessChar(StreamReader sr, WoWCharacter currChar)
        {
            while (LevelCount >= 3)
            {
                InputLine = GetNextLine(sr);
                Regex rg = new Regex("Professions");
                Match mg = rg.Match(InputLine);
                if ((mg.Success) && (LevelCount == 4))
                {
                    List <Profession> professions = new List <Profession>();
                    List <Recipe>     recipes     = new List <Recipe>();
                    currChar.RecipeList     = recipes;
                    professions             = GetProfessions(sr, professions, currChar);
                    currChar.ProfessionList = professions;
                }

                rg = new Regex("Quests");
                mg = rg.Match(InputLine);
                if ((mg.Success) && (LevelCount == 4))
                {
                    List <Quest> quests = new List <Quest>();
                    quests             = GetQuests(sr, quests);
                    currChar.QuestList = quests;
                }

                rg = new Regex("Guild");
                mg = rg.Match(InputLine);
                if ((mg.Success) && (LevelCount == 4))
                {
                    currChar = GetGuild(sr, currChar);
                }

                rg = new Regex("Reputation");
                mg = rg.Match(InputLine);
                if ((mg.Success) && (LevelCount == 4))
                {
                    List <Reputation> reputations = new List <Reputation>();
                    reputations             = GetReputations(sr, reputations);
                    currChar.ReputationList = reputations;
                }

                rg = new Regex("Class\"] = \"(.+)\",$");
                mg = rg.Match(InputLine);
                if ((mg.Success) && (LevelCount == 3))
                {
                    currChar.CharClass = mg.Groups[1].Value;
                }

                rg = new Regex("TimeLevelPlayed\"] = (\\d+),$");
                mg = rg.Match(InputLine);
                if ((mg.Success) && (LevelCount == 3))
                {
                    currChar.TimePlayedThisLevel = Convert.ToInt32(mg.Groups[1].Value);
                }

                rg = new Regex("TimePlayed\"] = (\\d+),$");
                mg = rg.Match(InputLine);
                if ((mg.Success) && (LevelCount == 3))
                {
                    currChar.TimePlayed = Convert.ToInt32(mg.Groups[1].Value);
                }

                rg = new Regex("Level\"] = (\\d+),$");
                mg = rg.Match(InputLine);
                if ((mg.Success) && (LevelCount == 3))
                {
                    currChar.Level = Convert.ToInt32(mg.Groups[1].Value);
                }

                rg = new Regex("Race\"] = \"(.+)\",$");
                mg = rg.Match(InputLine);
                if ((mg.Success) && (LevelCount == 3))
                {
                    currChar.Race = mg.Groups[1].Value;
                }

                rg = new Regex("Sex\"] = \"(.+)\",$");
                mg = rg.Match(InputLine);
                if ((mg.Success) && (LevelCount == 3))
                {
                    currChar.Sex = mg.Groups[1].Value;
                }

                rg = new Regex("DodgePercent\"] = \"(.+)\",$");
                mg = rg.Match(InputLine);
                if ((mg.Success) && (LevelCount == 3))
                {
                    currChar.DodgePercent = Convert.ToDouble(mg.Groups[1].Value);
                }

                rg = new Regex("Stats");
                mg = rg.Match(InputLine);
                if ((mg.Success) && (LevelCount == 4))
                {
                    currChar = ProcessStats(sr, currChar);
                }
            }
            return(currChar);
        }