mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2025-08-02 12:35:27 +02:00
Added some JSON, much more to come.
This commit is contained in:
100
src/main/java/com/gmail/nossr50/util/skills/RankUtils.java
Normal file
100
src/main/java/com/gmail/nossr50/util/skills/RankUtils.java
Normal file
@@ -0,0 +1,100 @@
|
||||
package com.gmail.nossr50.util.skills;
|
||||
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkill;
|
||||
import com.gmail.nossr50.util.player.UserManager;
|
||||
import org.bukkit.entity.Player;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class RankUtils {
|
||||
public static HashMap<SubSkill, HashMap<Integer, Integer>> subSkillRanks;
|
||||
|
||||
/**
|
||||
* Adds ranks to subSkillRanks for target SubSkill
|
||||
* @param subSkill Target SubSkill
|
||||
*/
|
||||
private static void addRanks(SubSkill subSkill) {
|
||||
int numRanks = subSkill.getNumRanks();
|
||||
|
||||
//Fill out the rank array
|
||||
for(int i = 0; i < numRanks; i++)
|
||||
{
|
||||
//This adds the highest ranks first
|
||||
addRank(subSkill, numRanks-i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the current rank of the subskill for the player
|
||||
* @param player The player in question
|
||||
* @param subSkill Target subskill
|
||||
* @return The rank the player currently has achieved in this skill. -1 for skills without ranks.
|
||||
*/
|
||||
public static int getRank(Player player, SubSkill subSkill)
|
||||
{
|
||||
if(subSkillRanks == null)
|
||||
subSkillRanks = new HashMap<>();
|
||||
|
||||
if(subSkill.getNumRanks() == 0)
|
||||
return -1; //-1 Means the skill doesn't have ranks
|
||||
|
||||
if(subSkillRanks.get(subSkill) == null && subSkill.getNumRanks() > 0)
|
||||
addRanks(subSkill);
|
||||
|
||||
//Get our rank map
|
||||
HashMap<Integer, Integer> rankMap = subSkillRanks.get(subSkill);
|
||||
|
||||
//Skill level of parent skill
|
||||
int currentSkillLevel = UserManager.getPlayer(player).getSkillLevel(subSkill.getParentSkill());
|
||||
|
||||
for(int i = 0; i < subSkill.getNumRanks(); i++)
|
||||
{
|
||||
//Compare against the highest to lowest rank in that order
|
||||
int rank = subSkill.getNumRanks()-i;
|
||||
//System.out.println("Checking rank "+rank+" of "+subSkill.getNumRanks());
|
||||
int unlockLevel = getUnlockLevel(subSkill, rank);
|
||||
//System.out.println("Rank "+rank+" -- Unlock level: "+unlockLevel);
|
||||
//System.out.println("Rank" +rank+" -- Player Skill Level: "+currentSkillLevel);
|
||||
|
||||
//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
|
||||
* @param subSkill The subskill to add ranks for
|
||||
* @param rank The rank to add
|
||||
*/
|
||||
private static void addRank(SubSkill subSkill, int rank)
|
||||
{
|
||||
if(subSkillRanks == null)
|
||||
subSkillRanks = new HashMap<>();
|
||||
|
||||
if(subSkillRanks.get(subSkill) == null)
|
||||
subSkillRanks.put(subSkill, new HashMap<>());
|
||||
|
||||
HashMap<Integer, Integer> rankMap = subSkillRanks.get(subSkill);
|
||||
|
||||
rankMap.put(rank, getUnlockLevel(subSkill, rank));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the unlock level for a specific rank in a subskill
|
||||
* @param subSkill The target subskill
|
||||
* @param rank The target rank
|
||||
* @return The level at which this rank unlocks
|
||||
*/
|
||||
private static int getUnlockLevel(SubSkill subSkill, int rank)
|
||||
{
|
||||
return AdvancedConfig.getInstance().getSubSkillUnlockLevel(subSkill, rank);
|
||||
}
|
||||
}
|
@@ -1,55 +0,0 @@
|
||||
package com.gmail.nossr50.util.skills;
|
||||
|
||||
import com.gmail.nossr50.config.AdvancedConfig;
|
||||
import com.gmail.nossr50.datatypes.skills.SkillMilestone;
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkill;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* This Factory class builds SkillMilestone chains as needed
|
||||
* SkillMilestones are stored in a hash map
|
||||
*/
|
||||
public class SkillMilestoneFactory {
|
||||
|
||||
private static HashMap<SubSkill, SkillMilestone> skillMilestoneMap;
|
||||
|
||||
/**
|
||||
* Gets a the SkillMilestone chain for this subskill
|
||||
* Builds that chain if it doesn't exist before returning the parent node
|
||||
* @param subSkill The SubSkill to get the SkillMilestone chain for
|
||||
* @return The parent node of the SkillMilestone chain for the target subskill
|
||||
*/
|
||||
public static SkillMilestone getSkillMilestone(SubSkill subSkill)
|
||||
{
|
||||
//Init the map
|
||||
if(skillMilestoneMap == null)
|
||||
skillMilestoneMap = new HashMap<>();
|
||||
|
||||
if(skillMilestoneMap.get(subSkill) == null)
|
||||
return buildSkillMilestone(subSkill);
|
||||
else
|
||||
return skillMilestoneMap.get(subSkill);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a SkillMilestone chain for a given subskill
|
||||
* @param subSkill The subskill to build the SkillMilestone chain for
|
||||
* @return The base node of the SkillMilestone chain
|
||||
*/
|
||||
private static SkillMilestone buildSkillMilestone(SubSkill subSkill)
|
||||
{
|
||||
//Init our parent node
|
||||
SkillMilestone newSkillMilestone = new SkillMilestone(subSkill, AdvancedConfig.getInstance().getSubSkillUnlockLevel(subSkill, 1));
|
||||
|
||||
//There's probably a better way to do this
|
||||
for(int x = 0; x < subSkill.getNumRanks()-1; x++)
|
||||
{
|
||||
newSkillMilestone.addChildMilestone();
|
||||
}
|
||||
|
||||
//DEBUG
|
||||
System.out.println("Milestone constructed for "+subSkill);
|
||||
return skillMilestoneMap.put(subSkill, newSkillMilestone);
|
||||
}
|
||||
}
|
@@ -1,33 +0,0 @@
|
||||
package com.gmail.nossr50.util.skills;
|
||||
|
||||
import com.gmail.nossr50.datatypes.skills.SubSkill;
|
||||
import com.gmail.nossr50.datatypes.skills.PrimarySkill;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
/**
|
||||
* This class will handle the following things
|
||||
* 1) Informing the player of important milestones in a skill (Every 5 levels)
|
||||
* 2) Getting lists of milestones (skill unlocks) a player has
|
||||
* 3) Propagating events for milestones (API)
|
||||
*
|
||||
* By setting up a skill milestone system it will make managing the audio/visual feedback for progression a lot easier
|
||||
*
|
||||
*/
|
||||
//TODO: Inform players of milestones
|
||||
//TODO: Helper methods for getting milestones
|
||||
//TODO: Propagate events when milestones are achieved
|
||||
//TODO: Update existing parts of the codebase to use this where appropriate
|
||||
public class SkillMilestoneManager {
|
||||
public static final HashMap<PrimarySkill, SubSkill> subskillMilestones;
|
||||
|
||||
static {
|
||||
//Init our maps
|
||||
subskillMilestones = new HashMap<>();
|
||||
|
||||
for(PrimarySkill primarySkill : PrimarySkill.values())
|
||||
{
|
||||
//TODO: Setup these values
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user