Search in sources :

Example 6 with HeroesManager

use of com.elmakers.mine.bukkit.heroes.HeroesManager in project MagicPlugin by elBukkit.

the class Wand method tickMana.

@Override
public boolean tickMana() {
    if (isHeroes) {
        HeroesManager heroes = controller.getHeroes();
        if (heroes != null && mage != null && mage.isPlayer()) {
            Player player = mage.getPlayer();
            effectiveManaMax = heroes.getMaxMana(player);
            effectiveManaRegeneration = heroes.getManaRegen(player);
            setManaMax(effectiveManaMax);
            setManaRegeneration(effectiveManaRegeneration);
            setMana(heroes.getMana(player));
            return true;
        }
        return false;
    }
    return super.tickMana();
}
Also used : Player(org.bukkit.entity.Player) HeroesManager(com.elmakers.mine.bukkit.heroes.HeroesManager)

Example 7 with HeroesManager

use of com.elmakers.mine.bukkit.heroes.HeroesManager in project MagicPlugin by elBukkit.

the class SkillSelectorAction method perform.

@Override
public SpellResult perform(CastContext context) {
    this.context = context;
    MageController apiController = context.getController();
    Player player = context.getMage().getPlayer();
    if (player == null) {
        return SpellResult.PLAYER_REQUIRED;
    }
    if (!(apiController instanceof MagicController))
        return SpellResult.FAIL;
    MagicController controller = (MagicController) apiController;
    Messages messages = controller.getMessages();
    HeroesManager heroes = controller.getHeroes();
    allSkills.clear();
    if (controller.useHeroesSkills() && heroes != null) {
        @Nonnull String classString = heroes.getClassName(player);
        @Nonnull String class2String = heroes.getSecondaryClassName(player);
        String messageKey = !class2String.isEmpty() ? "skills.inventory_title_secondary" : "skills.inventory_title";
        inventoryTitle = controller.getMessages().get(messageKey, "Skills ($page/$pages)");
        inventoryTitle = inventoryTitle.replace("$class2", class2String).replace("$class", classString);
        List<String> heroesSkills = heroes.getSkillList(player, true, true);
        for (String heroesSkill : heroesSkills) {
            allSkills.add(new SkillDescription(heroes, controller, player, heroesSkill));
        }
    } else {
        inventoryTitle = messages.get("skills.inventory_title");
    }
    if (controller.usePermissionSkills()) {
        boolean bypassHidden = player.hasPermission("Magic.bypass_hidden");
        Collection<SpellTemplate> spells = controller.getSpellTemplates(bypassHidden);
        for (SpellTemplate spell : spells) {
            SpellKey key = spell.getSpellKey();
            if (key.isVariant())
                continue;
            if (key.getBaseKey().startsWith("heroes*"))
                continue;
            if (!spell.hasCastPermission(player))
                continue;
            allSkills.add(new SkillDescription(spell));
        }
    } else {
        Mage mage = controller.getMage(player);
        MageClass activeClass = mage.getActiveClass();
        if (activeClass != null) {
            // gather spells in player's inventory to avoid showing
            Set<String> hasSpells = new HashSet<>();
            for (ItemStack item : player.getInventory().getContents()) {
                String spellKey = controller.getSpell(item);
                if (spellKey != null) {
                    hasSpells.add(spellKey);
                }
            }
            classKey = activeClass.getKey();
            skillsConfig = activeClass.getProperty("skills", ConfigurationSection.class);
            inventoryLimit = activeClass.getProperty("skills.skill_limit", 0);
            Collection<String> spells = activeClass.getSpells();
            for (String spellKey : spells) {
                if (hasSpells.contains(spellKey)) {
                    extraSlots++;
                    continue;
                }
                SpellTemplate spell = controller.getSpellTemplate(spellKey);
                if (spell != null) {
                    allSkills.add(new SkillDescription(spell));
                }
            }
        }
    }
    if (allSkills.size() == 0) {
        player.sendMessage(messages.get("skills.none"));
        return SpellResult.NO_ACTION;
    }
    Collections.sort(allSkills);
    openInventory();
    return SpellResult.CAST;
}
Also used : Player(org.bukkit.entity.Player) Messages(com.elmakers.mine.bukkit.api.magic.Messages) MageClass(com.elmakers.mine.bukkit.api.magic.MageClass) Nonnull(javax.annotation.Nonnull) HeroesManager(com.elmakers.mine.bukkit.heroes.HeroesManager) SpellKey(com.elmakers.mine.bukkit.api.spell.SpellKey) MageController(com.elmakers.mine.bukkit.api.magic.MageController) Mage(com.elmakers.mine.bukkit.api.magic.Mage) MagicController(com.elmakers.mine.bukkit.magic.MagicController) ItemStack(org.bukkit.inventory.ItemStack) SpellTemplate(com.elmakers.mine.bukkit.api.spell.SpellTemplate) HashSet(java.util.HashSet) ConfigurationSection(org.bukkit.configuration.ConfigurationSection)

Example 8 with HeroesManager

use of com.elmakers.mine.bukkit.heroes.HeroesManager in project MagicPlugin by elBukkit.

the class SkillSelectorAction method openInventory.

protected void openInventory() {
    MageController apiController = context.getController();
    if (!(apiController instanceof MagicController))
        return;
    MagicController controller = (MagicController) apiController;
    HeroesManager heroes = controller.getHeroes();
    int inventorySize = 9 * controller.getSkillInventoryRows();
    float numSlots = extraSlots + allSkills.size();
    int numPages = (int) Math.ceil(numSlots / inventorySize);
    if (page < 1)
        page = numPages;
    else if (page > numPages)
        page = 1;
    Mage mage = context.getMage();
    Player player = mage.getPlayer();
    int pageIndex = page - 1;
    int startIndex = pageIndex * inventorySize;
    int maxIndex = (pageIndex + 1) * inventorySize - 1;
    List<SkillDescription> skills = new ArrayList<>();
    for (int i = startIndex; i <= maxIndex && i < allSkills.size(); i++) {
        skills.add(allSkills.get(i));
    }
    if (skills.size() == 0) {
        String messageTemplate = controller.getMessages().get("skills.none_on_page", "$page");
        player.sendMessage(messageTemplate.replace("$page", Integer.toString(page)));
        return;
    }
    int invSize = (int) Math.ceil(numSlots / 9.0f) * 9;
    String title = inventoryTitle;
    title = title.replace("$pages", Integer.toString(numPages)).replace("$page", Integer.toString(page));
    Inventory displayInventory = CompatibilityUtils.createInventory(null, invSize, title);
    for (SkillDescription skill : skills) {
        ItemStack skillItem = controller.getAPI().createItem(skill.getSkillKey(), mage);
        if (skillItem == null)
            continue;
        InventoryUtils.configureSkillItem(skillItem, classKey, skillsConfig);
        if (skill.isHeroes() && heroes != null && !heroes.canUseSkill(player, skill.heroesSkill)) {
            String nameTemplate = controller.getMessages().get("skills.item_name_unavailable", "$skill");
            String spellName = skill.spell != null ? skill.spell.getName() : skill.heroesSkill;
            CompatibilityUtils.setDisplayName(skillItem, nameTemplate.replace("$skill", spellName));
            InventoryUtils.setMetaBoolean(skillItem, "unavailable", true);
            if (skill.spell != null) {
                MaterialAndData disabledIcon = skill.spell.getDisabledIcon();
                if (disabledIcon != null) {
                    disabledIcon.applyToItem(skillItem);
                } else {
                    String disabledIconURL = skill.spell.getDisabledIconURL();
                    if (disabledIconURL != null && !disabledIconURL.isEmpty()) {
                        InventoryUtils.setNewSkullURL(skillItem, disabledIconURL);
                    }
                }
            }
        }
        displayInventory.addItem(skillItem);
    }
    mage.deactivateGUI();
    mage.activateGUI(this, displayInventory);
}
Also used : Player(org.bukkit.entity.Player) ArrayList(java.util.ArrayList) HeroesManager(com.elmakers.mine.bukkit.heroes.HeroesManager) MageController(com.elmakers.mine.bukkit.api.magic.MageController) Mage(com.elmakers.mine.bukkit.api.magic.Mage) MagicController(com.elmakers.mine.bukkit.magic.MagicController) MaterialAndData(com.elmakers.mine.bukkit.api.block.MaterialAndData) ItemStack(org.bukkit.inventory.ItemStack) Inventory(org.bukkit.inventory.Inventory)

Aggregations

HeroesManager (com.elmakers.mine.bukkit.heroes.HeroesManager)8 Player (org.bukkit.entity.Player)7 ArrayList (java.util.ArrayList)3 ItemStack (org.bukkit.inventory.ItemStack)3 Mage (com.elmakers.mine.bukkit.api.magic.Mage)2 MageController (com.elmakers.mine.bukkit.api.magic.MageController)2 MagicController (com.elmakers.mine.bukkit.magic.MagicController)2 Plugin (org.bukkit.plugin.Plugin)2 MaterialAndData (com.elmakers.mine.bukkit.api.block.MaterialAndData)1 UndoList (com.elmakers.mine.bukkit.api.block.UndoList)1 WandPreActivateEvent (com.elmakers.mine.bukkit.api.event.WandPreActivateEvent)1 MageClass (com.elmakers.mine.bukkit.api.magic.MageClass)1 Messages (com.elmakers.mine.bukkit.api.magic.Messages)1 SpellKey (com.elmakers.mine.bukkit.api.spell.SpellKey)1 SpellTemplate (com.elmakers.mine.bukkit.api.spell.SpellTemplate)1 CitizensController (com.elmakers.mine.bukkit.citizens.CitizensController)1 DynmapController (com.elmakers.mine.bukkit.dynmap.DynmapController)1 EffectPlayer (com.elmakers.mine.bukkit.effect.EffectPlayer)1 ElementalsController (com.elmakers.mine.bukkit.elementals.ElementalsController)1 MagicItemDb (com.elmakers.mine.bukkit.essentials.MagicItemDb)1