public static void UpdateQuestRanking(Mobile m, XmlQuestPoints attachment) { if (_QuestRankList == null) { _QuestRankList = new List<QuestRankEntry>(); } // flag the rank list for updating on the next attempt to retrieve a rank _NeedsUpdate = true; bool found = false; // rank the entries foreach (QuestRankEntry p in _QuestRankList.Where(p => p != null && p.Quester == m)) { // update the entry with the new points value p.QuestPointsAttachment = attachment; found = true; break; } // a new entry so add it if (!found) { _QuestRankList.Add(new QuestRankEntry(m, attachment)); } }
public static void GiveQuestPoints(Mobile from, IXmlQuest quest) { if(from == null || quest == null) return; // find the XmlQuestPoints attachment XmlQuestPoints p = (XmlQuestPoints)XmlAttach.FindAttachment(from, typeof(XmlQuestPoints)); // if doesnt have one yet, then add it if(p == null) { p = new XmlQuestPoints(); XmlAttach.AttachTo(from, p); } // if you wanted to scale the points given based on party size, karma, fame, etc. // this would be the place to do it int points = quest.Difficulty; // update the questpoints attachment information p.Points += points; p.Credits += points; p.QuestsCompleted++; if(from != null) { from.SendMessage("You have received {0} quest points!",points); } // add the completed quest to the quest list QuestEntry.AddQuestEntry(from, quest); // update the overall ranking list XmlQuestLeaders.UpdateQuestRanking(from, p); }
public TopQuestPlayersGump(XmlQuestPoints attachment) : base( 0,0) { if(QuestRankList == null || attachment == null) return; m_attachment = attachment; int numberToDisplay = 20; int height = numberToDisplay*20 + 65; // prepare the page AddPage( 0 ); int width = 740; #if(FACTIONS) width = 790; #endif AddBackground( 0, 0, width, height, 5054 ); AddAlphaRegion( 0, 0, width, height ); AddImageTiled( 20, 20, width - 40, height - 45, 0xBBC ); AddLabel( 20, 2, 55, "Top Quest Player Rankings" ); // guild filter AddLabel( 40, height - 20, 55, "Filter by Guild" ); string filter = null; if(m_attachment != null) filter = m_attachment.guildFilter; AddImageTiled( 140, height - 20, 160, 19, 0xBBC ); AddTextEntry( 140, height - 20, 160, 19, 0, 200, filter ); AddButton( 20, height - 20, 0x15E1, 0x15E5, 200, GumpButtonType.Reply, 0 ); // name filter AddLabel( 340, height - 20, 55, "Filter by Name" ); // string nfilter = null; if(m_attachment != null) nfilter = m_attachment.nameFilter; AddImageTiled( 440, height - 20, 160, 19, 0xBBC ); AddTextEntry( 440, height - 20, 160, 19, 0, 100, nfilter ); AddButton( 320, height - 20, 0x15E1, 0x15E5, 100, GumpButtonType.Reply, 0 ); RefreshQuestRankList(); int xloc = 23; AddLabel( xloc, 20, 0, "Name" ); xloc += 177; AddLabel( xloc, 20, 0, "Guild" ); #if(FACTIONS) xloc += 35; AddLabel( xloc, 20, 0, "Faction" ); xloc += 15; #endif xloc += 50; AddLabel( xloc, 20, 0, "Points" ); xloc += 50; AddLabel( xloc, 20, 0, "Quests" ); xloc += 50; //AddLabel( xloc, 20, 0, "" ); xloc += 70; AddLabel( xloc, 20, 0, "Rank" ); xloc += 45; AddLabel( xloc, 20, 0, "Change" ); xloc += 45; AddLabel( xloc, 20, 0, "Time at Rank" ); // go through the sorted list and display the top ranked players int y = 40; int count = 0; for(int i= 0; i<QuestRankList.Count;i++) { if(count >= numberToDisplay) break; QuestRankEntry r = QuestRankList[i] as QuestRankEntry; if(r == null) continue; XmlQuestPoints a = r.QuestPointsAttachment; if(a == null) continue; if(r.Quester != null && !r.Quester.Deleted && r.Rank > 0 && a != null && !a.Deleted) { string guildname = null; if(r.Quester.Guild != null) guildname = r.Quester.Guild.Abbreviation; #if(FACTIONS) string factionname = null; if(r.Quester is PlayerMobile && ((PlayerMobile)r.Quester).FactionPlayerState != null) factionname = ((PlayerMobile)r.Quester).FactionPlayerState.Faction.ToString(); #endif // check for any ranking change and update rank date if(r.Rank != a.Rank) { a.WhenRanked = DateTime.Now; if(a.Rank > 0) a.DeltaRank = a.Rank - r.Rank; a.Rank = r.Rank; } // check for guild filter if(m_attachment != null && m_attachment.guildFilter != null && m_attachment.guildFilter.Length > 0) { // parse the comma separated list string [] args = m_attachment.guildFilter.Split(','); if(args != null) { bool found = false; foreach(string arg in args) { if(arg != null && guildname == arg.Trim()) { found = true; break; } } if(!found) continue; } } // check for name filter if(m_attachment != null && m_attachment.nameFilter != null && m_attachment.nameFilter.Length > 0) { // parse the comma separated list string [] args = m_attachment.nameFilter.Split(','); if(args != null) { bool found = false; foreach(string arg in args) { if(arg != null && r.Quester.Name != null && (r.Quester.Name.ToLower().IndexOf(arg.Trim().ToLower()) >= 0)) { found = true; break; } } if(!found) continue; } } count++; TimeSpan timeranked = DateTime.Now - a.WhenRanked; int days = (int)timeranked.TotalDays; int hours = (int)(timeranked.TotalHours - days*24); int mins = (int)(timeranked.TotalMinutes - ((int)timeranked.TotalHours)*60); string quests = "???"; try { quests = a.QuestsCompleted.ToString(); } catch{} xloc = 23; AddLabel( xloc, y, 0, r.Quester.Name ); xloc += 177; AddLabel( xloc, y, 0, guildname ); #if(FACTIONS) xloc += 35; AddLabelCropped( xloc, y, 60, 21, 0, factionname ); xloc += 15; #endif xloc += 50; AddLabel( xloc, y, 0, a.Points.ToString() ); xloc += 50; AddLabel( xloc, y, 0, quests ); xloc += 50; //AddLabel( xloc, y, 0, "" ); xloc += 70; AddLabel( xloc, y, 0, a.Rank.ToString() ); string label=null; if(days > 0) label += String.Format("{0} days ",days); if(hours > 0) label += String.Format("{0} hours ",hours); if(mins > 0) label += String.Format("{0} mins",mins); if(label == null) { label = "just changed"; } string deltalabel = a.DeltaRank.ToString(); int deltahue = 0; if(a.DeltaRank > 0) { deltalabel = String.Format("+{0}",a.DeltaRank); deltahue = 68; } else if(a.DeltaRank < 0) { deltahue = 33; } xloc += 50; AddLabel( xloc, y, deltahue, deltalabel ); xloc += 40; AddLabel( xloc, y, 0, label); y += 20; } } }
public QuestRankEntry(Mobile m, XmlQuestPoints attachment) { Quester = m; QuestPointsAttachment = attachment; }
public static void UpdateQuestRanking(Mobile m, XmlQuestPoints attachment) { if(QuestRankList == null) QuestRankList = new ArrayList(); // flag the rank list for updating on the next attempt to retrieve a rank needsupdate = true; bool found = false; // rank the entries for(int i= 0; i<QuestRankList.Count;i++) { QuestRankEntry p = QuestRankList[i] as QuestRankEntry; // found a match if(p != null && p.Quester == m) { // update the entry with the new points value p.QuestPointsAttachment = attachment; found = true; break; } } // a new entry so add it if(!found) { QuestRankList.Add(new QuestRankEntry(m, attachment)); } }
public TopQuestPlayersGump(XmlQuestPoints attachment) : base(0, 0) { if (QuestRankList == null || attachment == null) { return; } m_attachment = attachment; int numberToDisplay = 20; int height = numberToDisplay * 20 + 65; // prepare the page AddPage(0); int width = 740; #if (FACTIONS) width = 790; #endif AddBackground(0, 0, width, height, 5054); AddAlphaRegion(0, 0, width, height); AddImageTiled(20, 20, width - 40, height - 45, 0xBBC); AddLabel(20, 2, 55, "Top Quest Player Rankings"); // guild filter AddLabel(40, height - 20, 55, "Filter by Guild"); string filter = null; if (m_attachment != null) { filter = m_attachment.guildFilter; } AddImageTiled(140, height - 20, 160, 19, 0xBBC); AddTextEntry(140, height - 20, 160, 19, 0, 200, filter); AddButton(20, height - 20, 0x15E1, 0x15E5, 200, GumpButtonType.Reply, 0); // name filter AddLabel(340, height - 20, 55, "Filter by Name"); // string nfilter = null; if (m_attachment != null) { nfilter = m_attachment.nameFilter; } AddImageTiled(440, height - 20, 160, 19, 0xBBC); AddTextEntry(440, height - 20, 160, 19, 0, 100, nfilter); AddButton(320, height - 20, 0x15E1, 0x15E5, 100, GumpButtonType.Reply, 0); RefreshQuestRankList(); int xloc = 23; AddLabel(xloc, 20, 0, "Name"); xloc += 177; AddLabel(xloc, 20, 0, "Guild"); #if (FACTIONS) xloc += 35; AddLabel(xloc, 20, 0, "Faction"); xloc += 15; #endif xloc += 50; AddLabel(xloc, 20, 0, "Points"); xloc += 50; AddLabel(xloc, 20, 0, "Quests"); xloc += 50; //AddLabel( xloc, 20, 0, "" ); xloc += 70; AddLabel(xloc, 20, 0, "Rank"); xloc += 45; AddLabel(xloc, 20, 0, "Change"); xloc += 45; AddLabel(xloc, 20, 0, "Time at Rank"); // go through the sorted list and display the top ranked players int y = 40; int count = 0; for (int i = 0; i < QuestRankList.Count; i++) { if (count >= numberToDisplay) { break; } QuestRankEntry r = QuestRankList[i] as QuestRankEntry; if (r == null) { continue; } XmlQuestPoints a = r.QuestPointsAttachment; if (a == null) { continue; } if (r.Quester != null && !r.Quester.Deleted && r.Rank > 0 && a != null && !a.Deleted) { string guildname = null; if (r.Quester.Guild != null) { guildname = r.Quester.Guild.Abbreviation; } #if (FACTIONS) string factionname = null; if (r.Quester is PlayerMobile && ((PlayerMobile)r.Quester).FactionPlayerState != null) { factionname = ((PlayerMobile)r.Quester).FactionPlayerState.Faction.ToString(); } #endif // check for any ranking change and update rank date if (r.Rank != a.Rank) { a.WhenRanked = DateTime.UtcNow; if (a.Rank > 0) { a.DeltaRank = a.Rank - r.Rank; } a.Rank = r.Rank; } // check for guild filter if (m_attachment != null && m_attachment.guildFilter != null && m_attachment.guildFilter.Length > 0) { // parse the comma separated list string [] args = m_attachment.guildFilter.Split(','); if (args != null) { bool found = false; foreach (string arg in args) { if (arg != null && guildname == arg.Trim()) { found = true; break; } } if (!found) { continue; } } } // check for name filter if (m_attachment != null && m_attachment.nameFilter != null && m_attachment.nameFilter.Length > 0) { // parse the comma separated list string [] args = m_attachment.nameFilter.Split(','); if (args != null) { bool found = false; foreach (string arg in args) { if (arg != null && r.Quester.Name != null && (r.Quester.Name.ToLower().IndexOf(arg.Trim().ToLower()) >= 0)) { found = true; break; } } if (!found) { continue; } } } count++; TimeSpan timeranked = DateTime.UtcNow - a.WhenRanked; int days = (int)timeranked.TotalDays; int hours = (int)(timeranked.TotalHours - days * 24); int mins = (int)(timeranked.TotalMinutes - ((int)timeranked.TotalHours) * 60); string quests = "???"; try { quests = a.QuestsCompleted.ToString(); } catch {} xloc = 23; AddLabel(xloc, y, 0, r.Quester.Name); xloc += 177; AddLabel(xloc, y, 0, guildname); #if (FACTIONS) xloc += 35; AddLabelCropped(xloc, y, 60, 21, 0, factionname); xloc += 15; #endif xloc += 50; AddLabel(xloc, y, 0, a.Points.ToString()); xloc += 50; AddLabel(xloc, y, 0, quests); xloc += 50; //AddLabel( xloc, y, 0, "" ); xloc += 70; AddLabel(xloc, y, 0, a.Rank.ToString()); string label = null; if (days > 0) { label += String.Format("{0} days ", days); } if (hours > 0) { label += String.Format("{0} hours ", hours); } if (mins > 0) { label += String.Format("{0} mins", mins); } if (label == null) { label = "just changed"; } string deltalabel = a.DeltaRank.ToString(); int deltahue = 0; if (a.DeltaRank > 0) { deltalabel = String.Format("+{0}", a.DeltaRank); deltahue = 68; } else if (a.DeltaRank < 0) { deltahue = 33; } xloc += 50; AddLabel(xloc, y, deltahue, deltalabel); xloc += 40; AddLabel(xloc, y, 0, label); y += 20; } } }
public static void WriteQuestLeaderboardHtml(string filename, int nranks) { string dirname = Path.Combine(m_QuestLeaderboardSaveDirectory, filename); StreamWriter sw = new StreamWriter(dirname); if (sw == null) { Console.WriteLine("Error: unable to save HTML quest leaderboard to {0}", dirname); return; } sw.WriteLine("<TABLE border=\"1\" summary=\"This table gives quest leaderboard stats\"> "); sw.WriteLine("<CAPTION><B>Quest Leaderboard</B></CAPTION>"); #if (FACTIONS) sw.WriteLine("<TR><TH><TH>Player Name<TH>Guild<TH>Faction<TH>Points<TH>Quests<TH>Rank<TH>Change<TH>Time at current rank"); #else sw.WriteLine("<TR><TH><TH>Player Name<TH>Guild<TH>Points<TH>Quests<TH>Rank<TH>Change<TH>Time at current rank"); #endif // go through the sorted list and display the top ranked players for (int i = 0; i < QuestRankList.Count; i++) { if (nranks > 0 && i >= nranks) { break; } QuestRankEntry r = QuestRankList[i] as QuestRankEntry; XmlQuestPoints a = r.QuestPointsAttachment; if (r.Quester != null && !r.Quester.Deleted && r.Rank > 0 && a != null && !a.Deleted) { string guildname = null; if (r.Quester.Guild != null) { guildname = r.Quester.Guild.Abbreviation; } #if (FACTIONS) string factionname = null; if (r.Quester is PlayerMobile && ((PlayerMobile)r.Quester).FactionPlayerState != null) { factionname = ((PlayerMobile)r.Quester).FactionPlayerState.Faction.ToString(); } #endif // check for any ranking change and update rank date if (r.Rank != a.Rank) { a.WhenRanked = DateTime.UtcNow; if (a.Rank > 0) { a.DeltaRank = a.Rank - r.Rank; } a.Rank = r.Rank; } TimeSpan timeranked = DateTime.UtcNow - a.WhenRanked; string quests = "???"; try { quests = a.QuestsCompleted.ToString(); } catch {} #if (FACTIONS) // write out the entry information sw.WriteLine("<TR><TH><TD>{0}<TD>{1}<TD>{2}<TD>{3}<TD>{4}<TD>{5}<TD>{6}<TD>{7}", r.Quester.Name, guildname, factionname, a.Points, quests, a.Rank, a.DeltaRank, timeranked ); #else // write out the entry information sw.WriteLine("<TR><TH><TD>{0}<TD>{1}<TD>{2}<TD>{3}<TD>{4}<TD>{5}<TD>{6}", r.Quester.Name, guildname, a.Points, quests, a.Rank, a.DeltaRank, timeranked ); #endif } } sw.WriteLine("</TABLE>"); sw.Close(); }
public static void WriteQuestLeaderboardXml(string filename, int nranks) { string dirname = Path.Combine(m_QuestLeaderboardSaveDirectory, filename); StreamWriter sw = new StreamWriter(dirname); XmlTextWriter xf = new XmlTextWriter(sw); if (xf == null) { Console.WriteLine("Error: unable to save XML quest leaderboard to {0}", dirname); return; } xf.Formatting = Formatting.Indented; xf.WriteStartDocument(true); xf.WriteStartElement("QuestLeaderboard"); if (nranks > 0) { xf.WriteAttributeString("nentries", nranks.ToString()); } else { xf.WriteAttributeString("nentries", QuestRankList.Count.ToString()); } // go through the sorted list and display the top ranked players for (int i = 0; i < QuestRankList.Count; i++) { if (nranks > 0 && i >= nranks) { break; } QuestRankEntry r = QuestRankList[i] as QuestRankEntry; XmlQuestPoints a = r.QuestPointsAttachment; if (r.Quester != null && !r.Quester.Deleted && r.Rank > 0 && a != null && !a.Deleted) { string guildname = null; if (r.Quester.Guild != null) { guildname = r.Quester.Guild.Abbreviation; } #if (FACTIONS) string factionname = null; if (r.Quester is PlayerMobile && ((PlayerMobile)r.Quester).FactionPlayerState != null) { factionname = ((PlayerMobile)r.Quester).FactionPlayerState.Faction.ToString(); } #endif // check for any ranking change and update rank date if (r.Rank != a.Rank) { a.WhenRanked = DateTime.UtcNow; if (a.Rank > 0) { a.DeltaRank = a.Rank - r.Rank; } a.Rank = r.Rank; } TimeSpan timeranked = DateTime.UtcNow - a.WhenRanked; // write out the entry information xf.WriteStartElement("Entry"); xf.WriteAttributeString("number", i.ToString()); xf.WriteStartElement("Player"); xf.WriteString(r.Quester.Name); xf.WriteEndElement(); xf.WriteStartElement("Guild"); xf.WriteString(guildname); xf.WriteEndElement(); #if (FACTIONS) xf.WriteStartElement("Faction"); xf.WriteString(factionname); xf.WriteEndElement(); #endif xf.WriteStartElement("Points"); xf.WriteString(a.Points.ToString()); xf.WriteEndElement(); string quests = "???"; try { quests = a.QuestsCompleted.ToString(); } catch {} xf.WriteStartElement("Quests"); xf.WriteString(quests); xf.WriteEndElement(); xf.WriteStartElement("Rank"); xf.WriteString(a.Rank.ToString()); xf.WriteEndElement(); xf.WriteStartElement("Change"); xf.WriteString(a.DeltaRank.ToString()); xf.WriteEndElement(); xf.WriteStartElement("Duration"); xf.WriteString(timeranked.ToString()); xf.WriteEndElement(); // end the entry xf.WriteEndElement(); } } xf.WriteEndElement(); xf.Close(); }