Search in sources :

Example 91 with Mage

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

the class CastContext method finish.

@Override
public void finish() {
    if (finished)
        return;
    finished = true;
    Mage mage = getMage();
    if (finishedHandlers != null) {
        for (ActionHandlerContext context : finishedHandlers) {
            context.finish();
        }
        finishedHandlers = null;
    }
    if (undoSpell != null && undoSpell.isUndoable()) {
        if (!undoList.isScheduled()) {
            getController().update(undoList);
        }
        mage.registerForUndo(undoList);
    }
    result = result.max(initialResult);
    if (spell != null) {
        mage.sendDebugMessage(ChatColor.WHITE + "Finish " + ChatColor.GOLD + spell.getName() + ChatColor.WHITE + ": " + ChatColor.AQUA + result.name().toLowerCase(), 2);
        spell.finish(this);
    }
    String resultName = result.name().toLowerCase();
    castMessageKey(resultName + "_finish");
    playEffects(resultName + "_finish");
}
Also used : Mage(com.elmakers.mine.bukkit.api.magic.Mage)

Example 92 with Mage

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

the class AbsorbAction method perform.

@SuppressWarnings("deprecation")
@Override
public SpellResult perform(CastContext context) {
    Block target = context.getTargetBlock();
    Mage mage = context.getMage();
    Wand wand = context.getWand();
    if (wand == null) {
        return SpellResult.FAIL;
    }
    MageController controller = context.getController();
    Material material = target.getType();
    byte data = target.getData();
    MaterialSet buildingMaterials = controller.getBuildingMaterialSet();
    MaterialSet restrictedMaterials = mage.getRestrictedMaterialSet();
    if (material == null || material == Material.AIR) {
        return SpellResult.NO_TARGET;
    }
    if (!mage.getCommandSender().hasPermission("Magic.bypass_restricted") && (!buildingMaterials.testBlock(target) || restrictedMaterials.testBlock(target))) {
        return SpellResult.NO_TARGET;
    }
    // Add to the wand
    MaterialAndData mat = new MaterialAndData(material, data);
    if (!wand.addBrush(mat.getKey())) {
        // Still try and activate it
        wand.setActiveBrush(mat.getKey());
        return SpellResult.NO_TARGET;
    }
    // And activate it
    wand.setActiveBrush(mat.getKey());
    return SpellResult.CAST;
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) Mage(com.elmakers.mine.bukkit.api.magic.Mage) MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) MaterialSet(com.elmakers.mine.bukkit.api.magic.MaterialSet) Block(org.bukkit.block.Block) Wand(com.elmakers.mine.bukkit.api.wand.Wand) Material(org.bukkit.Material)

Example 93 with Mage

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

the class ApplyCooldownAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Mage targetMage = context.getMage();
    if (!targetCaster) {
        Entity entity = context.getTargetEntity();
        MageController controller = context.getController();
        if (entity == null || !controller.isMage(entity)) {
            return SpellResult.NO_TARGET;
        }
        targetMage = controller.getMage(entity);
    }
    int amount = cooldownAmount;
    if (!bypassReduction && cooldownAmount > 0) {
        double cooldownReduction = targetMage.getCooldownReduction();
        if (cooldownReduction < 1) {
            amount = (int) Math.ceil((1.0f - cooldownReduction) * amount);
        } else {
            amount = 0;
        }
    }
    if (spells != null) {
        Wand wand = targetMage.getActiveWand();
        for (String spellName : spells) {
            Spell spell = null;
            if (wand != null) {
                spell = wand.getSpell(spellName);
            }
            if (spell == null) {
                spell = targetMage.getSpell(spellName);
            }
            if (spell != null) {
                if (clear) {
                    spell.clearCooldown();
                }
                if (amount > 0) {
                    spell.setRemainingCooldown(amount);
                }
            }
        }
    } else if (excludeSpells != null) {
        Collection<Spell> allSpells = targetMage.getSpells();
        for (Spell spell : allSpells) {
            if (!excludeSpells.contains(spell.getSpellKey().getBaseKey())) {
                if (clear) {
                    spell.clearCooldown();
                }
                if (amount > 0) {
                    spell.setRemainingCooldown(amount);
                }
            }
        }
    } else {
        if (clear) {
            targetMage.clearCooldown();
        }
        if (amount > 0) {
            targetMage.setRemainingCooldown(amount);
        }
    }
    return SpellResult.CAST;
}
Also used : Entity(org.bukkit.entity.Entity) MageController(com.elmakers.mine.bukkit.api.magic.MageController) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Wand(com.elmakers.mine.bukkit.api.wand.Wand) Collection(java.util.Collection) BaseSpell(com.elmakers.mine.bukkit.spell.BaseSpell) Spell(com.elmakers.mine.bukkit.api.spell.Spell)

Example 94 with Mage

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

the class AreaOfEffectAction method addEntities.

@Override
public void addEntities(CastContext context, List<WeakReference<Entity>> entities) {
    Mage mage = context.getMage();
    Entity sourceEntity = context.getMage().getEntity();
    Location sourceLocation = context.getTargetLocation();
    if (mage.getDebugLevel() > 8) {
        mage.sendDebugMessage(ChatColor.GREEN + "AOE Targeting from " + ChatColor.GRAY + sourceLocation.getBlockX() + ChatColor.DARK_GRAY + "," + ChatColor.GRAY + sourceLocation.getBlockY() + ChatColor.DARK_GRAY + "," + ChatColor.GRAY + sourceLocation.getBlockZ() + ChatColor.DARK_GREEN + " with radius of " + ChatColor.GREEN + radius + ChatColor.GRAY + " self? " + ChatColor.DARK_GRAY + context.getTargetsCaster(), 14);
    }
    List<Entity> candidates = CompatibilityUtils.getNearbyEntities(sourceLocation, radius, yRadius, radius);
    if (targetCount > 0) {
        List<Target> targets = new ArrayList<>();
        Entity targetEntity = context.getTargetEntity();
        for (Entity entity : candidates) {
            boolean canTarget = true;
            if (entity == sourceEntity && !context.getTargetsCaster())
                canTarget = false;
            if (entity == targetEntity && !targetSource)
                canTarget = false;
            if (canTarget && context.canTarget(entity)) {
                Target target = new Target(sourceLocation, entity, radius, 0);
                targets.add(target);
                mage.sendDebugMessage(ChatColor.DARK_GREEN + "Target " + ChatColor.GREEN + entity.getType() + ChatColor.DARK_GREEN + ": " + ChatColor.YELLOW + target.getScore(), 12);
            } else if (mage.getDebugLevel() > 7) {
                mage.sendDebugMessage(ChatColor.DARK_RED + "Skipped Target " + ChatColor.GREEN + entity.getType(), 16);
            }
        }
        Collections.sort(targets);
        for (int i = 0; i < targetCount && i < targets.size(); i++) {
            Target target = targets.get(i);
            entities.add(new WeakReference<>(target.getEntity()));
        }
    } else {
        for (Entity entity : candidates) {
            if ((context.getTargetsCaster() || !entity.equals(sourceEntity)) && context.canTarget(entity)) {
                entities.add(new WeakReference<>(entity));
                mage.sendDebugMessage(ChatColor.DARK_GREEN + "Target " + ChatColor.GREEN + entity.getType(), 12);
            } else if (mage.getDebugLevel() > 7) {
                mage.sendDebugMessage(ChatColor.DARK_RED + "Skipped Target " + ChatColor.GREEN + entity.getType(), 16);
            }
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) Target(com.elmakers.mine.bukkit.utility.Target) Mage(com.elmakers.mine.bukkit.api.magic.Mage) ArrayList(java.util.ArrayList) Location(org.bukkit.Location)

Example 95 with Mage

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

the class BaseShopAction method checkContext.

public SpellResult checkContext(CastContext context) {
    Mage mage = context.getMage();
    MageController controller = mage.getController();
    Player player = mage.getPlayer();
    if (player == null) {
        return SpellResult.PLAYER_REQUIRED;
    }
    if (permissionNode != null && !player.hasPermission(permissionNode)) {
        return SpellResult.INSUFFICIENT_PERMISSION;
    }
    if (!requireWand) {
        return SpellResult.CAST;
    }
    Wand wand = mage.getActiveWand();
    if (wand == null) {
        context.showMessage("no_wand", getDefaultMessage(context, "no_wand"));
        return SpellResult.FAIL;
    }
    WandUpgradePath path = wand.getPath();
    if (requiredTemplate != null) {
        String template = wand.getTemplateKey();
        if (template == null || !template.equals(requiredTemplate)) {
            context.showMessage(context.getMessage("no_template", getDefaultMessage(context, "no_template")).replace("$wand", wand.getName()));
            return SpellResult.FAIL;
        }
    }
    // Check path requirements
    if (requiredPath != null || exactPath != null) {
        if (path == null) {
            context.showMessage(context.getMessage("no_path", getDefaultMessage(context, "no_path")).replace("$wand", wand.getName()));
            return SpellResult.FAIL;
        }
        if (requiredPath != null && !path.hasPath(requiredPath)) {
            WandUpgradePath requiresPath = controller.getPath(requiredPath);
            if (requiresPath != null) {
                context.showMessage(context.getMessage("no_required_path", getDefaultMessage(context, "no_required_path")).replace("$path", requiresPath.getName()));
            } else {
                context.getLogger().warning("Invalid path specified in Shop action: " + requiredPath);
            }
            return SpellResult.FAIL;
        }
        if (exactPath != null && !exactPath.equals(path.getKey())) {
            WandUpgradePath requiresPath = controller.getPath(exactPath);
            if (requiresPath != null) {
                context.showMessage(context.getMessage("no_path_exact", getDefaultMessage(context, "no_path_exact")).replace("$path", requiresPath.getName()));
            } else {
                context.getLogger().warning("Invalid path specified in Shop action: " + exactPath);
            }
            return SpellResult.FAIL;
        }
        if (requiresCompletedPath != null) {
            if (path.canEnchant(wand)) {
                context.showMessage(context.getMessage("no_path_end", getDefaultMessage(context, "no_path_end")).replace("$path", path.getName()));
                return SpellResult.FAIL;
            }
        }
    }
    return SpellResult.CAST;
}
Also used : WandUpgradePath(com.elmakers.mine.bukkit.api.wand.WandUpgradePath) MageController(com.elmakers.mine.bukkit.api.magic.MageController) Player(org.bukkit.entity.Player) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Wand(com.elmakers.mine.bukkit.api.wand.Wand)

Aggregations

Mage (com.elmakers.mine.bukkit.api.magic.Mage)187 Player (org.bukkit.entity.Player)62 Entity (org.bukkit.entity.Entity)56 Wand (com.elmakers.mine.bukkit.api.wand.Wand)47 MageController (com.elmakers.mine.bukkit.api.magic.MageController)45 ItemStack (org.bukkit.inventory.ItemStack)38 Location (org.bukkit.Location)33 LivingEntity (org.bukkit.entity.LivingEntity)31 ArrayList (java.util.ArrayList)25 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)18 Inventory (org.bukkit.inventory.Inventory)16 MageClass (com.elmakers.mine.bukkit.api.magic.MageClass)15 Spell (com.elmakers.mine.bukkit.api.spell.Spell)14 SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)14 Block (org.bukkit.block.Block)14 Target (com.elmakers.mine.bukkit.utility.Target)13 EventHandler (org.bukkit.event.EventHandler)13 ItemMeta (org.bukkit.inventory.meta.ItemMeta)12 CasterProperties (com.elmakers.mine.bukkit.api.magic.CasterProperties)10 Vector (org.bukkit.util.Vector)10