Attributes now follow class slots

This commit is contained in:
Aria 2019-09-12 03:43:56 +02:00
parent efc387d7a2
commit 5c35e35ee6
4 changed files with 89 additions and 7 deletions

View File

@ -31,6 +31,7 @@ import net.Indyuce.mmocore.api.Waypoint;
import net.Indyuce.mmocore.api.event.PlayerCastSkillEvent;
import net.Indyuce.mmocore.api.event.PlayerLevelUpEvent;
import net.Indyuce.mmocore.api.math.particle.SmallParticleEffect;
import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
import net.Indyuce.mmocore.api.player.attribute.PlayerAttributes;
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
import net.Indyuce.mmocore.api.player.profess.PlayerClass.Subclass;
@ -103,7 +104,7 @@ public class PlayerData {
this.attributeReallocationPoints = config.getInt("attribute-realloc-points");
this.level = config.getInt("level");
this.experience = config.getInt("experience");
this.profess = config.contains("class") ? MMOCore.plugin.classManager.get(config.getString("class")) : null;
this.profess = config.contains("class") ? MMOCore.plugin.classManager.get(config.getString("class")) : MMOCore.plugin.classManager.getDefaultClass();
this.mana = getStats().getStat(StatType.MAX_MANA);
this.stamina = getStats().getStat(StatType.MAX_STAMINA);
this.stellium = getStats().getStat(StatType.MAX_STELLIUM);
@ -178,7 +179,10 @@ public class PlayerData {
config.set("class-info." + key + ".level", info.getLevel());
config.set("class-info." + key + ".experience", info.getExperience());
config.set("class-info." + key + ".skill-points", info.getSkillPoints());
config.set("class-info." + key + ".attribute-points", info.getAttributePoints());
config.set("class-info." + key + ".attribute-realloc-points", info.getAttributeReallocationPoints());
info.getSkillKeys().forEach(skill -> config.set("class-info." + key + ".skill." + skill, info.getSkillLevel(skill)));
info.getAttributeKeys().forEach(attribute -> config.set("class-info." + key + ".attribute." + attribute, info.getAttributeLevel(attribute)));
}
}
@ -566,6 +570,25 @@ public class PlayerData {
player.spigot().sendMessage(ChatMessageType.ACTION_BAR, TextComponent.fromLegacyText(getProfess().getManaDisplay().generateBar(getMana(), getStats().getStat(StatType.MAX_MANA))));
}
public void setAttributes(PlayerAttribute attribute, int value) {
setAttributes(attribute.getId(), value);
}
public void setAttributes(String id, int value) {
attributes.setBaseAttribute(id, value);
}
public void clearAttributePoints() {
attributes.getAttributeInstances().forEach(ins -> ins.setBase(0));
}
public Map<String, Integer> mapAttributePoints() {
Map<String, Integer> ap = new HashMap<String, Integer>();
attributes.getAttributeInstances().forEach(ins -> ap.put(ins.getId(), ins.getBase()));
return ap;
}
public void setSkillLevel(Skill skill, int level) {
setSkillLevel(skill.getId(), level);
}

View File

@ -158,5 +158,16 @@ public class PlayerAttributes {
int total = getTotal();
attribute.getStats().forEach(stat -> data.getStats().getInstance(stat).addModifier("attribute." + attribute.getId(), attribute.getBuff(stat).multiply(total)));
}
public String getId() {
return id;
}
}
public void setBaseAttribute(String id, int value) {
getAttributeInstances().forEach(ins -> {
if(ins.getId().equals(id))
ins.setBase(value);
});
}
}

View File

@ -7,18 +7,25 @@ import java.util.Set;
import org.bukkit.configuration.ConfigurationSection;
import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.player.attribute.PlayerAttribute;
import net.Indyuce.mmocore.api.player.profess.PlayerClass.ClassOption;
import net.Indyuce.mmocore.api.skill.Skill;
public class SavedClassInformation {
private final int level, experience, skillPoints;
private final int level, experience, skillPoints, attributePoints, attributeReallocationPoints;
private final Map<String, Integer> attributes;
private final Map<String, Integer> skills;
public SavedClassInformation(ConfigurationSection config) {
level = config.getInt("level");
experience = config.getInt("experience");
skillPoints = config.getInt("skill-points");
attributePoints = config.getInt("attribute-points");
attributeReallocationPoints = config.getInt("attribute-realloc-points");
attributes = new HashMap<>();
if (config.contains("attribute"))
config.getKeys(false).forEach(key -> attributes.put(key, config.getInt(key)));
skills = new HashMap<>();
if (config.contains("skill"))
config.getKeys(false).forEach(key -> skills.put(key, config.getInt(key)));
@ -29,12 +36,18 @@ public class SavedClassInformation {
skillPoints = player.getSkillPoints();
experience = player.getExperience();
skills = player.mapSkillLevels();
attributes = player.mapAttributePoints();
attributePoints = player.getAttributePoints();
attributeReallocationPoints = player.getAttributeReallocationPoints();
}
public SavedClassInformation(int level, int experience, int skillPoints) {
public SavedClassInformation(int level, int experience, int skillPoints, int attributePoints, int attributeReallocationPoints) {
this.level = level;
this.experience = experience;
this.skillPoints = skillPoints;
this.attributePoints = attributePoints;
this.attributeReallocationPoints = attributeReallocationPoints;
attributes = new HashMap<>();
skills = new HashMap<>();
}
@ -50,6 +63,14 @@ public class SavedClassInformation {
return skillPoints;
}
public int getAttributePoints() {
return attributePoints;
}
public int getAttributeReallocationPoints() {
return attributeReallocationPoints;
}
public Set<String> getSkillKeys() {
return skills.keySet();
}
@ -66,8 +87,29 @@ public class SavedClassInformation {
registerSkillLevel(skill.getId(), level);
}
public void registerSkillLevel(String skill, int level) {
skills.put(skill, level);
public void registerSkillLevel(String attribute, int level) {
skills.put(attribute, level);
}
public Set<String> getAttributeKeys() {
return attributes.keySet();
}
public int getAttributeLevel(PlayerAttribute attribute) {
return getAttributeLevel(attribute.getId());
}
public int getAttributeLevel(String id) {
return attributes.get(id);
}
public void registerAttributeLevel(PlayerAttribute attribute, int level) {
registerSkillLevel(attribute.getId(), level);
}
public void registerAttributeLevel(String attribute, int level) {
attributes.put(attribute, level);
}
public void load(PlayerClass profess, PlayerData player) {
@ -85,6 +127,7 @@ public class SavedClassInformation {
player.clearSkillLevels();
while (player.hasSkillBound(0))
player.unbindSkill(0);
player.clearAttributePoints();
/*
* reads this class info, applies it to the player. set class after
@ -94,7 +137,10 @@ public class SavedClassInformation {
player.setLevel(level);
player.setExperience(experience);
player.setSkillPoints(skillPoints);
player.setAttributePoints(attributePoints);
player.setAttributeReallocationPoints(attributeReallocationPoints);
skills.keySet().forEach(id -> player.setSkillLevel(id, skills.get(id)));
attributes.keySet().forEach(id -> player.setAttributes(id, attributes.get(id)));
/*
* unload current class information and set the new profess once

View File

@ -128,7 +128,9 @@ public class ClassConfirmation extends EditableInventory {
return;
playerData.giveClassPoints(-1);
(playerData.hasSavedClass(profess) ? playerData.getClassInfo(profess) : new SavedClassInformation(1, 0, 0)).load(profess, playerData);
(playerData.hasSavedClass(profess) ? playerData.getClassInfo(profess) : new SavedClassInformation(1, 0, 0, 0, 0)).load(profess, playerData);
while (playerData.hasSkillBound(0))
playerData.unbindSkill(0);
player.sendMessage(MMOCore.plugin.configManager.getSimpleMessage("class-select", "class", profess.getName()));
player.playSound(player.getLocation(), Sound.UI_TOAST_CHALLENGE_COMPLETE, 1, 1);
player.closeInventory();