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-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);
super ( mcMMO . p . getDataFolder ( ) . getAbsoluteFile ( ) , " skillranks.yml " , 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-17 08:59:09 -08:00
/ * public static RankConfig getInstance ( ) {
2019-02-16 16:09:48 -08:00
if ( instance = = null )
return new RankConfig ( ) ;
2019-01-12 23:54:53 -08:00
2019-02-16 16:09:48 -08:00
return instance ;
2019-02-17 08:59:09 -08:00
} * /
2019-01-12 23:54:53 -08:00
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-01-15 02:43:44 -08:00
String key = subSkillType . getRankConfigAddress ( ) ;
return findRankByRootAddress ( rank , key ) ;
}
/ * *
* 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 ) {
String key = abstractSubSkill . getPrimaryKeyName ( ) + " . " + abstractSubSkill . getConfigKeyName ( ) ;
2019-01-15 02:43:44 -08:00
return findRankByRootAddress ( rank , key ) ;
}
/ * *
* 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
* /
private int findRankByRootAddress ( int rank , String key ) {
2019-02-17 11:32:53 -08:00
String scalingKey = MainConfig . getInstance ( ) . getIsRetroMode ( ) ? " .RetroMode. " : " .Standard. " ;
2019-01-15 02:43:44 -08:00
String targetRank = " Rank_ " + rank ;
key + = scalingKey ;
key + = targetRank ;
2019-02-16 16:09:48 -08:00
return getIntValue ( key ) ;
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 ) ;
//Do we really care if its below 0? Probably not
2019-02-16 16:09:48 -08:00
if ( curRank < 0 ) {
reasons . add ( subSkillType . getAdvConfigAddress ( ) + " .Rank_Levels.Rank_ " + curRank + " .LevelReq should be above or equal to 0! " ) ;
2019-01-15 02:43:44 -08:00
}
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-17 11:32:53 -08:00
mcMMO . p . getLogger ( ) . info ( " You have the ranks for the subskill " + subSkillType . toString ( ) + " 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
}