Search in sources :

Example 86 with Mage

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

the class BaseShopAction method takeCosts.

protected boolean takeCosts(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.removeExperience((int) worth);
    } else if (isItems) {
        worth = Math.ceil(costScale * worth * controller.getWorthBase() / controller.getWorthItemAmount());
        removeItems(controller, mage, (int) Math.ceil(worth));
    } else if (isSkillPoints) {
        worth = Math.ceil(costScale * worth * controller.getWorthBase() / controller.getWorthSkillPoints());
        mage.addSkillPoints(-(int) Math.ceil(worth));
    } else {
        worth = Math.ceil(costScale * worth * controller.getWorthBase());
        VaultController.getInstance().withdrawPlayer(mage.getPlayer(), worth);
    }
    return true;
}
Also used : MageController(com.elmakers.mine.bukkit.api.magic.MageController) Mage(com.elmakers.mine.bukkit.api.magic.Mage)

Example 87 with Mage

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

the class BaseShopAction method showItems.

public SpellResult showItems(CastContext context, List<ShopItem> items) {
    Mage mage = context.getMage();
    this.context = context;
    Player player = mage.getPlayer();
    if (player == null) {
        return SpellResult.PLAYER_REQUIRED;
    }
    this.showingItems = new HashMap<>();
    // Load items
    itemStacks = new ArrayList<>();
    String costString = context.getMessage("cost_lore", "Costs: $cost");
    for (ShopItem shopItem : items) {
        int currentSlot = itemStacks.size();
        if (filterBound && shopItem != null) {
            String template = com.elmakers.mine.bukkit.wand.Wand.getWandTemplate(shopItem.getItem());
            if (template != null && mage.getBoundWand(template) != null) {
                shopItem = null;
            }
        }
        if (shopItem == null) {
            this.showingItems.put(currentSlot, null);
            itemStacks.add(new ItemStack(Material.AIR));
            continue;
        }
        ItemStack item = InventoryUtils.getCopy(shopItem.getItem());
        if (item == null)
            continue;
        String permission = shopItem.getPermission();
        if (permission != null && !permission.isEmpty() && !player.hasPermission(permission)) {
            continue;
        }
        ItemMeta meta = item.getItemMeta();
        if (meta == null) {
            itemStacks.add(item);
            continue;
        }
        List<String> lore = meta.getLore();
        if (lore == null) {
            lore = new ArrayList<>();
        }
        String costs = costString.replace("$cost", getItemCost(context, shopItem));
        lore.add(ChatColor.GOLD + costs);
        meta.setLore(lore);
        item.setItemMeta(meta);
        item = InventoryUtils.makeReal(item);
        InventoryUtils.setMeta(item, "shop", Integer.toString(currentSlot));
        if (showConfirmation) {
            InventoryUtils.setMeta(item, "confirm", "true");
        }
        this.showingItems.put(currentSlot, shopItem);
        itemStacks.add(item);
    }
    if (itemStacks.size() == 0) {
        context.showMessage("no_items", getDefaultMessage(context, "no_items"));
        return SpellResult.FAIL;
    }
    isActive = true;
    finalResult = SpellResult.NO_ACTION;
    Inventory displayInventory = getInventory(context);
    mage.activateGUI(this, displayInventory);
    return SpellResult.PENDING;
}
Also used : Player(org.bukkit.entity.Player) Mage(com.elmakers.mine.bukkit.api.magic.Mage) ItemStack(org.bukkit.inventory.ItemStack) ItemMeta(org.bukkit.inventory.meta.ItemMeta) Inventory(org.bukkit.inventory.Inventory) PlayerInventory(org.bukkit.inventory.PlayerInventory)

Example 88 with Mage

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

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

the class CastContext method playEffects.

@Override
public void playEffects(String effectName, float scale, Location sourceLocation, Entity sourceEntity, Location targetLocation, Entity targetEntity, Block sourceBlock) {
    if (targetEntity != null) {
        String entityKey = effectName + "_" + targetEntity.getType().name().toLowerCase();
        if (baseSpell != null && baseSpell.hasEffects(entityKey)) {
            effectName = entityKey;
        }
    }
    Collection<EffectPlayer> effects = getEffects(effectName);
    if (effects.size() > 0) {
        Location location = getLocation();
        Collection<Entity> targeted = getTargetedEntities();
        for (EffectPlayer player : effects) {
            // Set scale
            player.setScale(scale);
            Mage mage = getMage();
            Location source = sourceLocation;
            if (source == null) {
                if (mage.getEntity() == sourceEntity && player.playsAtOrigin()) {
                    source = player.getSourceLocation(this);
                } else {
                    source = location;
                }
            }
            Location target = targetLocation;
            if (target == null) {
                target = player.getTargetLocation(this);
            }
            if (sourceBlock != null) {
                player.setMaterial(sourceBlock);
            }
            player.start(source, sourceEntity, target, targetEntity, targeted);
        }
    }
}
Also used : Entity(org.bukkit.entity.Entity) LivingEntity(org.bukkit.entity.LivingEntity) Mage(com.elmakers.mine.bukkit.api.magic.Mage) EffectPlayer(com.elmakers.mine.bukkit.api.effect.EffectPlayer) Location(org.bukkit.Location)

Example 90 with Mage

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

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