use of com.elmakers.mine.bukkit.api.spell.SpellTemplate 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;
}
use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.
the class SpellProgressAction method perform.
@Override
public SpellResult perform(CastContext context) {
Mage mage = context.getMage();
CasterProperties casterProperties = context.getActiveProperties();
this.context = context;
Player player = mage.getPlayer();
if (player == null) {
return SpellResult.PLAYER_REQUIRED;
}
Collection<String> spells = casterProperties.getSpells();
Collection<ItemStack> upgrades = new ArrayList<>();
Messages messages = context.getController().getMessages();
for (String spellKey : spells) {
MageSpell spell = mage.getSpell(spellKey);
SpellTemplate upgradeSpell = spell.getUpgrade();
if (upgradeSpell != null) {
ItemStack spellItem = MagicPlugin.getAPI().createSpellItem(upgradeSpell.getKey());
if (spellItem != null) {
long requiredCastCount = spell.getRequiredUpgradeCasts();
String requiredPathKey = spell.getRequiredUpgradePath();
Set<String> requiredPathTags = spell.getRequiredUpgradeTags();
ItemMeta meta = spellItem.getItemMeta();
List<String> lore = new ArrayList<>();
String levelDescription = upgradeSpell.getLevelDescription();
if (levelDescription == null || levelDescription.isEmpty()) {
levelDescription = upgradeSpell.getName();
}
lore.add(levelDescription);
String upgradeDescription = upgradeSpell.getUpgradeDescription();
if (upgradeDescription != null && !upgradeDescription.isEmpty()) {
upgradeDescription = context.getController().getMessages().get("spell.upgrade_description_prefix") + upgradeDescription;
InventoryUtils.wrapText(upgradeDescription, lore);
}
ProgressionPath currentPath = casterProperties.getPath();
if (requiredPathKey != null && currentPath == null) {
continue;
}
if (!upgradeSpell.getName().equals(spell.getName())) {
lore.add(context.getMessage("upgrade_name_change", "&r&4Upgrades: &r$name").replace("$name", spell.getName()));
}
if (requiredPathKey != null && !currentPath.hasPath(requiredPathKey)) {
requiredPathKey = currentPath.translatePath(requiredPathKey);
com.elmakers.mine.bukkit.wand.WandUpgradePath upgradePath = com.elmakers.mine.bukkit.wand.WandUpgradePath.getPath(requiredPathKey);
if (upgradePath == null)
continue;
lore.add(context.getMessage("level_requirement").replace("$path", upgradePath.getName()));
}
if (requiredPathTags != null && !requiredPathTags.isEmpty() && !currentPath.hasAllTags(requiredPathTags)) {
Set<String> tags = currentPath.getMissingTags(requiredPathTags);
lore.add(context.getMessage("tags_requirement").replace("$tags", messages.formatList("tags", tags, "name")));
}
long castCount = Math.min(spell.getCastCount(), requiredCastCount);
if (castCount == requiredCastCount) {
lore.add(ChatColor.GREEN + context.getMessage("cast_requirement").replace("$current", Long.toString(castCount)).replace("$required", Long.toString(requiredCastCount)));
} else {
lore.add(ChatColor.RED + context.getMessage("cast_requirement").replace("$current", Long.toString(castCount)).replace("$required", Long.toString(requiredCastCount)));
}
meta.setLore(lore);
spellItem.setItemMeta(meta);
upgrades.add(spellItem);
}
}
}
String inventoryTitle = context.getMessage("title", "Spell Upgrades");
int invSize = ((upgrades.size() + 9) / 9) * 9;
Inventory displayInventory = CompatibilityUtils.createInventory(null, invSize, inventoryTitle);
for (ItemStack item : upgrades) {
displayInventory.addItem(item);
}
mage.activateGUI(this, displayInventory);
return SpellResult.CAST;
}
use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.
the class BaseSpell method finish.
@Override
public void finish(com.elmakers.mine.bukkit.api.action.CastContext context) {
SpellResult result = context.getResult();
// Notify other plugins of this spell cast
CastEvent castEvent = new CastEvent(mage, this, result);
Bukkit.getPluginManager().callEvent(castEvent);
// Message targets
if (result.isSuccess() && (loud || (!mage.isQuiet() && !quiet))) {
messageTargets("cast_player_message");
}
// Clear cooldown on miss
if (result.shouldRefundCooldown(castOnNoTarget)) {
clearCooldown();
}
if (cancelEffects) {
context.cancelEffects();
}
// Track cast counts
if (result.isSuccess() && !passive) {
spellData.addCast();
if (template != null && template.spellData != null) {
template.spellData.addCast();
SpellCategory category = template.getCategory();
if (category != null) {
category.addCast();
}
}
// Reward SP
Wand wand = context.getWand();
Wand activeWand = mage.getActiveWand();
if (activeWand != null && wand != null && activeWand.getItem() != null && wand.getItem() != null && !InventoryUtils.isSameInstance(wand.getItem(), activeWand.getItem()) && activeWand.getItem().equals(wand.getItem())) {
wand = activeWand;
}
Wand offhandWand = mage.getOffhandWand();
if (offhandWand != null && wand != null && offhandWand.getItem() != null && wand.getItem() != null && !InventoryUtils.isSameInstance(wand.getItem(), offhandWand.getItem()) && offhandWand.getItem().equals(wand.getItem())) {
wand = offhandWand;
}
WandUpgradePath path = wand == null ? null : wand.getPath();
if (earns > 0 && wand != null && path != null && path.earnsSP() && controller.isSPEnabled() && controller.isSPEarnEnabled() && !mage.isAtMaxSkillPoints()) {
long now = System.currentTimeMillis();
int scaledEarn = earns;
if (spellData.getLastEarn() > 0 && earnCooldown > 0 && now < spellData.getLastEarn() + earnCooldown) {
scaledEarn = (int) Math.floor((double) earns * (now - spellData.getLastEarn()) / earnCooldown);
if (scaledEarn > 0) {
context.playEffects("earn_scaled_sp");
}
} else {
context.playEffects("earn_sp");
}
if (scaledEarn > 0) {
mage.addSkillPoints((int) Math.floor(mage.getSPMultiplier() * scaledEarn));
spellData.setLastEarn(now);
}
}
// This currently only works on wands.
if (wand != null && wand.upgradesAllowed() && wand.getSpellLevel(spellKey.getBaseKey()) == spellKey.getLevel()) {
if (controller.isSpellUpgradingEnabled()) {
SpellTemplate upgrade = getUpgrade();
long requiredCasts = getRequiredUpgradeCasts();
String upgradePath = getRequiredUpgradePath();
WandUpgradePath currentPath = wand.getPath();
Set<String> upgradeTags = getRequiredUpgradeTags();
if ((upgrade != null && requiredCasts > 0 && getCastCount() >= requiredCasts) && (upgradePath == null || upgradePath.isEmpty() || (currentPath != null && currentPath.hasPath(upgradePath))) && (upgradeTags == null || upgradeTags.isEmpty() || (currentPath != null && currentPath.hasAllTags(upgradeTags)))) {
if (PrerequisiteSpell.hasPrerequisites(wand, upgrade)) {
MageSpell newSpell = mage.getSpell(upgrade.getKey());
if (isActive()) {
deactivate(true, true);
if (newSpell != null) {
newSpell.activate();
}
}
wand.forceAddSpell(upgrade.getKey());
playEffects("upgrade");
if (controller.isPathUpgradingEnabled()) {
wand.checkAndUpgrade(true);
}
// return so progress upgrade doesn't also happen
return;
}
}
}
if (maxLevels > 0 && controller.isSpellProgressionEnabled()) {
long previousLevel = getPreviousCastProgressLevel();
long currentLevel = getProgressLevel();
if (currentLevel != previousLevel) {
wand.addSpell(getKey());
if (currentLevel > previousLevel) {
Messages messages = controller.getMessages();
String progressDescription = getProgressDescription();
playEffects("progress");
if (progressDescription != null && !progressDescription.isEmpty()) {
mage.sendMessage(messages.get("wand.spell_progression").replace("$name", getName()).replace("$wand", getName()).replace("$level", Long.toString(getProgressLevel())).replace("$max_level", Long.toString(maxLevels)));
}
}
if (controller.isPathUpgradingEnabled()) {
wand.checkAndUpgrade(true);
}
}
}
}
}
}
use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.
the class WandCommandExecutor method onWandRemove.
public boolean onWandRemove(CommandSender sender, Player player, String[] parameters) {
if (parameters.length < 1) {
sender.sendMessage("Use: /wand remove <spell|material> [material:data]");
return true;
}
Wand wand = checkWand(sender, player);
if (wand == null) {
return true;
}
Mage mage = controller.getMage(player);
String spellName = parameters[0];
if (spellName.equals("material") || spellName.equals("brush")) {
if (parameters.length < 2) {
sender.sendMessage("Use: /wand remove brush <material:data>");
return true;
}
String materialKey = parameters[1];
if (wand.removeBrush(materialKey)) {
mage.sendMessage("Brush '" + materialKey + "' has been removed from your wand");
if (sender != player) {
sender.sendMessage("Removed brush '" + materialKey + "' from " + player.getName() + "'s wand");
}
wand.saveState();
} else {
if (sender != player) {
sender.sendMessage(player.getName() + "'s wand does not have brush " + materialKey);
}
}
return true;
}
if (wand.removeSpell(spellName)) {
SpellTemplate template = api.getSpellTemplate(spellName);
if (template != null) {
spellName = template.getName();
}
mage.sendMessage("Spell '" + spellName + "' has been removed from your wand");
if (sender != player) {
sender.sendMessage("Removed '" + spellName + "' from " + player.getName() + "'s wand");
}
wand.saveState();
} else {
if (sender != player) {
sender.sendMessage(player.getName() + "'s wand does not have " + spellName);
}
}
return true;
}
use of com.elmakers.mine.bukkit.api.spell.SpellTemplate in project MagicPlugin by elBukkit.
the class WandCommandExecutor method onWandDescribe.
public boolean onWandDescribe(CommandSender sender, Player player, String[] parameters) {
// Force-save wand data so it is up to date
Mage mage = controller.getMage(player);
Wand activeWand = mage.getActiveWand();
if (activeWand != null) {
activeWand.saveState();
}
ItemStack itemInHand = player.getInventory().getItemInMainHand();
if (itemInHand == null) {
if (sender != player) {
sender.sendMessage(api.getMessages().getParameterized("wand.player_no_item", "$name", player.getName()));
} else {
player.sendMessage(api.getMessages().get("wand.no_item"));
}
return true;
}
if (api.isSpell(itemInHand)) {
String spellKey = api.getSpell(itemInHand);
sender.sendMessage(ChatColor.GOLD + "Spell: " + spellKey);
SpellTemplate spell = api.getSpellTemplate(spellKey);
if (spell != null) {
sender.sendMessage(" " + ChatColor.GOLD + spell.getName());
} else {
sender.sendMessage(ChatColor.RED + " (Unknown Spell)");
}
} else if (api.isBrush(itemInHand)) {
String brushKey = api.getBrush(itemInHand);
sender.sendMessage(ChatColor.GRAY + "Brush: " + brushKey);
MaterialAndData brush = new MaterialAndData(brushKey);
sender.sendMessage(" " + ChatColor.GRAY + brush.getName());
} else if (api.isWand(itemInHand) || api.isUpgrade(itemInHand)) {
Wand wand = api.getWand(itemInHand);
if (parameters.length == 0) {
sender.sendMessage(ChatColor.BLUE + "Use " + ChatColor.AQUA + "/wand describe <property>" + ChatColor.BLUE + " for specific properties");
wand.describe(sender, BaseMagicProperties.HIDDEN_PROPERTY_KEYS);
} else {
Object property = wand.getProperty(parameters[0]);
if (property == null) {
sender.sendMessage(ChatColor.DARK_AQUA + parameters[0] + ChatColor.GRAY + ": " + ChatColor.RED + "(Not Set)");
} else {
sender.sendMessage(ChatColor.DARK_AQUA + parameters[0] + ChatColor.GRAY + ": " + ChatColor.WHITE + InventoryUtils.describeProperty(property));
}
}
} else {
sender.sendMessage(ChatColor.RED + "That is not a magic item");
}
return true;
}
Aggregations