Merge remote-tracking branch 'origin/master'

This commit is contained in:
Indyuce 2022-12-23 18:03:16 +01:00
commit f677119961
4 changed files with 31 additions and 10 deletions

View File

@ -190,7 +190,6 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
for (SkillTree skillTree : MMOCore.plugin.skillTreeManager.getAll())
for (SkillTreeNode node : skillTree.getNodes())
node.getExperienceTable().claimStatTriggers(this, node);
statsLoaded = true;
}
}
@ -788,8 +787,10 @@ public class PlayerData extends OfflinePlayerData implements Closable, Experienc
* @param splitExp Should the exp be split among party members
*/
public void giveExperience(double value, EXPSource source, @Nullable Location hologramLocation, boolean splitExp) {
if (value <= 0)
if (value <= 0) {
experience = Math.max(0, experience + value);
return;
}
// Splitting exp through party members
AbstractParty party;

View File

@ -8,6 +8,7 @@ import net.Indyuce.mmocore.MMOCore;
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.experience.Profession;
import net.Indyuce.mmocore.manager.data.PlayerDataManager;
import net.Indyuce.mmocore.skill.ClassSkill;
import net.Indyuce.mmocore.skill.RegisteredSkill;
@ -102,7 +103,7 @@ public class SavedClassInformation {
this(player.getLevel(), player.getExperience(), player.getSkillPoints(), player.getAttributePoints(), player.getAttributeReallocationPoints()
, player.getSkillTreeReallocationPoints(), player.getSkillReallocationPoints(),
player.getAttributes().mapPoints(), player.mapSkillLevels(), player.getSkillTreePoints(), player.getNodeLevels(), player.getNodeTimesClaimed(), player.getBoundSkills(),player.getBoundPassiveSkills());
player.getAttributes().mapPoints(), player.mapSkillLevels(), player.getSkillTreePoints(), player.getNodeLevels(), player.getNodeTimesClaimed(), player.getBoundSkills(), player.getBoundPassiveSkills());
}
public SavedClassInformation(PlayerDataManager.DefaultPlayerData data) {
@ -111,7 +112,7 @@ public class SavedClassInformation {
public SavedClassInformation(int level, double experience, int skillPoints, int attributePoints,
int attributeReallocationPoints, int skillTreeReallocationPoints, int skillReallocationPoints) {
this(level, experience, skillPoints, attributePoints, attributeReallocationPoints, skillTreeReallocationPoints, skillReallocationPoints, new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(),new ArrayList<>(),new ArrayList<>());
this(level, experience, skillPoints, attributePoints, attributeReallocationPoints, skillTreeReallocationPoints, skillReallocationPoints, new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(), new HashMap<>(), new ArrayList<>(), new ArrayList<>());
}
public SavedClassInformation(int level, double experience, int skillPoints, int attributePoints,
@ -133,7 +134,7 @@ public class SavedClassInformation {
this.skillTreePoints = skillTreePoints;
this.nodeLevels = nodeLevels;
this.nodeTimesClaimed = nodeTimesClaimed;
this.boundSkills=boundSkills;
this.boundSkills = boundSkills;
}
public int getLevel() {
@ -237,11 +238,12 @@ public class SavedClassInformation {
player.clearNodeLevels();
player.clearNodeStates();
player.clearPointsSpent();
// We reset the experience table for each skill tree node to remove the perm stat.
// We remove perm stats for nodes and class.
for (SkillTree skillTree : player.getProfess().getSkillTrees()) {
for (SkillTreeNode node : skillTree.getNodes())
node.getExperienceTable().reset(player, node);
node.getExperienceTable().removePermStats(player, node);
}
player.getProfess().getExperienceTable().removePermStats(player, player.getProfess());
while (player.hasPassiveSkillBound(0))
player.unbindPassiveSkill(0);
@ -289,7 +291,7 @@ public class SavedClassInformation {
for (SkillTree skillTree : profess.getSkillTrees())
for (SkillTreeNode node : skillTree.getNodes())
node.getExperienceTable().claimStatTriggers(player, node);
profess.getExperienceTable().claimStatTriggers(player,profess);
/*
* unload current class information and set the new profess once
* everything is changed

View File

@ -100,11 +100,15 @@ public class PlayerProfessions {
for (Entry<String, JsonElement> entry : obj.getAsJsonObject("timesClaimed").entrySet())
playerData.getItemClaims().put("profession." + entry.getKey(), entry.getValue().getAsInt());
if (!playerData.areStatsLoaded())
if (!playerData.areStatsLoaded()) {
for (Profession profession : MMOCore.plugin.professionManager.getAll()) {
if (profession.hasExperienceTable())
profession.getExperienceTable().claimStatTriggers(playerData, profession);
}
if (playerData.getProfess().hasExperienceTable())
playerData.getProfess().getExperienceTable().claimStatTriggers(playerData, playerData.getProfess());
}
}
@ -166,8 +170,10 @@ public class PlayerProfessions {
public void giveExperience(Profession profession, double value, EXPSource source, @Nullable Location hologramLocation, boolean splitExp) {
Validate.isTrue(playerData.isOnline(), "Cannot give experience to offline player");
if (value <= 0)
if (value <= 0) {
exp.put(profession.getId(), Math.max(0, exp.get(profession.getId() + value)));
return;
}
if (hasReachedMaxLevel(profession)) {
setExperience(profession, 0);

View File

@ -54,6 +54,18 @@ public class ExperienceTable {
}
}
/**
* Called when a player changes its class.
* Removes the perm stat but keeps the item claims in memory.
*/
public void removePermStats(PlayerData playerData, ExperienceObject object) {
for (ExperienceItem item : items) {
int timesClaimed = playerData.getClaims(object, this, item);
for (int i = 0; i < timesClaimed; i++)
item.removeStatTriggers(playerData);
}
}
/**
* Called when the progression is reset(e.g skill tree reallocation)
*/