Skip to content

Commit dce8304

Browse files
committed
Add commands for zone time, weather and acidity
1 parent 6ed5948 commit dce8304

File tree

6 files changed

+215
-0
lines changed

6 files changed

+215
-0
lines changed

gameserver/src/main/java/brainwine/gameserver/command/CommandManager.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.apache.logging.log4j.LogManager;
1414
import org.apache.logging.log4j.Logger;
1515

16+
import brainwine.gameserver.command.commands.AcidityCommand;
1617
import brainwine.gameserver.command.commands.AdminCommand;
1718
import brainwine.gameserver.command.commands.BanCommand;
1819
import brainwine.gameserver.command.commands.BroadcastCommand;
@@ -39,8 +40,10 @@
3940
import brainwine.gameserver.command.commands.StopCommand;
4041
import brainwine.gameserver.command.commands.TeleportCommand;
4142
import brainwine.gameserver.command.commands.ThinkCommand;
43+
import brainwine.gameserver.command.commands.TimeCommand;
4244
import brainwine.gameserver.command.commands.UnbanCommand;
4345
import brainwine.gameserver.command.commands.UnmuteCommand;
46+
import brainwine.gameserver.command.commands.WeatherCommand;
4447
import brainwine.gameserver.command.commands.ZoneIdCommand;
4548
import brainwine.gameserver.entity.player.Player;
4649

@@ -93,6 +96,9 @@ private static void registerCommands() {
9396
registerCommand(new LevelCommand());
9497
registerCommand(new SkillPointsCommand());
9598
registerCommand(new SettleLiquidsCommand());
99+
registerCommand(new WeatherCommand());
100+
registerCommand(new AcidityCommand());
101+
registerCommand(new TimeCommand());
96102
}
97103

98104
public static void executeCommand(CommandExecutor executor, String commandLine) {
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package brainwine.gameserver.command.commands;
2+
3+
import static brainwine.gameserver.entity.player.NotificationType.SYSTEM;
4+
5+
import brainwine.gameserver.command.Command;
6+
import brainwine.gameserver.command.CommandExecutor;
7+
import brainwine.gameserver.entity.player.Player;
8+
import brainwine.gameserver.zone.Zone;
9+
10+
public class AcidityCommand extends Command {
11+
12+
@Override
13+
public void execute(CommandExecutor executor, String[] args) {
14+
Zone zone = ((Player)executor).getZone();
15+
16+
if(args.length < 1) {
17+
executor.notify(String.format("The current acidity of %s is %s", zone.getName(), zone.getAcidity()), SYSTEM);
18+
return;
19+
}
20+
21+
float value = 0.0f;
22+
23+
try {
24+
value = Float.parseFloat(args[0]);
25+
} catch(NumberFormatException e) {
26+
executor.notify("Acidity must be a number between 0.0 and 1.0", SYSTEM);
27+
return;
28+
}
29+
30+
if(value < 0.0f || value > 1.0f) {
31+
executor.notify("Acidity must be a number between 0.0 and 1.0", SYSTEM);
32+
return;
33+
}
34+
35+
zone.setAcidity(value);
36+
executor.notify(String.format("Acidity has been set to %s in %s.", value, zone.getName()), SYSTEM);
37+
}
38+
39+
@Override
40+
public String getName() {
41+
return "acidity";
42+
}
43+
44+
@Override
45+
public String getDescription() {
46+
return "Displays or changes the acidity in the current zone.";
47+
}
48+
49+
@Override
50+
public String getUsage(CommandExecutor executor) {
51+
return "/acidity [value]";
52+
}
53+
54+
@Override
55+
public boolean canExecute(CommandExecutor executor) {
56+
return executor.isAdmin() && executor instanceof Player;
57+
}
58+
}
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package brainwine.gameserver.command.commands;
2+
3+
import static brainwine.gameserver.entity.player.NotificationType.SYSTEM;
4+
5+
import brainwine.gameserver.command.Command;
6+
import brainwine.gameserver.command.CommandExecutor;
7+
import brainwine.gameserver.entity.player.Player;
8+
import brainwine.gameserver.zone.Zone;
9+
10+
public class TimeCommand extends Command {
11+
12+
@Override
13+
public void execute(CommandExecutor executor, String[] args) {
14+
Zone zone = ((Player)executor).getZone();
15+
16+
if(args.length < 1) {
17+
executor.notify(String.format("The current time in %s is %s", zone.getName(), zone.getTime()), SYSTEM);
18+
return;
19+
}
20+
21+
String time = args[0].toLowerCase();
22+
float value = 0.0f;
23+
24+
switch(time) {
25+
case "day": value = 0.5f; break;
26+
case "night": value = 0.0f; break;
27+
case "dawn": value = 0.25f; break;
28+
case "dusk": value = 0.75f; break;
29+
default:
30+
try {
31+
value = Float.parseFloat(time);
32+
} catch(NumberFormatException e) {
33+
executor.notify("Time must be day, night, dawn, dusk or a number between 0.0 and 1.0", SYSTEM);
34+
return;
35+
}
36+
37+
if(value < 0.0f || value > 1.0f) {
38+
executor.notify("Time must be a number between 0.0 and 1.0", SYSTEM);
39+
return;
40+
}
41+
42+
break;
43+
}
44+
45+
zone.setTime(value);
46+
executor.notify(String.format("Time has been set to %s in %s.", value, zone.getName()), SYSTEM);
47+
}
48+
49+
@Override
50+
public String getName() {
51+
return "time";
52+
}
53+
54+
@Override
55+
public String getDescription() {
56+
return "Displays or changes the time in the current zone.";
57+
}
58+
59+
@Override
60+
public String getUsage(CommandExecutor executor) {
61+
return "/time [value|(day|night|dawn|dusk)]";
62+
}
63+
64+
@Override
65+
public boolean canExecute(CommandExecutor executor) {
66+
return executor.isAdmin() && executor instanceof Player;
67+
}
68+
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package brainwine.gameserver.command.commands;
2+
3+
import static brainwine.gameserver.entity.player.NotificationType.SYSTEM;
4+
5+
import brainwine.gameserver.command.Command;
6+
import brainwine.gameserver.command.CommandExecutor;
7+
import brainwine.gameserver.entity.player.Player;
8+
import brainwine.gameserver.zone.Biome;
9+
import brainwine.gameserver.zone.WeatherManager;
10+
import brainwine.gameserver.zone.Zone;
11+
12+
public class WeatherCommand extends Command {
13+
14+
@Override
15+
public void execute(CommandExecutor executor, String[] args) {
16+
Zone zone = ((Player)executor).getZone();
17+
WeatherManager weatherManager = zone.getWeatherManager();
18+
19+
if(args.length < 1) {
20+
if(weatherManager.isRaining()) {
21+
String rainString = zone.getBiome() == Biome.ARCTIC ? "snowing" : zone.getBiome() == Biome.HELL ? "raining ash" : "raining";
22+
executor.notify(String.format("It is currently %s in %s with an intensity of %s",
23+
rainString, zone.getName(), weatherManager.getPrecipitation()), SYSTEM);
24+
} else {
25+
executor.notify(String.format("It is currently dry in %s.", zone.getName()), SYSTEM);
26+
}
27+
28+
return;
29+
}
30+
31+
boolean dry = args[0].equalsIgnoreCase("clear");
32+
zone.getWeatherManager().createRandomRain(dry);
33+
executor.notify(String.format("Weather has been %s in %s.", dry ? "cleared" : "made rainy", zone.getName()), SYSTEM);
34+
}
35+
36+
@Override
37+
public String getName() {
38+
return "weather";
39+
}
40+
41+
@Override
42+
public String getDescription() {
43+
return "Displays or changes the weather in the current zone.";
44+
}
45+
46+
@Override
47+
public String getUsage(CommandExecutor executor) {
48+
return "/weather [clear|rain]";
49+
}
50+
51+
@Override
52+
public boolean canExecute(CommandExecutor executor) {
53+
return executor.isAdmin() && executor instanceof Player;
54+
}
55+
}

gameserver/src/main/java/brainwine/gameserver/zone/WeatherManager.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ public void createRandomRain(boolean dry) {
4747
}
4848
}
4949

50+
public boolean isRaining() {
51+
return rainPower > 0;
52+
}
53+
54+
public long getRainStart() {
55+
return rainStart;
56+
}
57+
58+
public long getRainDuration() {
59+
return rainDuration;
60+
}
61+
62+
public float getRainPower() {
63+
return rainPower;
64+
}
65+
5066
public float getPrecipitation() {
5167
return precipitation;
5268
}

gameserver/src/main/java/brainwine/gameserver/zone/Zone.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,6 +1068,10 @@ public ChunkManager getChunkManager() {
10681068
return chunkManager;
10691069
}
10701070

1071+
public WeatherManager getWeatherManager() {
1072+
return weatherManager;
1073+
}
1074+
10711075
public void setSurface(int x, int surface) {
10721076
if(areCoordinatesInBounds(x, surface)) {
10731077
this.surface[x] = surface;
@@ -1237,6 +1241,14 @@ public int getChunkCount() {
12371241
return numChunksWidth * numChunksHeight;
12381242
}
12391243

1244+
public void setTime(float time) {
1245+
this.time = time;
1246+
}
1247+
1248+
public float getTime() {
1249+
return time;
1250+
}
1251+
12401252
public void setAcidity(float acidity) {
12411253
this.acidity = acidity;
12421254
}

0 commit comments

Comments
 (0)