Search in sources :

Example 21 with Wand

use of com.elmakers.mine.bukkit.wand.Wand in project MagicPlugin by elBukkit.

the class Mage method tick.

@Override
public void tick() {
    if (isNPC)
        return;
    long now = System.currentTimeMillis();
    if (entityData != null) {
        if (lastTick != 0) {
            long tickInterval = entityData.getTickInterval();
            if (tickInterval > 0 && now - lastTick > tickInterval) {
                updateVelocity();
                entityData.tick(this);
                lastTick = now;
            }
        } else {
            lastTick = now;
        }
    } else {
        updateVelocity();
        lastTick = now;
    }
    // We don't tick non-player or offline Mages, except
    // above where entityData is ticked if present.
    Player player = getPlayer();
    if (player != null && player.isOnline()) {
        checkWand();
        if (activeWand != null) {
            activeWand.tick();
        } else if (virtualExperience) {
            resetSentExperience();
        }
        if (offhandWand != null) {
            offhandWand.tick();
        }
        if (activeClass != null) {
            activeClass.tick();
        }
        properties.tick();
        if (Wand.LiveHotbarSkills && (activeWand == null || !activeWand.isInventoryOpen())) {
            updateHotbarStatus();
        }
        // it turns out that is not easy to check efficiently.
        if (JUMP_EFFECT_FLIGHT_EXEMPTION_DURATION > 0 && player.hasPotionEffect(PotionEffectType.JUMP)) {
            controller.addFlightExemption(player, JUMP_EFFECT_FLIGHT_EXEMPTION_DURATION);
        }
        for (Wand armorWand : activeArmor.values()) {
            armorWand.updateEffects(this);
        }
        // Copy this set since spells may get removed while iterating!
        List<MageSpell> active = new ArrayList<>(activeSpells);
        for (MageSpell spell : active) {
            spell.tick();
            if (!spell.isActive()) {
                deactivateSpell(spell);
            }
        }
    }
}
Also used : Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) Wand(com.elmakers.mine.bukkit.wand.Wand) LostWand(com.elmakers.mine.bukkit.api.wand.LostWand) MageSpell(com.elmakers.mine.bukkit.api.spell.MageSpell)

Example 22 with Wand

use of com.elmakers.mine.bukkit.wand.Wand in project MagicPlugin by elBukkit.

the class Mage method restoreWand.

@Override
public boolean restoreWand() {
    if (boundWands.size() == 0)
        return false;
    Player player = getPlayer();
    if (player == null)
        return false;
    Set<String> foundTemplates = new HashSet<>();
    ItemStack[] inventory = getInventory().getContents();
    for (ItemStack item : inventory) {
        if (Wand.isWand(item)) {
            Wand tempWand = controller.getWand(item);
            String template = tempWand.getTemplateKey();
            if (template != null) {
                foundTemplates.add(template);
            }
        }
    }
    inventory = player.getEnderChest().getContents();
    for (ItemStack item : inventory) {
        if (Wand.isWand(item)) {
            Wand tempWand = controller.getWand(item);
            String template = tempWand.getTemplateKey();
            if (template != null) {
                foundTemplates.add(template);
            }
        }
    }
    int givenWands = 0;
    for (Map.Entry<String, Wand> wandEntry : boundWands.entrySet()) {
        if (foundTemplates.contains(wandEntry.getKey()))
            continue;
        givenWands++;
        ItemStack wandItem = wandEntry.getValue().duplicate().getItem();
        wandItem.setAmount(1);
        giveItem(wandItem);
    }
    return givenWands > 0;
}
Also used : Player(org.bukkit.entity.Player) Wand(com.elmakers.mine.bukkit.wand.Wand) LostWand(com.elmakers.mine.bukkit.api.wand.LostWand) ItemStack(org.bukkit.inventory.ItemStack) Map(java.util.Map) HashMap(java.util.HashMap) HashSet(java.util.HashSet)

Example 23 with Wand

use of com.elmakers.mine.bukkit.wand.Wand in project MagicPlugin by elBukkit.

the class Mage method checkWand.

@Nullable
private Wand checkWand(ItemStack itemInHand) {
    Player player = getPlayer();
    if (isLoading() || player == null)
        return null;
    ItemStack activeWandItem = activeWand != null ? activeWand.getItem() : null;
    if (InventoryUtils.isSameInstance(activeWandItem, itemInHand))
        return activeWand;
    if (!Wand.isWand(itemInHand))
        itemInHand = null;
    if ((itemInHand != null && activeWandItem == null) || (activeWandItem != null && itemInHand == null) || (activeWandItem != null && itemInHand != null && !itemInHand.equals(activeWandItem))) {
        if (activeWand != null) {
            activeWand.deactivate();
        }
        if (itemInHand != null && controller.hasWandPermission(player)) {
            Wand newActiveWand = controller.getWand(itemInHand);
            if (!newActiveWand.activate(this)) {
                setActiveWand(null);
            }
        }
    }
    return activeWand;
}
Also used : Player(org.bukkit.entity.Player) Wand(com.elmakers.mine.bukkit.wand.Wand) LostWand(com.elmakers.mine.bukkit.api.wand.LostWand) ItemStack(org.bukkit.inventory.ItemStack) Nullable(javax.annotation.Nullable)

Example 24 with Wand

use of com.elmakers.mine.bukkit.wand.Wand in project MagicPlugin by elBukkit.

the class MagicController method checkForItem.

public boolean checkForItem(Player player, ItemStack requireItem, boolean take) {
    boolean foundItem = false;
    ItemStack[] contents = player.getInventory().getContents();
    for (int i = 0; i < contents.length; i++) {
        ItemStack item = contents[i];
        if (itemsAreEqual(item, requireItem)) {
            Wand wand = null;
            if (Wand.isWand(item) && Wand.isBound(item)) {
                wand = getWand(item);
                if (!wand.canUse(player))
                    continue;
            }
            if (take) {
                player.getInventory().setItem(i, null);
                if (wand != null) {
                    wand.unbind();
                }
            }
            foundItem = true;
            break;
        }
    }
    return foundItem;
}
Also used : Wand(com.elmakers.mine.bukkit.wand.Wand) LostWand(com.elmakers.mine.bukkit.wand.LostWand) ItemStack(org.bukkit.inventory.ItemStack)

Example 25 with Wand

use of com.elmakers.mine.bukkit.wand.Wand in project MagicPlugin by elBukkit.

the class CasterProperties method updateMaxMana.

public boolean updateMaxMana(Mage mage) {
    if (!usesMana()) {
        return false;
    }
    int currentMana = effectiveManaMax;
    int currentManaRegen = effectiveManaRegeneration;
    float effectiveBoost = getManaMaxBoost();
    float effectiveRegenBoost = getManaRegenerationBoost();
    if (mage != null) {
        Collection<Wand> activeArmor = mage.getActiveArmor();
        for (Wand armorWand : activeArmor) {
            effectiveBoost += armorWand.getManaMaxBoost();
            effectiveRegenBoost += armorWand.getManaRegenerationBoost();
        }
        Wand activeWand = mage.getActiveWand();
        if (activeWand != null && !activeWand.isPassive()) {
            effectiveBoost += activeWand.getManaMaxBoost();
            effectiveRegenBoost += activeWand.getManaRegenerationBoost();
        }
        Wand offhandWand = mage.getOffhandWand();
        if (offhandWand != null && !offhandWand.isPassive()) {
            effectiveBoost += offhandWand.getManaMaxBoost();
            effectiveRegenBoost += offhandWand.getManaRegenerationBoost();
        }
    }
    boolean boostable = getBoolean("boostable", true);
    effectiveManaMax = getManaMax();
    if (boostable && effectiveBoost != 0) {
        effectiveManaMax = (int) Math.ceil(effectiveManaMax + effectiveBoost * effectiveManaMax);
    }
    effectiveManaRegeneration = getManaRegeneration();
    if (boostable && effectiveRegenBoost != 0) {
        effectiveManaRegeneration = (int) Math.ceil(effectiveManaRegeneration + effectiveRegenBoost * effectiveManaRegeneration);
    }
    return (currentMana != effectiveManaMax || effectiveManaRegeneration != currentManaRegen);
}
Also used : Wand(com.elmakers.mine.bukkit.wand.Wand)

Aggregations

Wand (com.elmakers.mine.bukkit.wand.Wand)36 Player (org.bukkit.entity.Player)24 ItemStack (org.bukkit.inventory.ItemStack)23 EventHandler (org.bukkit.event.EventHandler)17 LostWand (com.elmakers.mine.bukkit.api.wand.LostWand)11 Mage (com.elmakers.mine.bukkit.magic.Mage)11 PlayerInventory (org.bukkit.inventory.PlayerInventory)6 Spell (com.elmakers.mine.bukkit.api.spell.Spell)5 Nullable (javax.annotation.Nullable)5 LostWand (com.elmakers.mine.bukkit.wand.LostWand)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 Map (java.util.Map)4 Inventory (org.bukkit.inventory.Inventory)4 GUIAction (com.elmakers.mine.bukkit.api.action.GUIAction)3 Messages (com.elmakers.mine.bukkit.api.magic.Messages)3 Location (org.bukkit.Location)3 Block (org.bukkit.block.Block)3 Entity (org.bukkit.entity.Entity)3 Item (org.bukkit.entity.Item)3