using System;
using System.Data;
using System.Text;
using System.Collections;
using System.Threading;
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(bool Update)
{
Out.WriteLine("Intializing user rank fuserights...");
userRanks = new Hashtable();
for (byte b = 1; b <= 7; b++)
userRanks.Add(b, new userRank(b));
Out.WriteLine("Fuserights for 7 ranks loaded.");
Out.WriteBlank();
Out.WriteLine("Initializing game ranks...");
Database dbClient = new Database(true, false, 17);
DataTable dTable = dbClient.getTable("SELECT title, minpoints, maxpoints FROM games_ranks WHERE type = 'bb' ORDER BY id ASC");
gameRanksBB = new gameRank[dTable.Rows.Count];
int i = 0;
foreach (DataRow dRow in dTable.Rows)
{
gameRanksBB[i] = new gameRank(Convert.ToString(dRow["title"]), Convert.ToInt32(dRow["minpoints"]), Convert.ToInt32(dRow["maxpoints"]));
i++;
}
Out.WriteLine("Loaded " + gameRanksBB.Length + " ranks for game 'BattleBall'.");
dTable = dbClient.getTable("SELECT title, minpoints, maxpoints FROM games_ranks WHERE type = 'ss' ORDER BY id ASC");
dbClient.Close();
gameRanksSS = new gameRank[dTable.Rows.Count];
i = 0;
foreach (DataRow dRow in dTable.Rows)
{
gameRanksSS[i] = new gameRank(Convert.ToString(dRow["title"]), Convert.ToInt32(dRow["minpoints"]), Convert.ToInt32(dRow["maxpoints"]));
i++;
}
Out.WriteLine("Loaded " + gameRanksSS.Length + " ranks for game 'SnowStorm'.");
if (Update)
Thread.CurrentThread.Abort();
}
///
/// 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)
{
Database dbClient = new Database(true, true, 16);
DataColumn dCol = dbClient.getColumn("SELECT fuseright FROM system_fuserights WHERE minrank <= " + rankID);
fuseRights = dataHandling.dColToArray(dCol);
}
}
///
/// 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;
}
}
}
}