mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-11-27 00:45:40 +01:00
Perm Stats
This commit is contained in:
parent
da6893bf67
commit
37a5179d30
@ -17,12 +17,12 @@ public class DefaultMMOLoader extends MMOLoader {
|
||||
|
||||
@Override
|
||||
public Trigger loadTrigger(MMOLineConfig config) {
|
||||
if(config.getKey().equals("from"))
|
||||
if (config.getKey().equals("from"))
|
||||
return new FromTrigger(config);
|
||||
|
||||
if (config.getKey().equals("stat"))
|
||||
return new StatTrigger(config);
|
||||
if (config.getKey().equals("message"))
|
||||
return new MessageTrigger(config);
|
||||
|
||||
if (config.getKey().equals("sound") || config.getKey().equals("playsound"))
|
||||
return new SoundTrigger(config);
|
||||
|
||||
@ -83,7 +83,7 @@ public class DefaultMMOLoader extends MMOLoader {
|
||||
|
||||
@Override
|
||||
public Condition loadCondition(MMOLineConfig config) {
|
||||
if(config.getKey().equals("from")) {
|
||||
if (config.getKey().equals("from")) {
|
||||
return new FromCondition(config);
|
||||
}
|
||||
if (config.getKey().equals("distance"))
|
||||
@ -106,8 +106,8 @@ public class DefaultMMOLoader extends MMOLoader {
|
||||
|
||||
@Override
|
||||
public ExperienceSource<?> loadExperienceSource(MMOLineConfig config, ExperienceDispenser dispenser) {
|
||||
if(config.getKey().equals("from"))
|
||||
return new FromExperienceSource(dispenser,config);
|
||||
if (config.getKey().equals("from"))
|
||||
return new FromExperienceSource(dispenser, config);
|
||||
|
||||
if (config.getKey().equals("resource"))
|
||||
return new ResourceExperienceSource(dispenser, config);
|
||||
|
@ -3,7 +3,6 @@ package net.Indyuce.mmocore.api.player;
|
||||
import io.lumine.mythic.lib.MythicLib;
|
||||
import io.lumine.mythic.lib.api.player.MMOPlayerData;
|
||||
import io.lumine.mythic.lib.player.cooldown.CooldownMap;
|
||||
import io.lumine.mythic.lib.player.modifier.PlayerModifier;
|
||||
import net.Indyuce.mmocore.party.provided.Party;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.ConfigMessage;
|
||||
@ -20,7 +19,6 @@ import net.Indyuce.mmocore.api.player.profess.resource.PlayerResource;
|
||||
import net.Indyuce.mmocore.api.player.social.FriendRequest;
|
||||
import net.Indyuce.mmocore.api.player.stats.PlayerStats;
|
||||
import net.Indyuce.mmocore.api.quest.PlayerQuests;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
|
||||
import net.Indyuce.mmocore.api.util.Closable;
|
||||
import net.Indyuce.mmocore.api.util.MMOCoreUtils;
|
||||
import net.Indyuce.mmocore.experience.EXPSource;
|
||||
@ -39,7 +37,6 @@ import net.Indyuce.mmocore.skill.cast.SkillCastingHandler;
|
||||
import net.Indyuce.mmocore.tree.IntegerCoordinates;
|
||||
import net.Indyuce.mmocore.tree.NodeState;
|
||||
import net.Indyuce.mmocore.tree.SkillTreeNode;
|
||||
import net.Indyuce.mmocore.tree.skilltree.LinkedSkillTree;
|
||||
import net.Indyuce.mmocore.tree.skilltree.SkillTree;
|
||||
import net.Indyuce.mmocore.tree.skilltree.display.DisplayInfo;
|
||||
import net.Indyuce.mmocore.tree.skilltree.display.Icon;
|
||||
@ -96,7 +93,7 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
|
||||
/**
|
||||
* Maps each skill tree to the number of points spent in it. Just in cache memory.
|
||||
*/
|
||||
private final HashMap<SkillTree,Integer> pointSpent= new HashMap<>();
|
||||
private final HashMap<SkillTree, Integer> pointSpent = new HashMap<>();
|
||||
private final Map<SkillTreeNode, Integer> nodeLevels = new HashMap<>();
|
||||
private final Map<SkillTreeNode, NodeState> nodeStates = new HashMap<>();
|
||||
private final Map<String, Integer> skillTreePoints = new HashMap<>();
|
||||
@ -176,9 +173,18 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
|
||||
}
|
||||
}
|
||||
|
||||
public void setupNodeState() {
|
||||
public void setupSkillTree() {
|
||||
//Node states setup
|
||||
for (SkillTree skillTree : MMOCore.plugin.skillTreeManager.getAll())
|
||||
skillTree.setupNodeState(this);
|
||||
|
||||
//Stat triggers setup
|
||||
for (SkillTree skillTree : MMOCore.plugin.skillTreeManager.getAll()) {
|
||||
for(SkillTreeNode node: skillTree.getNodes()) {
|
||||
node.getExperienceTable().claimStatTriggers(this,node);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -296,8 +302,8 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
|
||||
}
|
||||
|
||||
public void setNodeLevel(SkillTreeNode node, int nodeLevel) {
|
||||
int delta=nodeLevel-nodeLevels.getOrDefault(node,0);
|
||||
pointSpent.put(node.getTree(),pointSpent.getOrDefault(node.getTree(),0)+delta);
|
||||
int delta = nodeLevel - nodeLevels.getOrDefault(node, 0);
|
||||
pointSpent.put(node.getTree(), pointSpent.getOrDefault(node.getTree(), 0) + delta);
|
||||
nodeLevels.put(node, nodeLevel);
|
||||
}
|
||||
|
||||
|
@ -0,0 +1,52 @@
|
||||
package net.Indyuce.mmocore.api.quest.trigger;
|
||||
|
||||
import io.lumine.mythic.lib.MythicLib;
|
||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||
import io.lumine.mythic.lib.api.stat.modifier.StatModifier;
|
||||
import io.lumine.mythic.lib.player.modifier.ModifierType;
|
||||
import io.lumine.mythic.lib.player.modifier.PlayerModifier;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
public class StatTrigger extends Trigger {
|
||||
private final String stat;
|
||||
private final double amount;
|
||||
private final ModifierType type;
|
||||
private double totalAmount;
|
||||
|
||||
public StatTrigger(MMOLineConfig config) {
|
||||
super(config);
|
||||
|
||||
config.validateKeys("amount");
|
||||
config.validateKeys("stat");
|
||||
config.validateKeys("type");
|
||||
String type = config.getString("type").toUpperCase();
|
||||
Validate.isTrue(type.equals("FLAT") || type.equals("RELATIVE"));
|
||||
stat = config.getString("stat");
|
||||
amount = config.getDouble("amount");
|
||||
this.type = ModifierType.valueOf(type);
|
||||
this.totalAmount = 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void apply(PlayerData player) {
|
||||
totalAmount+=amount;
|
||||
new StatModifier("trigger",stat,totalAmount,type).register(player.getMMOPlayerData());
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Removes the effect of the trigger to the player by registering the
|
||||
* opposite amount. (Little corrective term for the relative to have the inverse.
|
||||
* Not a problem to store twice the stat modifiers are there only remain in the RAM.
|
||||
*/
|
||||
public void remove(PlayerData playerData) {
|
||||
Bukkit.broadcastMessage(totalAmount+"");
|
||||
totalAmount-=amount;
|
||||
new StatModifier("trigger", stat, totalAmount, type).register(playerData.getMMOPlayerData());
|
||||
}
|
||||
}
|
@ -99,6 +99,11 @@ public class PlayerProfessions {
|
||||
if (obj.has("timesClaimed"))
|
||||
for (Entry<String, JsonElement> entry : obj.getAsJsonObject("timesClaimed").entrySet())
|
||||
playerData.getItemClaims().put("profession." + entry.getKey(), entry.getValue().getAsInt());
|
||||
|
||||
for (Profession profession : MMOCore.plugin.professionManager.getAll()) {
|
||||
profession.getExperienceTable().claimStatTriggers(playerData, profession);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public PlayerData getPlayerData() {
|
||||
@ -218,7 +223,7 @@ public class PlayerProfessions {
|
||||
if (check) {
|
||||
Bukkit.getPluginManager().callEvent(new PlayerLevelUpEvent(playerData, profession, oldLevel, level));
|
||||
new SmallParticleEffect(playerData.getPlayer(), Particle.SPELL_INSTANT);
|
||||
new ConfigMessage("profession-level-up").addPlaceholders("level", "" + level, "profession", profession.getId(),"profession-name", profession.getName())
|
||||
new ConfigMessage("profession-level-up").addPlaceholders("level", "" + level, "profession", profession.getId(), "profession-name", profession.getName())
|
||||
.send(playerData.getPlayer());
|
||||
MMOCore.plugin.soundManager.getSound(SoundEvent.LEVEL_UP).playTo(playerData.getPlayer());
|
||||
playerData.getStats().updateStats();
|
||||
@ -229,7 +234,7 @@ public class PlayerProfessions {
|
||||
for (int j = 0; j < 20; j++)
|
||||
bar.append(j == chars ? "" + ChatColor.WHITE + ChatColor.BOLD : "").append("|");
|
||||
if (playerData.isOnline())
|
||||
MMOCore.plugin.configManager.getSimpleMessage("exp-notification","profession",profession.getId(), "profession-name", profession.getName(), "progress", bar.toString(), "ratio",
|
||||
MMOCore.plugin.configManager.getSimpleMessage("exp-notification", "profession", profession.getId(), "profession-name", profession.getName(), "progress", bar.toString(), "ratio",
|
||||
MythicLib.plugin.getMMOConfig().decimal.format((double) exp / needed * 100)).send(playerData.getPlayer());
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@ package net.Indyuce.mmocore.experience.droptable;
|
||||
import io.lumine.mythic.lib.api.MMOLineConfig;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.StatTrigger;
|
||||
import net.Indyuce.mmocore.api.quest.trigger.Trigger;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
@ -99,4 +100,27 @@ public class ExperienceItem {
|
||||
for (Trigger trigger : triggers)
|
||||
trigger.apply(levelingUp);
|
||||
}
|
||||
|
||||
/**
|
||||
* Used when the player level is reset to 0 ( reallocate point in skill tree for instance)
|
||||
* Creates an opposite playerModifier to compensate all the effect that existed before.
|
||||
*/
|
||||
public void removeStatTriggers(PlayerData playerData) {
|
||||
for (Trigger trigger : triggers) {
|
||||
if (trigger instanceof StatTrigger statTrigger)
|
||||
statTrigger.remove(playerData);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Used when a player connects back to give back all the stats that he should have.
|
||||
* @param playerData
|
||||
*/
|
||||
public void applyStatTriggers(PlayerData playerData) {
|
||||
for (Trigger trigger : triggers) {
|
||||
if (trigger instanceof StatTrigger statTrigger)
|
||||
statTrigger.apply(playerData);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -4,6 +4,7 @@ import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.experience.ExperienceObject;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -43,14 +44,44 @@ public class ExperienceTable {
|
||||
* @param object Either profession or class leveling up
|
||||
*/
|
||||
public void claim(PlayerData levelingUp, int professionLevel, ExperienceObject object) {
|
||||
for (ExperienceItem item : items) {
|
||||
|
||||
for (ExperienceItem item : items) {
|
||||
int timesClaimed = levelingUp.getClaims(object, this, item);
|
||||
if (!item.roll(professionLevel, timesClaimed))
|
||||
continue;
|
||||
|
||||
levelingUp.setClaims(object, this, item, timesClaimed + 1);
|
||||
item.applyTriggers(levelingUp);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the progression is reset(e.g skill tree reallocation)
|
||||
*/
|
||||
public void reset(PlayerData playerData, ExperienceObject object) {
|
||||
for (ExperienceItem item : items) {
|
||||
int timesClaimed = playerData.getClaims(object, this, item);
|
||||
playerData.setClaims(object, this, item, 0);
|
||||
for (int i = 0; i < timesClaimed; i++)
|
||||
item.removeStatTriggers(playerData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Called when a player joins and all the statTriggers are all triggered back
|
||||
*
|
||||
* @param data PlayerData
|
||||
* @param object Either profession, skillTreeNode or class leveling up
|
||||
*/
|
||||
public void claimStatTriggers(PlayerData data, ExperienceObject object) {
|
||||
for (ExperienceItem item : items) {
|
||||
int timesClaimed = data.getClaims(object, this, item);
|
||||
//MMOCore.log(object.getKey() + "." + getId() + "." + item.getId());
|
||||
//data.getItemClaims().keySet().forEach(str->MMOCore.log(str));
|
||||
//MMOCore.log(timesClaimed+"");
|
||||
for (int i = 0; i < timesClaimed; i++)
|
||||
item.applyStatTriggers(data);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -383,8 +383,10 @@ public class SkillTreeViewer extends EditableInventory {
|
||||
playerData.giveSkillTreePoints(skillTree.getId(), reallocated);
|
||||
playerData.giveSkillTreeReallocationPoints(-1);
|
||||
for (SkillTreeNode node : skillTree.getNodes()) {
|
||||
node.getExperienceTable().reset(playerData,node);
|
||||
playerData.setNodeLevel(node, 0);
|
||||
playerData.setNodeState(node, NodeState.LOCKED);
|
||||
|
||||
}
|
||||
skillTree.setupNodeState(playerData);
|
||||
MMOCore.plugin.configManager.getSimpleMessage("reallocated-points", "points", "" + playerData.getSkillTreePoint(skillTree.getId()), "skill-tree", skillTree.getName()).send(player);
|
||||
|
@ -15,7 +15,6 @@ import net.Indyuce.mmocore.manager.data.PlayerDataManager;
|
||||
import net.Indyuce.mmocore.tree.SkillTreeNode;
|
||||
import net.Indyuce.mmocore.tree.skilltree.SkillTree;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.scheduler.BukkitRunnable;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -91,7 +90,7 @@ public class MySQLPlayerDataManager extends PlayerDataManager {
|
||||
data.setNodeLevel(skillTreeNode,json.has(skillTreeNode.getFullId())?json.get(skillTreeNode.getFullId()).getAsInt():0);
|
||||
}
|
||||
}
|
||||
data.setupNodeState();
|
||||
data.setupSkillTree();
|
||||
|
||||
|
||||
if (!isEmpty(result.getString("guild"))) {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.Indyuce.mmocore.manager.data.yaml;
|
||||
|
||||
import com.massivecraft.factions.Conf;
|
||||
import net.Indyuce.mmocore.MMOCore;
|
||||
import net.Indyuce.mmocore.api.player.PlayerData;
|
||||
import net.Indyuce.mmocore.api.player.profess.PlayerClass;
|
||||
@ -11,7 +12,7 @@ import net.Indyuce.mmocore.manager.data.DataProvider;
|
||||
import net.Indyuce.mmocore.manager.data.PlayerDataManager;
|
||||
import net.Indyuce.mmocore.tree.SkillTreeNode;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.bukkit.Bukkit;
|
||||
import org.bukkit.configuration.ConfigurationSection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@ -42,9 +43,9 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
|
||||
data.setClass(MMOCore.plugin.classManager.get(config.getString("class")));
|
||||
|
||||
if (!data.hasUsedTemporaryData() && data.isOnline()) {
|
||||
data.setMana(config.contains("mana")?config.getDouble("mana"):data.getStats().getStat("MAX_MANA"));
|
||||
data.setStamina(config.contains("stamina")?config.getDouble("stamina"):data.getStats().getStat("MAX_STAMINA"));
|
||||
data.setStellium(config.contains("stellium")?config.getDouble("stellium"):data.getStats().getStat("MAX_STELLIUM"));
|
||||
data.setMana(config.contains("mana") ? config.getDouble("mana") : data.getStats().getStat("MAX_MANA"));
|
||||
data.setStamina(config.contains("stamina") ? config.getDouble("stamina") : data.getStats().getStat("MAX_STAMINA"));
|
||||
data.setStellium(config.contains("stellium") ? config.getDouble("stellium") : data.getStats().getStat("MAX_STELLIUM"));
|
||||
}
|
||||
|
||||
if (config.contains("guild")) {
|
||||
@ -74,27 +75,42 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
|
||||
}
|
||||
data.setSkillTreePoints("global", config.getInt("skill-tree-points.global", 0));
|
||||
|
||||
|
||||
if (config.contains("times-claimed"))
|
||||
for (String key : config.getConfigurationSection("times-claimed").getKeys(false)) {
|
||||
ConfigurationSection section = config.getConfigurationSection("times-claimed." + key);
|
||||
if (section != null)
|
||||
for (String key1 : section.getKeys(false)) {
|
||||
ConfigurationSection section1 = section.getConfigurationSection(key1);
|
||||
if (section1 != null)
|
||||
for (String key2 : config.getConfigurationSection("times-claimed." + key + "." + key1).getKeys(false)) {
|
||||
data.getItemClaims().put(key + "." + key1 + "." + key2, config.getInt("times-claimed." + key + "." + key1 + "." + key2));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (SkillTreeNode node : MMOCore.plugin.skillTreeManager.getAllNodes()) {
|
||||
data.setNodeLevel(node, config.getInt("skill-tree-level." + node.getFullId(), 0));
|
||||
}
|
||||
data.setupNodeState();
|
||||
|
||||
|
||||
if (config.contains("times-claimed"))
|
||||
for (String key : config.getConfigurationSection("times-claimed").getKeys(true))
|
||||
data.getItemClaims().put(key, config.getInt("times-claimed." + key));
|
||||
data.setupSkillTree();
|
||||
|
||||
// Load class slots, use try so the player can log in.
|
||||
if (config.contains("class-info"))
|
||||
for (String key : config.getConfigurationSection("class-info").getKeys(false))
|
||||
for (
|
||||
String key : config.getConfigurationSection("class-info").
|
||||
|
||||
getKeys(false))
|
||||
try {
|
||||
PlayerClass profess = MMOCore.plugin.classManager.get(key);
|
||||
Validate.notNull(profess, "Could not find class '" + key + "'");
|
||||
data.applyClassInfo(profess, new SavedClassInformation(config.getConfigurationSection("class-info." + key)));
|
||||
} catch (IllegalArgumentException exception) {
|
||||
} catch (
|
||||
IllegalArgumentException exception) {
|
||||
MMOCore.log(Level.WARNING, "Could not load class info '" + key + "': " + exception.getMessage());
|
||||
}
|
||||
|
||||
|
||||
data.setFullyLoaded();
|
||||
}
|
||||
|
||||
@ -119,9 +135,9 @@ public class YAMLPlayerDataManager extends PlayerDataManager {
|
||||
data.getSkillTreePoints().forEach((key1, value) -> config.set("skill-tree-points." + key1, value));
|
||||
config.set("skill-tree-reallocation-points", data.getSkillTreeReallocationPoints());
|
||||
config.set("skill", null);
|
||||
config.set("mana",data.getMana());
|
||||
config.set("stellium",data.getStellium());
|
||||
config.set("stamina",data.getStamina());
|
||||
config.set("mana", data.getMana());
|
||||
config.set("stellium", data.getStellium());
|
||||
config.set("stamina", data.getStamina());
|
||||
//Saves the nodes levels
|
||||
MMOCore.plugin.skillTreeManager.getAllNodes().forEach(node -> config.set("skill-tree-level." + node.getFullId(), data.getNodeLevel(node)));
|
||||
data.mapSkillLevels().forEach((key1, value) -> config.set("skill." + key1, value));
|
||||
|
@ -145,7 +145,7 @@ public class SkillTreeNode implements Unlockable, ExperienceObject {
|
||||
|
||||
|
||||
public String getFullId() {
|
||||
return tree.getId() + "." + id;
|
||||
return tree.getId() + "_" + id;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
@ -158,7 +158,7 @@ public class SkillTreeNode implements Unlockable, ExperienceObject {
|
||||
|
||||
@Override
|
||||
public String getKey() {
|
||||
return "skill_tree_node:" + getFullId().replace("-", "_");
|
||||
return "node_" + getFullId().replace("-", "_");
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
2
pom.xml
2
pom.xml
@ -16,7 +16,7 @@
|
||||
<description>Offer your players a brand new RPG experience!!</description>
|
||||
|
||||
<properties>
|
||||
<revision>1.10.3-SNAPSHOT</revision>
|
||||
<revision>1.10.4-SNAPSHOT</revision>
|
||||
<downloadSources>false</downloadSources>
|
||||
<downloadJavadocs>false</downloadJavadocs>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
|
Loading…
Reference in New Issue
Block a user