Search in sources :

Example 6 with ProgressionPath

use of com.elmakers.mine.bukkit.api.magic.ProgressionPath in project MagicPlugin by elBukkit.

the class SpellProgressAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Mage mage = context.getMage();
    CasterProperties casterProperties = context.getActiveProperties();
    this.context = context;
    Player player = mage.getPlayer();
    if (player == null) {
        return SpellResult.PLAYER_REQUIRED;
    }
    Collection<String> spells = casterProperties.getSpells();
    Collection<ItemStack> upgrades = new ArrayList<>();
    Messages messages = context.getController().getMessages();
    for (String spellKey : spells) {
        MageSpell spell = mage.getSpell(spellKey);
        SpellTemplate upgradeSpell = spell.getUpgrade();
        if (upgradeSpell != null) {
            ItemStack spellItem = MagicPlugin.getAPI().createSpellItem(upgradeSpell.getKey());
            if (spellItem != null) {
                long requiredCastCount = spell.getRequiredUpgradeCasts();
                String requiredPathKey = spell.getRequiredUpgradePath();
                Set<String> requiredPathTags = spell.getRequiredUpgradeTags();
                ItemMeta meta = spellItem.getItemMeta();
                List<String> lore = new ArrayList<>();
                String levelDescription = upgradeSpell.getLevelDescription();
                if (levelDescription == null || levelDescription.isEmpty()) {
                    levelDescription = upgradeSpell.getName();
                }
                lore.add(levelDescription);
                String upgradeDescription = upgradeSpell.getUpgradeDescription();
                if (upgradeDescription != null && !upgradeDescription.isEmpty()) {
                    upgradeDescription = context.getController().getMessages().get("spell.upgrade_description_prefix") + upgradeDescription;
                    InventoryUtils.wrapText(upgradeDescription, lore);
                }
                ProgressionPath currentPath = casterProperties.getPath();
                if (requiredPathKey != null && currentPath == null) {
                    continue;
                }
                if (!upgradeSpell.getName().equals(spell.getName())) {
                    lore.add(context.getMessage("upgrade_name_change", "&r&4Upgrades: &r$name").replace("$name", spell.getName()));
                }
                if (requiredPathKey != null && !currentPath.hasPath(requiredPathKey)) {
                    requiredPathKey = currentPath.translatePath(requiredPathKey);
                    com.elmakers.mine.bukkit.wand.WandUpgradePath upgradePath = com.elmakers.mine.bukkit.wand.WandUpgradePath.getPath(requiredPathKey);
                    if (upgradePath == null)
                        continue;
                    lore.add(context.getMessage("level_requirement").replace("$path", upgradePath.getName()));
                }
                if (requiredPathTags != null && !requiredPathTags.isEmpty() && !currentPath.hasAllTags(requiredPathTags)) {
                    Set<String> tags = currentPath.getMissingTags(requiredPathTags);
                    lore.add(context.getMessage("tags_requirement").replace("$tags", messages.formatList("tags", tags, "name")));
                }
                long castCount = Math.min(spell.getCastCount(), requiredCastCount);
                if (castCount == requiredCastCount) {
                    lore.add(ChatColor.GREEN + context.getMessage("cast_requirement").replace("$current", Long.toString(castCount)).replace("$required", Long.toString(requiredCastCount)));
                } else {
                    lore.add(ChatColor.RED + context.getMessage("cast_requirement").replace("$current", Long.toString(castCount)).replace("$required", Long.toString(requiredCastCount)));
                }
                meta.setLore(lore);
                spellItem.setItemMeta(meta);
                upgrades.add(spellItem);
            }
        }
    }
    String inventoryTitle = context.getMessage("title", "Spell Upgrades");
    int invSize = ((upgrades.size() + 9) / 9) * 9;
    Inventory displayInventory = CompatibilityUtils.createInventory(null, invSize, inventoryTitle);
    for (ItemStack item : upgrades) {
        displayInventory.addItem(item);
    }
    mage.activateGUI(this, displayInventory);
    return SpellResult.CAST;
}
Also used : ProgressionPath(com.elmakers.mine.bukkit.api.magic.ProgressionPath) CasterProperties(com.elmakers.mine.bukkit.api.magic.CasterProperties) Player(org.bukkit.entity.Player) Messages(com.elmakers.mine.bukkit.api.magic.Messages) ArrayList(java.util.ArrayList) Mage(com.elmakers.mine.bukkit.api.magic.Mage) ItemStack(org.bukkit.inventory.ItemStack) MageSpell(com.elmakers.mine.bukkit.api.spell.MageSpell) ItemMeta(org.bukkit.inventory.meta.ItemMeta) Inventory(org.bukkit.inventory.Inventory) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate)

Example 7 with ProgressionPath

use of com.elmakers.mine.bukkit.api.magic.ProgressionPath in project MagicPlugin by elBukkit.

the class MagicRequirement method getRequirementDescription.

@Nullable
public String getRequirementDescription(@Nonnull CastContext context) {
    Mage mage = context.getMage();
    MageController controller = mage.getController();
    Player player = mage.getPlayer();
    if (permissionNode != null && (player == null || !player.hasPermission(permissionNode))) {
        return context.getMessage(SpellResult.INSUFFICIENT_PERMISSION.name().toLowerCase());
    }
    Wand wand = context.getWand();
    if (wand == null && requireWand) {
        return getMessage(context, "no_wand");
    }
    if (requiredTemplate != null) {
        String template = wand.getTemplateKey();
        if (template == null || !template.equals(requiredTemplate)) {
            return getMessage(context, "no_template").replace("$wand", wand.getName());
        }
    }
    if (requiredTemplates != null) {
        String template = wand.getTemplateKey();
        if (template == null || !requiredTemplates.contains(template)) {
            return getMessage(context, "no_template").replace("$wand", wand.getName());
        }
    }
    if (mageClass != null && !mageClass.isEmpty()) {
        if (mage.hasClassUnlocked(mageClass)) {
            return getMessage(context, "no_class").replace("$class", mageClass);
        }
    }
    CasterProperties checkProperties = context.getActiveProperties();
    ProgressionPath path = checkProperties.getPath();
    if (requiredPath != null || exactPath != null) {
        if (path == null) {
            return getMessage(context, "no_path");
        }
        if (requiredPath != null && !path.hasPath(requiredPath)) {
            WandUpgradePath requiresPath = controller.getPath(requiredPath);
            String pathName = requiredPath;
            if (requiresPath != null) {
                pathName = requiresPath.getName();
            } else {
                context.getLogger().warning("Invalid path specified in requirement " + requiredPath);
            }
            return getMessage(context, "no_required_path").replace("$path", pathName);
        }
        if (exactPath != null && !exactPath.equals(path.getKey())) {
            WandUpgradePath requiresPath = controller.getPath(exactPath);
            String pathName = exactPath;
            if (requiresPath != null) {
                pathName = requiresPath.getName();
            } else {
                context.getLogger().warning("Invalid path specified in requirement: " + exactPath);
            }
            return getMessage(context, "no_path_exact").replace("$path", pathName);
        }
        if (requiresCompletedPath != null) {
            boolean hasPathCompleted = false;
            if (path.hasPath(requiresCompletedPath)) {
                if (path.getKey().equals(requiresCompletedPath)) {
                    hasPathCompleted = !path.canProgress(checkProperties);
                } else {
                    hasPathCompleted = true;
                }
            }
            if (!hasPathCompleted) {
                WandUpgradePath requiresPath = controller.getPath(requiresCompletedPath);
                String pathName = requiresCompletedPath;
                if (requiresPath != null) {
                    pathName = requiresPath.getName();
                } else {
                    context.getLogger().warning("Invalid path specified in requirement: " + exactPath);
                }
                return getMessage(context, "no_path_end").replace("$path", pathName);
            }
        }
    }
    if (wandProperties != null) {
        String message = getRequiredProperty(context, wand, wandProperties);
        if (message != null) {
            return message;
        }
    }
    if (classProperties != null) {
        MageClass activeClass = mageClass == null ? mage.getActiveClass() : mage.getClass(mageClass);
        if (activeClass == null) {
            return getMessage(context, "no_path");
        }
        String message = getRequiredProperty(context, activeClass, classProperties);
        if (message != null) {
            return message;
        }
    }
    if (attributes != null) {
        for (PropertyRequirement requirement : attributes) {
            String key = requirement.key;
            Double value = mage.getAttribute(key);
            String message = checkRequiredProperty(context, requirement, key, value);
            if (message != null) {
                return message;
            }
        }
    }
    return null;
}
Also used : ProgressionPath(com.elmakers.mine.bukkit.api.magic.ProgressionPath) WandUpgradePath(com.elmakers.mine.bukkit.api.wand.WandUpgradePath) MageController(com.elmakers.mine.bukkit.api.magic.MageController) CasterProperties(com.elmakers.mine.bukkit.api.magic.CasterProperties) Player(org.bukkit.entity.Player) MageClass(com.elmakers.mine.bukkit.api.magic.MageClass) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Wand(com.elmakers.mine.bukkit.api.wand.Wand) Nullable(javax.annotation.Nullable)

Aggregations

ProgressionPath (com.elmakers.mine.bukkit.api.magic.ProgressionPath)7 CasterProperties (com.elmakers.mine.bukkit.api.magic.CasterProperties)6 Mage (com.elmakers.mine.bukkit.api.magic.Mage)6 Wand (com.elmakers.mine.bukkit.api.wand.Wand)4 ItemStack (org.bukkit.inventory.ItemStack)4 MageClass (com.elmakers.mine.bukkit.api.magic.MageClass)3 MageSpell (com.elmakers.mine.bukkit.api.spell.MageSpell)3 SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)3 ArrayList (java.util.ArrayList)3 Nullable (javax.annotation.Nullable)3 Player (org.bukkit.entity.Player)3 ItemMeta (org.bukkit.inventory.meta.ItemMeta)3 MageController (com.elmakers.mine.bukkit.api.magic.MageController)2 Spell (com.elmakers.mine.bukkit.api.spell.Spell)2 Messages (com.elmakers.mine.bukkit.api.magic.Messages)1 Requirement (com.elmakers.mine.bukkit.api.requirements.Requirement)1 PrerequisiteSpell (com.elmakers.mine.bukkit.api.spell.PrerequisiteSpell)1 WandUpgradePath (com.elmakers.mine.bukkit.api.wand.WandUpgradePath)1 BaseSpell (com.elmakers.mine.bukkit.spell.BaseSpell)1 HashMap (java.util.HashMap)1