From dce8304c6851dfc6a13f66708faecab9cc0cb685 Mon Sep 17 00:00:00 2001 From: kuroppoi <68156848+kuroppoi@users.noreply.github.com> Date: Wed, 3 Jan 2024 04:42:16 +0100 Subject: [PATCH] Add commands for zone time, weather and acidity --- .../gameserver/command/CommandManager.java | 6 ++ .../command/commands/AcidityCommand.java | 58 ++++++++++++++++ .../command/commands/TimeCommand.java | 68 +++++++++++++++++++ .../command/commands/WeatherCommand.java | 55 +++++++++++++++ .../gameserver/zone/WeatherManager.java | 16 +++++ .../java/brainwine/gameserver/zone/Zone.java | 12 ++++ 6 files changed, 215 insertions(+) create mode 100644 gameserver/src/main/java/brainwine/gameserver/command/commands/AcidityCommand.java create mode 100644 gameserver/src/main/java/brainwine/gameserver/command/commands/TimeCommand.java create mode 100644 gameserver/src/main/java/brainwine/gameserver/command/commands/WeatherCommand.java diff --git a/gameserver/src/main/java/brainwine/gameserver/command/CommandManager.java b/gameserver/src/main/java/brainwine/gameserver/command/CommandManager.java index ddae533..2a731f2 100644 --- a/gameserver/src/main/java/brainwine/gameserver/command/CommandManager.java +++ b/gameserver/src/main/java/brainwine/gameserver/command/CommandManager.java @@ -13,6 +13,7 @@ import java.util.Set; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import brainwine.gameserver.command.commands.AcidityCommand; import brainwine.gameserver.command.commands.AdminCommand; import brainwine.gameserver.command.commands.BanCommand; import brainwine.gameserver.command.commands.BroadcastCommand; @@ -39,8 +40,10 @@ import brainwine.gameserver.command.commands.SkillPointsCommand; import brainwine.gameserver.command.commands.StopCommand; import brainwine.gameserver.command.commands.TeleportCommand; import brainwine.gameserver.command.commands.ThinkCommand; +import brainwine.gameserver.command.commands.TimeCommand; import brainwine.gameserver.command.commands.UnbanCommand; import brainwine.gameserver.command.commands.UnmuteCommand; +import brainwine.gameserver.command.commands.WeatherCommand; import brainwine.gameserver.command.commands.ZoneIdCommand; import brainwine.gameserver.entity.player.Player; @@ -93,6 +96,9 @@ public class CommandManager { registerCommand(new LevelCommand()); registerCommand(new SkillPointsCommand()); registerCommand(new SettleLiquidsCommand()); + registerCommand(new WeatherCommand()); + registerCommand(new AcidityCommand()); + registerCommand(new TimeCommand()); } public static void executeCommand(CommandExecutor executor, String commandLine) { diff --git a/gameserver/src/main/java/brainwine/gameserver/command/commands/AcidityCommand.java b/gameserver/src/main/java/brainwine/gameserver/command/commands/AcidityCommand.java new file mode 100644 index 0000000..77aa568 --- /dev/null +++ b/gameserver/src/main/java/brainwine/gameserver/command/commands/AcidityCommand.java @@ -0,0 +1,58 @@ +package brainwine.gameserver.command.commands; + +import static brainwine.gameserver.entity.player.NotificationType.SYSTEM; + +import brainwine.gameserver.command.Command; +import brainwine.gameserver.command.CommandExecutor; +import brainwine.gameserver.entity.player.Player; +import brainwine.gameserver.zone.Zone; + +public class AcidityCommand extends Command { + + @Override + public void execute(CommandExecutor executor, String[] args) { + Zone zone = ((Player)executor).getZone(); + + if(args.length < 1) { + executor.notify(String.format("The current acidity of %s is %s", zone.getName(), zone.getAcidity()), SYSTEM); + return; + } + + float value = 0.0f; + + try { + value = Float.parseFloat(args[0]); + } catch(NumberFormatException e) { + executor.notify("Acidity must be a number between 0.0 and 1.0", SYSTEM); + return; + } + + if(value < 0.0f || value > 1.0f) { + executor.notify("Acidity must be a number between 0.0 and 1.0", SYSTEM); + return; + } + + zone.setAcidity(value); + executor.notify(String.format("Acidity has been set to %s in %s.", value, zone.getName()), SYSTEM); + } + + @Override + public String getName() { + return "acidity"; + } + + @Override + public String getDescription() { + return "Displays or changes the acidity in the current zone."; + } + + @Override + public String getUsage(CommandExecutor executor) { + return "/acidity [value]"; + } + + @Override + public boolean canExecute(CommandExecutor executor) { + return executor.isAdmin() && executor instanceof Player; + } +} diff --git a/gameserver/src/main/java/brainwine/gameserver/command/commands/TimeCommand.java b/gameserver/src/main/java/brainwine/gameserver/command/commands/TimeCommand.java new file mode 100644 index 0000000..e61c24e --- /dev/null +++ b/gameserver/src/main/java/brainwine/gameserver/command/commands/TimeCommand.java @@ -0,0 +1,68 @@ +package brainwine.gameserver.command.commands; + +import static brainwine.gameserver.entity.player.NotificationType.SYSTEM; + +import brainwine.gameserver.command.Command; +import brainwine.gameserver.command.CommandExecutor; +import brainwine.gameserver.entity.player.Player; +import brainwine.gameserver.zone.Zone; + +public class TimeCommand extends Command { + + @Override + public void execute(CommandExecutor executor, String[] args) { + Zone zone = ((Player)executor).getZone(); + + if(args.length < 1) { + executor.notify(String.format("The current time in %s is %s", zone.getName(), zone.getTime()), SYSTEM); + return; + } + + String time = args[0].toLowerCase(); + float value = 0.0f; + + switch(time) { + case "day": value = 0.5f; break; + case "night": value = 0.0f; break; + case "dawn": value = 0.25f; break; + case "dusk": value = 0.75f; break; + default: + try { + value = Float.parseFloat(time); + } catch(NumberFormatException e) { + executor.notify("Time must be day, night, dawn, dusk or a number between 0.0 and 1.0", SYSTEM); + return; + } + + if(value < 0.0f || value > 1.0f) { + executor.notify("Time must be a number between 0.0 and 1.0", SYSTEM); + return; + } + + break; + } + + zone.setTime(value); + executor.notify(String.format("Time has been set to %s in %s.", value, zone.getName()), SYSTEM); + } + + @Override + public String getName() { + return "time"; + } + + @Override + public String getDescription() { + return "Displays or changes the time in the current zone."; + } + + @Override + public String getUsage(CommandExecutor executor) { + return "/time [value|(day|night|dawn|dusk)]"; + } + + @Override + public boolean canExecute(CommandExecutor executor) { + return executor.isAdmin() && executor instanceof Player; + } +} diff --git a/gameserver/src/main/java/brainwine/gameserver/command/commands/WeatherCommand.java b/gameserver/src/main/java/brainwine/gameserver/command/commands/WeatherCommand.java new file mode 100644 index 0000000..e7027c7 --- /dev/null +++ b/gameserver/src/main/java/brainwine/gameserver/command/commands/WeatherCommand.java @@ -0,0 +1,55 @@ +package brainwine.gameserver.command.commands; + +import static brainwine.gameserver.entity.player.NotificationType.SYSTEM; + +import brainwine.gameserver.command.Command; +import brainwine.gameserver.command.CommandExecutor; +import brainwine.gameserver.entity.player.Player; +import brainwine.gameserver.zone.Biome; +import brainwine.gameserver.zone.WeatherManager; +import brainwine.gameserver.zone.Zone; + +public class WeatherCommand extends Command { + + @Override + public void execute(CommandExecutor executor, String[] args) { + Zone zone = ((Player)executor).getZone(); + WeatherManager weatherManager = zone.getWeatherManager(); + + if(args.length < 1) { + if(weatherManager.isRaining()) { + String rainString = zone.getBiome() == Biome.ARCTIC ? "snowing" : zone.getBiome() == Biome.HELL ? "raining ash" : "raining"; + executor.notify(String.format("It is currently %s in %s with an intensity of %s", + rainString, zone.getName(), weatherManager.getPrecipitation()), SYSTEM); + } else { + executor.notify(String.format("It is currently dry in %s.", zone.getName()), SYSTEM); + } + + return; + } + + boolean dry = args[0].equalsIgnoreCase("clear"); + zone.getWeatherManager().createRandomRain(dry); + executor.notify(String.format("Weather has been %s in %s.", dry ? "cleared" : "made rainy", zone.getName()), SYSTEM); + } + + @Override + public String getName() { + return "weather"; + } + + @Override + public String getDescription() { + return "Displays or changes the weather in the current zone."; + } + + @Override + public String getUsage(CommandExecutor executor) { + return "/weather [clear|rain]"; + } + + @Override + public boolean canExecute(CommandExecutor executor) { + return executor.isAdmin() && executor instanceof Player; + } +} diff --git a/gameserver/src/main/java/brainwine/gameserver/zone/WeatherManager.java b/gameserver/src/main/java/brainwine/gameserver/zone/WeatherManager.java index 546a427..5bd5c62 100644 --- a/gameserver/src/main/java/brainwine/gameserver/zone/WeatherManager.java +++ b/gameserver/src/main/java/brainwine/gameserver/zone/WeatherManager.java @@ -47,6 +47,22 @@ public class WeatherManager { } } + public boolean isRaining() { + return rainPower > 0; + } + + public long getRainStart() { + return rainStart; + } + + public long getRainDuration() { + return rainDuration; + } + + public float getRainPower() { + return rainPower; + } + public float getPrecipitation() { return precipitation; } diff --git a/gameserver/src/main/java/brainwine/gameserver/zone/Zone.java b/gameserver/src/main/java/brainwine/gameserver/zone/Zone.java index 96cfac1..97cedf5 100644 --- a/gameserver/src/main/java/brainwine/gameserver/zone/Zone.java +++ b/gameserver/src/main/java/brainwine/gameserver/zone/Zone.java @@ -1068,6 +1068,10 @@ public class Zone { return chunkManager; } + public WeatherManager getWeatherManager() { + return weatherManager; + } + public void setSurface(int x, int surface) { if(areCoordinatesInBounds(x, surface)) { this.surface[x] = surface; @@ -1237,6 +1241,14 @@ public class Zone { return numChunksWidth * numChunksHeight; } + public void setTime(float time) { + this.time = time; + } + + public float getTime() { + return time; + } + public void setAcidity(float acidity) { this.acidity = acidity; }