using System; using System.Text; using System.Collections; namespace Holo.Managers { /// /// Provides information about the various user ranks/levels, aswell as ranks for games such as 'BattleBall' and 'SnowStorm'. /// public static class rankManager { private static Hashtable userRanks; private static gameRank[] gameRanksBB; private static gameRank[] gameRanksSS; /// /// Initializes the various user ranks, aswell as the ranks for games such as 'BattleBall' and 'SnowStorm'. /// public static void Init() { Out.WriteLine("Intializing user rank fuserights..."); userRanks = new Hashtable(); for (byte i = 1; i <= 7; i++) userRanks.Add(i, new userRank(i)); Out.WriteLine("Fuserights for 7 ranks loaded."); Out.WriteBlank(); Out.WriteLine("Initializing game ranks..."); string[] Titles = DB.runReadColumn("SELECT title FROM games_ranks WHERE type = 'bb' ORDER BY id ASC", 0); int[] Mins = DB.runReadColumn("SELECT minpoints FROM games_ranks WHERE type = 'bb' ORDER BY id ASC", 0, null); int[] Maxs = DB.runReadColumn("SELECT maxpoints FROM games_ranks WHERE type = 'bb' ORDER BY id ASC", 0, null); gameRanksBB = new gameRank[Titles.Length]; for (int i = 0; i < gameRanksBB.Length; i++) { gameRanksBB[i] = new gameRank(Titles[i], Mins[i], Maxs[i]); Out.WriteLine("Loaded gamerank '" + Titles[i] + "' [" + Mins[i] + "-" + Maxs[i] + "] for game 'BattleBall'."); } Out.WriteLine("Loaded " + Titles.Length + " ranks for game 'BattleBall'."); Titles = DB.runReadColumn("SELECT title FROM games_ranks WHERE type = 'ss' ORDER BY id ASC", 0); Mins = DB.runReadColumn("SELECT minpoints FROM games_ranks WHERE type = 'ss' ORDER BY id ASC", 0, null); Maxs = DB.runReadColumn("SELECT maxpoints FROM games_ranks WHERE type = 'ss' ORDER BY id ASC", 0, null); gameRanksSS = new gameRank[Titles.Length]; for (int i = 0; i < gameRanksSS.Length; i++) { gameRanksSS[i] = new gameRank(Titles[i], Mins[i], Maxs[i]); Out.WriteLine("Loaded gamerank '" + Titles[i] + "' [" + Mins[i] + "-" + Maxs[i] + "] for game 'SnowStorm'."); } Out.WriteLine("Loaded " + Titles.Length + " ranks for game 'SnowStorm'."); } /// /// Returns the fuserights string for a certain user rank. /// /// The ID of the user rank. public static string fuseRights(byte rankID) { string[] fuseRights = ((userRank)userRanks[rankID]).fuseRights; StringBuilder strBuilder = new StringBuilder(); for (int i = 0; i < fuseRights.Length; i++) strBuilder.Append(fuseRights[i] + Convert.ToChar(2)); return strBuilder.ToString(); } /// /// Returns a bool that indicates if a certain user rank contains a certain fuseright. /// /// The ID of the user rank. /// The fuseright to look for. /// public static bool containsRight(byte rankID, string fuseRight) { userRank objRank = ((userRank)userRanks[rankID]); for (int i = 0; i < objRank.fuseRights.Length; i++) if (objRank.fuseRights[i] == fuseRight) return true; return false; } public static gameRank getGameRank(bool isBattleBall, string Title) { gameRank[] Ranks = null; if (isBattleBall) Ranks = gameRanksBB; else Ranks = gameRanksSS; foreach (gameRank Rank in Ranks) if (Rank.Title == Title) return Rank; return new gameRank("holo.cast.gamerank.null", 0, 0); } /// /// Returns the game rank title as a string for a certain game type ('BattleBall' or 'SnowStorm') and score. /// /// Specifies if to lookup a 'BattleBall' game. If false, then the rank for a 'SnowStorm' game will be returned. /// The score to get the rank for. public static string getGameRankTitle(bool isBattleBall, int Score) { gameRank[] Ranks = null; if (isBattleBall) Ranks = gameRanksBB; else Ranks = gameRanksSS; foreach (gameRank Rank in Ranks) if (Score >= Rank.minPoints && (Rank.maxPoints == 0 || Score <= Rank.maxPoints)) return Rank.Title; return "holo.cast.gamerank.null"; } /// /// Represents a user rank. /// private struct userRank { internal string[] fuseRights; /// /// Initializes a user rank. /// /// The ID of the rank to initialize. internal userRank(byte rankID) { fuseRights = DB.runReadColumn("SELECT fuseright FROM system_fuserights WHERE minrank <= " + rankID + "", 0); } } /// /// Represents a game rank, containing the min and max score and the rank name. /// public struct gameRank { /// /// The minimum amount of points of this rank. /// internal int minPoints; /// /// The maximum amount of points of this rank. /// internal int maxPoints; /// /// The title of this rank. /// internal string Title; /// /// Initializes the gamerank with given values. /// /// The title of this rank. /// The minimum amount of points of this rank. /// The maximum amount of points of this rank. internal gameRank(string Title, int minPoints, int maxPoints) { this.Title = Title; this.minPoints = minPoints; this.maxPoints = maxPoints; } } } }