From c9363ef5e5a56b9f91c984ae8d898d17637f7121 Mon Sep 17 00:00:00 2001 From: AnimeGitB Date: Thu, 23 Jun 2022 02:32:38 +0930 Subject: [PATCH] Move weather from Scene to Player --- .../command/commands/WeatherCommand.java | 9 ++--- .../emu/grasscutter/game/player/Player.java | 29 ++++++++++++++- .../emu/grasscutter/game/world/Scene.java | 37 ------------------- .../send/PacketSceneAreaWeatherNotify.java | 4 +- 4 files changed, 34 insertions(+), 45 deletions(-) diff --git a/src/main/java/emu/grasscutter/command/commands/WeatherCommand.java b/src/main/java/emu/grasscutter/command/commands/WeatherCommand.java index bb93df2bc..c3dff4968 100644 --- a/src/main/java/emu/grasscutter/command/commands/WeatherCommand.java +++ b/src/main/java/emu/grasscutter/command/commands/WeatherCommand.java @@ -13,12 +13,11 @@ public final class WeatherCommand implements CommandHandler { @Override public void execute(Player sender, Player targetPlayer, List args) { - Scene scene = targetPlayer.getScene(); - int weatherId = scene.getWeather(); + int weatherId = targetPlayer.getWeatherId(); 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(); + climate = targetPlayer.getClimate(); CommandHandler.sendTranslatedMessage(sender, "commands.weather.status", Integer.toString(weatherId), climate.getShortName()); return; } @@ -38,8 +37,8 @@ public final class WeatherCommand implements CommandHandler { } } - scene.setWeather(weatherId, climate); - climate = scene.getClimate(); // Might be different to what we set + targetPlayer.setWeather(weatherId, climate); + climate = targetPlayer.getClimate(); // Might be different to what we set CommandHandler.sendTranslatedMessage(sender, "commands.weather.success", Integer.toString(weatherId), climate.getShortName()); } } diff --git a/src/main/java/emu/grasscutter/game/player/Player.java b/src/main/java/emu/grasscutter/game/player/Player.java index 15df38c18..15bc57698 100644 --- a/src/main/java/emu/grasscutter/game/player/Player.java +++ b/src/main/java/emu/grasscutter/game/player/Player.java @@ -5,6 +5,7 @@ import emu.grasscutter.GameConstants; import emu.grasscutter.Grasscutter; import emu.grasscutter.data.GameData; import emu.grasscutter.data.excels.PlayerLevelData; +import emu.grasscutter.data.excels.WeatherData; import emu.grasscutter.database.DatabaseHelper; import emu.grasscutter.game.Account; import emu.grasscutter.game.CoopRequest; @@ -38,6 +39,7 @@ import emu.grasscutter.game.managers.mapmark.*; import emu.grasscutter.game.managers.stamina.StaminaManager; import emu.grasscutter.game.managers.SotSManager; import emu.grasscutter.game.props.ActionReason; +import emu.grasscutter.game.props.ClimateType; import emu.grasscutter.game.props.PlayerProperty; import emu.grasscutter.game.props.SceneType; import emu.grasscutter.game.quest.QuestManager; @@ -71,6 +73,7 @@ import emu.grasscutter.utils.MessageHandler; import emu.grasscutter.utils.Utils; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +import lombok.Getter; import java.util.*; import java.util.concurrent.LinkedBlockingQueue; @@ -112,6 +115,8 @@ public class Player { @Transient private int peerId; @Transient private World world; @Transient private Scene scene; + @Transient @Getter private int weatherId = 0; + @Transient @Getter private ClimateType climate = ClimateType.CLIMATE_SUNNY; @Transient private GameSession session; @Transient private AvatarStorage avatars; @Transient private Inventory inventory; @@ -140,8 +145,8 @@ public class Player { private int regionId; private int mainCharacterId; private boolean godmode; - private boolean stamina; + private boolean moonCard; private Date moonCardStartTime; private int moonCardDuration; @@ -324,6 +329,28 @@ public class Player { this.scene = scene; } + synchronized public void setClimate(ClimateType climate) { + this.climate = climate; + this.session.send(new PacketSceneAreaWeatherNotify(this)); + } + + synchronized public void setWeather(int weather) { + this.setWeather(weather, ClimateType.CLIMATE_NONE); + } + + synchronized public void setWeather(int weatherId, ClimateType climate) { + // Lookup default climate for this weather + if (climate == ClimateType.CLIMATE_NONE) { + WeatherData w = GameData.getWeatherDataMap().get(weatherId); + if (w != null) { + climate = w.getDefaultClimate(); + } + } + this.weatherId = weatherId; + this.climate = climate; + this.session.send(new PacketSceneAreaWeatherNotify(this)); + } + public int getGmLevel() { return 1; } diff --git a/src/main/java/emu/grasscutter/game/world/Scene.java b/src/main/java/emu/grasscutter/game/world/Scene.java index 4e5dd07e7..43007bcc0 100644 --- a/src/main/java/emu/grasscutter/game/world/Scene.java +++ b/src/main/java/emu/grasscutter/game/world/Scene.java @@ -45,8 +45,6 @@ public class Scene { private int autoCloseTime; private int time; - private ClimateType climate; - private int weather; private SceneScriptManager scriptManager; private WorldChallenge challenge; @@ -61,7 +59,6 @@ public class Scene { this.entities = Int2ObjectMaps.synchronize(new Int2ObjectOpenHashMap<>()); this.time = 8 * 60; - this.climate = ClimateType.CLIMATE_SUNNY; this.prevScene = 3; this.spawnedEntities = new HashSet<>(); @@ -129,40 +126,6 @@ public class Scene { public void changeTime(int time) { this.time = time % 1440; } - - public ClimateType getClimate() { - return climate; - } - - public int getWeather() { - return weather; - } - - synchronized public void setClimate(ClimateType climate) { - this.climate = climate; - for (Player player : this.players) { - this.broadcastPacket(new PacketSceneAreaWeatherNotify(player)); - } - } - - 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() { return prevScene; diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneAreaWeatherNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneAreaWeatherNotify.java index 91112871d..b49df5fef 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketSceneAreaWeatherNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketSceneAreaWeatherNotify.java @@ -12,8 +12,8 @@ public class PacketSceneAreaWeatherNotify extends BasePacket { super(PacketOpcodes.SceneAreaWeatherNotify); SceneAreaWeatherNotify proto = SceneAreaWeatherNotify.newBuilder() - .setWeatherAreaId(player.getScene().getWeather()) - .setClimateType(player.getScene().getClimate().getValue()) + .setWeatherAreaId(player.getWeatherId()) + .setClimateType(player.getClimate().getValue()) .build(); this.setData(proto);