Search in sources :

Example 1 with DynamicLevelRule

use of de.Keyle.MyPet.api.skill.skilltree.levelrule.DynamicLevelRule in project MyPet by xXKeyleXx.

the class SkillTreeLoaderJSON method loadLevelRule.

private static LevelRule loadLevelRule(String levelRuleString) {
    LevelRule levelRule;
    if (levelRuleString.contains("%")) {
        int modulo = 1;
        int min = 0;
        int max = 0;
        Matcher matcher = LEVEL_RULE_REGEX.matcher(levelRuleString);
        while (matcher.find()) {
            if (matcher.group(0).startsWith("%")) {
                modulo = Math.max(1, Integer.parseInt(matcher.group(1)));
            } else if (matcher.group(0).startsWith(">")) {
                min = Integer.parseInt(matcher.group(3));
            } else if (matcher.group(0).startsWith("<")) {
                max = Integer.parseInt(matcher.group(2));
            }
        }
        levelRule = new DynamicLevelRule(modulo, min, max);
    } else {
        String[] levelStrings = levelRuleString.split(",");
        List<Integer> levels = new ArrayList<>();
        for (String levelString : levelStrings) {
            if (Util.isInt(levelString.trim())) {
                levels.add(Integer.parseInt(levelString.trim()));
            }
        }
        levelRule = new StaticLevelRule(levels);
    }
    return levelRule;
}
Also used : Matcher(java.util.regex.Matcher) DynamicLevelRule(de.Keyle.MyPet.api.skill.skilltree.levelrule.DynamicLevelRule) StaticLevelRule(de.Keyle.MyPet.api.skill.skilltree.levelrule.StaticLevelRule) DynamicLevelRule(de.Keyle.MyPet.api.skill.skilltree.levelrule.DynamicLevelRule) StaticLevelRule(de.Keyle.MyPet.api.skill.skilltree.levelrule.StaticLevelRule) LevelRule(de.Keyle.MyPet.api.skill.skilltree.levelrule.LevelRule)

Aggregations

DynamicLevelRule (de.Keyle.MyPet.api.skill.skilltree.levelrule.DynamicLevelRule)1 LevelRule (de.Keyle.MyPet.api.skill.skilltree.levelrule.LevelRule)1 StaticLevelRule (de.Keyle.MyPet.api.skill.skilltree.levelrule.StaticLevelRule)1 Matcher (java.util.regex.Matcher)1