Commit c9363ef5 authored by AnimeGitB's avatar AnimeGitB
Browse files

Move weather from Scene to Player

parent aa835eca
......@@ -13,12 +13,11 @@ public final class WeatherCommand implements CommandHandler {
@Override
public void execute(Player sender, Player targetPlayer, List<String> 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());
}
}
......@@ -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;
}
......
......@@ -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<>();
......@@ -130,40 +127,6 @@ public class Scene {
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;
}
......
......@@ -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);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment