diff --git a/src/games/stendhal/server/maps/kikareukin/islands/HeavenGateKeeper.java b/src/games/stendhal/server/maps/kikareukin/islands/HeavenGateKeeper.java index 130bf8bd36..34777bc237 100644 --- a/src/games/stendhal/server/maps/kikareukin/islands/HeavenGateKeeper.java +++ b/src/games/stendhal/server/maps/kikareukin/islands/HeavenGateKeeper.java @@ -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; @@ -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> visitors = new HashMap<>(); @@ -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); } /** @@ -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; } /**