Search in sources :

Example 1 with MageClass

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

the class MagicRequirement method checkRequirement.

public boolean checkRequirement(@Nonnull CastContext context) {
    Mage mage = context.getMage();
    Player player = mage.getPlayer();
    if (permissionNode != null && (player == null || !player.hasPermission(permissionNode))) {
        return false;
    }
    Wand wand = context.getWand();
    if (wand == null && requireWand) {
        return false;
    }
    if (requiredTemplate != null) {
        String template = wand.getTemplateKey();
        if (template == null || !template.equals(requiredTemplate)) {
            return false;
        }
    }
    if (requiredTemplates != null) {
        String template = wand.getTemplateKey();
        if (template == null || !requiredTemplates.contains(template)) {
            return false;
        }
    }
    CasterProperties checkProperties = context.getActiveProperties();
    ProgressionPath path = checkProperties.getPath();
    if (mageClass != null && !mageClass.isEmpty()) {
        if (!mage.hasClassUnlocked(mageClass)) {
            return false;
        }
    }
    if (requiredPath != null || exactPath != null) {
        if (path == null) {
            return false;
        }
        if (requiredPath != null && !path.hasPath(requiredPath)) {
            return false;
        }
        if (exactPath != null && !exactPath.equals(path.getKey())) {
            return false;
        }
        if (requiresCompletedPath != null) {
            boolean hasPathCompleted = false;
            if (path.hasPath(requiresCompletedPath)) {
                if (path.getKey().equals(requiresCompletedPath)) {
                    hasPathCompleted = !path.canProgress(checkProperties);
                } else {
                    hasPathCompleted = true;
                }
            }
            if (!hasPathCompleted) {
                return false;
            }
        }
    }
    if (wandProperties != null) {
        if (!checkProperties(wand, wandProperties)) {
            return false;
        }
    }
    if (classProperties != null) {
        MageClass activeClass = mageClass == null ? mage.getActiveClass() : mage.getClass(mageClass);
        if (activeClass == null) {
            return false;
        }
        if (!checkProperties(activeClass, classProperties)) {
            return false;
        }
    }
    if (attributes != null) {
        for (PropertyRequirement requirement : attributes) {
            String key = requirement.key;
            Double value = mage.getAttribute(key);
            if (!checkProperty(requirement, value)) {
                return false;
            }
        }
    }
    return true;
}
Also used : ProgressionPath(com.elmakers.mine.bukkit.api.magic.ProgressionPath) 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)

Example 2 with MageClass

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

the class MageCommandExecutor method onMageAttribute.

public boolean onMageAttribute(CommandSender sender, Player player, String[] args) {
    Mage mage = controller.getMage(player);
    Set<String> attributes = api.getController().getAttributes();
    if (attributes.isEmpty()) {
        sender.sendMessage(ChatColor.RED + "No attributes configured, see attributes.yml");
        return true;
    }
    if (args.length == 0) {
        sender.sendMessage(ChatColor.GOLD + "Attributes for: " + ChatColor.AQUA + player.getName());
        for (String key : attributes) {
            Double value = mage.getAttribute(key);
            String valueDescription = value == null ? ChatColor.RED + "(not set)" : ChatColor.AQUA + Double.toString(value);
            sender.sendMessage(ChatColor.DARK_AQUA + key + ChatColor.BLUE + " = " + valueDescription);
        }
        return true;
    }
    String key = args[0];
    if (args.length == 1) {
        if (!attributes.contains(key)) {
            sender.sendMessage(ChatColor.RED + "Unknown attribute: " + ChatColor.YELLOW + key);
            return true;
        }
        Double value = mage.getAttribute(key);
        String valueDescription = value == null ? ChatColor.RED + "(not set)" : ChatColor.AQUA + Double.toString(value);
        sender.sendMessage(ChatColor.AQUA + player.getName() + " has " + ChatColor.DARK_AQUA + key + ChatColor.BLUE + " of " + valueDescription);
        return true;
    }
    MageClass activeClass = mage.getActiveClass();
    CasterProperties attributeProperties = activeClass == null ? mage.getProperties() : activeClass;
    String value = args[1];
    for (int i = 2; i < args.length; i++) {
        value = value + " " + args[i];
    }
    if (value.equals("-")) {
        Double oldValue = attributeProperties.getAttribute(key);
        attributeProperties.setAttribute(key, null);
        String valueDescription = oldValue == null ? ChatColor.RED + "(not set)" : ChatColor.AQUA + Double.toString(oldValue);
        sender.sendMessage(ChatColor.BLUE + "Removed attribute " + ChatColor.DARK_AQUA + key + ChatColor.BLUE + ", was " + valueDescription);
        return true;
    }
    double transformed = Double.NaN;
    try {
        transformed = Double.parseDouble(value);
    } catch (Exception ex) {
        EquationTransform transform = EquationStore.getInstance().getTransform(value);
        if (transform.getException() == null) {
            Double property = attributeProperties.getAttribute(key);
            if (property == null || Double.isNaN(property)) {
                property = 0.0;
            }
            transform.setVariable("x", property);
            transformed = transform.get();
        }
    }
    if (Double.isNaN(transformed)) {
        sender.sendMessage(ChatColor.RED + "Could not set " + ChatColor.YELLOW + key + ChatColor.RED + " to " + ChatColor.YELLOW + value);
        return true;
    }
    attributeProperties.setAttribute(key, transformed);
    sender.sendMessage(ChatColor.GOLD + "Set " + ChatColor.DARK_AQUA + key + ChatColor.GOLD + " to " + ChatColor.AQUA + transformed + ChatColor.GOLD + " for " + ChatColor.DARK_AQUA + player.getDisplayName());
    return true;
}
Also used : CasterProperties(com.elmakers.mine.bukkit.api.magic.CasterProperties) EquationTransform(de.slikey.effectlib.math.EquationTransform) MageClass(com.elmakers.mine.bukkit.api.magic.MageClass) Mage(com.elmakers.mine.bukkit.api.magic.Mage)

Example 3 with MageClass

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

the class MageCommandExecutor method onMageConfigure.

public boolean onMageConfigure(CommandSender sender, Player player, String[] parameters, boolean safe) {
    Mage mage = controller.getMage(player);
    MageClass activeClass = mage.getActiveClass();
    return onConfigure("mage", activeClass == null ? mage.getProperties() : activeClass, sender, player, parameters, safe);
}
Also used : MageClass(com.elmakers.mine.bukkit.api.magic.MageClass) Mage(com.elmakers.mine.bukkit.api.magic.Mage)

Example 4 with MageClass

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

the class MageCommandExecutor method onMageUnlock.

public boolean onMageUnlock(CommandSender sender, Player player, String[] parameters) {
    if (parameters.length < 1) {
        sender.sendMessage(ChatColor.RED + "Usage: " + ChatColor.WHITE + "/mage unlock [player] <class>");
        return true;
    }
    Mage mage = controller.getMage(player);
    String classKey = parameters[0];
    MageClass mageClass = mage.unlockClass(classKey);
    if (mageClass == null) {
        sender.sendMessage(ChatColor.RED + "Invalid class: " + ChatColor.WHITE + classKey);
    } else {
        sender.sendMessage("Unlocked class " + classKey + " for " + player.getName());
    }
    return true;
}
Also used : MageClass(com.elmakers.mine.bukkit.api.magic.MageClass) Mage(com.elmakers.mine.bukkit.api.magic.Mage)

Example 5 with MageClass

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

the class MageCommandExecutor method onMageSwitch.

public boolean onMageSwitch(CommandSender sender, Player player, String[] parameters) {
    if (parameters.length < 1) {
        sender.sendMessage(ChatColor.RED + "Usage: " + ChatColor.WHITE + "/mage switch [player] <class>");
        return true;
    }
    String classKey = parameters[0];
    Mage mage = controller.getMage(player);
    MageClass activeClass = mage.getActiveClass();
    if (activeClass != null && activeClass.getKey().equals(classKey)) {
        sender.sendMessage(ChatColor.RED + "Player " + ChatColor.WHITE + player.getName() + ChatColor.RED + " already has class active: " + ChatColor.WHITE + classKey);
        return true;
    }
    MageClass targetClass = mage.unlockClass(classKey);
    if (targetClass == null) {
        sender.sendMessage(ChatColor.RED + "Invalid class: " + ChatColor.WHITE + classKey);
        return true;
    }
    if (activeClass != null) {
        mage.lockClass(activeClass.getKey());
    }
    mage.setActiveClass(targetClass.getKey());
    sender.sendMessage("Switched class to " + classKey + " for " + player.getName());
    return true;
}
Also used : MageClass(com.elmakers.mine.bukkit.api.magic.MageClass) Mage(com.elmakers.mine.bukkit.api.magic.Mage)

Aggregations

Mage (com.elmakers.mine.bukkit.api.magic.Mage)15 MageClass (com.elmakers.mine.bukkit.api.magic.MageClass)15 Wand (com.elmakers.mine.bukkit.api.wand.Wand)5 CasterProperties (com.elmakers.mine.bukkit.api.magic.CasterProperties)4 SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)4 ProgressionPath (com.elmakers.mine.bukkit.api.magic.ProgressionPath)3 Spell (com.elmakers.mine.bukkit.api.spell.Spell)3 Player (org.bukkit.entity.Player)3 Checker (ch.njol.util.Checker)2 MageController (com.elmakers.mine.bukkit.api.magic.MageController)2 ArrayList (java.util.ArrayList)2 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)2 Entity (org.bukkit.entity.Entity)2 ItemStack (org.bukkit.inventory.ItemStack)2 MagicProperties (com.elmakers.mine.bukkit.api.magic.MagicProperties)1 Messages (com.elmakers.mine.bukkit.api.magic.Messages)1 SpellKey (com.elmakers.mine.bukkit.api.spell.SpellKey)1 WandUpgradePath (com.elmakers.mine.bukkit.api.wand.WandUpgradePath)1 HeroesManager (com.elmakers.mine.bukkit.heroes.HeroesManager)1 BaseMagicProperties (com.elmakers.mine.bukkit.magic.BaseMagicProperties)1