2019-01-12 23:54:53 -08:00
package com.gmail.nossr50.config ;
2019-01-15 02:43:44 -08:00
import com.gmail.nossr50.datatypes.skills.SubSkillType ;
import com.gmail.nossr50.datatypes.skills.subskills.AbstractSubSkill ;
2019-02-16 16:09:48 -08:00
import com.gmail.nossr50.mcMMO ;
2019-01-15 02:43:44 -08:00
import java.util.ArrayList ;
import java.util.List ;
2019-02-16 16:09:48 -08:00
public class RankConfig extends ConfigValidated {
2019-02-21 14:33:36 -08:00
public static final String RETRO_MODE = " RetroMode " ;
public static final String STANDARD = " Standard " ;
2019-02-17 08:59:09 -08:00
//private static RankConfig instance;
2019-01-12 23:54:53 -08:00
2019-02-16 16:09:48 -08:00
public RankConfig ( ) {
//super(McmmoCore.getDataFolderPath().getAbsoluteFile(),"skillranks.yml", true);
2019-02-20 22:08:46 -08:00
super ( mcMMO . p . getDataFolder ( ) . getAbsoluteFile ( ) , " skillranks.yml " , true , true ) ;
2019-02-17 08:59:09 -08:00
//this.instance = this;
2019-01-12 23:54:53 -08:00
}
2019-02-17 11:32:53 -08:00
/ * *
* This grabs an instance of this config class from the Config Manager
* This method is deprecated and will be removed in the future
* @see mcMMO # getConfigManager ( )
* @return the instance of this config
* @deprecated Please use mcMMO . getConfigManager ( ) to grab a specific config instead
* /
@Deprecated
public static RankConfig getInstance ( ) {
return mcMMO . getConfigManager ( ) . getRankConfig ( ) ;
}
2019-02-16 16:09:48 -08:00
@Override
public void unload ( ) {
2019-02-17 11:32:53 -08:00
//Do nothing
2019-02-16 16:09:48 -08:00
}
2019-01-12 23:54:53 -08:00
2019-02-16 16:09:48 -08:00
/ * *
* The version of this config
*
* @return
* /
@Override
public double getConfigVersion ( ) {
return 1 ;
2019-01-12 23:54:53 -08:00
}
2019-01-15 02:43:44 -08:00
@Override
2019-02-16 16:09:48 -08:00
public List < String > validateKeys ( ) {
2019-01-15 02:43:44 -08:00
List < String > reason = new ArrayList < String > ( ) ;
/ *
* In the future this method will check keys for all skills , but for now it only checks overhauled skills
* /
checkKeys ( reason ) ;
2019-02-16 16:09:48 -08:00
return reason ;
2019-01-15 02:43:44 -08:00
}
/ * *
* Returns the unlock level for a subskill depending on the gamemode
2019-02-16 16:09:48 -08:00
*
2019-01-15 02:43:44 -08:00
* @param subSkillType target subskill
2019-02-16 16:09:48 -08:00
* @param rank the rank we are checking
2019-01-15 02:43:44 -08:00
* @return the level requirement for a subskill at this particular rank
* /
2019-02-16 16:09:48 -08:00
public int getSubSkillUnlockLevel ( SubSkillType subSkillType , int rank ) {
2019-02-21 14:33:36 -08:00
return findRankByRootAddress ( rank , subSkillType . getRankConfigAddress ( ) ) ;
2019-01-15 02:43:44 -08:00
}
/ * *
* Returns the unlock level for a subskill depending on the gamemode
2019-02-16 16:09:48 -08:00
*
2019-01-15 02:43:44 -08:00
* @param abstractSubSkill target subskill
2019-02-16 16:09:48 -08:00
* @param rank the rank we are checking
2019-01-15 02:43:44 -08:00
* @return the level requirement for a subskill at this particular rank
* /
2019-02-16 16:09:48 -08:00
public int getSubSkillUnlockLevel ( AbstractSubSkill abstractSubSkill , int rank ) {
2019-02-21 14:33:36 -08:00
return findRankByRootAddress ( rank , abstractSubSkill . getSubSkillType ( ) . getRankConfigAddress ( ) ) ;
2019-01-15 02:43:44 -08:00
}
/ * *
* Returns the unlock level for a subskill depending on the gamemode
2019-02-16 16:09:48 -08:00
*
* @param key root address of the subskill in the rankskills . yml file
2019-01-15 02:43:44 -08:00
* @param rank the rank we are checking
* @return the level requirement for a subskill at this particular rank
* /
2019-02-21 14:33:36 -08:00
private int findRankByRootAddress ( int rank , String [ ] key ) {
String scalingKey = mcMMO . isRetroModeEnabled ( ) ? RETRO_MODE : STANDARD ;
2019-01-15 02:43:44 -08:00
String targetRank = " Rank_ " + rank ;
2019-02-21 14:33:36 -08:00
//key[0] = parent skill config node, key[1] subskill child node, scalingkey = retro/standard, targetrank = rank node
return getIntValue ( key [ 0 ] , key [ 1 ] , scalingKey , targetRank ) ;
2019-01-15 02:43:44 -08:00
}
/ * *
* Checks for valid keys for subskill ranks
* /
2019-02-16 16:09:48 -08:00
private void checkKeys ( List < String > reasons ) {
2019-01-15 02:43:44 -08:00
//For now we will only check ranks of stuff I've overhauled
2019-02-16 16:09:48 -08:00
for ( SubSkillType subSkillType : SubSkillType . values ( ) ) {
2019-01-15 02:43:44 -08:00
//Keeping track of the rank requirements and making sure there are no logical errors
int curRank = 0 ;
int prevRank = 0 ;
2019-02-16 16:09:48 -08:00
for ( int x = 0 ; x < subSkillType . getNumRanks ( ) ; x + + ) {
if ( curRank > 0 )
2019-01-15 02:43:44 -08:00
prevRank = curRank ;
curRank = getSubSkillUnlockLevel ( subSkillType , x ) ;
2019-02-16 16:09:48 -08:00
if ( prevRank > curRank ) {
2019-01-15 02:43:44 -08:00
//We're going to allow this but we're going to warn them
2019-02-21 14:33:36 -08:00
mcMMO . p . getLogger ( ) . severe ( " You have the ranks for the subskill " + subSkillType . toString ( ) + " in skillranks config set up poorly, sequential ranks should have ascending requirements " ) ;
2019-01-15 02:43:44 -08:00
}
}
}
}
2019-01-12 23:54:53 -08:00
}