Skip to content

Commit

Permalink
Add ability descriptions to level up message
Browse files Browse the repository at this point in the history
  • Loading branch information
Archy-X committed Dec 10, 2023
1 parent 326070a commit 74e63d7
Show file tree
Hide file tree
Showing 9 changed files with 237 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import com.archyx.slate.menu.ActiveMenu;
import dev.aurelium.auraskills.api.ability.Ability;
import dev.aurelium.auraskills.api.ability.AbstractAbility;
import dev.aurelium.auraskills.api.mana.ManaAbilities;
import dev.aurelium.auraskills.api.mana.ManaAbility;
import dev.aurelium.auraskills.api.util.NumberUtil;
import dev.aurelium.auraskills.bukkit.AuraSkills;
import dev.aurelium.auraskills.bukkit.menus.AbstractComponent;
import dev.aurelium.auraskills.common.ability.AbilityUtil;
import dev.aurelium.auraskills.common.user.User;
import dev.aurelium.auraskills.api.util.NumberUtil;
import dev.aurelium.auraskills.common.util.math.RomanNumber;
import dev.aurelium.auraskills.common.util.text.Replacer;
import dev.aurelium.auraskills.common.util.text.TextUtil;
Expand Down Expand Up @@ -74,15 +74,18 @@ public <T> String onPlaceholderReplace(String placeholder, Player player, Active
Locale locale = plugin.getUser(player).getLocale();
if (placeholder.equals("desc")) {
User user = plugin.getUser(player);
String format = activeMenu.getFormat("desc_upgrade_value");
if (context instanceof Ability ability) {
int level = user.getAbilityLevel(ability);
return TextUtil.replace(ability.getDescription(locale),
"{value}", getUpgradeValue(ability, user, activeMenu),
"{value_2}", getUpgradeValue2(ability, user, activeMenu));
"{value}", AbilityUtil.getUpgradeValue(ability, level, format),
"{value_2}", AbilityUtil.getUpgradeValue2(ability, level, format));
} else if (context instanceof ManaAbility manaAbility) {
int level = user.getManaAbilityLevel(manaAbility);
return TextUtil.replace(manaAbility.getDescription(locale),
"{value}", getUpgradeValue(manaAbility, user, activeMenu),
"{value}", AbilityUtil.getUpgradeValue(manaAbility, level, format),
"{haste_level}", String.valueOf(manaAbility.optionInt("haste_level", 10)),
"{duration}", getUpgradeDuration(manaAbility, user, activeMenu));
"{duration}", AbilityUtil.getUpgradeDuration(manaAbility, level, format));
}
}
return replaceMenuMessage(placeholder, player, activeMenu, new Replacer()
Expand All @@ -101,46 +104,6 @@ private int getNextUpgradeLevel(AbstractAbility ability, User user) {
return unlock + levelUp * user.getAbstractAbilityLevel(ability);
}

private String getCurrentValue(Ability ability, User user) {
return NumberUtil.format1(ability.getValue(user.getAbilityLevel(ability)));
}

private String getCurrentValue2(Ability ability, User user) {
return NumberUtil.format1(ability.getSecondaryValue(user.getAbilityLevel(ability)));
}

private String getUpgradeValue(Ability ability, User user, ActiveMenu activeMenu) {
String currentValue = getCurrentValue(ability, user);
String nextValue = NumberUtil.format1(ability.getValue(user.getAbilityLevel(ability) + 1));
return TextUtil.replace(activeMenu.getFormat("desc_upgrade_value"),
"{current}", currentValue,
"{next}", nextValue);
}

private String getUpgradeValue2(Ability ability, User user, ActiveMenu activeMenu) {
String currentValue = getCurrentValue2(ability, user);
String nextValue = NumberUtil.format1(ability.getSecondaryValue(user.getAbilityLevel(ability) + 1));
return TextUtil.replace(activeMenu.getFormat("desc_upgrade_value"),
"{current}", currentValue,
"{next}", nextValue);
}

private String getUpgradeValue(ManaAbility manaAbility, User user, ActiveMenu activeMenu) {
String currentValue = NumberUtil.format1(manaAbility.getDisplayValue(user.getManaAbilityLevel(manaAbility)));
String nextValue = NumberUtil.format1(manaAbility.getDisplayValue(user.getManaAbilityLevel(manaAbility) + 1));
return TextUtil.replace(activeMenu.getFormat("desc_upgrade_value"),
"{current}", currentValue,
"{next}", nextValue);
}

private String getUpgradeDuration(ManaAbility manaAbility, User user, ActiveMenu activeMenu) {
String currentDuration = NumberUtil.format1(getDuration(manaAbility, user.getManaAbilityLevel(manaAbility)));
String nextDuration = NumberUtil.format1(getDuration(manaAbility, user.getManaAbilityLevel(manaAbility) + 1));
return TextUtil.replace(activeMenu.getFormat("desc_upgrade_value"),
"{current}", currentDuration,
"{next}", nextDuration);
}

}

public static class UnlockedDescMaxed extends AbstractComponent implements ComponentProvider {
Expand All @@ -162,7 +125,7 @@ public <T> String onPlaceholderReplace(String placeholder, Player player, Active
return TextUtil.replace(manaAbility.getDescription(locale),
"{value}", NumberUtil.format1(manaAbility.getDisplayValue(user.getManaAbilityLevel(manaAbility))),
"{haste_level}", String.valueOf(manaAbility.optionInt("haste_level", 10)),
"{duration}", NumberUtil.format1(getDuration(manaAbility, user.getManaAbilityLevel(manaAbility))));
"{duration}", NumberUtil.format1(AbilityUtil.getDuration(manaAbility, user.getManaAbilityLevel(manaAbility))));
}
}
return replaceMenuMessage(placeholder, player, activeMenu);
Expand All @@ -185,14 +148,4 @@ private static boolean isNotMaxed(User user, AbstractAbility ability) {
return user.getAbstractAbilityLevel(ability) < maxLevel;
}

private static double getDuration(ManaAbility manaAbility, int level) {
if (manaAbility == ManaAbilities.LIGHTNING_BLADE) {
double baseDuration = ManaAbilities.LIGHTNING_BLADE.optionDouble("base_duration");
double durationPerLevel = ManaAbilities.LIGHTNING_BLADE.optionDouble("duration_per_level");
return baseDuration + (durationPerLevel * (level - 1));
} else {
return manaAbility.getValue(level);
}
}

}
12 changes: 7 additions & 5 deletions bukkit/src/main/resources/messages/messages_de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -562,12 +562,14 @@ leveler:
subtitle: "<gold>{old} ➜ {new}"
level_up: "<dark_aqua><strikethrough>----------------------------------------\n<reset> <dark_aqua>Fähigkeiten Levelaufstieg! <aqua><bold>{skill} </bold><dark_grey>{old}➜<dark_aqua><bold>{new}\n \n </bold><aqua>Belohnung:{stat_level}{ability_unlock}{ability_level_up}{mana_ability_unlock}{mana_ability_level_up}{money_reward}\n<dark_aqua><strikethrough>----------------------------------------"
stat_level: "\n {color}+{num}{symbol} {stat}"
ability_unlock: "\n <green>Fähigkeit freigeschaltet! <gold><bold>{ability} </bold><gray>wurde freigeschaltet"
ability_level_up: "\n <green>Fähigkeiten Levelaufstieg! <gold><bold>{ability} </bold><gray> ist nun Level <gold>{level}"
mana_ability_unlock: "\n <light_purple>Manafähigkeit freigeschaltet! <blue><bold>{mana_ability} </bold><gray>wurde freigeschaltet"
mana_ability_level_up: "\n <light_purple>Manafähigkeiten Levelaufstieg! <blue><bold>{mana_ability} </bold><gray>ist nun Level <gold>{level}"
ability_unlock: "\n <green>Fähigkeit freigeschaltet! <gold><bold>{ability} </bold><gray>wurde freigeschaltet\n <white>{desc}"
ability_level_up: "\n <green>Fähigkeiten Levelaufstieg! <gold><bold>{ability} </bold><gray> ist nun Level <gold>{level}\n <white>{desc}"
mana_ability_unlock: "\n <light_purple>Manafähigkeit freigeschaltet! <blue><bold>{mana_ability} </bold><gray>wurde freigeschaltet\n <white>{desc}"
mana_ability_level_up: "\n <light_purple>Manafähigkeiten Levelaufstieg! <blue><bold>{mana_ability} </bold><gray>ist nun Level <gold>{level}\n <white>{desc}"
money_reward: "\n <green>${amount}"
unclaimed_item: "<red>Du hast unbeanspruchte Gegenstände, weil dein Inventar voll war, benutze <yellow>/Skills um <red>to sie zu beanspruchen"
desc_upgrade_value: "<dark_gray>{current}→<white>{next}"
desc_wrap: "<white> "
menus:
common:
close: "Schließen"
Expand Down Expand Up @@ -1086,4 +1088,4 @@ units:
mana: Mana
hp: LP
xp: EP
file_version: 30
file_version: 31
12 changes: 7 additions & 5 deletions bukkit/src/main/resources/messages/messages_en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -562,12 +562,14 @@ leveler:
subtitle: "<gold>{old} ➜ {new}"
level_up: "<dark_aqua><strikethrough>----------------------------------------\n<reset> <dark_aqua>Skill Level Up! <aqua><bold>{skill}</bold> <dark_gray>{old}➜<dark_aqua><bold>{new}</bold>\n \n <aqua>Rewards:{stat_level}{ability_unlock}{ability_level_up}{mana_ability_unlock}{mana_ability_level_up}{money_reward}\n<dark_aqua><strikethrough>----------------------------------------"
stat_level: "\n {color}+{num}{symbol} {stat}"
ability_unlock: "\n <green>Ability Unlock! <gold><bold>{ability}</bold> <gray>has been unlocked"
ability_level_up: "\n <green>Ability Level Up! <gold><bold>{ability}</bold> <gray>is now level <gold>{level}"
mana_ability_unlock: "\n <light_purple>Mana Ability Unlock! <blue><bold>{mana_ability}</bold> <gray>has been unlocked"
mana_ability_level_up: "\n <light_purple>Mana Ability Level Up! <blue><bold>{mana_ability}</bold> <gray>is now level <gold>{level}"
ability_unlock: "\n <green>Ability Unlock! <gold><bold>{ability}</bold>\n <white>{desc}"
ability_level_up: "\n <green>Ability Level Up! <gold><bold>{ability}</bold> <dark_gray>{previous}→<gold>{level}\n <white>{desc}"
mana_ability_unlock: "\n <light_purple>Mana Ability Unlock! <blue><bold>{mana_ability}</bold>\n <white>{desc}"
mana_ability_level_up: "\n <light_purple>Mana Ability Level Up! <blue><bold>{mana_ability}</bold> <dark_gray>{previous}→<gold>{level}\n <white>{desc}"
money_reward: "\n <green>${amount}"
unclaimed_item: "<red>You have unclaimed items because your inventory was full, use <yellow>/skills claimitems <red>to claim them"
desc_upgrade_value: "<dark_gray>{current}→<white>{next}"
desc_wrap: "<white> "
menus:
common:
close: "Close"
Expand Down Expand Up @@ -1086,4 +1088,4 @@ units:
mana: Mana
hp: HP
xp: XP
file_version: 30
file_version: 31
12 changes: 7 additions & 5 deletions bukkit/src/main/resources/messages/messages_es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -562,12 +562,14 @@ leveler:
subtitle: "<gold>{old} ➜ {new}"
level_up: "<dark_aqua><strikethrough>----------------------------------------\n<reset> <dark_aqua>¡Nuevo Nivel! <aqua><bold>{skill} </bold><dark_grey>{old}➜<dark_aqua><bold>{new}\n \n </bold><aqua>Recompensas:{stat_level}{ability_unlock}{ability_level_up}{mana_ability_unlock}{mana_ability_level_up}{money_reward}\n<dark_aqua><strikethrough>----------------------------------------"
stat_level: "\n {color}+{num}{symbol} {stat}"
ability_unlock: "\n <green>¡Habilidad Desbloqueada! <gold><bold>{ability} </bold><gray>ha sido desbloqueada"
ability_level_up: "\n <green>¡Nuevo Nivel de Habilidad! <gold><bold>{ability} </bold><gray>es ahora nivel <gold>{level}"
mana_ability_unlock: "\n <light_purple>¡Habilidad de Maná Desbloqueada! <blue><bold>{mana_ability} </bold><gray>se ha desbloqueado"
mana_ability_level_up: "\n <light_purple>¡Nuevo Nivel de Habilidad de Maná! <blue><bold>{mana_ability} </bold><gray>es ahora nivel <gold>{level}"
ability_unlock: "\n <green>¡Habilidad Desbloqueada! <gold><bold>{ability} </bold><gray>ha sido desbloqueada\n <white>{desc}"
ability_level_up: "\n <green>¡Nuevo Nivel de Habilidad! <gold><bold>{ability} </bold><gray>es ahora nivel <gold>{level}\n <white>{desc}"
mana_ability_unlock: "\n <light_purple>¡Habilidad de Maná Desbloqueada! <blue><bold>{mana_ability} </bold><gray>se ha desbloqueado\n <white>{desc}"
mana_ability_level_up: "\n <light_purple>¡Nuevo Nivel de Habilidad de Maná! <blue><bold>{mana_ability} </bold><gray>es ahora nivel <gold>{level}\n <white>{desc}"
money_reward: "\n <green>${amount}"
unclaimed_item: "<red>Tienes objetos sin reclamar porque tu invnetario estaba lleno, usa <yellow>/skills claimitems <red>para reclamarlos"
desc_upgrade_value: "<dark_gray>{current}→<white>{next}"
desc_wrap: "<white> "
menus:
common:
close: "Cerrar"
Expand Down Expand Up @@ -1086,4 +1088,4 @@ units:
mana: Maná
hp: HP
xp: XP
file_version: 30
file_version: 31
12 changes: 7 additions & 5 deletions bukkit/src/main/resources/messages/messages_fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -562,12 +562,14 @@ leveler:
subtitle: "<gold>{old} ➜ {new}"
level_up: "<dark_aqua><strikethrough>----------------------------------------\n<reset> <dark_aqua>Niveau supérieur! <aqua><bold>{skill}</bold> <dark_gray>{old}➜<dark_aqua><bold>{new}</bold> \n \n <aqua>Récompenses:{stat_level}{ability_unlock}{ability_level_up}{mana_ability_unlock}{mana_ability_level_up}{money_reward}\n<dark_aqua><strikethrough>----------------------------------------"
stat_level: "\n {color}+{num}{symbol} {stat}"
ability_unlock: "\n <green>Compétence débloquée! <gold><bold>{ability}</bold> <gray>a été débloquée"
ability_level_up: "\n <green>Niveau de compétence supérieur! <gold><bold>{ability}</bold> <gray>est maintenant niveau <gold>{level}"
mana_ability_unlock: "\n<light_purple>Capacité de mana débloquée! <blue><bold>{mana_ability}</bold> <gray>a été débloquée"
mana_ability_level_up: "\n <light_purple>Niveau de compétence de mana supérieur! <blue><bold>{mana_ability}</bold> <gray>est maintenant niveau <gold>{level}"
ability_unlock: "\n <green>Compétence débloquée! <gold><bold>{ability}</bold> <gray>a été débloquée\n <white>{desc}"
ability_level_up: "\n <green>Niveau de compétence supérieur! <gold><bold>{ability}</bold> <gray>est maintenant niveau <gold>{level}\n <white>{desc}"
mana_ability_unlock: "\n<light_purple>Capacité de mana débloquée! <blue><bold>{mana_ability}</bold> <gray>a été débloquée\n <white>{desc}"
mana_ability_level_up: "\n <light_purple>Niveau de compétence de mana supérieur! <blue><bold>{mana_ability}</bold> <gray>est maintenant niveau <gold>{level}\n <white>{desc}"
money_reward: "\n <green>${amount}"
unclaimed_item: "<red>Vous avez des objets non réclamés parce que votre inventaire était plein, utilisez <yellow>/skills claimitems <red>pour les réclamer"
desc_upgrade_value: "<dark_gray>{current}→<white>{next}"
desc_wrap: "<white> "
menus:
common:
close: "Fermer"
Expand Down Expand Up @@ -1086,4 +1088,4 @@ units:
mana: Mana
hp: PV
xp: XP
file_version: 30
file_version: 31
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package dev.aurelium.auraskills.common.ability;

import dev.aurelium.auraskills.api.ability.Ability;
import dev.aurelium.auraskills.api.mana.ManaAbilities;
import dev.aurelium.auraskills.api.mana.ManaAbility;
import dev.aurelium.auraskills.api.util.NumberUtil;
import dev.aurelium.auraskills.common.util.text.TextUtil;

public class AbilityUtil {

public static String getUpgradeValue(Ability ability, int level, String format) {
String currentValue = getCurrentValue(ability, level);
String nextValue = NumberUtil.format1(ability.getValue(level + 1));
return TextUtil.replace(format,
"{current}", currentValue,
"{next}", nextValue);
}

public static String getUpgradeValue2(Ability ability, int level, String format) {
String currentValue = getCurrentValue2(ability, level);
String nextValue = NumberUtil.format1(ability.getSecondaryValue(level + 1));
return TextUtil.replace(format,
"{current}", currentValue,
"{next}", nextValue);
}

public static String getCurrentValue(Ability ability, int level) {
return NumberUtil.format1(ability.getValue(level));
}

public static String getCurrentValue2(Ability ability, int level) {
return NumberUtil.format1(ability.getSecondaryValue(level));
}

public static String getUpgradeValue(ManaAbility manaAbility, int level, String format) {
String currentValue = NumberUtil.format1(manaAbility.getDisplayValue(level));
String nextValue = NumberUtil.format1(manaAbility.getDisplayValue(level + 1));
return TextUtil.replace(format,
"{current}", currentValue,
"{next}", nextValue);
}

public static String getUpgradeDuration(ManaAbility manaAbility, int level, String format) {
String currentDuration = NumberUtil.format1(getDuration(manaAbility, level));
String nextDuration = NumberUtil.format1(getDuration(manaAbility, level + 1));
return TextUtil.replace(format,
"{current}", currentDuration,
"{next}", nextDuration);
}

public static double getDuration(ManaAbility manaAbility, int level) {
if (manaAbility == ManaAbilities.LIGHTNING_BLADE) {
double baseDuration = ManaAbilities.LIGHTNING_BLADE.optionDouble("base_duration");
double durationPerLevel = ManaAbilities.LIGHTNING_BLADE.optionDouble("duration_per_level");
return baseDuration + (durationPerLevel * (level - 1));
} else {
return manaAbility.getValue(level);
}
}

}
Loading

0 comments on commit 74e63d7

Please sign in to comment.