use of com.elmakers.mine.bukkit.api.spell.CostReducer in project MagicPlugin by elBukkit.
the class BaseSpell method addLore.
@Override
public void addLore(Messages messages, Mage mage, Wand wand, List<String> lore) {
CostReducer reducer = wand == null ? mage : wand;
if (reducer == null) {
reducer = this;
}
if (levelDescription != null && levelDescription.length() > 0) {
String descriptionTemplate = messages.get("spell.level_lore", "");
if (!descriptionTemplate.isEmpty()) {
InventoryUtils.wrapText(descriptionTemplate.replace("$level", levelDescription), lore);
}
}
if (description != null && description.length() > 0) {
String descriptionTemplate = messages.get("spell.description_lore", "");
if (!descriptionTemplate.isEmpty()) {
InventoryUtils.wrapText(descriptionTemplate.replace("$description", description), lore);
}
}
if (usage != null && usage.length() > 0) {
InventoryUtils.wrapText(usage, lore);
}
if (category != null) {
String categoryLore = messages.get("spell.category", "");
String categoryName = category.getName();
if (!categoryLore.isEmpty() && !categoryName.isEmpty()) {
lore.add(categoryLore.replace("$category", categoryName));
}
}
if (quickCast && wand != null && !wand.isQuickCastDisabled() && wand.hasInventory()) {
String quickCastText = messages.get("spell.quick_cast", "");
if (!quickCastText.isEmpty()) {
lore.add(quickCastText);
}
}
String warmupDescription = getWarmupDescription();
if (warmupDescription != null && !warmupDescription.isEmpty()) {
lore.add(messages.get("warmup.description").replace("$time", warmupDescription));
}
String cooldownDescription = getCooldownDescription(mage, wand);
if (cooldownDescription != null && !cooldownDescription.isEmpty()) {
lore.add(messages.get("cooldown.description").replace("$time", cooldownDescription));
}
String mageCooldownDescription = getMageCooldownDescription(mage, wand);
if (mageCooldownDescription != null && !mageCooldownDescription.isEmpty()) {
lore.add(messages.get("cooldown.mage_description").replace("$time", mageCooldownDescription));
}
double range = getRange();
if (range > 0) {
lore.add(ChatColor.GRAY + messages.get("wand.range_description").replace("$range", RANGE_FORMATTER.format(range)));
}
String effectiveDuration = this.getDurationDescription(messages);
if (effectiveDuration != null) {
lore.add(ChatColor.GRAY + effectiveDuration);
} else if (showUndoable()) {
if (isUndoable()) {
String undoableText = messages.get("spell.undoable", "");
if (!undoableText.isEmpty()) {
lore.add(undoableText);
}
} else {
String undoableText = messages.get("spell.not_undoable", "");
if (!undoableText.isEmpty()) {
lore.add(undoableText);
}
}
}
if (usesBrush()) {
String brushText = messages.get("spell.brush");
if (!brushText.isEmpty()) {
lore.add(ChatColor.GOLD + brushText);
}
}
if (costs != null) {
for (CastingCost cost : costs) {
if (!cost.isEmpty(reducer)) {
lore.add(ChatColor.YELLOW + messages.get("wand.costs_description").replace("$description", cost.getFullDescription(messages, reducer)));
}
}
}
if (activeCosts != null) {
for (CastingCost cost : activeCosts) {
if (!cost.isEmpty(reducer)) {
lore.add(ChatColor.YELLOW + messages.get("wand.active_costs_description").replace("$description", cost.getFullDescription(messages, reducer)));
}
}
}
if (toggle != ToggleType.NONE) {
String toggleText = messages.get("spell.toggle", "");
if (!toggleText.isEmpty()) {
lore.add(toggleText);
}
}
if (earns > 0 && controller.isSPEnabled() && controller.isSPEarnEnabled()) {
int scaledEarn = earns;
if (mage != null) {
scaledEarn = (int) Math.floor(mage.getSPMultiplier() * scaledEarn);
}
if (scaledEarn > 0) {
String earnsText = messages.get("spell.earns").replace("$earns", Integer.toString(scaledEarn));
if (!earnsText.isEmpty()) {
lore.add(earnsText);
}
}
}
if (controller.isSpellProgressionEnabled() && progressDescription != null && progressDescription.length() > 0 && maxLevels > 0 && template != null) {
InventoryUtils.wrapText(progressDescription.replace("$level", Long.toString(Math.max(0, getProgressLevel()))).replace("$max_level", Long.toString(maxLevels)), lore);
}
}
use of com.elmakers.mine.bukkit.api.spell.CostReducer in project MagicPlugin by elBukkit.
the class MagicController method getSpellBook.
public ItemStack getSpellBook(com.elmakers.mine.bukkit.api.spell.SpellCategory category, int count) {
Map<String, List<SpellTemplate>> categories = new HashMap<>();
Collection<SpellTemplate> spellVariants = spells.values();
String categoryKey = category == null ? null : category.getKey();
for (SpellTemplate spell : spellVariants) {
if (spell.isHidden() || spell.getSpellKey().isVariant())
continue;
com.elmakers.mine.bukkit.api.spell.SpellCategory spellCategory = spell.getCategory();
if (spellCategory == null)
continue;
String spellCategoryKey = spellCategory.getKey();
if (categoryKey == null || spellCategoryKey.equalsIgnoreCase(categoryKey)) {
List<SpellTemplate> categorySpells = categories.get(spellCategoryKey);
if (categorySpells == null) {
categorySpells = new ArrayList<>();
categories.put(spellCategoryKey, categorySpells);
}
categorySpells.add(spell);
}
}
List<String> categoryKeys = new ArrayList<>(categories.keySet());
Collections.sort(categoryKeys);
// Hrm? So much Copy+paste! :(
CostReducer reducer = null;
ItemStack bookItem = new ItemStack(Material.WRITTEN_BOOK, count);
BookMeta book = (BookMeta) bookItem.getItemMeta();
book.setAuthor(messages.get("books.default.author"));
String title = null;
if (category != null) {
title = messages.get("books.default.title").replace("$category", category.getName());
} else {
title = messages.get("books.all.title");
}
book.setTitle(title);
List<String> pages = new ArrayList<>();
Set<String> paths = WandUpgradePath.getPathKeys();
for (String key : categoryKeys) {
category = getCategory(key);
title = messages.get("books.default.title").replace("$category", category.getName());
String description = "" + ChatColor.BOLD + ChatColor.BLUE + title + "\n\n";
description += "" + ChatColor.RESET + ChatColor.DARK_BLUE + category.getDescription();
pages.add(description);
List<SpellTemplate> categorySpells = categories.get(key);
Collections.sort(categorySpells);
for (SpellTemplate spell : categorySpells) {
List<String> lines = new ArrayList<>();
lines.add("" + ChatColor.GOLD + ChatColor.BOLD + spell.getName());
lines.add("" + ChatColor.RESET);
String spellDescription = spell.getDescription();
if (spellDescription != null && spellDescription.length() > 0) {
lines.add("" + ChatColor.BLACK + spellDescription);
lines.add("");
}
String spellCooldownDescription = spell.getCooldownDescription();
if (spellCooldownDescription != null && spellCooldownDescription.length() > 0) {
spellCooldownDescription = messages.get("cooldown.description").replace("$time", spellCooldownDescription);
lines.add("" + ChatColor.DARK_PURPLE + spellCooldownDescription);
}
String spellMageCooldownDescription = spell.getMageCooldownDescription();
if (spellMageCooldownDescription != null && spellMageCooldownDescription.length() > 0) {
spellMageCooldownDescription = messages.get("cooldown.mage_description").replace("$time", spellMageCooldownDescription);
lines.add("" + ChatColor.RED + spellMageCooldownDescription);
}
Collection<CastingCost> costs = spell.getCosts();
if (costs != null) {
for (CastingCost cost : costs) {
if (!cost.isEmpty(reducer)) {
lines.add(ChatColor.DARK_PURPLE + messages.get("wand.costs_description").replace("$description", cost.getFullDescription(messages, reducer)));
}
}
}
Collection<CastingCost> activeCosts = spell.getActiveCosts();
if (activeCosts != null) {
for (CastingCost cost : activeCosts) {
if (!cost.isEmpty(reducer)) {
lines.add(ChatColor.DARK_PURPLE + messages.get("wand.active_costs_description").replace("$description", cost.getFullDescription(messages, reducer)));
}
}
}
for (String pathKey : paths) {
WandUpgradePath checkPath = WandUpgradePath.getPath(pathKey);
if (!checkPath.isHidden() && (checkPath.hasSpell(spell.getKey()) || checkPath.hasExtraSpell(spell.getKey()))) {
lines.add(ChatColor.DARK_BLUE + messages.get("spell.available_path").replace("$path", checkPath.getName()));
break;
}
}
for (String pathKey : paths) {
WandUpgradePath checkPath = WandUpgradePath.getPath(pathKey);
if (checkPath.requiresSpell(spell.getKey())) {
lines.add(ChatColor.DARK_RED + messages.get("spell.required_path").replace("$path", checkPath.getName()));
break;
}
}
String duration = spell.getDurationDescription(messages);
if (duration != null) {
lines.add(ChatColor.DARK_GREEN + duration);
} else if (spell.showUndoable()) {
if (spell.isUndoable()) {
String undoable = messages.get("spell.undoable", "");
if (undoable != null && !undoable.isEmpty()) {
lines.add(undoable);
}
} else {
String notUndoable = messages.get("spell.not_undoable", "");
if (notUndoable != null && !notUndoable.isEmpty()) {
lines.add(notUndoable);
}
}
}
if (spell.usesBrush()) {
lines.add(ChatColor.DARK_GRAY + messages.get("spell.brush"));
}
SpellKey baseKey = spell.getSpellKey();
SpellKey upgradeKey = new SpellKey(baseKey.getBaseKey(), baseKey.getLevel() + 1);
SpellTemplate upgradeSpell = getSpellTemplate(upgradeKey.getKey());
int spellLevels = 0;
while (upgradeSpell != null) {
spellLevels++;
upgradeKey = new SpellKey(upgradeKey.getBaseKey(), upgradeKey.getLevel() + 1);
upgradeSpell = getSpellTemplate(upgradeKey.getKey());
}
if (spellLevels > 0) {
spellLevels++;
lines.add(ChatColor.DARK_AQUA + messages.get("spell.levels_available").replace("$levels", Integer.toString(spellLevels)));
}
String usage = spell.getUsage();
if (usage != null && usage.length() > 0) {
lines.add("" + ChatColor.GRAY + ChatColor.ITALIC + usage + ChatColor.RESET);
lines.add("");
}
String spellExtendedDescription = spell.getExtendedDescription();
if (spellExtendedDescription != null && spellExtendedDescription.length() > 0) {
lines.add("" + ChatColor.BLACK + spellExtendedDescription);
lines.add("");
}
pages.add(StringUtils.join(lines, "\n"));
}
}
book.setPages(pages);
bookItem.setItemMeta(book);
return bookItem;
}
Aggregations