Search in sources :

Example 6 with MageSpell

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

the class HeroesManager method createSkillSpell.

@Nullable
public SpellTemplate createSkillSpell(MagicController controller, String skillName) {
    if (skills == null)
        return null;
    Skill skill = skills.getSkill(skillName);
    if (skill == null)
        return null;
    MageSpell newSpell = new HeroesSkillSpell();
    newSpell.initialize(controller);
    ConfigurationSection config = new MemoryConfiguration();
    String iconURL = SkillConfigManager.getRaw(skill, "icon-url", SkillConfigManager.getRaw(skill, "icon_url", null));
    if (iconURL == null || iconURL.isEmpty()) {
        String icon = SkillConfigManager.getRaw(skill, "icon", null);
        if (icon == null || icon.isEmpty()) {
            config.set("icon", controller.getDefaultSkillIcon());
        } else if (icon.startsWith("http://")) {
            config.set("icon_url", icon);
        } else {
            config.set("icon", icon);
        }
    } else {
        config.set("icon_url", iconURL);
    }
    String iconDisabledURL = SkillConfigManager.getRaw(skill, "icon-disabled-url", SkillConfigManager.getRaw(skill, "icon_disabled_url", null));
    if (iconDisabledURL == null || iconDisabledURL.isEmpty()) {
        String icon = SkillConfigManager.getRaw(skill, "icon-disabled", SkillConfigManager.getRaw(skill, "icon_disabled", null));
        if (icon != null && !icon.isEmpty()) {
            if (icon.startsWith("http://")) {
                config.set("icon_disabled_url", icon);
            } else {
                config.set("icon_disabled", icon);
            }
        }
    } else {
        config.set("icon_disabled_url", iconDisabledURL);
    }
    String nameTemplate = controller.getMessages().get("skills.item_name", "$skill");
    String skillDisplayName = SkillConfigManager.getRaw(skill, "name", skill.getName());
    config.set("name", nameTemplate.replace("$skill", skillDisplayName));
    config.set("category", "skills");
    String descriptionTemplate = controller.getMessages().get("skills.item_description", "$description");
    descriptionTemplate = descriptionTemplate.replace("$description", SkillConfigManager.getRaw(skill, "description", ""));
    config.set("description", descriptionTemplate);
    newSpell.loadTemplate("heroes*" + skillName, config);
    return newSpell;
}
Also used : Skill(com.herocraftonline.heroes.characters.skill.Skill) ActiveSkill(com.herocraftonline.heroes.characters.skill.ActiveSkill) MemoryConfiguration(org.bukkit.configuration.MemoryConfiguration) MageSpell(com.elmakers.mine.bukkit.api.spell.MageSpell) ConfigurationSection(org.bukkit.configuration.ConfigurationSection) Nullable(javax.annotation.Nullable)

Example 7 with MageSpell

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

the class SpellShopAction method getItems.

@Nullable
@Override
public List<ShopItem> getItems(CastContext context) {
    Mage mage = context.getMage();
    Wand wand = mage.getActiveWand();
    CasterProperties caster = getCaster(context);
    // Check for auto upgrade, if the player can no longer progress on their current path and is
    // eligible for an upgrade, we will upgrade them and skip showing the spell shop so the player
    // can see their upgrade rewards.
    boolean canProgress = false;
    // TODO: Make this work on CasterProperties
    if (autoUpgrade && wand != null) {
        canProgress = caster.canProgress();
        if (!canProgress && wand.checkUpgrade(true) && wand.upgrade(false)) {
            return null;
        }
    }
    ProgressionPath currentPath = caster.getPath();
    if (!castsSpells && !allowLocked && wand != null && wand.isLocked()) {
        context.showMessage(context.getMessage("no_path", getDefaultMessage(context, "no_path")).replace("$wand", wand.getName()));
        return null;
    }
    // Load spells
    Map<String, Double> spellPrices = new HashMap<>();
    if (spells.size() > 0) {
        spellPrices.putAll(spells);
    } else {
        if (currentPath == null) {
            String name = wand == null ? "" : wand.getName();
            context.showMessage(context.getMessage("no_path", getDefaultMessage(context, "no_path")).replace("$wand", name));
            return null;
        }
        if (showPath) {
            Collection<String> pathSpells = currentPath.getSpells();
            for (String pathSpell : pathSpells) {
                spellPrices.put(pathSpell, null);
            }
        }
        if (showRequired) {
            Collection<String> requiredSpells = currentPath.getRequiredSpells();
            for (String requiredSpell : requiredSpells) {
                spellPrices.put(requiredSpell, null);
            }
        }
        if (showUpgrades) {
            Collection<String> spells = caster.getSpells();
            for (String spellKey : spells) {
                MageSpell spell = mage.getSpell(spellKey);
                SpellTemplate upgradeSpell = spell.getUpgrade();
                if (upgradeSpell != null) {
                    spellPrices.put(upgradeSpell.getKey(), null);
                }
            }
        }
    }
    List<ShopItem> shopItems = new ArrayList<>();
    for (Map.Entry<String, Double> spellValue : spellPrices.entrySet()) {
        ShopItem shopItem = createShopItem(spellValue.getKey(), spellValue.getValue(), context);
        if (shopItem != null) {
            shopItems.add(shopItem);
        }
    }
    Collections.sort(shopItems);
    if (spells.size() == 0 && showExtra && !castsSpells && currentPath != null) {
        Collection<String> extraSpells = currentPath.getExtraSpells();
        List<ShopItem> extraItems = new ArrayList<>();
        for (String spellKey : extraSpells) {
            ShopItem shopItem = createShopItem(spellKey, null, context);
            if (shopItem != null) {
                ItemStack spellItem = shopItem.getItem();
                ItemMeta meta = spellItem.getItemMeta();
                List<String> itemLore = meta.getLore();
                itemLore.add(context.getMessage("extra_spell", getDefaultMessage(context, "extra_spell")));
                meta.setLore(itemLore);
                spellItem.setItemMeta(meta);
                extraItems.add(shopItem);
            }
        }
        Collections.sort(extraItems);
        shopItems.addAll(extraItems);
    }
    // If there is nothing here for us to do, check for upgrades being blocked
    // we will upgrade the wand here, but in theory that should never happen since we
    // checked for upgrades above.
    // TODO: Make this work for caster...
    mage.sendDebugMessage(ChatColor.GOLD + "Spells to buy: " + shopItems.size(), 2);
    if (wand != null && shopItems.size() == 0) {
        boolean canUpgrade = autoUpgrade && wand.checkUpgrade(false);
        boolean hasUpgrade = autoUpgrade && wand.hasUpgrade();
        if (!canProgress && !hasUpgrade) {
            context.showMessage(context.getMessage("no_upgrade", getDefaultMessage(context, "no_upgrade")).replace("$wand", wand.getName()));
            return null;
        } else if (canUpgrade) {
            wand.upgrade(false);
            return null;
        } else {
            return null;
        }
    }
    return shopItems;
}
Also used : ProgressionPath(com.elmakers.mine.bukkit.api.magic.ProgressionPath) CasterProperties(com.elmakers.mine.bukkit.api.magic.CasterProperties) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Wand(com.elmakers.mine.bukkit.api.wand.Wand) Mage(com.elmakers.mine.bukkit.api.magic.Mage) ItemStack(org.bukkit.inventory.ItemStack) HashMap(java.util.HashMap) Map(java.util.Map) MageSpell(com.elmakers.mine.bukkit.api.spell.MageSpell) ItemMeta(org.bukkit.inventory.meta.ItemMeta) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate) Nullable(javax.annotation.Nullable)

Example 8 with MageSpell

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

the class SpellShopAction method createShopItem.

@Nullable
private ShopItem createShopItem(String key, Double worth, CastContext context) {
    CasterProperties caster = getCaster(context);
    Mage mage = context.getMage();
    MageController controller = context.getController();
    ProgressionPath currentPath = caster.getPath();
    key = context.parameterize(key);
    String spellKey = key.split(" ", 2)[0];
    if (!castsSpells && caster.hasSpell(spellKey)) {
        mage.sendDebugMessage(ChatColor.GRAY + " Skipping " + spellKey + ", already have it", 3);
        return null;
    }
    SpellTemplate spell = controller.getSpellTemplate(spellKey);
    if (spell == null) {
        mage.sendDebugMessage(ChatColor.RED + " Skipping " + spellKey + ", invalid spell", 0);
        return null;
    }
    if (worth == null) {
        worth = spell.getWorth();
    }
    if (worth <= 0 && !showFree) {
        mage.sendDebugMessage(ChatColor.YELLOW + " Skipping " + spellKey + ", is free (worth " + worth + ")", 3);
        return null;
    }
    if (!spell.hasCastPermission(mage.getCommandSender())) {
        mage.sendDebugMessage(ChatColor.YELLOW + " Skipping " + spellKey + ", no permission", 3);
        return null;
    }
    ItemStack spellItem = controller.createSpellItem(key, castsSpells);
    if (!castsSpells) {
        Spell mageSpell = caster.getSpell(spellKey);
        String requiredPathKey = mageSpell != null ? mageSpell.getRequiredUpgradePath() : null;
        Set<String> requiredPathTags = mageSpell != null ? mageSpell.getRequiredUpgradeTags() : null;
        long requiredCastCount = mageSpell != null ? mageSpell.getRequiredUpgradeCasts() : 0;
        long castCount = mageSpell != null ? Math.min(mageSpell.getCastCount(), requiredCastCount) : 0;
        Collection<PrerequisiteSpell> missingSpells = PrerequisiteSpell.getMissingRequirements(caster, spell);
        ItemMeta meta = spellItem.getItemMeta();
        List<String> itemLore = meta.getLore();
        if (itemLore == null) {
            mage.sendDebugMessage(ChatColor.RED + " Skipping " + spellKey + ", spell item is invalid", 0);
            return null;
        }
        List<String> lore = new ArrayList<>();
        if (spell.getSpellKey().getLevel() > 1 && itemLore.size() > 0) {
            lore.add(itemLore.get(0));
        }
        String upgradeDescription = spell.getUpgradeDescription();
        if (showUpgrades && upgradeDescription != null && !upgradeDescription.isEmpty()) {
            upgradeDescription = controller.getMessages().get("spell.upgrade_description_prefix") + upgradeDescription;
            InventoryUtils.wrapText(upgradeDescription, lore);
        }
        String unpurchasableMessage = null;
        Collection<Requirement> requirements = spell.getRequirements();
        String requirementMissing = controller.checkRequirements(context, requirements);
        if (requirementMissing != null) {
            unpurchasableMessage = requirementMissing;
            InventoryUtils.wrapText(unpurchasableMessage, lore);
        }
        if ((requiredPathKey != null && !currentPath.hasPath(requiredPathKey)) || (requiresCastCounts && requiredCastCount > 0 && castCount < requiredCastCount) || (requiredPathTags != null && !currentPath.hasAllTags(requiredPathTags)) || !missingSpells.isEmpty()) {
            if (mageSpell != null && !spell.getName().equals(mageSpell.getName())) {
                lore.add(context.getMessage("upgrade_name_change", getDefaultMessage(context, "upgrade_name_change")).replace("$name", mageSpell.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) {
                    unpurchasableMessage = context.getMessage("level_requirement", getDefaultMessage(context, "level_requirement")).replace("$path", upgradePath.getName());
                    InventoryUtils.wrapText(unpurchasableMessage, lore);
                }
            } else if (requiredPathTags != null && !requiredPathTags.isEmpty() && !currentPath.hasAllTags(requiredPathTags)) {
                Set<String> tags = currentPath.getMissingTags(requiredPathTags);
                unpurchasableMessage = context.getMessage("tags_requirement", getDefaultMessage(context, "tags_requirement")).replace("$tags", controller.getMessages().formatList("tags", tags, "name"));
                InventoryUtils.wrapText(unpurchasableMessage, lore);
            }
            if (requiresCastCounts && requiredCastCount > 0 && castCount < requiredCastCount) {
                unpurchasableMessage = ChatColor.RED + context.getMessage("cast_requirement", getDefaultMessage(context, "cast_requirement")).replace("$current", Long.toString(castCount)).replace("$required", Long.toString(requiredCastCount));
                InventoryUtils.wrapText(unpurchasableMessage, lore);
            }
            if (!missingSpells.isEmpty()) {
                List<String> spells = new ArrayList<>(missingSpells.size());
                for (PrerequisiteSpell s : missingSpells) {
                    SpellTemplate template = context.getController().getSpellTemplate(s.getSpellKey().getKey());
                    String spellMessage = context.getMessage("prerequisite_spell_level", getDefaultMessage(context, "prerequisite_spell_level")).replace("$name", template.getName());
                    if (s.getProgressLevel() > 1) {
                        spellMessage += context.getMessage("prerequisite_spell_progress_level", getDefaultMessage(context, "prerequisite_spell_progress_level")).replace("$level", Long.toString(s.getProgressLevel())).replace("$max_level", Long.toString(Math.max(1, template.getMaxProgressLevel())));
                    }
                    spells.add(spellMessage);
                }
                unpurchasableMessage = ChatColor.RED + context.getMessage("required_spells", getDefaultMessage(context, "required_spells")).replace("$spells", StringUtils.join(spells, ", "));
                InventoryUtils.wrapText(ChatColor.GOLD + unpurchasableMessage, lore);
            }
        }
        for (int i = (spell.getSpellKey().getLevel() > 1 ? 1 : 0); i < itemLore.size(); i++) {
            lore.add(itemLore.get(i));
        }
        meta.setLore(lore);
        spellItem.setItemMeta(meta);
        if (unpurchasableMessage != null)
            InventoryUtils.setMeta(spellItem, "unpurchasable", unpurchasableMessage);
    }
    return new ShopItem(spellItem, worth);
}
Also used : ProgressionPath(com.elmakers.mine.bukkit.api.magic.ProgressionPath) CasterProperties(com.elmakers.mine.bukkit.api.magic.CasterProperties) Set(java.util.Set) ArrayList(java.util.ArrayList) Spell(com.elmakers.mine.bukkit.api.spell.Spell) MageSpell(com.elmakers.mine.bukkit.api.spell.MageSpell) BaseSpell(com.elmakers.mine.bukkit.spell.BaseSpell) PrerequisiteSpell(com.elmakers.mine.bukkit.api.spell.PrerequisiteSpell) MageController(com.elmakers.mine.bukkit.api.magic.MageController) Requirement(com.elmakers.mine.bukkit.api.requirements.Requirement) Mage(com.elmakers.mine.bukkit.api.magic.Mage) PrerequisiteSpell(com.elmakers.mine.bukkit.api.spell.PrerequisiteSpell) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate) Nullable(javax.annotation.Nullable)

Example 9 with MageSpell

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

the class CastContext method setSpell.

public void setSpell(Spell spell) {
    this.spell = spell;
    if (spell instanceof BaseSpell) {
        this.baseSpell = (BaseSpell) spell;
    }
    if (spell instanceof MageSpell) {
        MageSpell mageSpell = (MageSpell) spell;
        this.mage = mageSpell.getMage();
        this.wand = mage.getActiveWand();
        this.mageClass = (this.wand == null ? this.mage.getActiveClass() : this.wand.getMageClass());
    }
    if (spell instanceof UndoableSpell) {
        this.undoSpell = (UndoableSpell) spell;
        undoList = this.undoSpell.getUndoList();
    }
    if (spell instanceof TargetingSpell) {
        this.targetingSpell = (TargetingSpell) spell;
    }
    if (spell instanceof BlockSpell) {
        this.blockSpell = (BlockSpell) spell;
    }
    if (spell instanceof BrushSpell) {
        this.brushSpell = (BrushSpell) spell;
    }
}
Also used : BrushSpell(com.elmakers.mine.bukkit.spell.BrushSpell) BaseSpell(com.elmakers.mine.bukkit.spell.BaseSpell) MageSpell(com.elmakers.mine.bukkit.api.spell.MageSpell) TargetingSpell(com.elmakers.mine.bukkit.spell.TargetingSpell) BlockSpell(com.elmakers.mine.bukkit.spell.BlockSpell) UndoableSpell(com.elmakers.mine.bukkit.spell.UndoableSpell)

Example 10 with MageSpell

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

the class Mage method createSpell.

@Nullable
protected MageSpell createSpell(String key) {
    MageSpell playerSpell = spells.get(key);
    if (playerSpell != null) {
        playerSpell.setMage(this);
        return playerSpell;
    }
    SpellTemplate spellTemplate = controller.getSpellTemplate(key);
    if (spellTemplate == null)
        return null;
    Spell newSpell = spellTemplate.createSpell();
    if (newSpell == null || !(newSpell instanceof MageSpell))
        return null;
    playerSpell = (MageSpell) newSpell;
    spells.put(newSpell.getKey(), playerSpell);
    playerSpell.setMage(this);
    return playerSpell;
}
Also used : MageSpell(com.elmakers.mine.bukkit.api.spell.MageSpell) MageSpell(com.elmakers.mine.bukkit.api.spell.MageSpell) ActionSpell(com.elmakers.mine.bukkit.spell.ActionSpell) Spell(com.elmakers.mine.bukkit.api.spell.Spell) BaseSpell(com.elmakers.mine.bukkit.spell.BaseSpell) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate) Nullable(javax.annotation.Nullable)

Aggregations

MageSpell (com.elmakers.mine.bukkit.api.spell.MageSpell)14 SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)6 ArrayList (java.util.ArrayList)6 Nullable (javax.annotation.Nullable)6 CasterProperties (com.elmakers.mine.bukkit.api.magic.CasterProperties)3 Mage (com.elmakers.mine.bukkit.api.magic.Mage)3 ProgressionPath (com.elmakers.mine.bukkit.api.magic.ProgressionPath)3 BaseSpell (com.elmakers.mine.bukkit.spell.BaseSpell)3 ItemStack (org.bukkit.inventory.ItemStack)3 ItemMeta (org.bukkit.inventory.meta.ItemMeta)3 SpellData (com.elmakers.mine.bukkit.api.data.SpellData)2 Messages (com.elmakers.mine.bukkit.api.magic.Messages)2 Spell (com.elmakers.mine.bukkit.api.spell.Spell)2 Wand (com.elmakers.mine.bukkit.api.wand.Wand)2 ActionSpell (com.elmakers.mine.bukkit.spell.ActionSpell)2 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)2 Player (org.bukkit.entity.Player)2 CastEvent (com.elmakers.mine.bukkit.api.event.CastEvent)1 PreCastEvent (com.elmakers.mine.bukkit.api.event.PreCastEvent)1 MageController (com.elmakers.mine.bukkit.api.magic.MageController)1