Search in sources :

Example 6 with SkillInfo

use of de.Keyle.MyPet.api.skill.SkillInfo in project MyPet by xXKeyleXx.

the class SkillTreeLoader method manageInheritance.

protected static void manageInheritance(SkillTreeMobType skillTreeMobType, SkillTree startSkillTree, SkillTree skillTree, Map<SkillTree, SkillTree> clones, int depth) {
    if (skillTree.hasInheritance() && depth < 20) {
        if (skillTreeMobType.hasSkillTree(skillTree.getInheritance())) {
            SkillTree skillTreeInherit = skillTreeMobType.getSkillTree(skillTree.getInheritance());
            if (!alreadyLoadedInheritance.contains(skillTreeInherit)) {
                if (skillTreeInherit.hasInheritance() && Configuration.Skilltree.INHERIT_ALREADY_INHERITED_SKILLS) {
                    alreadyLoadedInheritance.add(skillTreeInherit);
                    manageInheritance(skillTreeMobType, startSkillTree, skillTreeInherit, clones, depth + 1);
                } else {
                    alreadyLoadedInheritance.add(skillTreeInherit);
                }
                SkillTree skillTreeClone = clones.get(skillTreeInherit);
                for (SkillTreeLevel level : skillTreeClone.getLevelList()) {
                    for (SkillInfo skill : level.getSkills()) {
                        SkillInfo skillClone = skill.cloneSkill();
                        if (skillClone != null) {
                            skillClone.setIsInherited(true);
                            startSkillTree.addSkillToLevel(level.getLevel(), skillClone, true);
                        }
                    }
                }
            }
        }
    }
}
Also used : SkillTreeLevel(de.Keyle.MyPet.api.skill.skilltree.SkillTreeLevel) SkillInfo(de.Keyle.MyPet.api.skill.SkillInfo) SkillTree(de.Keyle.MyPet.api.skill.skilltree.SkillTree)

Example 7 with SkillInfo

use of de.Keyle.MyPet.api.skill.SkillInfo in project MyPet by xXKeyleXx.

the class SkillTreeLoaderNBT method saveSkillTree.

protected boolean saveSkillTree(ConfigurationNBT nbtConfiguration, String petTypeName) {
    boolean saveMobType = false;
    SkillTreeMobType mobType;
    if (petTypeName.equalsIgnoreCase("default")) {
        mobType = SkillTreeMobType.DEFAULT;
    } else if (SkillTreeMobType.hasMobType(MyPetType.byName(petTypeName, false))) {
        mobType = SkillTreeMobType.getMobTypeByName(petTypeName);
    } else {
        return false;
    }
    if (mobType.getSkillTreeNames().size() != 0) {
        mobType.cleanupPlaces();
        List<TagCompound> skilltreeList = new ArrayList<>();
        for (SkillTree skillTree : mobType.getSkillTrees()) {
            TagCompound skilltreeCompound = new TagCompound();
            skilltreeCompound.getCompoundData().put("Name", new TagString(skillTree.getName()));
            skilltreeCompound.getCompoundData().put("Place", new TagInt(mobType.getSkillTreePlace(skillTree)));
            if (skillTree.hasInheritance()) {
                skilltreeCompound.getCompoundData().put("Inherits", new TagString(skillTree.getInheritance()));
            }
            if (skillTree.hasCustomPermissions()) {
                skilltreeCompound.getCompoundData().put("Permission", new TagString(skillTree.getPermission()));
            }
            if (skillTree.hasDisplayName()) {
                skilltreeCompound.getCompoundData().put("Display", new TagString(skillTree.getDisplayName()));
            }
            if (skillTree.getMaxLevel() > 0) {
                skilltreeCompound.getCompoundData().put("MaxLevel", new TagInt(skillTree.getMaxLevel()));
            }
            if (skillTree.getRequiredLevel() > 1) {
                skilltreeCompound.getCompoundData().put("RequiredLevel", new TagInt(skillTree.getRequiredLevel()));
            }
            if (skillTree.getDescription().size() > 0) {
                List<TagString> descriptionTagList = new ArrayList<>();
                for (String line : skillTree.getDescription()) {
                    descriptionTagList.add(new TagString(line));
                }
                skilltreeCompound.getCompoundData().put("Description", new TagList(descriptionTagList));
            }
            skilltreeCompound.getCompoundData().put("IconItem", skillTree.getIconItem());
            List<TagCompound> levelList = new ArrayList<>();
            for (SkillTreeLevel level : skillTree.getLevelList()) {
                TagCompound levelCompound = new TagCompound();
                levelCompound.getCompoundData().put("Level", new TagInt(level.getLevel()));
                if (level.hasLevelupMessage()) {
                    levelCompound.getCompoundData().put("Message", new TagString(level.getLevelupMessage()));
                }
                List<TagCompound> skillList = new ArrayList<>();
                for (SkillInfo skill : skillTree.getLevel(level.getLevel()).getSkills()) {
                    if (!skill.isAddedByInheritance()) {
                        TagCompound skillCompound = new TagCompound();
                        skillCompound.getCompoundData().put("Name", new TagString(skill.getName()));
                        skillCompound.getCompoundData().put("Properties", skill.getProperties());
                        skillList.add(skillCompound);
                    }
                }
                levelCompound.getCompoundData().put("Skills", new TagList(skillList));
                levelList.add(levelCompound);
            }
            skilltreeCompound.getCompoundData().put("Level", new TagList(levelList));
            skilltreeList.add(skilltreeCompound);
        }
        nbtConfiguration.getNBTCompound().getCompoundData().put("Skilltrees", new TagList(skilltreeList));
        if (mobType.getSkillTreeNames().size() > 0) {
            nbtConfiguration.save();
            saveMobType = true;
        }
    }
    return saveMobType;
}
Also used : SkillInfo(de.Keyle.MyPet.api.skill.SkillInfo) ArrayList(java.util.ArrayList) SkillTree(de.Keyle.MyPet.api.skill.skilltree.SkillTree) SkillTreeLevel(de.Keyle.MyPet.api.skill.skilltree.SkillTreeLevel) SkillTreeMobType(de.Keyle.MyPet.api.skill.skilltree.SkillTreeMobType)

Example 8 with SkillInfo

use of de.Keyle.MyPet.api.skill.SkillInfo in project MyPet by xXKeyleXx.

the class SkillTreeLoaderNBT method loadSkillTree.

protected void loadSkillTree(ConfigurationNBT nbtConfiguration, SkillTreeMobType skillTreeMobType) {
    TagList skilltreeList = nbtConfiguration.getNBTCompound().getAs("Skilltrees", TagList.class);
    for (int i_skilltree = 0; i_skilltree < skilltreeList.size(); i_skilltree++) {
        TagCompound skilltreeCompound = skilltreeList.getTagAs(i_skilltree, TagCompound.class);
        SkillTree skillTree = new SkillTree(skilltreeCompound.getAs("Name", TagString.class).getStringData());
        int place = skilltreeCompound.getAs("Place", TagInt.class).getIntData();
        if (skilltreeCompound.getCompoundData().containsKey("Inherits")) {
            skillTree.setInheritance(skilltreeCompound.getAs("Inherits", TagString.class).getStringData());
        }
        if (skilltreeCompound.getCompoundData().containsKey("Permission")) {
            skillTree.setPermission(skilltreeCompound.getAs("Permission", TagString.class).getStringData());
        }
        if (skilltreeCompound.getCompoundData().containsKey("Display")) {
            skillTree.setDisplayName(skilltreeCompound.getAs("Display", TagString.class).getStringData());
        }
        if (skilltreeCompound.getCompoundData().containsKey("MaxLevel")) {
            skillTree.setMaxLevel(skilltreeCompound.getAs("MaxLevel", TagInt.class).getIntData());
        }
        if (skilltreeCompound.getCompoundData().containsKey("RequiredLevel")) {
            skillTree.setRequiredLevel(skilltreeCompound.getAs("RequiredLevel", TagInt.class).getIntData());
        }
        if (skilltreeCompound.getCompoundData().containsKey("IconItem")) {
            skillTree.setIconItem(skilltreeCompound.getAs("IconItem", TagCompound.class));
        }
        if (skilltreeCompound.getCompoundData().containsKey("Description")) {
            TagList descriptionTagList = skilltreeCompound.getAs("Description", TagList.class);
            for (int i = 0; i < descriptionTagList.size(); i++) {
                skillTree.addDescriptionLine(descriptionTagList.getTagAs(i, TagString.class).getStringData());
            }
        }
        if (skilltreeCompound.getCompoundData().containsKey("Level")) {
            TagList levelList = skilltreeCompound.getAs("Level", TagList.class);
            for (int i_level = 0; i_level < levelList.size(); i_level++) {
                TagCompound levelCompound = levelList.getTag(i_level);
                int thisLevel;
                if (levelCompound.containsKeyAs("Level", TagInt.class)) {
                    thisLevel = levelCompound.getAs("Level", TagInt.class).getIntData();
                } else {
                    thisLevel = levelCompound.getAs("Level", TagShort.class).getShortData();
                }
                SkillTreeLevel newLevel = skillTree.addLevel(thisLevel);
                if (levelCompound.getCompoundData().containsKey("Message")) {
                    String message = levelCompound.getAs("Message", TagString.class).getStringData();
                    newLevel.setLevelupMessage(message);
                }
                TagList skillList = levelCompound.get("Skills");
                for (int i_skill = 0; i_skill < skillList.size(); i_skill++) {
                    TagCompound skillCompound = skillList.getTag(i_skill);
                    String skillName = skillCompound.getAs("Name", TagString.class).getStringData();
                    if (SkillsInfo.getSkillInfoClass(skillName) != null) {
                        TagCompound skillPropertyCompound = skillCompound.get("Properties");
                        SkillInfo skill = SkillsInfo.getNewSkillInfoInstance(skillName);
                        if (skill != null) {
                            skill.setProperties(skillPropertyCompound);
                            skill.setDefaultProperties();
                            skillTree.addSkillToLevel(thisLevel, skill);
                        }
                    }
                }
            }
        }
        skillTreeMobType.addSkillTree(skillTree, place);
    }
}
Also used : SkillTreeLevel(de.Keyle.MyPet.api.skill.skilltree.SkillTreeLevel) SkillInfo(de.Keyle.MyPet.api.skill.SkillInfo) SkillTree(de.Keyle.MyPet.api.skill.skilltree.SkillTree)

Aggregations

SkillInfo (de.Keyle.MyPet.api.skill.SkillInfo)8 SkillTreeLevel (de.Keyle.MyPet.api.skill.skilltree.SkillTreeLevel)7 SkillTree (de.Keyle.MyPet.api.skill.skilltree.SkillTree)6 SkillTreeMobType (de.Keyle.MyPet.api.skill.skilltree.SkillTreeMobType)3 MyPet (de.Keyle.MyPet.api.entity.MyPet)1 MyPetBukkitEntity (de.Keyle.MyPet.api.entity.MyPetBukkitEntity)1 MyPetType (de.Keyle.MyPet.api.entity.MyPetType)1 SpiralAnimation (de.Keyle.MyPet.api.util.animation.particle.SpiralAnimation)1 EntityLocationHolder (de.Keyle.MyPet.api.util.location.EntityLocationHolder)1 ArrayList (java.util.ArrayList)1 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)1 TreePath (javax.swing.tree.TreePath)1 Location (org.bukkit.Location)1 EventHandler (org.bukkit.event.EventHandler)1