Search in sources :

Example 36 with MageController

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

the class BaseShopAction method giveCosts.

protected void giveCosts(CastContext context, ShopItem shopItem) {
    Mage mage = context.getMage();
    MageController controller = context.getController();
    double worth = shopItem.getWorth();
    if (isXP) {
        worth = Math.ceil(costScale * worth * controller.getWorthBase() / controller.getWorthXP());
        mage.giveExperience((int) worth);
    } else if (isItems) {
        worth = Math.ceil(costScale * worth * controller.getWorthBase() / controller.getWorthItemAmount());
        int amount = (int) Math.ceil(worth);
        ItemStack worthItem = getWorthItem(controller);
        while (amount > 0) {
            worthItem = InventoryUtils.getCopy(worthItem);
            worthItem.setAmount(Math.min(amount, 64));
            amount -= worthItem.getAmount();
            mage.giveItem(worthItem);
        }
    } else if (isSkillPoints) {
        worth = Math.ceil(costScale * worth * controller.getWorthBase() / controller.getWorthSkillPoints());
        int amount = (int) Math.ceil(worth);
        mage.addSkillPoints(amount);
    } else {
        worth = Math.ceil(costScale * worth * controller.getWorthBase());
        VaultController.getInstance().depositPlayer(mage.getPlayer(), worth);
    }
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) Mage(com.elmakers.mine.bukkit.api.magic.Mage) ItemStack(org.bukkit.inventory.ItemStack)

Example 37 with MageController

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

the class BaseShopAction method getItemCost.

protected String getItemCost(CastContext context, ShopItem shopItem) {
    String amountString = "?";
    MageController controller = context.getController();
    Messages messages = controller.getMessages();
    double worth = shopItem.getWorth();
    if (isXP) {
        worth = Math.ceil(costScale * worth * controller.getWorthBase() / controller.getWorthXP());
        amountString = Integer.toString((int) worth);
        amountString = messages.get("costs.xp_amount").replace("$amount", amountString);
    } else if (isItems) {
        worth = Math.ceil(costScale * worth * controller.getWorthBase() / controller.getWorthItemAmount());
        amountString = formatItemAmount(controller, worth);
    } else if (isSkillPoints) {
        worth = Math.ceil(costScale * worth * controller.getWorthBase() / controller.getWorthSkillPoints());
        amountString = Integer.toString((int) Math.ceil(worth));
        amountString = messages.get("costs.sp_amount").replace("$amount", amountString);
    } else {
        worth = Math.ceil(costScale * worth * controller.getWorthBase());
        amountString = VaultController.getInstance().format(worth);
    }
    return amountString;
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) Messages(com.elmakers.mine.bukkit.api.magic.Messages)

Example 38 with MageController

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

the class CastContext method messageTargets.

@Override
public void messageTargets(String messageKey) {
    Mage mage = getMage();
    if (mage.isStealth())
        return;
    Collection<Entity> targets = getTargetedEntities();
    if (targets == null || targets.isEmpty())
        return;
    MageController controller = getController();
    LivingEntity sourceEntity = mage.getLivingEntity();
    String playerMessage = getMessage(messageKey);
    if (playerMessage.length() > 0) {
        playerMessage = playerMessage.replace("$spell", spell.getName());
        for (Entity target : targets) {
            UUID targetUUID = target.getUniqueId();
            if (target instanceof Player && target != sourceEntity && !targetMessagesSent.contains(targetUUID)) {
                targetMessagesSent.add(targetUUID);
                Mage targetMage = controller.getRegisteredMage(target);
                if (targetMage != null) {
                    targetMage.sendMessage(playerMessage);
                }
            }
        }
    }
}
Also used : LivingEntity(org.bukkit.entity.LivingEntity) Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) MageController(com.elmakers.mine.bukkit.api.magic.MageController) Player(org.bukkit.entity.Player) EffectPlayer(com.elmakers.mine.bukkit.api.effect.EffectPlayer) Mage(com.elmakers.mine.bukkit.api.magic.Mage) UUID(java.util.UUID)

Example 39 with MageController

use of com.elmakers.mine.bukkit.api.magic.MageController 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 40 with MageController

use of com.elmakers.mine.bukkit.api.magic.MageController 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)

Aggregations

MageController (com.elmakers.mine.bukkit.api.magic.MageController)76 Mage (com.elmakers.mine.bukkit.api.magic.Mage)45 Entity (org.bukkit.entity.Entity)27 Player (org.bukkit.entity.Player)26 Location (org.bukkit.Location)16 ItemStack (org.bukkit.inventory.ItemStack)16 Wand (com.elmakers.mine.bukkit.api.wand.Wand)14 Block (org.bukkit.block.Block)11 LivingEntity (org.bukkit.entity.LivingEntity)11 ArrayList (java.util.ArrayList)10 Inventory (org.bukkit.inventory.Inventory)9 ItemMeta (org.bukkit.inventory.meta.ItemMeta)8 Spell (com.elmakers.mine.bukkit.api.spell.Spell)5 MagicController (com.elmakers.mine.bukkit.magic.MagicController)5 Nullable (javax.annotation.Nullable)5 ConfigurationSection (org.bukkit.configuration.ConfigurationSection)5 ItemData (com.elmakers.mine.bukkit.api.item.ItemData)4 SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)4 WandUpgradePath (com.elmakers.mine.bukkit.api.wand.WandUpgradePath)4 File (java.io.File)4