Search in sources :

Example 1 with SpellKey

use of com.elmakers.mine.bukkit.api.spell.SpellKey in project MagicPlugin by elBukkit.

the class BaseSpell method loadTemplate.

@Override
public void loadTemplate(String key, ConfigurationSection node) {
    spellKey = new SpellKey(key);
    this.configuration = node;
    this.loadTemplate(node);
}
Also used : SpellKey(com.elmakers.mine.bukkit.api.spell.SpellKey)

Example 2 with SpellKey

use of com.elmakers.mine.bukkit.api.spell.SpellKey in project MagicPlugin by elBukkit.

the class MagicController method loadSpellData.

protected void loadSpellData() {
    try {
        ConfigurationSection configNode = loadDataFile(SPELLS_DATA_FILE);
        if (configNode == null)
            return;
        Set<String> keys = configNode.getKeys(false);
        for (String key : keys) {
            ConfigurationSection node = configNode.getConfigurationSection(key);
            SpellKey spellKey = new SpellKey(key);
            SpellData templateData = templateDataMap.get(spellKey.getBaseKey());
            if (templateData == null) {
                templateData = new SpellData(spellKey.getBaseKey());
                templateDataMap.put(templateData.getKey().getBaseKey(), templateData);
            }
            templateData.setCastCount(templateData.getCastCount() + node.getLong("cast_count", 0));
            templateData.setLastCast(Math.max(templateData.getLastCast(), node.getLong("last_cast", 0)));
        }
    } catch (Exception ex) {
        getLogger().warning("Failed to load spell metrics");
    }
}
Also used : SpellData(com.elmakers.mine.bukkit.api.data.SpellData) SpellKey(com.elmakers.mine.bukkit.api.spell.SpellKey) InvalidConfigurationException(org.bukkit.configuration.InvalidConfigurationException) IOException(java.io.IOException) ParseException(java.text.ParseException) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 3 with SpellKey

use of com.elmakers.mine.bukkit.api.spell.SpellKey in project MagicPlugin by elBukkit.

the class MagicController method getSpellBook.

public ItemStack getSpellBook(com.elmakers.mine.bukkit.api.spell.SpellCategory category, int count) {
    Map<String, List<SpellTemplate>> categories = new HashMap<>();
    Collection<SpellTemplate> spellVariants = spells.values();
    String categoryKey = category == null ? null : category.getKey();
    for (SpellTemplate spell : spellVariants) {
        if (spell.isHidden() || spell.getSpellKey().isVariant())
            continue;
        com.elmakers.mine.bukkit.api.spell.SpellCategory spellCategory = spell.getCategory();
        if (spellCategory == null)
            continue;
        String spellCategoryKey = spellCategory.getKey();
        if (categoryKey == null || spellCategoryKey.equalsIgnoreCase(categoryKey)) {
            List<SpellTemplate> categorySpells = categories.get(spellCategoryKey);
            if (categorySpells == null) {
                categorySpells = new ArrayList<>();
                categories.put(spellCategoryKey, categorySpells);
            }
            categorySpells.add(spell);
        }
    }
    List<String> categoryKeys = new ArrayList<>(categories.keySet());
    Collections.sort(categoryKeys);
    // Hrm? So much Copy+paste! :(
    CostReducer reducer = null;
    ItemStack bookItem = new ItemStack(Material.WRITTEN_BOOK, count);
    BookMeta book = (BookMeta) bookItem.getItemMeta();
    book.setAuthor(messages.get("books.default.author"));
    String title = null;
    if (category != null) {
        title = messages.get("books.default.title").replace("$category", category.getName());
    } else {
        title = messages.get("books.all.title");
    }
    book.setTitle(title);
    List<String> pages = new ArrayList<>();
    Set<String> paths = WandUpgradePath.getPathKeys();
    for (String key : categoryKeys) {
        category = getCategory(key);
        title = messages.get("books.default.title").replace("$category", category.getName());
        String description = "" + ChatColor.BOLD + ChatColor.BLUE + title + "\n\n";
        description += "" + ChatColor.RESET + ChatColor.DARK_BLUE + category.getDescription();
        pages.add(description);
        List<SpellTemplate> categorySpells = categories.get(key);
        Collections.sort(categorySpells);
        for (SpellTemplate spell : categorySpells) {
            List<String> lines = new ArrayList<>();
            lines.add("" + ChatColor.GOLD + ChatColor.BOLD + spell.getName());
            lines.add("" + ChatColor.RESET);
            String spellDescription = spell.getDescription();
            if (spellDescription != null && spellDescription.length() > 0) {
                lines.add("" + ChatColor.BLACK + spellDescription);
                lines.add("");
            }
            String spellCooldownDescription = spell.getCooldownDescription();
            if (spellCooldownDescription != null && spellCooldownDescription.length() > 0) {
                spellCooldownDescription = messages.get("cooldown.description").replace("$time", spellCooldownDescription);
                lines.add("" + ChatColor.DARK_PURPLE + spellCooldownDescription);
            }
            String spellMageCooldownDescription = spell.getMageCooldownDescription();
            if (spellMageCooldownDescription != null && spellMageCooldownDescription.length() > 0) {
                spellMageCooldownDescription = messages.get("cooldown.mage_description").replace("$time", spellMageCooldownDescription);
                lines.add("" + ChatColor.RED + spellMageCooldownDescription);
            }
            Collection<CastingCost> costs = spell.getCosts();
            if (costs != null) {
                for (CastingCost cost : costs) {
                    if (!cost.isEmpty(reducer)) {
                        lines.add(ChatColor.DARK_PURPLE + messages.get("wand.costs_description").replace("$description", cost.getFullDescription(messages, reducer)));
                    }
                }
            }
            Collection<CastingCost> activeCosts = spell.getActiveCosts();
            if (activeCosts != null) {
                for (CastingCost cost : activeCosts) {
                    if (!cost.isEmpty(reducer)) {
                        lines.add(ChatColor.DARK_PURPLE + messages.get("wand.active_costs_description").replace("$description", cost.getFullDescription(messages, reducer)));
                    }
                }
            }
            for (String pathKey : paths) {
                WandUpgradePath checkPath = WandUpgradePath.getPath(pathKey);
                if (!checkPath.isHidden() && (checkPath.hasSpell(spell.getKey()) || checkPath.hasExtraSpell(spell.getKey()))) {
                    lines.add(ChatColor.DARK_BLUE + messages.get("spell.available_path").replace("$path", checkPath.getName()));
                    break;
                }
            }
            for (String pathKey : paths) {
                WandUpgradePath checkPath = WandUpgradePath.getPath(pathKey);
                if (checkPath.requiresSpell(spell.getKey())) {
                    lines.add(ChatColor.DARK_RED + messages.get("spell.required_path").replace("$path", checkPath.getName()));
                    break;
                }
            }
            String duration = spell.getDurationDescription(messages);
            if (duration != null) {
                lines.add(ChatColor.DARK_GREEN + duration);
            } else if (spell.showUndoable()) {
                if (spell.isUndoable()) {
                    String undoable = messages.get("spell.undoable", "");
                    if (undoable != null && !undoable.isEmpty()) {
                        lines.add(undoable);
                    }
                } else {
                    String notUndoable = messages.get("spell.not_undoable", "");
                    if (notUndoable != null && !notUndoable.isEmpty()) {
                        lines.add(notUndoable);
                    }
                }
            }
            if (spell.usesBrush()) {
                lines.add(ChatColor.DARK_GRAY + messages.get("spell.brush"));
            }
            SpellKey baseKey = spell.getSpellKey();
            SpellKey upgradeKey = new SpellKey(baseKey.getBaseKey(), baseKey.getLevel() + 1);
            SpellTemplate upgradeSpell = getSpellTemplate(upgradeKey.getKey());
            int spellLevels = 0;
            while (upgradeSpell != null) {
                spellLevels++;
                upgradeKey = new SpellKey(upgradeKey.getBaseKey(), upgradeKey.getLevel() + 1);
                upgradeSpell = getSpellTemplate(upgradeKey.getKey());
            }
            if (spellLevels > 0) {
                spellLevels++;
                lines.add(ChatColor.DARK_AQUA + messages.get("spell.levels_available").replace("$levels", Integer.toString(spellLevels)));
            }
            String usage = spell.getUsage();
            if (usage != null && usage.length() > 0) {
                lines.add("" + ChatColor.GRAY + ChatColor.ITALIC + usage + ChatColor.RESET);
                lines.add("");
            }
            String spellExtendedDescription = spell.getExtendedDescription();
            if (spellExtendedDescription != null && spellExtendedDescription.length() > 0) {
                lines.add("" + ChatColor.BLACK + spellExtendedDescription);
                lines.add("");
            }
            pages.add(StringUtils.join(lines, "\n"));
        }
    }
    book.setPages(pages);
    bookItem.setItemMeta(book);
    return bookItem;
}
Also used : WandUpgradePath(com.elmakers.mine.bukkit.wand.WandUpgradePath) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) SpellKey(com.elmakers.mine.bukkit.api.spell.SpellKey) CastingCost(com.elmakers.mine.bukkit.api.spell.CastingCost) CostReducer(com.elmakers.mine.bukkit.api.spell.CostReducer) ArrayList(java.util.ArrayList) UndoList(com.elmakers.mine.bukkit.api.block.UndoList) List(java.util.List) ItemStack(org.bukkit.inventory.ItemStack) BookMeta(org.bukkit.inventory.meta.BookMeta) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate)

Example 4 with SpellKey

use of com.elmakers.mine.bukkit.api.spell.SpellKey in project MagicPlugin by elBukkit.

the class HeroesSpellSkill method getDefaultConfig.

@Override
public ConfigurationSection getDefaultConfig() {
    ConfigurationSection node = super.getDefaultConfig();
    // Add in all configured spell parameters
    // Change keys to match heroes-format
    ConfigurationSection spellParameters = spellTemplate.getSpellParameters();
    if (spellParameters != null) {
        Set<String> parameterKeys = spellParameters.getKeys(false);
        for (String parameterKey : parameterKeys) {
            if (!spellParameters.isConfigurationSection(parameterKey) && !spellParameters.isList(parameterKey)) {
                String heroesKey = magicToHeroes(parameterKey);
                Object value = spellParameters.get(parameterKey);
                node.set(heroesKey, value);
                parameters.set(heroesKey, value);
            }
        }
    }
    node.set("icon-url", spellTemplate.getIconURL());
    MaterialAndData icon = spellTemplate.getIcon();
    if (icon != null && icon.getMaterial() != Material.AIR) {
        node.set("icon", icon.getKey());
    }
    MaterialAndData disabledIcon = spellTemplate.getDisabledIcon();
    if (disabledIcon != null && disabledIcon.getMaterial() != Material.AIR) {
        node.set("icon-disabled", disabledIcon.getKey());
    }
    node.set("icon-url", spellTemplate.getIconURL());
    node.set("icon-disabled-url", spellTemplate.getDisabledIconURL());
    node.set("cooldown", spellTemplate.getCooldown());
    node.set("name", spellTemplate.getName());
    Collection<CastingCost> costs = spellTemplate.getCosts();
    if (costs != null) {
        for (CastingCost cost : costs) {
            if (cost.getMana() > 0) {
                node.set(SkillSetting.MANA.node(), cost.getMana());
            }
        // TODO: Reagent costs from item costs
        }
    }
    // Check for an upgrade, set tier if present
    SpellKey upgradeKey = new SpellKey(spellTemplate.getSpellKey().getBaseKey(), 2);
    SpellTemplate upgrade = controller.getSpellTemplate(upgradeKey.getKey());
    if (upgrade != null) {
        int maxUpgrade = 2;
        while (upgrade != null) {
            upgradeKey = new SpellKey(spellTemplate.getSpellKey().getBaseKey(), maxUpgrade + 1);
            upgrade = controller.getSpellTemplate(upgradeKey.getKey());
            if (upgrade != null)
                maxUpgrade++;
        }
        node.set("tier", 1);
        node.set("tier-max", maxUpgrade);
    }
    return node;
}
Also used : CastingCost(com.elmakers.mine.bukkit.api.spell.CastingCost) MaterialAndData(com.elmakers.mine.bukkit.api.block.MaterialAndData) SpellKey(com.elmakers.mine.bukkit.api.spell.SpellKey) ConfigurationSection(org.bukkit.configuration.ConfigurationSection) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate)

Example 5 with SpellKey

use of com.elmakers.mine.bukkit.api.spell.SpellKey in project MagicPlugin by elBukkit.

the class CasterProperties method getSpellTemplate.

@Nullable
@Override
public SpellTemplate getSpellTemplate(String spellKey) {
    SpellKey key = new SpellKey(spellKey);
    Collection<String> spells = getBaseSpells();
    if (!spells.contains(key.getBaseKey()))
        return null;
    SpellKey baseKey = new SpellKey(key.getBaseKey(), getSpellLevel(key.getBaseKey()));
    return controller.getSpellTemplate(baseKey.getKey());
}
Also used : SpellKey(com.elmakers.mine.bukkit.api.spell.SpellKey) Nullable(javax.annotation.Nullable)

Aggregations

SpellKey (com.elmakers.mine.bukkit.api.spell.SpellKey)30 SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)9 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)9 ArrayList (java.util.ArrayList)6 ItemStack (org.bukkit.inventory.ItemStack)6 Nullable (javax.annotation.Nullable)5 HashMap (java.util.HashMap)4 HashSet (java.util.HashSet)4 List (java.util.List)4 Mage (com.elmakers.mine.bukkit.api.magic.Mage)3 MageController (com.elmakers.mine.bukkit.api.magic.MageController)3 Map (java.util.Map)3 Set (java.util.Set)3 CastingCost (com.elmakers.mine.bukkit.api.spell.CastingCost)2 Spell (com.elmakers.mine.bukkit.api.spell.Spell)2 MemoryConfiguration (org.bukkit.configuration.MemoryConfiguration)2 Inventory (org.bukkit.inventory.Inventory)2 MaterialAndData (com.elmakers.mine.bukkit.api.block.MaterialAndData)1 UndoList (com.elmakers.mine.bukkit.api.block.UndoList)1 SpellData (com.elmakers.mine.bukkit.api.data.SpellData)1