From 92a4fd379b4134bfc2f1e1b23c6b945bdaa21f60 Mon Sep 17 00:00:00 2001 From: Melledy <121644117+Melledy@users.noreply.github.com> Date: Sun, 10 Dec 2023 17:36:30 -0800 Subject: [PATCH] Add config options for starting TB level and auto equilibrium level upgrade --- src/main/java/emu/lunarcore/Config.java | 4 ++- .../java/emu/lunarcore/GameConstants.java | 1 + .../command/commands/SetLevelCommand.java | 4 +-- .../emu/lunarcore/game/player/Player.java | 34 ++++++++++++++++--- 4 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/main/java/emu/lunarcore/Config.java b/src/main/java/emu/lunarcore/Config.java index 8a14e75..e60d408 100644 --- a/src/main/java/emu/lunarcore/Config.java +++ b/src/main/java/emu/lunarcore/Config.java @@ -110,10 +110,12 @@ public class Config { public static class ServerOptions { public boolean autoCreateAccount = true; public int sceneMaxEntites = 500; - public boolean spendStamina = true; public boolean unlockAllChallenges = true; + public boolean spendStamina = true; public int staminaRecoveryRate = 5 * 60; public int staminaReserveRecoveryRate = 18 * 60; + public int startTrailblazerLevel = 1; // Starting trailblazer level for new players + public boolean autoUpgradeWorldLevel = true; // Automatically upgrades world level when the player reaches a certain TB level public String language = "EN"; public Set defaultPermissions = Set.of("*"); diff --git a/src/main/java/emu/lunarcore/GameConstants.java b/src/main/java/emu/lunarcore/GameConstants.java index a071a21..34b48f0 100644 --- a/src/main/java/emu/lunarcore/GameConstants.java +++ b/src/main/java/emu/lunarcore/GameConstants.java @@ -15,6 +15,7 @@ public class GameConstants { public static final String DEFAULT_NAME = "Trailblazer"; public static final int TRAILBLAZER_AVATAR_ID = 8001; public static final int MAX_TRAILBLAZER_LEVEL = 70; + public static final int[] WORLD_LEVEL_UPGRADES = {0, 20, 30, 40, 50, 60, 65}; public static final int MAX_STAMINA = 240; public static final int MAX_STAMINA_RESERVE = 2400; public static final int MAX_AVATARS_IN_TEAM = 4; diff --git a/src/main/java/emu/lunarcore/command/commands/SetLevelCommand.java b/src/main/java/emu/lunarcore/command/commands/SetLevelCommand.java index 1ac4155..243e463 100644 --- a/src/main/java/emu/lunarcore/command/commands/SetLevelCommand.java +++ b/src/main/java/emu/lunarcore/command/commands/SetLevelCommand.java @@ -11,9 +11,9 @@ public class SetLevelCommand implements CommandHandler { @Override public void execute(CommandArgs args) { int targetLevel = Utils.parseSafeInt(args.get(0)); + args.getTarget().setLevel(targetLevel); - - args.sendMessage("Set level to " + targetLevel); + args.sendMessage("Set level to " + args.getTarget().getLevel()); } } diff --git a/src/main/java/emu/lunarcore/game/player/Player.java b/src/main/java/emu/lunarcore/game/player/Player.java index 6753181..43bf650 100644 --- a/src/main/java/emu/lunarcore/game/player/Player.java +++ b/src/main/java/emu/lunarcore/game/player/Player.java @@ -160,6 +160,7 @@ public class Player { this.isNew = true; this.initUid(); this.resetPosition(); + this.setLevel(LunarCore.getConfig().getServerOptions().startTrailblazerLevel); // Setup player data this.name = GameConstants.DEFAULT_NAME; @@ -167,7 +168,6 @@ public class Player { this.headIcon = 200001; this.phoneTheme = 221000; this.chatBubble = 220000; - this.level = 1; this.stamina = GameConstants.MAX_STAMINA; this.nextStaminaRecover = System.currentTimeMillis(); @@ -196,13 +196,36 @@ public class Player { return session.getAccount(); } - public void setLevel(int newLevel) { - this.level = Math.max(Math.min(newLevel, GameConstants.MAX_TRAILBLAZER_LEVEL), 1); + public void setLevel(int lvl) { + int oldLevel = this.level; + int newLevel = Math.max(Math.min(lvl, GameConstants.MAX_TRAILBLAZER_LEVEL), 1); + this.onLevelChange(oldLevel, newLevel); + + this.level = newLevel; this.exp = GameData.getPlayerExpRequired(this.level); this.sendPacket(new PacketPlayerSyncScNotify(this)); this.save(); } + private void onLevelChange(int oldLevel, int newLevel) { + // Auto upgrades the player's world level when they level up to the right level + if (LunarCore.getConfig().getServerOptions().autoUpgradeWorldLevel) { + int maxWorldLevel = 0; + + for (int i = 0; i < GameConstants.WORLD_LEVEL_UPGRADES.length; i++) { + if (newLevel >= GameConstants.WORLD_LEVEL_UPGRADES[i]) { + maxWorldLevel = i; + } else { + break; + } + } + + if (maxWorldLevel > this.getWorldLevel()) { + this.setWorldLevel(maxWorldLevel); + } + } + } + public boolean isOnline() { return this.getSession() != null && this.loggedIn; } @@ -383,7 +406,8 @@ public class Player { } public void addExp(int amount) { - // Required exp + // Setup + int oldLevel = this.level; int reqExp = GameData.getPlayerExpRequired(level + 1); // Add exp @@ -394,7 +418,7 @@ public class Player { reqExp = GameData.getPlayerExpRequired(this.level + 1); } - // Save + this.onLevelChange(oldLevel, this.level); this.save(); // Send packet