public void GetAch_Pick_All() { string pickAll = @"<tr class=''><td><a href='/w/Pick_All' title='Pick All'>Pick All</a></td><td>Yes</td><td>Use a lockpick to open ALL of New Varrock's treasure chests.</td><td>Exploration</td><td>New Varrock</td><td>15<p><br></p></td></tr>"; HtmlNode achNode = HtmlNode.CreateNode(pickAll); AchievementObject achievementActual = Scrape.GetAchievementRow(achNode); AchievementObject achievementExpected = new AchievementObject { AName = "Pick All", AMembers = "Yes", ADescription = "Use a lockpick to open ALL of New Varrock's treasure chests.", ACategories = new List <string> { "Exploration" }, ASubcategories = new List <string> { "New Varrock" }, ARunescore = 15, ALink = "/w/Pick_All", AQuestReqs = new List <string> { "Dimension of Disaster: Shield of Arrav (partial)", "Dimension of Disaster: Demon Slayer (partial)" }, ASkillReqs = new List <string> { "70 Thieving" } }; AssertingAchObj(achievementExpected, achievementActual); }
public void GetAch_Great_Responsibility() { string greatResponsibility = @"<tr class=''><td><a href='/w/Great_Responsibility' title='Great Responsibility'>Great Responsibility</a></td><td>Yes</td><td>Have over 490,000 charge<sup class='noprint fact'>[<span class='fact-text' title='The preceding quote has been reproduced verbatim and is not a transcription error.'>sic</span>]</sup> in a jumbo generator in the Invention Guild.</td><td>Skills</td><td>Invention</td><td>20<p><br></p></td></tr>"; HtmlNode achNode = HtmlNode.CreateNode(greatResponsibility); AchievementObject achievementActual = Scrape.GetAchievementRow(achNode); AchievementObject achievementExpected = new AchievementObject { AName = "Great Responsibility", AMembers = "Yes", ADescription = "Have over 490,000 charge[sic] in a jumbo generator in the Invention Guild.", ACategories = new List <string> { "Skills" }, ASubcategories = new List <string> { "Invention" }, ARunescore = 20, ALink = "/w/Great_Responsibility", AQuestReqs = new List <string> { "None" }, ASkillReqs = new List <string> { "102 Invention" } }; AssertingAchObj(achievementExpected, achievementActual); }
public void Check_1Skill_1Quest_Requirements() { AchievementObject aCleanSlate = new AchievementObject { AName = "A Clean Slate", ADescription = "Cleanse the Corrupted Seren Stone with at least one crystal.", ARunescore = 15, AMembers = "Yes", ALink = "/w/A_Clean_Slate", ACategories = new List <string> { "Exploration" }, ASubcategories = new List <string> { "Tirannwn" }, AQuestReqs = new List <string>(), ASkillReqs = new List <string>() }; aCleanSlate = Scrape.GetRequirements(aCleanSlate); Assert.Contains("Plague's End", aCleanSlate.AQuestReqs); Assert.Contains("75 Prayer", aCleanSlate.ASkillReqs); }
async Task UpdateUserAchievements(User user) { AchievementsController achievementsController = AchievementsController.GetInstance(); if (achievementsController == null) { return; } List <Achievement> achievements = await DBUserAchievements.GetUserAchievements(user.id); achievements.ForEach(a => { AchievementObject achievement = achievementsController.achievements.Find(achievement => a.id == achievement.id); if (achievement.title != a.title) { achievement.title = a.title; } if (achievement.description != a.description) { achievement.title = a.title; } if (achievement.received != a.received) { achievement.received = a.received; } if (achievement.receiveDate != a.receiveDate) { achievement.receiveDate = a.receiveDate; } }); }
public void Check_3Skill_Requirements() { AchievementObject aBridgeNotFar = new AchievementObject { AName = "A Bridge Not Far", ADescription = "Cross the River Lum using a crossbow.", ARunescore = 10, AMembers = "Yes", ALink = "/w/A_Bridge_Not_Far", ACategories = new List <string> { "Exploration" }, ASubcategories = new List <string> { "Desert" }, AQuestReqs = new List <string>(), ASkillReqs = new List <string>() }; aBridgeNotFar = Scrape.GetRequirements(aBridgeNotFar); Assert.Contains("8 Agility", aBridgeNotFar.ASkillReqs); Assert.Contains("19 Strength", aBridgeNotFar.ASkillReqs); Assert.Contains("37 Ranged", aBridgeNotFar.ASkillReqs); }
public void GetAch_No_Smoke_Without_Pyre() { string noSmokeWithoutPyre = @"<tr class=''><td><a href='/w/No_Smoke_Without_Pyre' title='No Smoke Without Pyre'>No Smoke Without Pyre</a></td><td>Yes</td><td>Make a pyre ship from magic logs.</td><td>Exploration</td><td>Fremennik</td><td>25<p><br></p></td></tr>"; HtmlNode achNode = HtmlNode.CreateNode(noSmokeWithoutPyre); AchievementObject achievementActual = Scrape.GetAchievementRow(achNode); AchievementObject achievementExpected = new AchievementObject { AName = "No Smoke Without Pyre", AMembers = "Yes", ADescription = "Make a pyre ship from magic logs.", ACategories = new List <string> { "Exploration" }, ASubcategories = new List <string> { "Fremennik" }, ARunescore = 25, ALink = "/w/No_Smoke_Without_Pyre", AQuestReqs = new List <string> { "Completed Firemaking section of Barbarian Training" }, ASkillReqs = new List <string> { "85 Crafting", "85 Firemaking" } }; AssertingAchObj(achievementExpected, achievementActual); }
public int DeleteInformation(AchievementObject achievementObj) { SqlConnection con = GetConnection(); con.Open(); SqlCommand cmd = new SqlCommand("Delete_Achievement", con); cmd.CommandType = CommandType.StoredProcedure; cmd.Parameters.AddWithValue("@AchievementId", achievementObj.AchievementId); cmd.Parameters.AddWithValue("@UserId", achievementObj.UserId); try { return(cmd.ExecuteNonQuery()); } catch { throw; } finally { cmd.Dispose(); con.Close(); con.Dispose(); } }
public void GetAch_A_Mini_Shipment() { string aMiniShipmentRow = @"<tr class=''><td><a href='/w/A_Mini_Shipment' title='A Mini Shipment'>A Mini Shipment</a></td><td>Yes</td><td>Loot the trunk in the Temple of Aminishi.</td><td>Combat<br>Completionist</td><td>Elite Dungeons<br>Master Quest Cape</td><td>5<p><br></p></td></tr>"; HtmlNode achNode = HtmlNode.CreateNode(aMiniShipmentRow); AchievementObject achievementActual = Scrape.GetAchievementRow(achNode); AchievementObject achievementExpected = new AchievementObject { AName = "A Mini Shipment", AMembers = "Yes", ADescription = "Loot the trunk in the Temple of Aminishi.", ACategories = new List <string> { "Combat", "Completionist" }, ASubcategories = new List <string> { "Elite Dungeons", "Master Quest Cape" }, ARunescore = 5, AQuestReqs = new List <string> { "Curse of the Black Stone (partial)" }, ASkillReqs = new List <string> { "None" }, ALink = "/w/A_Mini_Shipment" }; AssertingAchObj(achievementExpected, achievementActual); }
// goes through each link and gets the requirements public static AchievementObject GetRequirements(AchievementObject achievement) { using (WebClient wb = new WebClient()) { string achievementPageString = wb.DownloadString(RSWIKIURL + achievement.ALink); var htmlDoc = new HtmlDocument(); htmlDoc.LoadHtml(achievementPageString); var infoTable = htmlDoc.DocumentNode.SelectSingleNode("//*[@id=\"infobox-achievement\"]/tbody"); if (infoTable != null) { var reqNode = infoTable.SelectSingleNode(".//td[@class='qc-active']"); // has requirements table if (reqNode != null) { string data = Regex.Replace(reqNode.InnerText, @"\r|\n|\t", "|"); achievement = SkillQuestReq(achievement, data); } } } // if empty requirements table achievement = IfSkillQuestIsEmpty(achievement); return achievement; }
// used for debugging purposes private static string AchObjToString(AchievementObject achievement) { string nam = achievement.AName; string des = achievement.ADescription; int run = achievement.ARunescore; string mem = achievement.AMembers; string lin = achievement.ALink; string cat = ""; string sub = ""; string que = ""; string ski = ""; foreach (var c in achievement.ACategories) cat += c + " "; foreach (var s in achievement.ASubcategories) sub += s + " "; foreach (var q in achievement.AQuestReqs) que += q + " "; foreach (var s in achievement.ASkillReqs) ski += s + " "; string line = string.Format( "Name: {0} |Description: {1} |Runescore: {2} |Members: {3} " + "|Link: {4} |Categories: {5} |Subcategories: {6} |Quest Requirements: {7} " + "|Skill Requirements: {8}\n", nam, des, run, mem, lin, cat, sub, que, ski ); return line; }
public void ReceiveDemo(AchievementObject achievement) { AchievementUI achievementUI = CreateAchievementUI(achievement); achievementUI.ShowAndHide(() => DesroyAchievementUI(achievementUI)); audioSource.Play(); }
public void GetAch_Kill_Kril_Vol_2_VI() { string killKrilVol2VI = @"<tr class=''><td><a href='/w/Kill_K%27ril_Vol_2_VI' title='Kill K''ril Vol 2 VI'>Kill K'ril Vol 2 VI</a></td><td>Yes</td><td>Defeat K'ril Tsutsaroth in hard mode. (X/100)</td><td>Combat</td><td>Boss Kills</td><td>5<p><br></p></td></tr>"; HtmlNode achNode = HtmlNode.CreateNode(killKrilVol2VI); AchievementObject achievementActual = Scrape.GetAchievementRow(achNode); AchievementObject achievementExpected = new AchievementObject { AName = "Kill K'ril Vol 2 VI", AMembers = "Yes", ADescription = "Defeat K'ril Tsutsaroth in hard mode. (X/100)", ACategories = new List <string> { "Combat" }, ASubcategories = new List <string> { "Boss Kills" }, ARunescore = 5, AQuestReqs = new List <string> { "Troll Stronghold (partial)" }, ASkillReqs = new List <string> { "60 Strength or 60 Agility", "70 Constitution" }, ALink = "/w/Kill_K%27ril_Vol_2_VI" }; AssertingAchObj(achievementExpected, achievementActual); }
private void CreateAchievement(GameObject achParent, AchievementObject achData) { GameObject achPrefab = Instantiate(m_achievementPrefab); SetAchievementInfo(achParent, achPrefab, achData); //Debug.Log("Create achievement in menu"); }
public void ShowClaimButton(AchievementObject achData) { Button claimButton = m_claimButton.GetComponent <Button>(); //If achievement is claimed //Hide coin button if (PlayerDataManager.instance.GetAchievementClaimed(achData.ach_ID)) { claimButton.gameObject.SetActive(false); } else { claimButton.gameObject.SetActive(true); if (achData.ach_Dynamic) { claimButton.onClick.AddListener(delegate { //Add coins PlayerDataManager.instance.AddCoins(achData.ach_Reward); UIManager.instance.PlusCoinAch(achData.ach_Reward); //Play Sound AudioManager.instance.Play("Checkpoint"); //Reset achievement PlayerDataManager.instance.ResetUnlockAch(achData.ach_ID); //Hide claim button HideClaimButton(claimButton); //Update coin in UI UIManager.instance.UpdateCoinValue(); //Save player data PlayerDataManager.instance.SaveDataLocal(); }); } else { claimButton.onClick.AddListener(delegate { //Add coins PlayerDataManager.instance.AddCoins(achData.ach_Reward); UIManager.instance.PlusCoinAch(achData.ach_Reward); //CoinChangeDisplayManager.instance.displayCoinChange() //Play sound AudioManager.instance.Play("Checkpoint"); //Hide Button HideClaimButton(claimButton); //Update coin in UI UIManager.instance.UpdateCoinValue(); //Set achievement as claimed PlayerDataManager.instance.SetAchievementClaimed(achData.ach_ID); //Save Data PlayerDataManager.instance.SaveDataLocal(); }); } //Show Button claimButton.interactable = true; } }
public void AddAchievement(AchievementObject @object) { if (containers.ContainsKey(@object.Id)) { throw new ArgumentException( $"Achievement with name '{@object.Id}' already exists."); } containers.Add(@object.Id, @object); }
public AchievementUI CreateAchievementUI(AchievementObject achievement) { AchievementUI achievementUI = Instantiate(template, body.transform); achievementUI.Title = achievement.title; achievementUI.Description = achievement.description; return(achievementUI); }
private static AchievementObject IfSkillQuestIsEmpty(AchievementObject achievement) { if (!achievement.AQuestReqs.Any()) achievement.AQuestReqs.Add("None"); if (!achievement.ASkillReqs.Any()) achievement.ASkillReqs.Add("None"); return achievement; }
public bool TryGetAchievement(string achievementId, out AchievementObject @object) { if (containers.ContainsKey(achievementId)) { @object = containers[achievementId]; return(true); } @object = null; return(false); }
public void AssertingAchObj(AchievementObject achievementExpected, AchievementObject achievementActual) { Assert.AreEqual(achievementExpected.AName, achievementActual.AName); Assert.AreEqual(achievementExpected.ADescription, achievementActual.ADescription); Assert.AreEqual(achievementExpected.AMembers, achievementActual.AMembers); Assert.AreEqual(achievementExpected.ALink, achievementActual.ALink); Assert.AreEqual(achievementExpected.ARunescore, achievementActual.ARunescore); CollectionAssert.AreEqual(achievementExpected.ACategories, achievementActual.ACategories); CollectionAssert.AreEqual(achievementExpected.ASubcategories, achievementActual.ASubcategories); CollectionAssert.AreEqual(achievementExpected.AQuestReqs, achievementActual.AQuestReqs); CollectionAssert.AreEqual(achievementExpected.ASkillReqs, achievementActual.ASkillReqs); }
//For checking all the trigger in achievement private bool AchCheckComplete(AchievementObject achToCheck) { for (int j = 0; j < achToCheck.ach_Trigger.Length; j++) { if (achToCheck.ach_Trigger[j].ach_Doned == false) { return(false); } } return(true); }
public static AchievementObject GetAchievementRow(HtmlNode row) { AchievementObject achievement = new AchievementObject(); int index = 0; // parses through each column to initialize the AchievementObject foreach (var column in row.ChildNodes) { if (!string.IsNullOrWhiteSpace(column.InnerText)) { switch (index) { // Name case 0: achievement.AName = column.InnerText; break; // Members case 1: achievement.AMembers = column.InnerText; break; // Description case 2: achievement.ADescription = column.InnerText; break; // Category case 3: achievement.ACategories = RemoveTags(column.InnerHtml); break; // Subcategory case 4: achievement.ASubcategories = RemoveTags(column.InnerHtml); break; // Runescore case 5: int num = 0; if (int.TryParse(column.InnerText, out num)) achievement.ARunescore = num; else achievement.ARunescore = num; break; } index++; } } // Link achievement.ALink = row.SelectSingleNode(".//a").Attributes["href"].Value; achievement.ASkillReqs = new List<string>(); achievement.AQuestReqs = new List<string>(); // Skill and Quest Reqs achievement = GetRequirements(achievement); return achievement; }
private static bool CompareSkillLevels(User currentUser, AchievementObject achievement) { bool eligible = true; List <ASkillReq> aSkillReqs = achievement.ASkillReqs; Dictionary <string, long[]> usersSkills = currentUser.Levels; foreach (var aSkillReq in aSkillReqs) { if (Regex.IsMatch(aSkillReq.LevelSkill, @" or ")) { var levelSkills = SeparateSkills(aSkillReq.LevelSkill); bool canComplete = aSkillReq.CanComplete; foreach (var levelSkill in levelSkills) { if (usersSkills.ContainsKey(levelSkill.Item2)) { int i = (int)usersSkills[levelSkill.Item2].ElementAt(1); if (i >= levelSkill.Item1) { canComplete = true; } else { eligible = false; } } } aSkillReq.CanComplete = canComplete; } else { var levelSkill = SplitLevelSkill(aSkillReq.LevelSkill); if (usersSkills.ContainsKey(levelSkill.Item2)) { int i = (int)usersSkills[levelSkill.Item2].ElementAt(1); if (i >= levelSkill.Item1) { aSkillReq.CanComplete = true; } else { eligible = false; } } } } return(eligible); }
private void SetAchievementInfo(GameObject achParent, GameObject achPrefab, AchievementObject achData) { achPrefab.transform.SetParent(achParent.transform); achPrefab.transform.localScale = new Vector3(1.0f, 1.0f, 1.0f); AchievementUI achievementPrefab = achPrefab.GetComponent <AchievementUI>(); achievementPrefab.SetTitle(achData.ach_Title); achievementPrefab.SetDescription(achData.ach_Description); achievementPrefab.SetReward(achData.ach_Reward); if (PlayerDataManager.instance.GetUnlockedAchievement(achData.ach_ID)) { achievementPrefab.ShowClaimButton(achData); } }
protected void btn_save_Click(object sender, EventArgs e) { AchievementObject achievementObj = new AchievementObject(); achievementObj.AchievementTitle = tbxAchievementTitle.Text; achievementObj.AchievementDetail = tbxAchievementDetail.Text; achievementObj.UserId = Int32.Parse(Session["user_id"].ToString()); if (ddlAchievementStatus.SelectedValue == "1") { achievementObj.Status = true; } else if (ddlAchievementStatus.SelectedValue == "0") { achievementObj.Status = false; } try { int result = dal.InsertInformation(achievementObj); if (result == 1) { LoadAchievement(); LoadAchievementTitle(); LoadAllAchievementPhoto(); SuccessPanel_story.Visible = true; tbxAchievementTitle.Text = ""; tbxAchievementDetail.Text = ""; } else { LoadAchievement(); LoadAchievementTitle(); LoadAllAchievementPhoto(); DangerPanel.Visible = true; tbxAchievementTitle.Text = ""; tbxAchievementDetail.Text = ""; } } catch { throw; } }
private static AchievementObject SkillQuestReq(AchievementObject achievement, string data) { var split = SplitString(data); // goes through each split string and adds it to the respective requirement foreach (var s in split) { string trimmedString = s.Trim().Replace(" ", " "); if (skillsList.Any(word => trimmedString.Contains(word)) && s.Any(c => char.IsDigit(c))) { trimmedString = trimmedString.Replace(" [B]", string.Empty); achievement.ASkillReqs.Add(trimmedString); } else achievement.AQuestReqs.Add(trimmedString); } return achievement; }
private static AchievementObject ConvertToAchObj(Achievement achievement) { string name = achievement.Name; string description = achievement.Description; int runescore = achievement.Runescore; string members = achievement.Members; List <string> categories = new List <string>(); foreach (var cat in achievement.Categories) { categories.Add(cat.Name); } List <string> subcategories = new List <string>(); foreach (var sub in achievement.Subcategories) { subcategories.Add(sub.Name); } List <string> questReqs = new List <string>(); foreach (var que in achievement.QuestReqs) { questReqs.Add(que.Quest); } List <string> skillReqs = new List <string>(); foreach (var ski in achievement.SkillReqs) { skillReqs.Add(ski.LevelSkill); } AchievementObject achievementObject = new AchievementObject( name, description, runescore, members, categories, subcategories, questReqs, skillReqs ); return(achievementObject); }
private static bool CompareQuests(User currentUser, AchievementObject achievement) { bool eligible = true; List <AQuestReq> aQuestReqs = achievement.AQuestReqs; List <string> usersQuests = new List <string>(); foreach (var uq in currentUser.Quests) { // if user completed that quest, add it to completed quest list if (uq.Status == "COMPLETED") { string replacedTitle = uq.Title; replacedTitle = Regex.Replace(uq.Title, @"\s+\(.*\)", string.Empty); usersQuests.Add(replacedTitle); } } // if user's completed quest list doesn't contain a quest requirement, false foreach (var aQuestReq in aQuestReqs) { string replacedString = aQuestReq.Quest; if (Regex.IsMatch(aQuestReq.Quest, @"\(.*\)")) { replacedString = Regex.Replace(aQuestReq.Quest, @"\s+\(.*\)", string.Empty); } if (usersQuests.Any(s => s.Equals(replacedString, StringComparison.OrdinalIgnoreCase))) { aQuestReq.CanComplete = true; } else { eligible = false; } } return(eligible); }
public static List<AchievementObject> GetData(HtmlDocument htmlDoc) { List<AchievementObject> tableData = new List<AchievementObject>(); // select the entire table that contains the achievements data var loaTable = htmlDoc.DocumentNode.SelectSingleNode("//*[@id='mw-content-text']/div/table[1]/tbody"); // collects all the rows from the table var loaRows = loaTable.SelectNodes(".//tr"); foreach (var row in loaRows) { AchievementObject achievementData = GetAchievementRow(row); tableData.Add(achievementData); string line = AchObjToString(achievementData); System.Diagnostics.Debug.Write(line); // limited to 2 requests/second System.Threading.Thread.Sleep(500); } return tableData; }
protected void btn_update_Click(object sender, EventArgs e) { int id = int.Parse(Session["Achievement_id"].ToString()); AchievementObject achievementObj = new AchievementObject(); achievementObj.AchievementId = id; achievementObj.AchievementTitle = tbxAchievementTitle.Text; achievementObj.AchievementDetail = tbxAchievementDetail.Text; achievementObj.UserId = Int32.Parse(Session["user_id"].ToString()); if (ddlAchievementStatus.SelectedValue == "1") { achievementObj.Status = true; } else if (ddlAchievementStatus.SelectedValue == "0") { achievementObj.Status = false; } try { int result = dal.UpdateInformation(achievementObj); if (result == 1) { SuccessPanel_story.Visible = true; } else { DangerPanel.Visible = true; } } catch { throw; } }
public async void Receive(AchievementObject achievement) { if (achievement.received) { return; } if (await DBUserAchievements.AchievementReceived(2, achievement.id)) { return; } DateTime receiveDate = DateTime.Now; bool result = await DBUserAchievements.Receive(2, achievement.id, receiveDate); if (result) { achievement.received = true; achievement.receiveDate = receiveDate; AchievementUI achievementUI = CreateAchievementUI(achievement); achievementUI.ShowAndHide(() => DesroyAchievementUI(achievementUI)); audioSource.Play(); } }