Commit d05b3207 authored by Magix's avatar Magix Committed by GitHub
Browse files

Add more events

Merge pull request #1516 from Grasscutters/more-events
parents 9a104f6f a3e0f7f5
package emu.grasscutter.server.packet.recv;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.binout.ScenePointEntry;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.SceneTransToPointReqOuterClass.SceneTransToPointReq;
import emu.grasscutter.net.proto.SceneTransToPointRspOuterClass.SceneTransToPointRsp;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketSceneTransToPointRsp;
import emu.grasscutter.utils.Position;
@Opcodes(PacketOpcodes.SceneTransToPointReq)
public class HandlerSceneTransToPointReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
SceneTransToPointReq req = SceneTransToPointReq.parseFrom(payload);
String code = req.getSceneId() + "_" + req.getPointId();
ScenePointEntry scenePointEntry = GameData.getScenePointEntries().get(code);
if (scenePointEntry != null) {
float x = scenePointEntry.getPointData().getTranPos().getX();
float y = scenePointEntry.getPointData().getTranPos().getY();
float z = scenePointEntry.getPointData().getTranPos().getZ();
session.getPlayer().getWorld().transferPlayerToScene(session.getPlayer(), req.getSceneId(), new Position(x, y, z));
session.send(new PacketSceneTransToPointRsp(session.getPlayer(), req.getPointId(), req.getSceneId()));
} else {
session.send(new PacketSceneTransToPointRsp());
}
}
}
package emu.grasscutter.server.packet.recv;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.binout.ScenePointEntry;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.SceneTransToPointReqOuterClass.SceneTransToPointReq;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.server.event.player.PlayerTeleportEvent.TeleportType;
import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketSceneTransToPointRsp;
import emu.grasscutter.utils.Position;
@Opcodes(PacketOpcodes.SceneTransToPointReq)
public class HandlerSceneTransToPointReq extends PacketHandler {
@Override
public void handle(GameSession session, byte[] header, byte[] payload) throws Exception {
SceneTransToPointReq req = SceneTransToPointReq.parseFrom(payload);
String code = req.getSceneId() + "_" + req.getPointId();
ScenePointEntry scenePointEntry = GameData.getScenePointEntries().get(code);
if (scenePointEntry != null) {
float x = scenePointEntry.getPointData().getTranPos().getX();
float y = scenePointEntry.getPointData().getTranPos().getY();
float z = scenePointEntry.getPointData().getTranPos().getZ();
if (session.getPlayer().getWorld().transferPlayerToScene(session.getPlayer(), req.getSceneId(), TeleportType.WAYPOINT, new Position(x, y, z))) {
session.send(new PacketSceneTransToPointRsp(session.getPlayer(), req.getPointId(), req.getSceneId()));
}
} else {
session.send(new PacketSceneTransToPointRsp());
}
}
}
package emu.grasscutter.server.packet.recv;
import emu.grasscutter.data.GameData;
import emu.grasscutter.database.DatabaseHelper;
import emu.grasscutter.game.home.GameHome;
import emu.grasscutter.game.world.Scene;
import emu.grasscutter.net.packet.Opcodes;
import emu.grasscutter.net.packet.PacketHandler;
import emu.grasscutter.net.packet.PacketOpcodes;
import emu.grasscutter.net.proto.TryEnterHomeReqOuterClass;
import emu.grasscutter.scripts.data.SceneConfig;
import emu.grasscutter.server.event.player.PlayerTeleportEvent.TeleportType;
import emu.grasscutter.server.game.GameSession;
import emu.grasscutter.server.packet.send.PacketTryEnterHomeRsp;
import emu.grasscutter.utils.Position;
......@@ -38,13 +35,10 @@ public class HandlerTryEnterHomeReq extends PacketHandler {
Scene scene = session.getPlayer().getWorld().getSceneById(realmId);
Position pos = scene.getScriptManager().getConfig().born_pos;
session.getPlayer().getWorld().transferPlayerToScene(
session.getPlayer(),
realmId,
pos
boolean result = session.getPlayer().getWorld().transferPlayerToScene(
session.getPlayer(), realmId,
TeleportType.WAYPOINT, pos
);
session.send(new PacketTryEnterHomeRsp(req.getTargetUid()));
if (result) session.send(new PacketTryEnterHomeRsp(req.getTargetUid()));
}
}
package emu.grasscutter.utils;
import dev.morphia.annotations.Entity;
import dev.morphia.annotations.Transient;
import emu.grasscutter.game.world.Scene;
import lombok.Getter;
import lombok.Setter;
@Entity
public class Location extends Position {
@Transient @Getter @Setter
private Scene scene;
public Location(Scene scene, Position position) {
this.set(position);
this.scene = scene;
}
public Location(Scene scene, float x, float y) {
this.set(x, y);
this.scene = scene;
}
public Location(Scene scene, float x, float y, float z) {
this.set(x, y, z);
this.scene = scene;
}
@Override
public Location clone() {
return new Location(this.scene, super.clone());
}
@Override
public String toString() {
return String.format("%s:%s,%s,%s", this.scene.getId(), this.getX(), this.getY(), this.getZ());
}
}
\ No newline at end of file
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