Search in sources :

Example 1 with CastEvent

use of com.elmakers.mine.bukkit.api.event.CastEvent in project MagicPlugin by elBukkit.

the class EvtCast method check.

@Override
public boolean check(Event event) {
    if (!(event instanceof CastEvent))
        return false;
    final CastEvent spellCast = (CastEvent) event;
    if (spells != null) {
        String spellKey = spellCast.getSpell().getKey();
        String spellName = ChatColor.stripColor(spellCast.getSpell().getName());
        for (String spell : spells.getAll()) {
            if (spellKey.equalsIgnoreCase(spell)) {
                return true;
            }
            if (spellName.equalsIgnoreCase(spell)) {
                return true;
            }
        }
        return false;
    }
    return true;
}
Also used : PreCastEvent(com.elmakers.mine.bukkit.api.event.PreCastEvent) CastEvent(com.elmakers.mine.bukkit.api.event.CastEvent)

Example 2 with CastEvent

use of com.elmakers.mine.bukkit.api.event.CastEvent in project MagicPlugin by elBukkit.

the class BaseSpell method finish.

@Override
public void finish(com.elmakers.mine.bukkit.api.action.CastContext context) {
    SpellResult result = context.getResult();
    // Notify other plugins of this spell cast
    CastEvent castEvent = new CastEvent(mage, this, result);
    Bukkit.getPluginManager().callEvent(castEvent);
    // Message targets
    if (result.isSuccess() && (loud || (!mage.isQuiet() && !quiet))) {
        messageTargets("cast_player_message");
    }
    // Clear cooldown on miss
    if (result.shouldRefundCooldown(castOnNoTarget)) {
        clearCooldown();
    }
    if (cancelEffects) {
        context.cancelEffects();
    }
    // Track cast counts
    if (result.isSuccess() && !passive) {
        spellData.addCast();
        if (template != null && template.spellData != null) {
            template.spellData.addCast();
            SpellCategory category = template.getCategory();
            if (category != null) {
                category.addCast();
            }
        }
        // Reward SP
        Wand wand = context.getWand();
        Wand activeWand = mage.getActiveWand();
        if (activeWand != null && wand != null && activeWand.getItem() != null && wand.getItem() != null && !InventoryUtils.isSameInstance(wand.getItem(), activeWand.getItem()) && activeWand.getItem().equals(wand.getItem())) {
            wand = activeWand;
        }
        Wand offhandWand = mage.getOffhandWand();
        if (offhandWand != null && wand != null && offhandWand.getItem() != null && wand.getItem() != null && !InventoryUtils.isSameInstance(wand.getItem(), offhandWand.getItem()) && offhandWand.getItem().equals(wand.getItem())) {
            wand = offhandWand;
        }
        WandUpgradePath path = wand == null ? null : wand.getPath();
        if (earns > 0 && wand != null && path != null && path.earnsSP() && controller.isSPEnabled() && controller.isSPEarnEnabled() && !mage.isAtMaxSkillPoints()) {
            long now = System.currentTimeMillis();
            int scaledEarn = earns;
            if (spellData.getLastEarn() > 0 && earnCooldown > 0 && now < spellData.getLastEarn() + earnCooldown) {
                scaledEarn = (int) Math.floor((double) earns * (now - spellData.getLastEarn()) / earnCooldown);
                if (scaledEarn > 0) {
                    context.playEffects("earn_scaled_sp");
                }
            } else {
                context.playEffects("earn_sp");
            }
            if (scaledEarn > 0) {
                mage.addSkillPoints((int) Math.floor(mage.getSPMultiplier() * scaledEarn));
                spellData.setLastEarn(now);
            }
        }
        // This currently only works on wands.
        if (wand != null && wand.upgradesAllowed() && wand.getSpellLevel(spellKey.getBaseKey()) == spellKey.getLevel()) {
            if (controller.isSpellUpgradingEnabled()) {
                SpellTemplate upgrade = getUpgrade();
                long requiredCasts = getRequiredUpgradeCasts();
                String upgradePath = getRequiredUpgradePath();
                WandUpgradePath currentPath = wand.getPath();
                Set<String> upgradeTags = getRequiredUpgradeTags();
                if ((upgrade != null && requiredCasts > 0 && getCastCount() >= requiredCasts) && (upgradePath == null || upgradePath.isEmpty() || (currentPath != null && currentPath.hasPath(upgradePath))) && (upgradeTags == null || upgradeTags.isEmpty() || (currentPath != null && currentPath.hasAllTags(upgradeTags)))) {
                    if (PrerequisiteSpell.hasPrerequisites(wand, upgrade)) {
                        MageSpell newSpell = mage.getSpell(upgrade.getKey());
                        if (isActive()) {
                            deactivate(true, true);
                            if (newSpell != null) {
                                newSpell.activate();
                            }
                        }
                        wand.forceAddSpell(upgrade.getKey());
                        playEffects("upgrade");
                        if (controller.isPathUpgradingEnabled()) {
                            wand.checkAndUpgrade(true);
                        }
                        // return so progress upgrade doesn't also happen
                        return;
                    }
                }
            }
            if (maxLevels > 0 && controller.isSpellProgressionEnabled()) {
                long previousLevel = getPreviousCastProgressLevel();
                long currentLevel = getProgressLevel();
                if (currentLevel != previousLevel) {
                    wand.addSpell(getKey());
                    if (currentLevel > previousLevel) {
                        Messages messages = controller.getMessages();
                        String progressDescription = getProgressDescription();
                        playEffects("progress");
                        if (progressDescription != null && !progressDescription.isEmpty()) {
                            mage.sendMessage(messages.get("wand.spell_progression").replace("$name", getName()).replace("$wand", getName()).replace("$level", Long.toString(getProgressLevel())).replace("$max_level", Long.toString(maxLevels)));
                        }
                    }
                    if (controller.isPathUpgradingEnabled()) {
                        wand.checkAndUpgrade(true);
                    }
                }
            }
        }
    }
}
Also used : WandUpgradePath(com.elmakers.mine.bukkit.api.wand.WandUpgradePath) SpellCategory(com.elmakers.mine.bukkit.api.spell.SpellCategory) Messages(com.elmakers.mine.bukkit.api.magic.Messages) CastEvent(com.elmakers.mine.bukkit.api.event.CastEvent) PreCastEvent(com.elmakers.mine.bukkit.api.event.PreCastEvent) Wand(com.elmakers.mine.bukkit.api.wand.Wand) SpellResult(com.elmakers.mine.bukkit.api.spell.SpellResult) MageSpell(com.elmakers.mine.bukkit.api.spell.MageSpell) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate)

Aggregations

CastEvent (com.elmakers.mine.bukkit.api.event.CastEvent)2 PreCastEvent (com.elmakers.mine.bukkit.api.event.PreCastEvent)2 Messages (com.elmakers.mine.bukkit.api.magic.Messages)1 MageSpell (com.elmakers.mine.bukkit.api.spell.MageSpell)1 SpellCategory (com.elmakers.mine.bukkit.api.spell.SpellCategory)1 SpellResult (com.elmakers.mine.bukkit.api.spell.SpellResult)1 SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)1 Wand (com.elmakers.mine.bukkit.api.wand.Wand)1 WandUpgradePath (com.elmakers.mine.bukkit.api.wand.WandUpgradePath)1