use of com.elmakers.mine.bukkit.api.magic.ProgressionPath 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.magic.ProgressionPath in project MagicPlugin by elBukkit.
the class MagicRequirement method getRequirementDescription.
@Nullable
public String getRequirementDescription(@Nonnull CastContext context) {
Mage mage = context.getMage();
MageController controller = mage.getController();
Player player = mage.getPlayer();
if (permissionNode != null && (player == null || !player.hasPermission(permissionNode))) {
return context.getMessage(SpellResult.INSUFFICIENT_PERMISSION.name().toLowerCase());
}
Wand wand = context.getWand();
if (wand == null && requireWand) {
return getMessage(context, "no_wand");
}
if (requiredTemplate != null) {
String template = wand.getTemplateKey();
if (template == null || !template.equals(requiredTemplate)) {
return getMessage(context, "no_template").replace("$wand", wand.getName());
}
}
if (requiredTemplates != null) {
String template = wand.getTemplateKey();
if (template == null || !requiredTemplates.contains(template)) {
return getMessage(context, "no_template").replace("$wand", wand.getName());
}
}
if (mageClass != null && !mageClass.isEmpty()) {
if (mage.hasClassUnlocked(mageClass)) {
return getMessage(context, "no_class").replace("$class", mageClass);
}
}
CasterProperties checkProperties = context.getActiveProperties();
ProgressionPath path = checkProperties.getPath();
if (requiredPath != null || exactPath != null) {
if (path == null) {
return getMessage(context, "no_path");
}
if (requiredPath != null && !path.hasPath(requiredPath)) {
WandUpgradePath requiresPath = controller.getPath(requiredPath);
String pathName = requiredPath;
if (requiresPath != null) {
pathName = requiresPath.getName();
} else {
context.getLogger().warning("Invalid path specified in requirement " + requiredPath);
}
return getMessage(context, "no_required_path").replace("$path", pathName);
}
if (exactPath != null && !exactPath.equals(path.getKey())) {
WandUpgradePath requiresPath = controller.getPath(exactPath);
String pathName = exactPath;
if (requiresPath != null) {
pathName = requiresPath.getName();
} else {
context.getLogger().warning("Invalid path specified in requirement: " + exactPath);
}
return getMessage(context, "no_path_exact").replace("$path", pathName);
}
if (requiresCompletedPath != null) {
boolean hasPathCompleted = false;
if (path.hasPath(requiresCompletedPath)) {
if (path.getKey().equals(requiresCompletedPath)) {
hasPathCompleted = !path.canProgress(checkProperties);
} else {
hasPathCompleted = true;
}
}
if (!hasPathCompleted) {
WandUpgradePath requiresPath = controller.getPath(requiresCompletedPath);
String pathName = requiresCompletedPath;
if (requiresPath != null) {
pathName = requiresPath.getName();
} else {
context.getLogger().warning("Invalid path specified in requirement: " + exactPath);
}
return getMessage(context, "no_path_end").replace("$path", pathName);
}
}
}
if (wandProperties != null) {
String message = getRequiredProperty(context, wand, wandProperties);
if (message != null) {
return message;
}
}
if (classProperties != null) {
MageClass activeClass = mageClass == null ? mage.getActiveClass() : mage.getClass(mageClass);
if (activeClass == null) {
return getMessage(context, "no_path");
}
String message = getRequiredProperty(context, activeClass, classProperties);
if (message != null) {
return message;
}
}
if (attributes != null) {
for (PropertyRequirement requirement : attributes) {
String key = requirement.key;
Double value = mage.getAttribute(key);
String message = checkRequiredProperty(context, requirement, key, value);
if (message != null) {
return message;
}
}
}
return null;
}
Aggregations