mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-15 08:25:21 +01:00
Add default Climates per weather
This commit is contained in:
@@ -1,47 +1,45 @@
|
||||
package emu.grasscutter.command.commands;
|
||||
|
||||
import emu.grasscutter.Grasscutter;
|
||||
import emu.grasscutter.command.Command;
|
||||
import emu.grasscutter.command.CommandHandler;
|
||||
import emu.grasscutter.game.player.Player;
|
||||
import emu.grasscutter.game.props.ClimateType;
|
||||
import emu.grasscutter.server.packet.send.PacketSceneAreaWeatherNotify;
|
||||
import emu.grasscutter.game.world.Scene;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static emu.grasscutter.utils.Language.translate;
|
||||
|
||||
@Command(label = "weather", usage = "weather <climate type(weatherId)> <weather type(climateId)>", aliases = {"w"}, permission = "player.weather", permissionTargeted = "player.weather.others", description = "commands.weather.description")
|
||||
@Command(label = "weather", usage = "weather [weatherId] [climateType]", aliases = {"w"}, permission = "player.weather", permissionTargeted = "player.weather.others", description = "commands.weather.description")
|
||||
public final class WeatherCommand implements CommandHandler {
|
||||
|
||||
@Override
|
||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||
int weatherId = 0;
|
||||
int climateId = 1;
|
||||
switch (args.size()) {
|
||||
case 2:
|
||||
try {
|
||||
climateId = Integer.parseInt(args.get(1));
|
||||
} catch (NumberFormatException ignored) {
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.weather.invalid_id"));
|
||||
}
|
||||
case 1:
|
||||
try {
|
||||
weatherId = Integer.parseInt(args.get(0));
|
||||
} catch (NumberFormatException ignored) {
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.weather.invalid_id"));
|
||||
}
|
||||
break;
|
||||
default:
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.weather.usage"));
|
||||
return;
|
||||
Scene scene = targetPlayer.getScene();
|
||||
int weatherId = scene.getWeather();
|
||||
ClimateType climate = ClimateType.CLIMATE_NONE; // Sending ClimateType.CLIMATE_NONE to Scene.setWeather will use the default climate for that weather
|
||||
|
||||
if (args.isEmpty()) {
|
||||
climate = scene.getClimate();
|
||||
CommandHandler.sendTranslatedMessage(sender, "commands.weather.status", Integer.toString(weatherId), climate.getShortName());
|
||||
return;
|
||||
}
|
||||
|
||||
ClimateType climate = ClimateType.getTypeByValue(climateId);
|
||||
for (String arg : args) {
|
||||
ClimateType c = ClimateType.getTypeByShortName(arg.toLowerCase());
|
||||
if (c != ClimateType.CLIMATE_NONE) {
|
||||
climate = c;
|
||||
} else {
|
||||
try {
|
||||
weatherId = Integer.parseInt(arg);
|
||||
} catch (NumberFormatException ignored) {
|
||||
CommandHandler.sendTranslatedMessage(sender, "commands.generic.invalid.id");
|
||||
CommandHandler.sendTranslatedMessage(sender, "commands.weather.usage");
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
targetPlayer.getScene().setWeather(weatherId);
|
||||
targetPlayer.getScene().setClimate(climate);
|
||||
targetPlayer.getScene().broadcastPacket(new PacketSceneAreaWeatherNotify(targetPlayer));
|
||||
CommandHandler.sendMessage(sender, translate(sender, "commands.weather.success", Integer.toString(weatherId), Integer.toString(climateId)));
|
||||
scene.setWeather(weatherId, climate);
|
||||
climate = scene.getClimate(); // Might be different to what we set
|
||||
CommandHandler.sendTranslatedMessage(sender, "commands.weather.success", Integer.toString(weatherId), climate.getShortName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -94,6 +94,7 @@ public class GameData {
|
||||
private static final Int2ObjectMap<FurnitureMakeConfigData> furnitureMakeConfigDataMap = new Int2ObjectOpenHashMap<>();
|
||||
private static final Int2ObjectMap<InvestigationMonsterData> investigationMonsterDataMap = new Int2ObjectOpenHashMap<>();
|
||||
private static final Int2ObjectMap<CityData> cityDataMap = new Int2ObjectOpenHashMap<>();
|
||||
private static final Int2ObjectMap<WeatherData> weatherDataMap = new Int2ObjectOpenHashMap<>();
|
||||
private static final Int2ObjectMap<BattlePassMissionExcelConfigData> battlePassMissionExcelConfigDataMap = new Int2ObjectOpenHashMap<>();
|
||||
private static final Int2ObjectMap<BattlePassRewardExcelConfigData> battlePassRewardExcelConfigDataMap = new Int2ObjectOpenHashMap<>();
|
||||
|
||||
@@ -414,10 +415,15 @@ public class GameData {
|
||||
public static Int2ObjectMap<InvestigationMonsterData> getInvestigationMonsterDataMap() {
|
||||
return investigationMonsterDataMap;
|
||||
}
|
||||
|
||||
public static Int2ObjectMap<CityData> getCityDataMap() {
|
||||
return cityDataMap;
|
||||
}
|
||||
|
||||
public static Int2ObjectMap<WeatherData> getWeatherDataMap() {
|
||||
return weatherDataMap;
|
||||
}
|
||||
|
||||
public static Int2ObjectMap<BattlePassMissionExcelConfigData> getBattlePassMissionExcelConfigDataMap() {
|
||||
return battlePassMissionExcelConfigDataMap;
|
||||
}
|
||||
|
||||
26
src/main/java/emu/grasscutter/data/excels/WeatherData.java
Normal file
26
src/main/java/emu/grasscutter/data/excels/WeatherData.java
Normal file
@@ -0,0 +1,26 @@
|
||||
package emu.grasscutter.data.excels;
|
||||
|
||||
import emu.grasscutter.data.GameResource;
|
||||
import emu.grasscutter.data.ResourceType;
|
||||
import emu.grasscutter.game.props.ClimateType;
|
||||
import lombok.Getter;
|
||||
|
||||
@ResourceType(name = "WeatherExcelConfigData.json")
|
||||
public class WeatherData extends GameResource {
|
||||
@Getter private int areaID;
|
||||
@Getter private int weatherAreaId;
|
||||
@Getter private String maxHeightStr;
|
||||
@Getter private int gadgetID;
|
||||
@Getter private boolean isDefaultValid;
|
||||
@Getter private String templateName;
|
||||
@Getter private int priority;
|
||||
@Getter private String profileName;
|
||||
@Getter private ClimateType defaultClimate;
|
||||
@Getter private boolean isUseDefault;
|
||||
@Getter private int sceneID;
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return this.areaID;
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,11 @@ public enum ClimateType {
|
||||
}
|
||||
|
||||
public int getValue() {
|
||||
return value;
|
||||
return this.value;
|
||||
}
|
||||
|
||||
public String getShortName() {
|
||||
return this.name().substring(8).toLowerCase();
|
||||
}
|
||||
|
||||
public static ClimateType getTypeByValue(int value) {
|
||||
@@ -42,4 +46,9 @@ public enum ClimateType {
|
||||
public static ClimateType getTypeByName(String name) {
|
||||
return stringMap.getOrDefault(name, CLIMATE_NONE);
|
||||
}
|
||||
|
||||
public static ClimateType getTypeByShortName(String shortName) {
|
||||
String name = "CLIMATE_" + shortName.toUpperCase();
|
||||
return stringMap.getOrDefault(name, CLIMATE_NONE);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -138,12 +138,30 @@ public class Scene {
|
||||
return weather;
|
||||
}
|
||||
|
||||
public void setClimate(ClimateType climate) {
|
||||
synchronized public void setClimate(ClimateType climate) {
|
||||
this.climate = climate;
|
||||
for (Player player : this.players) {
|
||||
this.broadcastPacket(new PacketSceneAreaWeatherNotify(player));
|
||||
}
|
||||
}
|
||||
|
||||
public void setWeather(int weather) {
|
||||
synchronized public void setWeather(int weather) {
|
||||
this.setWeather(weather, ClimateType.CLIMATE_NONE);
|
||||
}
|
||||
|
||||
synchronized public void setWeather(int weather, ClimateType climate) {
|
||||
// Lookup default climate for this weather
|
||||
if (climate == ClimateType.CLIMATE_NONE) {
|
||||
WeatherData w = GameData.getWeatherDataMap().get(weather);
|
||||
if (w != null) {
|
||||
climate = w.getDefaultClimate();
|
||||
}
|
||||
}
|
||||
this.weather = weather;
|
||||
this.climate = climate;
|
||||
for (Player player : this.players) {
|
||||
this.broadcastPacket(new PacketSceneAreaWeatherNotify(player));
|
||||
}
|
||||
}
|
||||
|
||||
public int getPrevScene() {
|
||||
|
||||
Reference in New Issue
Block a user