2019-01-02 17:06:18 +01:00
|
|
|
package com.gmail.nossr50.util.skills;
|
|
|
|
|
2019-01-15 11:43:44 +01:00
|
|
|
import com.gmail.nossr50.config.RankConfig;
|
2019-01-09 04:52:52 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.SubSkillType;
|
2019-01-15 11:43:44 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.SuperAbilityType;
|
2019-01-09 04:52:52 +01:00
|
|
|
import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill;
|
2019-01-02 17:06:18 +01:00
|
|
|
import com.gmail.nossr50.util.player.UserManager;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
|
|
public class RankUtils {
|
2019-01-09 04:52:52 +01:00
|
|
|
public static HashMap<String, HashMap<Integer, Integer>> subSkillRanks;
|
2019-01-02 17:06:18 +01:00
|
|
|
|
2019-01-09 04:52:52 +01:00
|
|
|
/* NEW SYSTEM */
|
|
|
|
private static void addRanks(AbstractSubSkill abstractSubSkill)
|
|
|
|
{
|
|
|
|
//Fill out the rank array
|
|
|
|
for(int i = 0; i < abstractSubSkill.getNumRanks(); i++)
|
|
|
|
{
|
|
|
|
//This adds the highest ranks first
|
|
|
|
addRank(abstractSubSkill, abstractSubSkill.getNumRanks()-i);
|
2019-01-02 17:06:18 +01:00
|
|
|
|
2019-01-09 04:52:52 +01:00
|
|
|
//TODO: Remove debug code
|
|
|
|
/*System.out.println("DEBUG: Adding rank "+(numRanks-i)+" to "+subSkillType.toString());*/
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void addRanks(SubSkillType subSkillType)
|
|
|
|
{
|
2019-01-02 17:06:18 +01:00
|
|
|
//Fill out the rank array
|
2019-01-09 04:52:52 +01:00
|
|
|
for(int i = 0; i < subSkillType.getNumRanks(); i++)
|
2019-01-02 17:06:18 +01:00
|
|
|
{
|
|
|
|
//This adds the highest ranks first
|
2019-01-09 04:52:52 +01:00
|
|
|
addRank(subSkillType, subSkillType.getNumRanks()-i);
|
2019-01-03 13:59:56 +01:00
|
|
|
|
|
|
|
//TODO: Remove debug code
|
2019-01-09 04:52:52 +01:00
|
|
|
/*System.out.println("DEBUG: Adding rank "+(numRanks-i)+" to "+subSkillType.toString());*/
|
2019-01-02 17:06:18 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-15 11:43:44 +01:00
|
|
|
/**
|
|
|
|
* Returns whether or not the player has unlocked the first rank in target subskill
|
|
|
|
* @param player the player
|
|
|
|
* @param subSkillType the target subskill
|
|
|
|
* @return true if the player has at least one rank in the skill
|
|
|
|
*/
|
|
|
|
public static boolean hasUnlockedSubskill(Player player, SubSkillType subSkillType)
|
|
|
|
{
|
|
|
|
int curRank = getRank(player, subSkillType);
|
|
|
|
|
|
|
|
//-1 means the skill has no unlockable levels and is therefor unlocked
|
|
|
|
return curRank == -1 || curRank >= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether or not the player has unlocked the first rank in target subskill
|
|
|
|
* @param player the player
|
|
|
|
* @param abstractSubSkill the target subskill
|
|
|
|
* @return true if the player has at least one rank in the skill
|
|
|
|
*/
|
|
|
|
public static boolean hasUnlockedSubskill(Player player, AbstractSubSkill abstractSubSkill)
|
|
|
|
{
|
|
|
|
int curRank = getRank(player, abstractSubSkill);
|
|
|
|
|
|
|
|
//-1 means the skill has no unlockable levels and is therefor unlocked
|
|
|
|
return curRank == -1 || curRank >= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether or not the player has reached the specified rank in target subskill
|
|
|
|
* @param rank the target rank
|
|
|
|
* @param player the player
|
|
|
|
* @param subSkillType the target subskill
|
|
|
|
* @return true if the player is at least that rank in this subskill
|
|
|
|
*/
|
|
|
|
public static boolean hasReachedRank(int rank, Player player, SubSkillType subSkillType)
|
|
|
|
{
|
|
|
|
return getRank(player, subSkillType) >= rank;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns whether or not the player has reached the specified rank in target subskill
|
|
|
|
* @param rank the target rank
|
|
|
|
* @param player the player
|
|
|
|
* @param abstractSubSkill the target subskill
|
|
|
|
* @return true if the player is at least that rank in this subskill
|
|
|
|
*/
|
|
|
|
public static boolean hasReachedRank(int rank, Player player, AbstractSubSkill abstractSubSkill)
|
|
|
|
{
|
|
|
|
return getRank(player, abstractSubSkill) >= rank;
|
|
|
|
}
|
|
|
|
|
2019-01-02 17:06:18 +01:00
|
|
|
/**
|
|
|
|
* Gets the current rank of the subskill for the player
|
|
|
|
* @param player The player in question
|
2019-01-09 04:52:52 +01:00
|
|
|
* @param subSkillType Target subskill
|
2019-01-02 17:06:18 +01:00
|
|
|
* @return The rank the player currently has achieved in this skill. -1 for skills without ranks.
|
|
|
|
*/
|
2019-01-09 04:52:52 +01:00
|
|
|
public static int getRank(Player player, SubSkillType subSkillType)
|
2019-01-02 17:06:18 +01:00
|
|
|
{
|
2019-01-09 04:52:52 +01:00
|
|
|
String skillName = subSkillType.toString();
|
|
|
|
int numRanks = subSkillType.getNumRanks();
|
|
|
|
|
2019-01-02 17:06:18 +01:00
|
|
|
if(subSkillRanks == null)
|
|
|
|
subSkillRanks = new HashMap<>();
|
|
|
|
|
2019-01-09 04:52:52 +01:00
|
|
|
if(numRanks == 0)
|
2019-01-02 17:06:18 +01:00
|
|
|
return -1; //-1 Means the skill doesn't have ranks
|
|
|
|
|
2019-01-09 04:52:52 +01:00
|
|
|
if(subSkillRanks.get(skillName) == null && numRanks > 0)
|
|
|
|
addRanks(subSkillType);
|
2019-01-02 17:06:18 +01:00
|
|
|
|
|
|
|
//Get our rank map
|
2019-01-09 04:52:52 +01:00
|
|
|
HashMap<Integer, Integer> rankMap = subSkillRanks.get(skillName);
|
2019-01-02 17:06:18 +01:00
|
|
|
|
|
|
|
//Skill level of parent skill
|
2019-01-09 04:52:52 +01:00
|
|
|
int currentSkillLevel = UserManager.getPlayer(player).getSkillLevel(subSkillType.getParentSkill());
|
2019-01-02 17:06:18 +01:00
|
|
|
|
2019-01-09 04:52:52 +01:00
|
|
|
for(int i = 0; i < numRanks; i++)
|
2019-01-02 17:06:18 +01:00
|
|
|
{
|
|
|
|
//Compare against the highest to lowest rank in that order
|
2019-01-09 04:52:52 +01:00
|
|
|
int rank = numRanks-i;
|
2019-01-17 17:46:10 +01:00
|
|
|
int unlockLevel = getRankUnlockLevel(subSkillType, rank);
|
2019-01-09 04:52:52 +01:00
|
|
|
|
|
|
|
//If we check all ranks and still cannot unlock the skill, we return rank 0
|
|
|
|
if(rank == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
//True if our skill level can unlock the current rank
|
|
|
|
if(currentSkillLevel >= unlockLevel)
|
|
|
|
return rank;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0; //We should never reach this
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets the current rank of the subskill for the player
|
|
|
|
* @param player The player in question
|
|
|
|
* @param abstractSubSkill Target subskill
|
|
|
|
* @return The rank the player currently has achieved in this skill. -1 for skills without ranks.
|
|
|
|
*/
|
|
|
|
public static int getRank(Player player, AbstractSubSkill abstractSubSkill)
|
|
|
|
{
|
|
|
|
String skillName = abstractSubSkill.getConfigKeyName();
|
|
|
|
int numRanks = abstractSubSkill.getNumRanks();
|
|
|
|
|
|
|
|
if(subSkillRanks == null)
|
|
|
|
subSkillRanks = new HashMap<>();
|
|
|
|
|
|
|
|
if(numRanks == 0)
|
|
|
|
return -1; //-1 Means the skill doesn't have ranks
|
2019-01-03 13:59:56 +01:00
|
|
|
|
2019-01-09 04:52:52 +01:00
|
|
|
if(subSkillRanks.get(skillName) == null && numRanks > 0)
|
|
|
|
addRanks(abstractSubSkill);
|
|
|
|
|
|
|
|
//Get our rank map
|
|
|
|
HashMap<Integer, Integer> rankMap = subSkillRanks.get(skillName);
|
|
|
|
|
|
|
|
//Skill level of parent skill
|
|
|
|
int currentSkillLevel = UserManager.getPlayer(player).getSkillLevel(abstractSubSkill.getPrimarySkill());
|
|
|
|
|
|
|
|
for(int i = 0; i < numRanks; i++)
|
|
|
|
{
|
|
|
|
//Compare against the highest to lowest rank in that order
|
|
|
|
int rank = numRanks-i;
|
2019-01-17 17:46:10 +01:00
|
|
|
int unlockLevel = getRankUnlockLevel(abstractSubSkill, rank);
|
2019-01-02 17:06:18 +01:00
|
|
|
|
|
|
|
//If we check all ranks and still cannot unlock the skill, we return rank 0
|
|
|
|
if(rank == 0)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
//True if our skill level can unlock the current rank
|
|
|
|
if(currentSkillLevel >= unlockLevel)
|
|
|
|
return rank;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0; //We should never reach this
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds ranks to our map
|
2019-01-09 04:52:52 +01:00
|
|
|
* @param abstractSubSkill The subskill to add ranks for
|
2019-01-02 17:06:18 +01:00
|
|
|
* @param rank The rank to add
|
|
|
|
*/
|
2019-01-09 04:52:52 +01:00
|
|
|
private static void addRank(AbstractSubSkill abstractSubSkill, int rank)
|
2019-01-02 17:06:18 +01:00
|
|
|
{
|
2019-01-09 04:52:52 +01:00
|
|
|
initMaps(abstractSubSkill.getConfigKeyName());
|
|
|
|
|
|
|
|
HashMap<Integer, Integer> rankMap = subSkillRanks.get(abstractSubSkill.getConfigKeyName());
|
2019-01-02 17:06:18 +01:00
|
|
|
|
2019-01-09 04:52:52 +01:00
|
|
|
//TODO: Remove this debug code
|
2019-01-17 17:46:10 +01:00
|
|
|
//System.out.println("[DEBUG]: Rank "+rank+" for "+subSkillName.toString()+" requires skill level "+getRankUnlockLevel(subSkillType, rank));
|
|
|
|
rankMap.put(rank, getRankUnlockLevel(abstractSubSkill, rank));
|
2019-01-09 04:52:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Deprecated
|
|
|
|
private static void addRank(SubSkillType subSkillType, int rank)
|
|
|
|
{
|
|
|
|
initMaps(subSkillType.toString());
|
2019-01-02 17:06:18 +01:00
|
|
|
|
2019-01-09 04:52:52 +01:00
|
|
|
HashMap<Integer, Integer> rankMap = subSkillRanks.get(subSkillType.toString());
|
2019-01-02 17:06:18 +01:00
|
|
|
|
2019-01-03 16:16:05 +01:00
|
|
|
//TODO: Remove this debug code
|
2019-01-17 17:46:10 +01:00
|
|
|
//System.out.println("[DEBUG]: Rank "+rank+" for "+subSkillName.toString()+" requires skill level "+getRankUnlockLevel(subSkillType, rank));
|
|
|
|
rankMap.put(rank, getRankUnlockLevel(subSkillType, rank));
|
2019-01-09 04:52:52 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
private static void initMaps(String s) {
|
|
|
|
if (subSkillRanks == null)
|
|
|
|
subSkillRanks = new HashMap<>();
|
|
|
|
|
|
|
|
if (subSkillRanks.get(s) == null)
|
|
|
|
subSkillRanks.put(s, new HashMap<>());
|
2019-01-02 17:06:18 +01:00
|
|
|
}
|
|
|
|
|
2019-01-15 11:43:44 +01:00
|
|
|
/* public static int getSubSkillUnlockRequirement(SubSkillType subSkillType)
|
|
|
|
{
|
|
|
|
String skillName = subSkillType.toString();
|
|
|
|
int numRanks = subSkillType.getNumRanks();
|
|
|
|
|
|
|
|
if(subSkillRanks == null)
|
|
|
|
subSkillRanks = new HashMap<>();
|
|
|
|
|
|
|
|
if(numRanks == 0)
|
|
|
|
return -1; //-1 Means the skill doesn't have ranks
|
|
|
|
|
|
|
|
if(subSkillRanks.get(skillName) == null && numRanks > 0)
|
|
|
|
addRanks(subSkillType);
|
|
|
|
|
|
|
|
return subSkillRanks.get(subSkillType.toString()).get(1);
|
|
|
|
}*/
|
|
|
|
|
2019-01-02 17:06:18 +01:00
|
|
|
/**
|
|
|
|
* Gets the unlock level for a specific rank in a subskill
|
2019-01-09 04:52:52 +01:00
|
|
|
* @param subSkillType The target subskill
|
2019-01-02 17:06:18 +01:00
|
|
|
* @param rank The target rank
|
|
|
|
* @return The level at which this rank unlocks
|
|
|
|
*/
|
2019-01-09 04:52:52 +01:00
|
|
|
@Deprecated
|
2019-01-17 17:46:10 +01:00
|
|
|
public static int getRankUnlockLevel(SubSkillType subSkillType, int rank)
|
2019-01-15 11:43:44 +01:00
|
|
|
{
|
|
|
|
return RankConfig.getInstance().getSubSkillUnlockLevel(subSkillType, rank);
|
|
|
|
}
|
|
|
|
|
2019-01-17 17:46:10 +01:00
|
|
|
public static int getRankUnlockLevel(AbstractSubSkill abstractSubSkill, int rank)
|
2019-01-09 04:52:52 +01:00
|
|
|
{
|
2019-01-15 11:43:44 +01:00
|
|
|
return RankConfig.getInstance().getSubSkillUnlockLevel(abstractSubSkill, rank);
|
2019-01-09 04:52:52 +01:00
|
|
|
}
|
|
|
|
|
2019-01-17 17:46:10 +01:00
|
|
|
/**
|
|
|
|
* Get the level at which a skill is unlocked for a player (this is the first rank of a skill)
|
|
|
|
* @param subSkillType target subskill
|
|
|
|
* @return The unlock requirements for rank 1 in this skill
|
|
|
|
*/
|
|
|
|
public static int getUnlockLevel(SubSkillType subSkillType)
|
|
|
|
{
|
|
|
|
return RankConfig.getInstance().getSubSkillUnlockLevel(subSkillType, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the level at which a skill is unlocked for a player (this is the first rank of a skill)
|
|
|
|
* @param abstractSubSkill target subskill
|
|
|
|
* @return The unlock requirements for rank 1 in this skill
|
|
|
|
*/
|
|
|
|
public static int getUnlockLevel(AbstractSubSkill abstractSubSkill)
|
|
|
|
{
|
|
|
|
return RankConfig.getInstance().getSubSkillUnlockLevel(abstractSubSkill, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the highest rank of a subskill
|
|
|
|
* @param subSkillType target subskill
|
|
|
|
* @return the last rank of a subskill
|
|
|
|
*/
|
|
|
|
public static int getHighestRank(SubSkillType subSkillType)
|
|
|
|
{
|
|
|
|
return subSkillType.getNumRanks();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the highest rank of a subskill
|
|
|
|
* @param abstractSubSkill target subskill
|
|
|
|
* @return the last rank of a subskill
|
|
|
|
*/
|
|
|
|
public static int getHighestRank(AbstractSubSkill abstractSubSkill)
|
|
|
|
{
|
|
|
|
return abstractSubSkill.getNumRanks();
|
|
|
|
}
|
|
|
|
|
2019-01-15 11:43:44 +01:00
|
|
|
public static int getSuperAbilityUnlockRequirement(SuperAbilityType superAbilityType)
|
2019-01-02 17:06:18 +01:00
|
|
|
{
|
2019-01-17 17:46:10 +01:00
|
|
|
return getRankUnlockLevel(superAbilityType.getSubSkillTypeDefinition(), 1);
|
2019-01-02 17:06:18 +01:00
|
|
|
}
|
2019-01-17 17:46:10 +01:00
|
|
|
}
|