forked from Upstream/mmocore
Addex exp tables to attributes
This commit is contained in:
parent
f9cc6bfb33
commit
7d2af8d787
@ -3,57 +3,109 @@ package net.Indyuce.mmocore.api.player.attribute;
|
|||||||
import io.lumine.mythic.lib.MythicLib;
|
import io.lumine.mythic.lib.MythicLib;
|
||||||
import io.lumine.mythic.lib.api.stat.modifier.StatModifier;
|
import io.lumine.mythic.lib.api.stat.modifier.StatModifier;
|
||||||
import net.Indyuce.mmocore.MMOCore;
|
import net.Indyuce.mmocore.MMOCore;
|
||||||
|
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||||
|
import net.Indyuce.mmocore.experience.EXPSource;
|
||||||
|
import net.Indyuce.mmocore.experience.ExpCurve;
|
||||||
|
import net.Indyuce.mmocore.experience.ExperienceObject;
|
||||||
|
import net.Indyuce.mmocore.experience.droptable.ExperienceTable;
|
||||||
import org.apache.commons.lang.Validate;
|
import org.apache.commons.lang.Validate;
|
||||||
|
import org.bukkit.Location;
|
||||||
import org.bukkit.configuration.ConfigurationSection;
|
import org.bukkit.configuration.ConfigurationSection;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.Objects;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
|
||||||
public class PlayerAttribute {
|
public class PlayerAttribute implements ExperienceObject {
|
||||||
private final String id, name;
|
private final String id, name;
|
||||||
private final int max;
|
private final int max;
|
||||||
|
private final ExperienceTable expTable;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Used to store stats using StatType, but attributes also need to access
|
* Used to store stats using StatType, but attributes also need to access
|
||||||
* non basic MMOCore stats hence the string maps keys
|
* non basic MMOCore stats hence the string maps keys
|
||||||
*/
|
*/
|
||||||
private final Set<StatModifier> buffs = new HashSet<>();
|
private final Set<StatModifier> buffs = new HashSet<>();
|
||||||
|
|
||||||
public PlayerAttribute(ConfigurationSection config) {
|
public PlayerAttribute(ConfigurationSection config) {
|
||||||
Validate.notNull(config, "Could not load config");
|
Validate.notNull(config, "Could not load config");
|
||||||
id = config.getName().toLowerCase().replace("_", "-").replace(" ", "-");
|
id = config.getName().toLowerCase().replace("_", "-").replace(" ", "-");
|
||||||
|
|
||||||
name = MythicLib.plugin.parseColors(config.getString("name", "Attribute"));
|
name = MythicLib.plugin.parseColors(config.getString("name", "Attribute"));
|
||||||
max = config.contains("max-points") ? Math.max(1, config.getInt("max-points")) : 0;
|
max = config.contains("max-points") ? Math.max(1, config.getInt("max-points")) : 0;
|
||||||
|
|
||||||
if (config.contains("buff"))
|
if (config.contains("buff"))
|
||||||
for (String key : config.getConfigurationSection("buff").getKeys(false))
|
for (String key : config.getConfigurationSection("buff").getKeys(false))
|
||||||
try {
|
try {
|
||||||
String stat = key.toUpperCase().replace("-", "_").replace(" ", "_");
|
String stat = key.toUpperCase().replace("-", "_").replace(" ", "_");
|
||||||
buffs.add(new StatModifier("attribute." + id, stat, config.getString("buff." + key)));
|
buffs.add(new StatModifier("attribute." + id, stat, config.getString("buff." + key)));
|
||||||
} catch (IllegalArgumentException exception) {
|
} catch (IllegalArgumentException exception) {
|
||||||
MMOCore.log(Level.WARNING, "Could not load buff '" + key + "' from attribute '" + id + "': " + exception.getMessage());
|
MMOCore.log(Level.WARNING, "Could not load buff '" + key + "' from attribute '" + id + "': " + exception.getMessage());
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
public String getId() {
|
// Load exp table
|
||||||
return id;
|
ExperienceTable expTable = null;
|
||||||
}
|
if (config.contains("exp-table"))
|
||||||
|
try {
|
||||||
|
expTable = MMOCore.plugin.experience.loadExperienceTable(config.get("exp-table"));
|
||||||
|
} catch (RuntimeException exception) {
|
||||||
|
MMOCore.plugin.getLogger().log(Level.WARNING, "Could not load exp table from class '" + id + "': " + exception.getMessage());
|
||||||
|
}
|
||||||
|
this.expTable = expTable;
|
||||||
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getId() {
|
||||||
return name;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean hasMax() {
|
public String getName() {
|
||||||
return max > 0;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getMax() {
|
public boolean hasMax() {
|
||||||
return max;
|
return max > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<StatModifier> getBuffs() {
|
public int getMax() {
|
||||||
return buffs;
|
return max;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Set<StatModifier> getBuffs() {
|
||||||
|
return buffs;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getKey() {
|
||||||
|
return "attribute:" + getId().replace("-", "_");
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
@Override
|
||||||
|
public ExperienceTable getExperienceTable() {
|
||||||
|
return Objects.requireNonNull(expTable);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean hasExperienceTable() {
|
||||||
|
return expTable != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
@Override
|
||||||
|
public ExpCurve getExpCurve() {
|
||||||
|
throw new RuntimeException("Attributes don't have experience");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void giveExperience(PlayerData playerData, double experience, @Nullable Location hologramLocation, @NotNull EXPSource source) {
|
||||||
|
throw new RuntimeException("Attributes don't have experience");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean shouldHandle(PlayerData playerData) {
|
||||||
|
throw new RuntimeException("Attributes don't have experience");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -129,8 +129,17 @@ public class PlayerAttributes {
|
|||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Adds X points to the base of the player attribute AND applies
|
||||||
|
* the attribute experience table.
|
||||||
|
*
|
||||||
|
* @param value Amount of attribute points spent in the attribute
|
||||||
|
*/
|
||||||
public void addBase(int value) {
|
public void addBase(int value) {
|
||||||
|
PlayerAttribute attribute = MMOCore.plugin.attributeManager.get(id);
|
||||||
setBase(spent + value);
|
setBase(spent + value);
|
||||||
|
if (attribute.hasExperienceTable())
|
||||||
|
attribute.getExperienceTable().claim(data, spent, attribute);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -159,14 +168,14 @@ public class PlayerAttributes {
|
|||||||
return map.get(key);
|
return map.get(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addModifier(String key, double value) {
|
public AttributeModifier addModifier(String key, double value) {
|
||||||
addModifier(new AttributeModifier(key, id, value, ModifierType.FLAT, EquipmentSlot.OTHER, ModifierSource.OTHER));
|
return addModifier(new AttributeModifier(key, id, value, ModifierType.FLAT, EquipmentSlot.OTHER, ModifierSource.OTHER));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addModifier(AttributeModifier modifier) {
|
public AttributeModifier addModifier(AttributeModifier modifier) {
|
||||||
map.put(modifier.getKey(), modifier);
|
AttributeModifier mod = map.put(modifier.getKey(), modifier);
|
||||||
|
|
||||||
update();
|
update();
|
||||||
|
return mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> getKeys() {
|
public Set<String> getKeys() {
|
||||||
@ -177,7 +186,7 @@ public class PlayerAttributes {
|
|||||||
return map.containsKey(key);
|
return map.containsKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeModifier(String key) {
|
public AttributeModifier removeModifier(String key) {
|
||||||
AttributeModifier mod = map.remove(key);
|
AttributeModifier mod = map.remove(key);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -190,12 +199,13 @@ public class PlayerAttributes {
|
|||||||
((Closeable) mod).close();
|
((Closeable) mod).close();
|
||||||
update();
|
update();
|
||||||
}
|
}
|
||||||
|
return mod;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void update() {
|
public void update() {
|
||||||
PlayerAttribute attribute = MMOCore.plugin.attributeManager.get(id);
|
PlayerAttribute attr = MMOCore.plugin.attributeManager.get(id);
|
||||||
int total = getTotal();
|
int total = getTotal();
|
||||||
attribute.getBuffs().forEach(buff -> buff.multiply(total).register(data.getMMOPlayerData()));
|
attr.getBuffs().forEach(buff -> buff.multiply(total).register(data.getMMOPlayerData()));
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
|
@ -36,13 +36,13 @@ public class ExperienceItem {
|
|||||||
* where n is the amount of successive claiming fails
|
* where n is the amount of successive claiming fails
|
||||||
* @param triggers Actions cast when the exp item is claimed
|
* @param triggers Actions cast when the exp item is claimed
|
||||||
*/
|
*/
|
||||||
public ExperienceItem(String id, int period, int firstTrigger,double claimChance, double failReduction, List<Trigger> triggers) {
|
public ExperienceItem(String id, int period, int firstTrigger, double claimChance, double failReduction, List<Trigger> triggers) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.period = period;
|
this.period = period;
|
||||||
this.claimChance = claimChance;
|
this.claimChance = claimChance;
|
||||||
this.failReduction = failReduction;
|
this.failReduction = failReduction;
|
||||||
this.triggers = triggers;
|
this.triggers = triggers;
|
||||||
this.firstTrigger=firstTrigger;
|
this.firstTrigger = firstTrigger;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ExperienceItem(ConfigurationSection config) {
|
public ExperienceItem(ConfigurationSection config) {
|
||||||
@ -51,7 +51,7 @@ public class ExperienceItem {
|
|||||||
id = config.getName();
|
id = config.getName();
|
||||||
|
|
||||||
period = config.getInt("period", 0);
|
period = config.getInt("period", 0);
|
||||||
firstTrigger=config.getInt("first-trigger",period);
|
firstTrigger = config.getInt("first-trigger", period);
|
||||||
claimChance = config.getDouble("chance", 100) / 100;
|
claimChance = config.getDouble("chance", 100) / 100;
|
||||||
failReduction = config.getDouble("fail-reduction", 80) / 100;
|
failReduction = config.getDouble("fail-reduction", 80) / 100;
|
||||||
triggers = new ArrayList<>();
|
triggers = new ArrayList<>();
|
||||||
@ -71,7 +71,7 @@ public class ExperienceItem {
|
|||||||
* account the randomness factor from the 'chance' parameter
|
* account the randomness factor from the 'chance' parameter
|
||||||
*/
|
*/
|
||||||
public boolean roll(int professionLevel, int timesCollected) {
|
public boolean roll(int professionLevel, int timesCollected) {
|
||||||
int claimsRequired = professionLevel+1 - (firstTrigger-+timesCollected * period);
|
int claimsRequired = professionLevel + 1 - (firstTrigger - timesCollected * period);
|
||||||
if (claimsRequired < 1)
|
if (claimsRequired < 1)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user