Skip to content

Commit

Permalink
Punishment includes percentage loss of excess XP
Browse files Browse the repository at this point in the history
  • Loading branch information
AntumDeluge committed May 3, 2024
1 parent 23f4884 commit 558649d
Showing 1 changed file with 35 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import java.util.HashMap;
import java.util.Map;

import games.stendhal.common.Level;
import games.stendhal.common.MathHelper;
import games.stendhal.common.NotificationType;
import games.stendhal.server.core.engine.SingletonRepository;
Expand All @@ -26,7 +27,12 @@

public class HeavenGateKeeper {

/** Number of requests allowed before being punished. */
private static final short REQUEST_LIMIT = 3;
/** Time period in which player requests are tracked (4 days). */
private static final long TIME_BUFFER = MathHelper.MILLISECONDS_IN_ONE_DAY * 4;
/** XP modifier for trying to requesting too often (15% of excess). */
private static final float XP_MODIFIER = 0.15f;

// FIXME: would it be better to store in database than using memory?
private static Map<String, Pair<Long, Integer>> visitors = new HashMap<>();
Expand Down Expand Up @@ -69,20 +75,41 @@ private static void punish(final Player player) {
// TODO:
// - add lightning (spell effect)
// - play thunder sound
// - delay teleport to allow for spell effect

// set player's HP to 1 & send to afterlife
final StendhalRPZone afterlife = SingletonRepository.getRPWorld().getZone("int_afterlife");
if (afterlife != null) {
player.teleport(afterlife, 31, 23, player.getDirection(), null);
}
final int loss = player.getHP() - 1;
final int xpStart = player.getXP();
// a percentage of XP based on difference requirement to next level (levels can be lost)
//final int xpDiff = (int) Math.floor(Level.getXPDiff(player.getLevel()-1) * HeavenGateKeeper.XP_MODIFIER);
final int xpBuffer = Math.max(xpStart - Level.getXP(player.getLevel()), 0);
// a percentage of player's gained XP relative to the current level (levels cannot be lost)
final int xpDiff = (int) Math.floor(xpBuffer * HeavenGateKeeper.XP_MODIFIER);
final int hpStart = player.getHP();
player.addXP(-xpDiff);
player.setHP(1);
final String msg = "It appears you you are not welcome in the clouds at this time.";
if (loss > 0) {
player.sendPrivateText(NotificationType.NEGATIVE, msg + " You lost " + loss + " health.");
} else {
player.sendPrivateText(NotificationType.INFORMATION, msg);
final int xpLoss = xpStart - player.getXP();
final int hpLoss = hpStart - player.getHP();

NotificationType ntype = NotificationType.INFORMATION;
String msg = "It appears you you are not welcome in the clouds at this time.";
if (xpLoss > 0 || hpLoss > 0) {
ntype = NotificationType.NEGATIVE;
msg += " You lost ";
if (hpLoss > 0) {
msg += hpLoss + " health";
if (xpLoss > 0) {
msg += " and ";
}
}
if (xpLoss > 0) {
msg += xpLoss + " experience";
}
msg += ".";
}
player.sendPrivateText(ntype, msg);
}

/**
Expand All @@ -100,7 +127,7 @@ private static boolean inViolation(final String name) {
HeavenGateKeeper.createVisitorInfo(name);
return false;
}
return HeavenGateKeeper.getRequestCount(name) > 3;
return HeavenGateKeeper.getRequestCount(name) > HeavenGateKeeper.REQUEST_LIMIT;
}

/**
Expand Down

0 comments on commit 558649d

Please sign in to comment.