Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.holojava.managers;
- import com.holojava.core.console.Output;
- import com.holojava.database.DatabaseManipulation;
- import java.util.Hashtable;
- /**
- * Summary: Provides information about the various user ranks/levels.
- * Also provides information for game ranks, games such as 'BattleBall' and 'SnowStorm'.
- */
- public class RankManager {
- private static Hashtable userRanks;
- private GameRank[] gameRanksBB;
- private GameRank[] gameRanksSS;
- private DatabaseManipulation dbManipulate;
- private Output output;
- /**
- * Summary: Initializes an instance of RankManager and makes calls to initialize UserRanks, BattleBallRanks,
- * and SnowStormRanks.
- */
- public RankManager() {
- dbManipulate = new DatabaseManipulation();
- output = new Output();
- initUserRanks();
- initBattleBallRanks();
- initSnowStormRanks();
- }
- /**
- * Summary - Initializes the set amount of UserRanks from table system_config in the database.
- */
- private void initUserRanks() {
- // Initializes all fuse rights for the set user ranks.
- output.writeLine("Initializing user rank fuserights...");
- int fuseMaxRank = Integer.parseInt(dbManipulate.runRead
- ("SELECT sval FROM system_config WHERE skey = '" + "fuse_rank_amount" + "'"));
- userRanks = new Hashtable();
- for (byte i = 1; i <= fuseMaxRank; i++) {
- userRanks.put(i, new UserRank(i));
- }
- output.writeLine("Fuserights for " + fuseMaxRank + " ranks loaded.");
- System.out.println();
- }
- /**
- * Summary - Initializes the set GameRanks, from table games_ranks in the database, for BattleBall.
- */
- private void initBattleBallRanks() {
- output.writeLine("Initializing BattleBall ranks...");
- // Sets GameRanks for BattleBall.
- String[] titles = dbManipulate.runReadColumn
- ("SELECT title FROM games_ranks WHERE type = 'bb' ORDER BY id ASC", 0);
- Integer[] minPoints = dbManipulate.runReadColumn
- ("SELECT minpoints FROM games_ranks WHERE type = 'bb' ORDER BY id ASC", 0, null);
- Integer[] maxPoints = dbManipulate.runReadColumn
- ("SELECT maxpoints FROM games_ranks WHERE type = 'bb' ORDER BY id ASC", 0, null);
- this.gameRanksBB = new GameRank[titles.length];
- for (int i = 0; i < this.gameRanksBB.length; i++) {
- this.gameRanksBB[i] = new GameRank(titles[i], minPoints[i], maxPoints[i]);
- output.writeLine("Loaded gamerank '" + titles[i] + "' [" + minPoints[i] + "-" + maxPoints[i] +
- "] for game 'BattleBall'.");
- }
- output.writeLine("Loaded " + titles.length + " ranks for game 'BattleBall'.");
- }
- /**
- * Summary - Initializes the set GameRanks, from table games_ranks in the database, for SnowStorm.
- */
- private void initSnowStormRanks() {
- output.writeLine("Initializing SnowStorm ranks...");
- // Sets GameRanks for SnowStorm.
- String[] titles = dbManipulate.runReadColumn
- ("SELECT title FROM games_ranks WHERE type = 'ss' ORDER BY id ASC", 0);
- Integer[] minPoints = dbManipulate.runReadColumn
- ("SELECT minpoints FROM games_ranks WHERE type = 'ss' ORDER BY id ASC", 0, null);
- Integer[] maxPoints = dbManipulate.runReadColumn
- ("SELECT maxpoints FROM games_ranks WHERE type = 'ss' ORDER BY id ASC", 0, null);
- this.gameRanksSS = new GameRank[titles.length];
- for (int i = 0; i < this.gameRanksSS.length; i++) {
- this.gameRanksSS[i] = new GameRank(titles[i], minPoints[i], maxPoints[i]);
- output.writeLine("Loaded gamerank '" + titles[i] + "' [" + minPoints[i] + "-" + maxPoints[i] +
- "] for game 'SnowStorm'.");
- }
- output.writeLine("Loaded " + titles.length + " ranks for game 'SnowStorm'.");
- }
- /**
- * Summary: Returns the fuse rights, as a string, for a certain user rank.
- * @param rankID - The ID of the user rank.
- * @return - The string of fuserights that a certain user rank possesses.
- */
- public String getFuseRights(byte rankID) {
- String[] fuseRights = ((UserRank)userRanks.get(rankID)).fuseRights ;
- StringBuilder sBuilder = new StringBuilder();
- for (String right : fuseRights) {
- sBuilder.append(right);
- }
- /*
- for (int i = 0; i < fuseRights.length; i++) {
- sBuilder.append(fuseRights[i] + '2');
- }
- */
- return sBuilder.toString();
- }
- /**
- * Summary: Returns a bool that indicates if a certain user rank contains a certain fuseright.
- * @param rankID - The ID of the user rank.
- * @param fuseRight - The fuseright to look for.
- * @return - True/False, depending on if the intended user rank possesed the fuseRight.
- */
- public boolean containsRight(byte rankID, String fuseRight) {
- UserRank objRank = ((UserRank)userRanks.get(rankID));
- for (int i = 0; i < objRank.fuseRights.length; i++) {
- if (objRank.fuseRights[i].equals(fuseRight)) {
- return true;
- }
- }
- return false;
- }
- /**
- * Summary: Returns the game rank title as a string for a certain game type ('BattleBall' or 'SnowStorm')
- * @param isBattleBall - True/False, if the game type is BattleBall or SnowStorm, respectively.
- * @param title - The title to get the rank for.
- * @return - The rank with the target title, or 'holo.cast.gamerank.null'.
- */
- public GameRank getGameRank(boolean isBattleBall, String title) {
- GameRank[] ranks;
- if (isBattleBall) {
- ranks = gameRanksBB.clone();
- } else {
- ranks = gameRanksSS.clone();
- }
- for (GameRank rank : ranks) {
- if (rank.title.equals(title)) {
- return rank;
- }
- }
- // No game rank found with that title.
- return new GameRank("holo.cast.gamerank.null", 0, 0);
- }
- /**
- * Summary: Returns the game rank title as a string for a certain game type ('BattleBall' or 'SnowStorm') and score.
- * @param isBattleBall - True/False, if the game type is BattleBall or SnowStorm, respectively.
- * @param score - The score to get the rank for.
- * @return - The rank with the target score, or 'holo.cast.gamerank.null'.
- */
- public String getGameRankTitle(boolean isBattleBall, int score) {
- GameRank[] ranks;
- if (isBattleBall) {
- ranks = gameRanksBB.clone();
- } else {
- ranks = gameRanksSS.clone();
- }
- for (GameRank rank : ranks) {
- if (score >= rank.minPoints && (rank.maxPoints == 0 || score <= rank.maxPoints)) {
- return rank.title;
- }
- }
- // No game rank with that score.
- return "holo.cast.gamerank.null";
- }
- /**
- * Summary: Represents a user rank.
- */
- private class UserRank {
- String[] fuseRights;
- /**
- * Summary: Initializes a UserRank.
- * @param rankID - The ID of the rank to initialize.
- */
- UserRank(byte rankID) {
- this.fuseRights = dbManipulate.runReadColumn
- ("SELECT fuseright FROM system_fuserights WHERE minrank <= " + rankID + "", 0);
- }
- }
- /**
- * Summary: Represents a game rank, containing the min and max score and the rank name.
- */
- private class GameRank {
- int minPoints;
- int maxPoints;
- String title;
- /**
- * Summary: Initializes the GameRank with given values.
- * @param title - The title of this rank.
- * @param minPoints - The minimum amount of points needed to be in this rank.
- * @param maxPoints - The maximum amount of points one can have to be in this rank.
- */
- GameRank(String title, int minPoints, int maxPoints) {
- this.title = title;
- this.minPoints = minPoints;
- this.maxPoints = maxPoints;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement