Search in sources :

Example 96 with Mage

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

the class BaseShopAction method hasItemCosts.

protected boolean hasItemCosts(CastContext context, ShopItem shopItem) {
    Mage mage = context.getMage();
    MageController controller = context.getController();
    double worth = shopItem.getWorth();
    boolean hasCosts = true;
    if (worth > 0) {
        if (isXP) {
            worth = Math.ceil(costScale * worth * controller.getWorthBase() / controller.getWorthXP());
            hasCosts = mage.getExperience() >= (int) worth;
        } else if (isItems) {
            worth = Math.ceil(costScale * worth * controller.getWorthBase() / controller.getWorthItemAmount());
            int hasAmount = getItemAmount(controller, mage);
            hasCosts = hasAmount >= worth;
        } else if (isSkillPoints) {
            worth = Math.ceil(costScale * worth * controller.getWorthBase() / controller.getWorthSkillPoints());
            hasCosts = mage.getSkillPoints() >= Math.ceil(worth);
        } else {
            worth = Math.ceil(costScale * worth * controller.getWorthBase());
            hasCosts = VaultController.getInstance().has(mage.getPlayer(), worth);
        }
    }
    return hasCosts;
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) Mage(com.elmakers.mine.bukkit.api.magic.Mage)

Example 97 with Mage

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

the class BaseShopAction method getBalanceDescription.

protected String getBalanceDescription(CastContext context) {
    Mage mage = context.getMage();
    MageController controller = context.getController();
    Messages messages = controller.getMessages();
    String description = "";
    if (isXP) {
        String xpAmount = Integer.toString(mage.getExperience());
        description = messages.get("costs.xp_amount").replace("$amount", xpAmount);
    } else if (isItems) {
        int itemAmount = getItemAmount(controller, mage);
        description = formatItemAmount(controller, itemAmount);
    } else if (isSkillPoints) {
        String spAmount = Integer.toString(mage.getSkillPoints());
        description = messages.get("costs.sp_amount").replace("$amount", spAmount);
    } else {
        double balance = VaultController.getInstance().getBalance(mage.getPlayer());
        description = VaultController.getInstance().format(balance);
    }
    return description;
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) Messages(com.elmakers.mine.bukkit.api.magic.Messages) Mage(com.elmakers.mine.bukkit.api.magic.Mage)

Example 98 with Mage

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

the class BrushAction method step.

@Override
public SpellResult step(CastContext context) {
    if (brushes.size() == 0 && !sample) {
        return startActions();
    }
    if (sample) {
        Block targetBlock = context.getTargetBlock();
        if (targetBlock != null) {
            Mage mage = context.getMage();
            MaterialBrush brush = new MaterialBrush(mage, targetBlock);
            actionContext.setBrush(brush);
        }
    } else {
        String brushKey = brushes.get(context.getRandom().nextInt(brushes.size()));
        MaterialBrush brush = new MaterialBrush(context.getMage(), context.getLocation(), brushKey);
        actionContext.setBrush(brush);
    }
    return startActions();
}
Also used : MaterialBrush(com.elmakers.mine.bukkit.block.MaterialBrush) Mage(com.elmakers.mine.bukkit.api.magic.Mage) Block(org.bukkit.block.Block)

Example 99 with Mage

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

the class BrushSelectAction method clicked.

@Override
public void clicked(InventoryClickEvent event) {
    event.setCancelled(true);
    InventoryAction action = event.getAction();
    if (context != null) {
        Mage mage = context.getMage();
        if (action == InventoryAction.NOTHING) {
            int direction = event.getClick() == ClickType.LEFT ? 1 : -1;
            page = page + direction;
            mage.deactivateGUI();
            perform(context);
            event.setCancelled(true);
            return;
        }
        ItemStack item = event.getCurrentItem();
        String set = InventoryUtils.getMetaString(item, "brush_set", null);
        if (set != null) {
            if (set.equals("schematics")) {
                String inventoryTitle = context.getMessage("schematics_title", "Schematics");
                int invSize = ((schematics.size() + 9) / 9) * 9;
                Inventory displayInventory = CompatibilityUtils.createInventory(null, invSize, inventoryTitle);
                for (ItemStack schematicItem : schematics) {
                    displayInventory.addItem(schematicItem);
                }
                mage.deactivateGUI();
                mage.activateGUI(this, displayInventory);
                return;
            } else if (set.equals("variants")) {
                MaterialAndData baseMaterial = new MaterialAndData(item);
                String baseName = baseMaterial.getBaseName();
                String inventoryTitle = context.getMessage("variants_title", "$variant Types").replace("$variant", baseName);
                String brushKey = com.elmakers.mine.bukkit.wand.Wand.getBrush(item);
                MaterialAndData brushMaterial = new MaterialAndData(brushKey);
                List<ItemStack> variantList = variants.get(brushMaterial.getMaterial());
                int invSize = ((variantList.size() + 9) / 9) * 9;
                Inventory displayInventory = CompatibilityUtils.createInventory(null, invSize, inventoryTitle);
                for (ItemStack variantItem : variantList) {
                    displayInventory.addItem(variantItem);
                }
                mage.deactivateGUI();
                mage.activateGUI(this, displayInventory);
                return;
            }
        }
        mage.deactivateGUI();
        Wand wand = context.getWand();
        if (wand != null && com.elmakers.mine.bukkit.wand.Wand.isBrush(item)) {
            String brushKey = com.elmakers.mine.bukkit.wand.Wand.getBrush(item);
            wand.setActiveBrush(brushKey);
        }
    }
}
Also used : Mage(com.elmakers.mine.bukkit.api.magic.Mage) MaterialAndData(com.elmakers.mine.bukkit.block.MaterialAndData) Wand(com.elmakers.mine.bukkit.api.wand.Wand) ArrayList(java.util.ArrayList) List(java.util.List) ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory) InventoryAction(org.bukkit.event.inventory.InventoryAction)

Example 100 with Mage

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

the class CancelAction method perform.

@Override
public SpellResult perform(CastContext context) {
    Entity targetEntity = context.getTargetEntity();
    MageController controller = context.getController();
    if (targetEntity == null || !controller.isMage(targetEntity)) {
        return SpellResult.NO_TARGET;
    }
    SpellResult result = SpellResult.NO_TARGET;
    Mage targetMage = controller.getMage(targetEntity);
    if (spellKeys == null) {
        Batch batch = targetMage.cancelPending(force);
        if (batch != null) {
            result = SpellResult.CAST;
            undoListName = batch.getName();
        }
    } else {
        for (String spellKey : spellKeys) {
            Batch batch = targetMage.cancelPending(spellKey, force);
            if (batch != null) {
                result = SpellResult.CAST;
                undoListName = batch.getName();
            }
        }
    }
    return result;
}
Also used : Entity(org.bukkit.entity.Entity) MageController(com.elmakers.mine.bukkit.api.magic.MageController) Batch(com.elmakers.mine.bukkit.api.batch.Batch) Mage(com.elmakers.mine.bukkit.api.magic.Mage) SpellResult(com.elmakers.mine.bukkit.api.spell.SpellResult)

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