Fixed subclass confirmation

This commit is contained in:
Jules 2023-04-13 19:43:43 +02:00
parent 3904b9a8b7
commit f9a4f65860
13 changed files with 95 additions and 66 deletions

View File

@ -264,8 +264,11 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
}
}
public Map<SkillTreeNode, Integer> getNodeLevels() {
return new HashMap<>(nodeLevels);
@Override
public Map<String, Integer> getNodeLevels() {
final Map<String, Integer> mapped = new HashMap<>();
this.nodeLevels.forEach((node, level) -> mapped.put(node.getFullId(), level));
return mapped;
}
public void clearNodeLevels() {

View File

@ -7,7 +7,6 @@ import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
import net.Indyuce.mmocore.player.ClassDataContainer;
import net.Indyuce.mmocore.skill.ClassSkill;
import net.Indyuce.mmocore.skill.RegisteredSkill;
import net.Indyuce.mmocore.skilltree.SkillTreeNode;
import net.Indyuce.mmocore.skilltree.tree.SkillTree;
@ -20,7 +19,7 @@ import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
public class SavedClassInformation {
public class SavedClassInformation implements ClassDataContainer {
private final int level, skillPoints, attributePoints, attributeReallocationPoints, skillTreeReallocationPoints, skillReallocationPoints;
private final double experience, health, mana, stellium, stamina;
private final Map<String, Integer> attributeLevels = new HashMap<>();
@ -128,44 +127,53 @@ public class SavedClassInformation {
data.mapAttributeLevels().forEach((key, val) -> this.attributeLevels.put(key, val));
data.mapSkillLevels().forEach((key, val) -> skillLevels.put(key, val));
data.mapSkillTreePoints().forEach((key, val) -> skillTreePoints.put(key, val));
data.getNodeLevels().forEach((node, level) -> nodeLevels.put(node.getFullId(), level));
data.getNodeLevels().forEach((node, level) -> nodeLevels.put(node, level));
data.getNodeTimesClaimed().forEach((key, val) -> nodeTimesClaimed.put(key, val));
data.mapBoundSkills().forEach((slot, skill) -> boundSkills.put(slot, skill));
data.getUnlockedItems().forEach(item->unlockedItems.add(item));
data.getUnlockedItems().forEach(item -> unlockedItems.add(item));
}
@Override
public int getLevel() {
return level;
}
@Override
public double getExperience() {
return experience;
}
@Override
public int getSkillPoints() {
return skillPoints;
}
@Override
public int getAttributePoints() {
return attributePoints;
}
@Override
public int getAttributeReallocationPoints() {
return attributeReallocationPoints;
}
@Override
public double getHealth() {
return health;
}
@Override
public double getMana() {
return mana;
}
@Override
public double getStellium() {
return stellium;
}
@Override
public double getStamina() {
return stamina;
}
@ -186,14 +194,27 @@ public class SavedClassInformation {
registerSkillLevel(skill.getHandler().getId(), level);
}
public Map<Integer, String> getBoundSkills() {
return boundSkills;
@Override
public Map<String, Integer> mapSkillLevels() {
return skillLevels;
}
@Override
public Map<String, Integer> mapSkillTreePoints() {
return skillTreePoints;
}
@Deprecated
public Map<Integer, String> getBoundSkills() {
return mapBoundSkills();
}
@Override
public int getSkillTreeReallocationPoints() {
return skillTreeReallocationPoints;
}
@Override
public int getSkillReallocationPoints() {
return skillReallocationPoints;
}
@ -210,6 +231,26 @@ public class SavedClassInformation {
return nodeLevels.get(node);
}
@Override
public Map<String, Integer> mapAttributeLevels() {
return attributeLevels;
}
@Override
public Map<Integer, String> mapBoundSkills() {
return boundSkills;
}
@Override
public Map<String, Integer> getNodeLevels() {
return nodeLevels;
}
@Override
public Map<String, Integer> getNodeTimesClaimed() {
return nodeTimesClaimed;
}
public Set<String> getSkillTreePointsKeys() {
return skillTreePoints.keySet();
}
@ -234,6 +275,7 @@ public class SavedClassInformation {
attributeLevels.put(attribute, level);
}
@Override
public Set<String> getUnlockedItems() {
return unlockedItems;
}

View File

@ -14,20 +14,20 @@ import net.Indyuce.mmocore.gui.api.PluginInventory;
import net.Indyuce.mmocore.gui.api.item.InventoryItem;
import net.Indyuce.mmocore.gui.api.item.Placeholders;
import net.Indyuce.mmocore.gui.api.item.SimplePlaceholderItem;
import net.Indyuce.mmocore.player.ClassDataContainer;
import org.apache.commons.lang.Validate;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Material;
import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.inventory.ItemStack;
public class ClassConfirmation extends EditableInventory {
private final PlayerClass playerClass;
public ClassConfirmation(PlayerClass playerClass, boolean isDefault) {
super("class-confirm-" + (isDefault ? "default" : UtilityMethods.ymlName(playerClass.getId())));
this.playerClass = playerClass;
}
@ -36,13 +36,8 @@ public class ClassConfirmation extends EditableInventory {
return function.equalsIgnoreCase("yes") ? new YesItem(config) : new SimplePlaceholderItem(config);
}
public GeneratedInventory newInventory(PlayerData data, PluginInventory last) {
return new ClassConfirmationInventory(data, this, playerClass, last);
}
@Override
public void reload(FileConfiguration config) {
super.reload(config);
public GeneratedInventory newInventory(PlayerData data, PluginInventory last, boolean subclass) {
return new ClassConfirmationInventory(data, this, playerClass, last, subclass);
}
public class UnlockedItem extends InventoryItem<ClassConfirmationInventory> {
@ -53,7 +48,7 @@ public class ClassConfirmation extends EditableInventory {
@Override
public Placeholders getPlaceholders(ClassConfirmationInventory inv, int n) {
PlayerClass profess = inv.profess;
SavedClassInformation info = inv.getPlayerData().getClassInfo(profess);
ClassDataContainer info = inv.subclass ? inv.getPlayerData() : inv.getPlayerData().getClassInfo(profess);
Placeholders holders = new Placeholders();
final double nextLevelExp = inv.getPlayerData().getLevelUpExperience();
@ -67,7 +62,7 @@ public class ClassConfirmation extends EditableInventory {
holders.register("percent", decimal.format(ratio * 100));
holders.register("progress", bar.toString());
holders.register("class", profess.getName());
holders.register("unlocked_skills", info.getSkillKeys().size());
holders.register("unlocked_skills", info.mapSkillLevels().size());
holders.register("class_skills", profess.getSkills().size());
holders.register("next_level", "" + nextLevelExp);
holders.register("level", info.getLevel());
@ -108,12 +103,14 @@ public class ClassConfirmation extends EditableInventory {
public class ClassConfirmationInventory extends GeneratedInventory {
private final PlayerClass profess;
private final PluginInventory last;
private final boolean subclass;
public ClassConfirmationInventory(PlayerData playerData, EditableInventory editable, PlayerClass profess, PluginInventory last) {
public ClassConfirmationInventory(PlayerData playerData, EditableInventory editable, PlayerClass profess, PluginInventory last, boolean subclass) {
super(playerData, editable);
this.profess = profess;
this.last = last;
this.subclass = subclass;
}
@Override
@ -129,8 +126,11 @@ public class ClassConfirmation extends EditableInventory {
return;
playerData.giveClassPoints(-1);
(playerData.hasSavedClass(profess) ? playerData.getClassInfo(profess)
: new SavedClassInformation(MMOCore.plugin.dataProvider.getDataManager().getDefaultData())).load(profess, playerData);
if (subclass)
playerData.setClass(profess);
else
(playerData.hasSavedClass(profess) ? playerData.getClassInfo(profess)
: new SavedClassInformation(MMOCore.plugin.dataProvider.getDataManager().getDefaultData())).load(profess, playerData);
MMOCore.plugin.configManager.getSimpleMessage("class-select", "class", profess.getName()).send(player);
MMOCore.plugin.soundManager.getSound(SoundEvent.SELECT_CLASS).playTo(player);
player.closeInventory();

View File

@ -90,14 +90,9 @@ public class ClassSelect extends EditableInventory {
item.setItemMeta(meta);
return item;
}
}
public class ProfessSelectionInventory extends GeneratedInventory {
private final List<PlayerClass> classes = MMOCore.plugin.classManager.getAll().stream().filter(c -> c.hasOption(ClassOption.DISPLAY))
.sorted(Comparator.comparingInt(PlayerClass::getDisplayOrder)).collect(Collectors.toList());
public ProfessSelectionInventory(PlayerData playerData, EditableInventory editable) {
super(playerData, editable);
}
@ -131,7 +126,7 @@ public class ClassSelect extends EditableInventory {
}
final PlayerClass playerClass = findDeepestSubclass(playerData, profess);
InventoryManager.CLASS_CONFIRM.get(MMOCoreUtils.ymlName(playerClass.getId())).newInventory(playerData, this).open();
InventoryManager.CLASS_CONFIRM.get(MMOCoreUtils.ymlName(playerClass.getId())).newInventory(playerData, this, false).open();
}
}
}

View File

@ -96,13 +96,8 @@ public class SubclassSelect extends EditableInventory {
}
public class SubclassSelectionInventory extends GeneratedInventory {
private final List<Subclass> subclasses;
public SubclassSelectionInventory(PlayerData playerData, EditableInventory editable) {
super(playerData, editable);
subclasses = playerData.getProfess().getSubclasses().stream().filter(sub -> playerData.getLevel() >= sub.getLevel())
.collect(Collectors.toList());
}
@Override
@ -116,7 +111,7 @@ public class SubclassSelect extends EditableInventory {
InventoryManager.CLASS_SELECT.newInventory(playerData).open();
if (item.getFunction().startsWith("sub-class")) {
String classId= item.getFunction().substring(10);
String classId = item.getFunction().substring(10);
if (playerData.getClassPoints() < 1) {
player.closeInventory();
@ -124,7 +119,8 @@ public class SubclassSelect extends EditableInventory {
new ConfigMessage("cant-choose-new-class").send(player);
return;
}
InventoryManager.CLASS_CONFIRM.get(classId).newInventory(playerData, this).open();
InventoryManager.CLASS_CONFIRM.get(classId).newInventory(playerData, this, true).open();
}
}
}

View File

@ -35,26 +35,20 @@ public class InventoryManager {
public static final List<EditableInventory> list = new ArrayList(Arrays.asList(PLAYER_STATS, ATTRIBUTE_VIEW, TREE_VIEW, SKILL_LIST, CLASS_SELECT, SUBCLASS_SELECT, QUEST_LIST, WAYPOINTS, FRIEND_LIST, FRIEND_REMOVAL, PARTY_VIEW, PARTY_CREATION, GUILD_VIEW, GUILD_CREATION));
private static List<String> defaultClass = Arrays.asList(new String[]{"human", "mage", "paladin", "warrior", "rogue", "arcane-mage"});
public static void load() {
String classConfirmFolder = "gui/class-confirm";
final String classConfirmFolder = "gui/class-confirm";
try {
MMOCore.plugin.configManager.loadDefaultFile(classConfirmFolder, "class-confirm-default.yml");
} catch (Exception exception) {
MMOCore.log(Level.WARNING, "Could not load inventory 'class-confirm/class-confirm-default" + "': " + exception.getMessage());
}
for (PlayerClass playerClass : MMOCore.plugin.classManager.getAll()) {
String classId = MMOCoreUtils.ymlName(playerClass.getId());
ConfigFile configFile = new ConfigFile(classConfirmFolder, "class-confirm-" + classId);
ClassConfirmation GUI;
if (configFile.exists())
GUI = new ClassConfirmation(playerClass, false);
else {
GUI = new ClassConfirmation(playerClass, true);
}
final String classId = MMOCoreUtils.ymlName(playerClass.getId());
final ConfigFile configFile = new ConfigFile(classConfirmFolder, "class-confirm-" + classId);
final ClassConfirmation GUI = configFile.exists() ? new ClassConfirmation(playerClass, false) : new ClassConfirmation(playerClass, true);
CLASS_CONFIRM.put(MMOCoreUtils.ymlName(playerClass.getId()), GUI);
GUI.reload(new ConfigFile("/" +classConfirmFolder, GUI.getId()).getConfig());
GUI.reload(new ConfigFile("/" + classConfirmFolder, GUI.getId()).getConfig());
}
list.forEach(inv ->

View File

@ -115,8 +115,8 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
classinfo.add("skill-tree-points", skillTreePointsInfo);
JsonObject boundSkillInfo = new JsonObject();
for (int slot : info.getBoundSkills().keySet())
boundSkillInfo.addProperty(slot + "", info.getBoundSkills().get(slot));
for (int slot : info.mapBoundSkills().keySet())
boundSkillInfo.addProperty(String.valueOf(slot), info.mapBoundSkills().get(slot));
classinfo.add("bound-skills", boundSkillInfo);
json.add(c, classinfo);

View File

@ -191,7 +191,7 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
info.getAttributeKeys().forEach(attribute -> config.set("class-info." + key + ".attribute." + attribute, info.getAttributeLevel(attribute)));
info.getNodeKeys().forEach(node -> config.set("class-info." + key + ".node-levels." + node, info.getNodeLevel(node)));
info.getSkillTreePointsKeys().forEach(skillTreeId -> config.set("class-info." + key + ".skill-tree-points." + skillTreeId, info.getAttributeLevel(skillTreeId)));
info.getBoundSkills().forEach((slot, skill) -> config.set("class-info." + key + ".bound-skills." + slot, skill));
info.mapBoundSkills().forEach((slot, skill) -> config.set("class-info." + key + ".bound-skills." + slot, skill));
config.set("class-info." + key + ".unlocked-items", new ArrayList<>(info.getUnlockedItems()));
}

View File

@ -1,15 +1,15 @@
package net.Indyuce.mmocore.player;
import net.Indyuce.mmocore.api.player.profess.SavedClassInformation;
import net.Indyuce.mmocore.skilltree.SkillTreeNode;
import java.util.Map;
import java.util.Set;
/**
* All the class-specific information i.e information being saved
* in {@link SavedClassInformation} when a player changes its current
* class.
* in {@link SavedClassInformation} when a player changes its current class.
*
* TODO move {@link SavedClassInformation} method to ClassDataContainer
*/
public interface ClassDataContainer {
@ -43,7 +43,7 @@ public interface ClassDataContainer {
Map<Integer,String> mapBoundSkills();
Map<SkillTreeNode, Integer> getNodeLevels();
Map<String, Integer> getNodeLevels();
Map<String, Integer> getNodeTimesClaimed();

View File

@ -110,7 +110,7 @@ public class DefaultPlayerData implements ClassDataContainer {
}
@Override
public Map<SkillTreeNode, Integer> getNodeLevels() {
public Map<String, Integer> getNodeLevels() {
return new HashMap<>();
}

View File

@ -200,11 +200,10 @@ death-exp-loss:
# Maximum number of skill slots. This means that you cannot unlock more than X skill slots.
max-skill-slots: 8
#If you want players to bound their passive skills.
#If false, all the passive skills unlocked will be active
#Also set max-bound-passive-skills to 0 if seting passive-skill-need-bound to false.
passive-skill-need-bound: true
# When set to true, passive skills must be bound in order to take effect.
# When set to false, unlocked skills will take effect right away.
# Temporarily disabled.
# passive-skill-need-bound: true
# Fun extra RPG feature that switches the player's hotbar with
# the 9 lower row items of his inventory. This allows the player

View File

@ -39,12 +39,16 @@ max-level: 100
skill-slots:
1:
name: "Skill Slot I"
unlocked-by-default: true
2:
name: "Skill Slot II"
unlocked-by-default: true
3:
name: "Skill Slot III"
unlocked-by-default: true
4:
name: "Skill Slot IV"
unlocked-by-default: true
skill-trees:
- 'general'

View File

@ -1,13 +1,9 @@
name: Ambers
name: Mana Ambers
lore:
- Dealing magic damage has &630% &7chance
- of dropping an amber on the ground.
- ''
- When picked up, ambers stack and
- refund &9{percent}% &7of your missing mana.
- ''
- '&oAmbers can be used in other damaging skills.'
- '&oThe more you collect, the more powerful the skills.'
- When picked up, ambers refund &9{percent}% &7of your missing mana.
- ''
- '&e{cooldown}s Cooldown'
material: EMERALD