Add diminished returns when a player has earned too much XP

When a player reaches a certain (configurable) threshold value of total
XP earned in a specific skill, his earned XP in this skill will be
decreased.

Depending on how far the player has exceeded the threshold value, his
XP will decrease more. After the (configurable) time interval of 10
minutes, the registered data will be cleared and the player can earn XP
as normal again.
This commit is contained in:
TfT_02 2013-05-03 21:26:20 +02:00
parent 1ae9b0f4d2
commit 092b7e39cd
6 changed files with 118 additions and 1 deletions

View File

@ -281,6 +281,9 @@ public class Config extends AutoUpdateConfigLoader {
*/ */
/* General Settings */ /* General Settings */
public boolean getExperienceGainsMobspawnersEnabled() { return config.getBoolean("Experience.Gains.Mobspawners.Enabled", false); }
public int getExperienceDeminishedReturnsThreshold() { return config.getInt("Experience.Gains.Deminished_Returns.Threshold", 20000); }
public int getExperienceDeminishedReturnsTimeInterval() { return config.getInt("Experience.Gains.Deminished_Returns.Time_Interval", 10); }
public boolean getExperienceGainsPlayerVersusPlayerEnabled() { return config.getBoolean("Experience.PVP.Rewards", true); } public boolean getExperienceGainsPlayerVersusPlayerEnabled() { return config.getBoolean("Experience.PVP.Rewards", true); }
public double getExperienceGainsGlobalMultiplier() { return config.getDouble("Experience.Gains.Multiplier.Global", 1.0); } public double getExperienceGainsGlobalMultiplier() { return config.getDouble("Experience.Gains.Multiplier.Global", 1.0); }

View File

@ -39,6 +39,9 @@ public class PlayerProfile {
private final Map<SkillType, Float> skillsXp = new HashMap<SkillType, Float>(); // Skill & XP private final Map<SkillType, Float> skillsXp = new HashMap<SkillType, Float>(); // Skill & XP
private final Map<AbilityType, Integer> skillsDATS = new HashMap<AbilityType, Integer>(); // Ability & Cooldown private final Map<AbilityType, Integer> skillsDATS = new HashMap<AbilityType, Integer>(); // Ability & Cooldown
// Store previous XP gains for deminished returns
private Map<SkillType, Float> gainedSkillsXp = new HashMap<SkillType, Float>();
public PlayerProfile(String playerName, boolean addNew) { public PlayerProfile(String playerName, boolean addNew) {
this.playerName = playerName; this.playerName = playerName;
@ -246,6 +249,47 @@ public class PlayerProfile {
skillsXp.put(skillType, skillsXp.get(skillType) + experience); skillsXp.put(skillType, skillsXp.get(skillType) + experience);
} }
/**
* Get the registered amount of experience gained
* This is used for diminished XP returns
*
* @return xp Experience amount registered
*/
public float getRegisteredXpGain(SkillType skillType) {
float xp;
if (gainedSkillsXp.get(skillType) == null) {
xp = 0F;
}
else {
xp = gainedSkillsXp.get(skillType);
}
return xp;
}
/**
* Set registered experience gains
* This is used for diminished XP returns
*
* @param skillType Skill being used
* @param xp Experience amount to set
*/
public void setRegisteredXpGain(SkillType skillType, float xp) {
gainedSkillsXp.put(skillType, xp);
}
/**
* Register an experience gain
* This is used for diminished XP returns
*
* @param skillType Skill being used
* @param xp Experience amount to add
*/
public void registeredXpGain(SkillType skillType, float xp) {
gainedSkillsXp.put(skillType, getRegisteredXpGain(skillType) + xp);
}
/** /**
* Get the amount of Xp remaining before the next level. * Get the amount of Xp remaining before the next level.
* *

View File

@ -6,7 +6,11 @@ import org.bukkit.event.EventPriority;
import org.bukkit.event.Listener; import org.bukkit.event.Listener;
import com.gmail.nossr50.config.Config; import com.gmail.nossr50.config.Config;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent; import com.gmail.nossr50.events.experience.McMMOPlayerLevelUpEvent;
import com.gmail.nossr50.events.experience.McMMOPlayerXpGainEvent;
import com.gmail.nossr50.util.player.UserManager;
import com.gmail.nossr50.util.skills.ParticleEffectUtils; import com.gmail.nossr50.util.skills.ParticleEffectUtils;
public class SelfListener implements Listener { public class SelfListener implements Listener {
@ -29,4 +33,35 @@ public class SelfListener implements Listener {
ParticleEffectUtils.runescapeModeCelebration(player, event.getSkill()); ParticleEffectUtils.runescapeModeCelebration(player, event.getSkill());
} }
} }
}
@EventHandler(priority = EventPriority.NORMAL, ignoreCancelled = true)
public void onPlayerXpGain(McMMOPlayerXpGainEvent event) {
int threshold = Config.getInstance().getExperienceDeminishedReturnsThreshold();
if (threshold <= 0) {
return;
}
Player player = event.getPlayer();
McMMOPlayer mcMMOPlayer = UserManager.getPlayer(player);
SkillType skillType = event.getSkill();
if (skillType.isChildSkill()) {
return;
}
float difference = (mcMMOPlayer.getProfile().getRegisteredXpGain(skillType) - threshold) / threshold;
if (difference > 0) {
// System.out.println("Total XP Earned: " + mcMMOPlayer.getProfile().getRegisteredXpGain(skillType) + " / Threshold value: " + threshold);
// System.out.println(difference * 100 + "% over the threshold!");
// System.out.println("Previous: " + event.getRawXpGained());
// System.out.println("Adjusted XP " + (event.getRawXpGained() - (event.getRawXpGained() * difference)));
float newValue = event.getRawXpGained() - (event.getRawXpGained() * difference);
event.setRawXpGained(newValue);
}
mcMMOPlayer.getProfile().registeredXpGain(skillType, event.getRawXpGained());
}
}

View File

@ -36,6 +36,7 @@ import com.gmail.nossr50.party.PartyManager;
import com.gmail.nossr50.runnables.SaveTimerTask; import com.gmail.nossr50.runnables.SaveTimerTask;
import com.gmail.nossr50.runnables.database.UserPurgeTask; import com.gmail.nossr50.runnables.database.UserPurgeTask;
import com.gmail.nossr50.runnables.party.PartyAutoKickTask; import com.gmail.nossr50.runnables.party.PartyAutoKickTask;
import com.gmail.nossr50.runnables.player.ClearRegisteredXPGainTask;
import com.gmail.nossr50.runnables.skills.BleedTimerTask; import com.gmail.nossr50.runnables.skills.BleedTimerTask;
import com.gmail.nossr50.skills.child.ChildConfig; import com.gmail.nossr50.skills.child.ChildConfig;
import com.gmail.nossr50.skills.repair.Repairable; import com.gmail.nossr50.skills.repair.Repairable;
@ -365,5 +366,12 @@ public class mcMMO extends JavaPlugin {
else if (kickIntervalTicks > 0) { else if (kickIntervalTicks > 0) {
new PartyAutoKickTask().runTaskTimer(this, kickIntervalTicks, kickIntervalTicks); new PartyAutoKickTask().runTaskTimer(this, kickIntervalTicks, kickIntervalTicks);
} }
// Clear the registered XP data so players can earn XP again
long clearRegisteredXPGainInterval = Config.getInstance().getExperienceDeminishedReturnsTimeInterval() * 60 * 20;
if (kickIntervalTicks > 0 && Config.getInstance().getExperienceDeminishedReturnsThreshold() > 0) {
new ClearRegisteredXPGainTask().runTaskTimer(this, clearRegisteredXPGainInterval, clearRegisteredXPGainInterval);
}
} }
} }

View File

@ -0,0 +1,21 @@
package com.gmail.nossr50.runnables.player;
import org.bukkit.scheduler.BukkitRunnable;
import com.gmail.nossr50.datatypes.player.McMMOPlayer;
import com.gmail.nossr50.datatypes.skills.SkillType;
import com.gmail.nossr50.util.player.UserManager;
public class ClearRegisteredXPGainTask extends BukkitRunnable {
@Override
public void run() {
for (McMMOPlayer mcMMOPlayer : UserManager.getPlayers().values()) {
for (SkillType skillType : SkillType.values()) {
if (skillType.isChildSkill()) {
continue;
}
mcMMOPlayer.getProfile().setRegisteredXpGain(skillType, 0F);
}
}
}
}

View File

@ -284,6 +284,12 @@ Experience:
Mobspawners: Mobspawners:
Multiplier: 0 Multiplier: 0
# Limit the amount of experience a player can earn:
# Threshold (amount of experience) per Time_Interval (in minutes)
Deminished_Returns:
Threshold: 20000
Time_Interval: 10
# Experience gained in every skill will get multiplied by this value. 1.0 by default, 2.0 means two times as much # Experience gained in every skill will get multiplied by this value. 1.0 by default, 2.0 means two times as much
Multiplier: Multiplier:
PVP: 1.0 PVP: 1.0