mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-26 14:17:58 +00:00
Fix player pausing
This commit is contained in:
parent
bb693cd222
commit
8438e94c6e
@ -771,7 +771,7 @@ public class Player implements PlayerHook {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void setPaused(boolean newPauseState) {
|
public void setPaused(boolean newPauseState) {
|
||||||
boolean oldPauseState = this.paused;
|
var oldPauseState = this.paused;
|
||||||
this.paused = newPauseState;
|
this.paused = newPauseState;
|
||||||
|
|
||||||
if (newPauseState && !oldPauseState) {
|
if (newPauseState && !oldPauseState) {
|
||||||
@ -1498,8 +1498,10 @@ public class Player implements PlayerHook {
|
|||||||
PropChangeReason.PROP_CHANGE_REASON_PLAYER_ADD_EXP));
|
PropChangeReason.PROP_CHANGE_REASON_PLAYER_ADD_EXP));
|
||||||
case PROP_PLAYER_LEVEL -> this.sendPacket(new PacketPlayerPropChangeReasonNotify(this, prop, currentValue, value,
|
case PROP_PLAYER_LEVEL -> this.sendPacket(new PacketPlayerPropChangeReasonNotify(this, prop, currentValue, value,
|
||||||
PropChangeReason.PROP_CHANGE_REASON_LEVELUP));
|
PropChangeReason.PROP_CHANGE_REASON_LEVELUP));
|
||||||
case PROP_PLAYER_WORLD_LEVEL -> this.sendPacket(new PacketPlayerPropChangeReasonNotify(this, prop, currentValue, value,
|
|
||||||
PropChangeReason.PROP_CHANGE_REASON_MANUAL_ADJUST_WORLD_LEVEL));
|
// TODO: Handle world level changing.
|
||||||
|
// case PROP_PLAYER_WORLD_LEVEL -> this.sendPacket(new PacketPlayerPropChangeReasonNotify(this, prop, currentValue, value,
|
||||||
|
// PropChangeReason.PROP_CHANGE_REASON_MANUAL_ADJUST_WORLD_LEVEL));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update player with packet.
|
// Update player with packet.
|
||||||
|
@ -1,7 +1,5 @@
|
|||||||
package emu.grasscutter.game.world;
|
package emu.grasscutter.game.world;
|
||||||
|
|
||||||
import static emu.grasscutter.server.event.player.PlayerTeleportEvent.TeleportType.SCRIPT;
|
|
||||||
|
|
||||||
import emu.grasscutter.data.GameData;
|
import emu.grasscutter.data.GameData;
|
||||||
import emu.grasscutter.data.excels.dungeon.DungeonData;
|
import emu.grasscutter.data.excels.dungeon.DungeonData;
|
||||||
import emu.grasscutter.game.player.Player;
|
import emu.grasscutter.game.player.Player;
|
||||||
@ -24,13 +22,17 @@ import emu.grasscutter.utils.Position;
|
|||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectMaps;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMaps;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.val;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.val;
|
import static emu.grasscutter.server.event.player.PlayerTeleportEvent.TeleportType.SCRIPT;
|
||||||
|
|
||||||
public final class World implements Iterable<Player> {
|
public final class World implements Iterable<Player> {
|
||||||
@Getter private final GameServer server;
|
@Getter private final GameServer server;
|
||||||
@ -477,7 +479,12 @@ public final class World implements Iterable<Player> {
|
|||||||
* @param paused True if the world should be paused.
|
* @param paused True if the world should be paused.
|
||||||
*/
|
*/
|
||||||
public void setPaused(boolean paused) {
|
public void setPaused(boolean paused) {
|
||||||
this.getWorldTime(); // Update the world time.
|
// Check if this world is a multiplayer world.
|
||||||
|
if (this.isMultiplayer) return;
|
||||||
|
|
||||||
|
// Update the world time.
|
||||||
|
this.getWorldTime();
|
||||||
|
this.updateTime();
|
||||||
|
|
||||||
// If the world is being un-paused, update the last update time.
|
// If the world is being un-paused, update the last update time.
|
||||||
if (this.isPaused != paused && !paused) {
|
if (this.isPaused != paused && !paused) {
|
||||||
@ -526,6 +533,16 @@ public final class World implements Iterable<Player> {
|
|||||||
player -> player.getQuestManager().queueEvent(QuestContent.QUEST_CONTENT_GAME_TIME_TICK));
|
player -> player.getQuestManager().queueEvent(QuestContent.QUEST_CONTENT_GAME_TIME_TICK));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Notifies all players of the current world time.
|
||||||
|
*/
|
||||||
|
public void updateTime() {
|
||||||
|
this.getPlayers().forEach(p ->
|
||||||
|
p.sendPacket(new PacketPlayerGameTimeNotify(p)));
|
||||||
|
this.getPlayers().forEach(p ->
|
||||||
|
p.sendPacket(new PacketSceneTimeNotify(p)));
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Locks the world time.
|
* Locks the world time.
|
||||||
*
|
*
|
||||||
@ -535,10 +552,12 @@ public final class World implements Iterable<Player> {
|
|||||||
this.timeLocked = locked;
|
this.timeLocked = locked;
|
||||||
|
|
||||||
// Notify players of the locking.
|
// Notify players of the locking.
|
||||||
|
this.updateTime();
|
||||||
this.getPlayers()
|
this.getPlayers()
|
||||||
.forEach(player -> player.setProperty(PlayerProperty.PROP_IS_GAME_TIME_LOCKED, locked));
|
.forEach(player -> player.setProperty(PlayerProperty.PROP_IS_GAME_TIME_LOCKED, locked));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
@Override
|
@Override
|
||||||
public Iterator<Player> iterator() {
|
public Iterator<Player> iterator() {
|
||||||
return this.getPlayers().iterator();
|
return this.getPlayers().iterator();
|
||||||
|
@ -4,22 +4,25 @@ import emu.grasscutter.net.packet.Opcodes;
|
|||||||
import emu.grasscutter.net.packet.PacketHandler;
|
import emu.grasscutter.net.packet.PacketHandler;
|
||||||
import emu.grasscutter.net.packet.PacketOpcodes;
|
import emu.grasscutter.net.packet.PacketOpcodes;
|
||||||
import emu.grasscutter.net.proto.PlayerSetPauseReqOuterClass.PlayerSetPauseReq;
|
import emu.grasscutter.net.proto.PlayerSetPauseReqOuterClass.PlayerSetPauseReq;
|
||||||
|
import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode;
|
||||||
import emu.grasscutter.server.game.GameSession;
|
import emu.grasscutter.server.game.GameSession;
|
||||||
import emu.grasscutter.server.packet.send.PacketPlayerSetPauseRsp;
|
import emu.grasscutter.server.packet.send.PacketPlayerSetPauseRsp;
|
||||||
import emu.grasscutter.server.packet.send.PacketPlayerTimeNotify;
|
|
||||||
import emu.grasscutter.server.packet.send.PacketSceneTimeNotify;
|
|
||||||
|
|
||||||
@Opcodes(PacketOpcodes.PlayerSetPauseReq)
|
@Opcodes(PacketOpcodes.PlayerSetPauseReq)
|
||||||
public class HandlerPlayerSetPauseReq extends PacketHandler {
|
public class HandlerPlayerSetPauseReq extends PacketHandler {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
|
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
|
||||||
PlayerSetPauseReq req = PlayerSetPauseReq.parseFrom(payload);
|
var req = PlayerSetPauseReq.parseFrom(payload);
|
||||||
|
var player = session.getPlayer();
|
||||||
|
var world = player.getWorld();
|
||||||
|
|
||||||
session.send(new PacketPlayerSetPauseRsp());
|
// Check if the player is in a multiplayer world.
|
||||||
session.getPlayer().setPaused(req.getIsPaused());
|
if (player.isInMultiplayer()) {
|
||||||
|
session.send(new PacketPlayerSetPauseRsp(Retcode.RET_FAIL));
|
||||||
session.send(new PacketPlayerTimeNotify(session.getPlayer()));
|
} else {
|
||||||
session.send(new PacketSceneTimeNotify(session.getPlayer()));
|
world.setPaused(req.getIsPaused());
|
||||||
|
session.send(new PacketPlayerSetPauseRsp(Retcode.RET_SUCC));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,9 +7,10 @@ import emu.grasscutter.net.proto.RetcodeOuterClass.Retcode;
|
|||||||
|
|
||||||
public class PacketPlayerSetPauseRsp extends BasePacket {
|
public class PacketPlayerSetPauseRsp extends BasePacket {
|
||||||
|
|
||||||
public PacketPlayerSetPauseRsp() {
|
public PacketPlayerSetPauseRsp(Retcode retcode) {
|
||||||
super(PacketOpcodes.PlayerSetPauseRsp);
|
super(PacketOpcodes.PlayerSetPauseRsp);
|
||||||
|
|
||||||
this.setData(PlayerSetPauseRsp.newBuilder().setRetcode(Retcode.RET_SUCC_VALUE));
|
this.setData(PlayerSetPauseRsp.newBuilder()
|
||||||
|
.setRetcode(retcode.getNumber()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user