From 49a2810e3eeeb448dfc93c1e722aee3140b88c05 Mon Sep 17 00:00:00 2001 From: Dark98 Date: Tue, 14 Dec 2021 00:31:37 +0000 Subject: [PATCH] Allow Loading VARIABLE_XP_RATES & PLAYER_XP_RATES From Config --- 2006Scape Server/ServerConfig.Sample.json | 5 +++-- .../src/main/java/com/rs2/ConfigLoader.java | 11 +++++++++-- .../src/main/java/com/rs2/GameConstants.java | 8 ++++---- .../java/com/rs2/game/dialogues/DialogueHandler.java | 2 +- .../java/com/rs2/game/players/PlayerAssistant.java | 3 +-- .../main/java/com/rs2/net/packets/impl/Commands.java | 8 ++++---- 6 files changed, 22 insertions(+), 15 deletions(-) diff --git a/2006Scape Server/ServerConfig.Sample.json b/2006Scape Server/ServerConfig.Sample.json index fed3bde3..a4619f61 100644 --- a/2006Scape Server/ServerConfig.Sample.json +++ b/2006Scape Server/ServerConfig.Sample.json @@ -4,7 +4,9 @@ "server_debug": false, "file_server": true, "world_id": 1, - "variable_xp_rate": false, + "variable_xp_rates": false, + "xp_rate": 1.0, + "player_xp_rates": [1, 2, 5, 10], "members_only": false, "tutorial_island_enabled": false, "party_room_enabled": true, @@ -16,6 +18,5 @@ "save_timer": 120, "timeout": 60, "item_requirements": true, - "xp_rate": 1.0, "max_players": 200 } \ No newline at end of file diff --git a/2006Scape Server/src/main/java/com/rs2/ConfigLoader.java b/2006Scape Server/src/main/java/com/rs2/ConfigLoader.java index 01bdecad..3f682cb8 100644 --- a/2006Scape Server/src/main/java/com/rs2/ConfigLoader.java +++ b/2006Scape Server/src/main/java/com/rs2/ConfigLoader.java @@ -3,6 +3,7 @@ package com.rs2; import com.rs2.integrations.PlayersOnlineWebsite; import com.rs2.integrations.RegisteredAccsWebsite; import com.rs2.integrations.discord.JavaCord; +import org.json.JSONArray; import org.json.JSONObject; import java.io.*; @@ -25,8 +26,6 @@ public class ConfigLoader { GameConstants.FILE_SERVER = obj.getBoolean("file_server"); if(obj.has("world_id")) GameConstants.WORLD = obj.getInt("world_id"); - if(obj.has("variable_xp_rate")) - GameConstants.VARIABLE_XP_RATE = obj.getBoolean("variable_xp_rate"); if(obj.has("members_only")) GameConstants.MEMBERS_ONLY = obj.getBoolean("members_only"); if(obj.has("tutorial_island_enabled")) @@ -51,10 +50,18 @@ public class ConfigLoader { GameConstants.TIMEOUT = obj.getInt("timeout"); if(obj.has("item_requirements")) GameConstants.ITEM_REQUIREMENTS = obj.getBoolean("item_requirements"); + if(obj.has("variable_xp_rates")) + GameConstants.VARIABLE_XP_RATES = obj.getBoolean("variable_xp_rates"); if(obj.has("xp_rate")) GameConstants.XP_RATE = obj.getDouble("xp_rate"); if(obj.has("max_players")) GameConstants.MAX_PLAYERS = obj.getInt("max_players"); + if (obj.has("player_xp_rates")) { + JSONArray rates = obj.optJSONArray("player_xp_rates"); + for (int i = 0; i < rates.length(); ++i) { + GameConstants.PLAYER_XP_RATES[i] = rates.optInt(i); + } + } } private static void initialize() { diff --git a/2006Scape Server/src/main/java/com/rs2/GameConstants.java b/2006Scape Server/src/main/java/com/rs2/GameConstants.java index e0448f08..b706299e 100644 --- a/2006Scape Server/src/main/java/com/rs2/GameConstants.java +++ b/2006Scape Server/src/main/java/com/rs2/GameConstants.java @@ -25,16 +25,16 @@ public class GameConstants { * ADMIN_CAN_TRADE Defines Whether Admins Can Trade * ADMIN_DROP_ITEMS Defines Whether Admins Can Drop Items * ADMIN_CAN_SELL_ITEMS Defines Whether Admins Can Sell Items - * VARIABLE_XP_RATE Allows Players To Choose An XP Rate(x1,x2,x5,x10) - * PLAYER_XP_RATES Defines The XP Rates That Should Be Available To Players When VARIABLE_XP_RATE is true - * XP_RATE Sets The XP Rate Multiplier For All Players/Skills If VARIABLE_XP_RATE is false + * VARIABLE_XP_RATES Allows Players To Choose An XP Rate Set In PLAYER_XP_RATES + * PLAYER_XP_RATES Defines The XP Rates That Should Be Available To Players When VARIABLE_XP_RATES is true(Array Must Contain Four Entries) + * XP_RATE Sets The XP Rate Multiplier For All Players/Skills If VARIABLE_XP_RATES is false */ public static String SERVER_NAME = "2006Scape", WEBSITE_LINK = "https://2006Scape.org"; public static int WORLD = 1, MAX_PLAYERS = 200, TIMEOUT = 60, SAVE_TIMER = 120, RESPAWN_X = 3222, RESPAWN_Y = 3218; public static boolean FILE_SERVER = true, SERVER_DEBUG = false, MEMBERS_ONLY = false, TUTORIAL_ISLAND = false, PARTY_ROOM_DISABLED = false, CLUES_ENABLED = true, ITEM_REQUIREMENTS = true, - ADMIN_CAN_TRADE = false, ADMIN_DROP_ITEMS = false, ADMIN_CAN_SELL_ITEMS = false, VARIABLE_XP_RATE = true; + ADMIN_CAN_TRADE = false, ADMIN_DROP_ITEMS = false, ADMIN_CAN_SELL_ITEMS = false, VARIABLE_XP_RATES = true; public static int[] PLAYER_XP_RATES = new int[] {1, 2, 5, 10}; public static double XP_RATE = 1.0; diff --git a/2006Scape Server/src/main/java/com/rs2/game/dialogues/DialogueHandler.java b/2006Scape Server/src/main/java/com/rs2/game/dialogues/DialogueHandler.java index 4fe1609b..bf3200e3 100644 --- a/2006Scape Server/src/main/java/com/rs2/game/dialogues/DialogueHandler.java +++ b/2006Scape Server/src/main/java/com/rs2/game/dialogues/DialogueHandler.java @@ -6137,7 +6137,7 @@ public class DialogueHandler { break; case 3116: - if(GameConstants.VARIABLE_XP_RATE) { + if(GameConstants.VARIABLE_XP_RATES) { player.getDialogueHandler().sendDialogues(10001, -1); } else { player.getPacketSender().showInterface(3559); diff --git a/2006Scape Server/src/main/java/com/rs2/game/players/PlayerAssistant.java b/2006Scape Server/src/main/java/com/rs2/game/players/PlayerAssistant.java index 94497641..02a78943 100644 --- a/2006Scape Server/src/main/java/com/rs2/game/players/PlayerAssistant.java +++ b/2006Scape Server/src/main/java/com/rs2/game/players/PlayerAssistant.java @@ -17,7 +17,6 @@ import com.rs2.game.content.music.sound.SoundList; import com.rs2.game.content.randomevents.RandomEventHandler; import com.rs2.game.content.skills.SkillData; import com.rs2.game.content.skills.SkillHandler; -import com.rs2.game.content.skills.smithing.Superheat; import com.rs2.game.items.GameItem; import com.rs2.game.items.ItemAssistant; import com.rs2.game.items.ItemConstants; @@ -2033,7 +2032,7 @@ public class PlayerAssistant { if (player.tutorialProgress < 36 && player.playerLevel[skill] == 3 && GameConstants.TUTORIAL_ISLAND) { return false; } - if (GameConstants.VARIABLE_XP_RATE){ + if (GameConstants.VARIABLE_XP_RATES){ amount *= player.getXPRate(); } else { amount *= GameConstants.XP_RATE; diff --git a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java index e5028b92..87461e3d 100644 --- a/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java +++ b/2006Scape Server/src/main/java/com/rs2/net/packets/impl/Commands.java @@ -46,12 +46,12 @@ public class Commands implements PacketType { switch (playerCommand.toLowerCase()) { case "myxprate": case "checkxprate": - if(GameConstants.VARIABLE_XP_RATE) { + if(GameConstants.VARIABLE_XP_RATES) { player.getPacketSender().sendMessage("Your current XP rate is x" + player.getXPRate()); break; } case "xprate": - if(GameConstants.VARIABLE_XP_RATE) { + if(GameConstants.VARIABLE_XP_RATES) { if (player.getXPRate() == GameConstants.PLAYER_XP_RATES[0]) { player.getDialogueHandler().sendDialogues(10005, 2244); return; @@ -304,8 +304,8 @@ public class Commands implements PacketType { "", "::snow", "Add some snow in your mainscreen(works only in december)", - (GameConstants.VARIABLE_XP_RATE ? "\\n" + "::xprate\\n" + "Opens dialogue for the player to set/increase their XP rate." : ""), - (GameConstants.VARIABLE_XP_RATE ? "\\n" + "::checkxprate(::myxprate)\\n" + "Displays the players currently set XP rate.." : ""), + (GameConstants.VARIABLE_XP_RATES ? "\\n" + "::xprate\\n" + "Opens dialogue for the player to set/increase their XP rate." : ""), + (GameConstants.VARIABLE_XP_RATES ? "\\n" + "::checkxprate(::myxprate)\\n" + "Displays the players currently set XP rate." : ""), }; // Clear all lines