mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-23 02:34:07 +00:00
Move weather from Scene to Player
This commit is contained in:
parent
aa835ecac7
commit
c9363ef5e5
@ -13,12 +13,11 @@ public final class WeatherCommand implements CommandHandler {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
public void execute(Player sender, Player targetPlayer, List<String> args) {
|
||||||
Scene scene = targetPlayer.getScene();
|
int weatherId = targetPlayer.getWeatherId();
|
||||||
int weatherId = scene.getWeather();
|
|
||||||
ClimateType climate = ClimateType.CLIMATE_NONE; // Sending ClimateType.CLIMATE_NONE to Scene.setWeather will use the default climate for that weather
|
ClimateType climate = ClimateType.CLIMATE_NONE; // Sending ClimateType.CLIMATE_NONE to Scene.setWeather will use the default climate for that weather
|
||||||
|
|
||||||
if (args.isEmpty()) {
|
if (args.isEmpty()) {
|
||||||
climate = scene.getClimate();
|
climate = targetPlayer.getClimate();
|
||||||
CommandHandler.sendTranslatedMessage(sender, "commands.weather.status", Integer.toString(weatherId), climate.getShortName());
|
CommandHandler.sendTranslatedMessage(sender, "commands.weather.status", Integer.toString(weatherId), climate.getShortName());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -38,8 +37,8 @@ public final class WeatherCommand implements CommandHandler {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
scene.setWeather(weatherId, climate);
|
targetPlayer.setWeather(weatherId, climate);
|
||||||
climate = scene.getClimate(); // Might be different to what we set
|
climate = targetPlayer.getClimate(); // Might be different to what we set
|
||||||
CommandHandler.sendTranslatedMessage(sender, "commands.weather.success", Integer.toString(weatherId), climate.getShortName());
|
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.Grasscutter;
|
||||||
import emu.grasscutter.data.GameData;
|
import emu.grasscutter.data.GameData;
|
||||||
import emu.grasscutter.data.excels.PlayerLevelData;
|
import emu.grasscutter.data.excels.PlayerLevelData;
|
||||||
|
import emu.grasscutter.data.excels.WeatherData;
|
||||||
import emu.grasscutter.database.DatabaseHelper;
|
import emu.grasscutter.database.DatabaseHelper;
|
||||||
import emu.grasscutter.game.Account;
|
import emu.grasscutter.game.Account;
|
||||||
import emu.grasscutter.game.CoopRequest;
|
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.stamina.StaminaManager;
|
||||||
import emu.grasscutter.game.managers.SotSManager;
|
import emu.grasscutter.game.managers.SotSManager;
|
||||||
import emu.grasscutter.game.props.ActionReason;
|
import emu.grasscutter.game.props.ActionReason;
|
||||||
|
import emu.grasscutter.game.props.ClimateType;
|
||||||
import emu.grasscutter.game.props.PlayerProperty;
|
import emu.grasscutter.game.props.PlayerProperty;
|
||||||
import emu.grasscutter.game.props.SceneType;
|
import emu.grasscutter.game.props.SceneType;
|
||||||
import emu.grasscutter.game.quest.QuestManager;
|
import emu.grasscutter.game.quest.QuestManager;
|
||||||
@ -71,6 +73,7 @@ import emu.grasscutter.utils.MessageHandler;
|
|||||||
import emu.grasscutter.utils.Utils;
|
import emu.grasscutter.utils.Utils;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.concurrent.LinkedBlockingQueue;
|
import java.util.concurrent.LinkedBlockingQueue;
|
||||||
@ -112,6 +115,8 @@ public class Player {
|
|||||||
@Transient private int peerId;
|
@Transient private int peerId;
|
||||||
@Transient private World world;
|
@Transient private World world;
|
||||||
@Transient private Scene scene;
|
@Transient private Scene scene;
|
||||||
|
@Transient @Getter private int weatherId = 0;
|
||||||
|
@Transient @Getter private ClimateType climate = ClimateType.CLIMATE_SUNNY;
|
||||||
@Transient private GameSession session;
|
@Transient private GameSession session;
|
||||||
@Transient private AvatarStorage avatars;
|
@Transient private AvatarStorage avatars;
|
||||||
@Transient private Inventory inventory;
|
@Transient private Inventory inventory;
|
||||||
@ -140,8 +145,8 @@ public class Player {
|
|||||||
private int regionId;
|
private int regionId;
|
||||||
private int mainCharacterId;
|
private int mainCharacterId;
|
||||||
private boolean godmode;
|
private boolean godmode;
|
||||||
|
|
||||||
private boolean stamina;
|
private boolean stamina;
|
||||||
|
|
||||||
private boolean moonCard;
|
private boolean moonCard;
|
||||||
private Date moonCardStartTime;
|
private Date moonCardStartTime;
|
||||||
private int moonCardDuration;
|
private int moonCardDuration;
|
||||||
@ -324,6 +329,28 @@ public class Player {
|
|||||||
this.scene = scene;
|
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() {
|
public int getGmLevel() {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -45,8 +45,6 @@ public class Scene {
|
|||||||
|
|
||||||
private int autoCloseTime;
|
private int autoCloseTime;
|
||||||
private int time;
|
private int time;
|
||||||
private ClimateType climate;
|
|
||||||
private int weather;
|
|
||||||
|
|
||||||
private SceneScriptManager scriptManager;
|
private SceneScriptManager scriptManager;
|
||||||
private WorldChallenge challenge;
|
private WorldChallenge challenge;
|
||||||
@ -61,7 +59,6 @@ public class Scene {
|
|||||||
this.entities = Int2ObjectMaps.synchronize(new Int2ObjectOpenHashMap<>());
|
this.entities = Int2ObjectMaps.synchronize(new Int2ObjectOpenHashMap<>());
|
||||||
|
|
||||||
this.time = 8 * 60;
|
this.time = 8 * 60;
|
||||||
this.climate = ClimateType.CLIMATE_SUNNY;
|
|
||||||
this.prevScene = 3;
|
this.prevScene = 3;
|
||||||
|
|
||||||
this.spawnedEntities = new HashSet<>();
|
this.spawnedEntities = new HashSet<>();
|
||||||
@ -129,40 +126,6 @@ public class Scene {
|
|||||||
public void changeTime(int time) {
|
public void changeTime(int time) {
|
||||||
this.time = time % 1440;
|
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() {
|
public int getPrevScene() {
|
||||||
return prevScene;
|
return prevScene;
|
||||||
|
@ -12,8 +12,8 @@ public class PacketSceneAreaWeatherNotify extends BasePacket {
|
|||||||
super(PacketOpcodes.SceneAreaWeatherNotify);
|
super(PacketOpcodes.SceneAreaWeatherNotify);
|
||||||
|
|
||||||
SceneAreaWeatherNotify proto = SceneAreaWeatherNotify.newBuilder()
|
SceneAreaWeatherNotify proto = SceneAreaWeatherNotify.newBuilder()
|
||||||
.setWeatherAreaId(player.getScene().getWeather())
|
.setWeatherAreaId(player.getWeatherId())
|
||||||
.setClimateType(player.getScene().getClimate().getValue())
|
.setClimateType(player.getClimate().getValue())
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
this.setData(proto);
|
this.setData(proto);
|
||||||
|
Loading…
Reference in New Issue
Block a user