Skip to content

Commit

Permalink
Add a changing weather id
Browse files Browse the repository at this point in the history
  • Loading branch information
yarik0chka committed Apr 21, 2022
1 parent 6863600 commit 38c0c9e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 8 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ There is a dummy user named "Server" in every player's friends list that you can

`!pos` - Gets your current coordinate.

`!weather [weather id]` - Changes the current weather.
`!weather [weather id] [climate id]` - Changes the current weather.

*More commands will be updated in the [wiki](https://github.com/Melledy/Grasscutter/wiki/).*

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import java.util.List;

@Command(label = "weather", usage = "weather <weatherId>",
@Command(label = "weather", usage = "weather <weatherId> [climateId]",
description = "Changes the weather.", aliases = {"w"}, permission = "player.weather")
public final class WeatherCommand implements CommandHandler {

Expand All @@ -20,20 +20,22 @@ public void execute(GenshinPlayer sender, List<String> args) {
}

if (args.size() < 1) {
CommandHandler.sendMessage(sender, "Usage: weather <weatherId>");
CommandHandler.sendMessage(sender, "Usage: weather <weatherId> [climateId]");
return;
}

try {
int weatherId = Integer.parseInt(args.get(0));
int climateId = args.size() > 1 ? Integer.parseInt(args.get(1)) : 1;

ClimateType climate = ClimateType.getTypeByValue(weatherId);
ClimateType climate = ClimateType.getTypeByValue(climateId);

sender.getScene().setWeather(weatherId);
sender.getScene().setClimate(climate);
sender.getScene().broadcastPacket(new PacketSceneAreaWeatherNotify(sender));
CommandHandler.sendMessage(sender, "Changed weather to " + weatherId);
CommandHandler.sendMessage(sender, "Changed weather to " + weatherId + " with climate " + climateId);
} catch (NumberFormatException ignored) {
CommandHandler.sendMessage(sender, "Invalid weather ID.");
CommandHandler.sendMessage(sender, "Invalid ID.");
}
}
}
11 changes: 10 additions & 1 deletion src/main/java/emu/grasscutter/game/GenshinScene.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ public class GenshinScene {

private int time;
private ClimateType climate;

private int weather;

public GenshinScene(World world, SceneData sceneData) {
this.world = world;
this.sceneData = sceneData;
Expand Down Expand Up @@ -89,10 +90,18 @@ public ClimateType getClimate() {
return climate;
}

public int getWeather() {
return weather;
}

public void setClimate(ClimateType climate) {
this.climate = climate;
}

public void setWeather(int weather) {
this.weather = weather;
}

public boolean isInScene(GenshinEntity entity) {
return this.entities.containsKey(entity.getId());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public PacketSceneAreaWeatherNotify(GenshinPlayer player) {
super(PacketOpcodes.SceneAreaWeatherNotify);

SceneAreaWeatherNotify proto = SceneAreaWeatherNotify.newBuilder()
.setWeatherAreaId(1)
.setWeatherAreaId(player.getScene().getWeather())
.setClimateType(player.getScene().getClimate().getValue())
.build();

Expand Down

0 comments on commit 38c0c9e

Please sign in to comment.