mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-11-23 00:05:52 +01:00
Perm Stats
This commit is contained in:
parent
da6893bf67
commit
37a5179d30
@ -19,10 +19,10 @@ public class DefaultMMOLoader extends MMOLoader {
|
||||
public Trigger loadTrigger(MMOLineConfig config) {
|
||||
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);
|
||||
|
||||
|
@ -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;
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -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() {
|
||||
|
@ -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;
|
||||
|
||||
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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