Spawn the player at the scene's start position when sent to a dungeon

This commit is contained in:
KingRainbow44 2023-04-12 02:34:13 -04:00
parent 0de69cd1fa
commit 60eb62fa42
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
2 changed files with 26 additions and 1 deletions

View File

@ -6,6 +6,9 @@ import emu.grasscutter.data.ResourceType;
import emu.grasscutter.data.excels.RewardPreviewData;
import emu.grasscutter.game.dungeons.enums.*;
import java.util.List;
import emu.grasscutter.scripts.data.SceneMeta;
import emu.grasscutter.utils.Position;
import lombok.Getter;
@ResourceType(name = "DungeonExcelConfigData.json")
@ -62,6 +65,20 @@ public class DungeonData extends GameResource {
return involveType;
}
/**
* @return The position of the player when they enter the dungeon.
*/
public Position getStartPosition() {
return SceneMeta.of(this.getSceneId()).config.born_pos;
}
/**
* @return The rotation of the player when they enter the dungeon.
*/
public Position getStartRotation() {
return SceneMeta.of(this.getSceneId()).config.born_rot;
}
@Override
public void onLoad() {
if (this.passRewardPreviewID > 0) {

View File

@ -279,17 +279,25 @@ public class World implements Iterable<Player> {
val sceneData = GameData.getSceneDataMap().get(sceneId);
if (dungeonData != null) {
teleportProps.enterType(EnterType.ENTER_TYPE_DUNGEON).enterReason(EnterReason.DungeonEnter);
teleportProps.teleportTo(dungeonData.getStartPosition())
.teleportRot(dungeonData.getStartRotation());
teleportProps.enterType(EnterType.ENTER_TYPE_DUNGEON)
.enterReason(EnterReason.DungeonEnter);
} else if (player.getSceneId() == sceneId) {
teleportProps.enterType(EnterType.ENTER_TYPE_GOTO);
} else if (sceneData != null && sceneData.getSceneType() == SceneType.SCENE_HOME_WORLD) {
// Home
teleportProps.enterType(EnterType.ENTER_TYPE_SELF_HOME).enterReason(EnterReason.EnterHome);
}
return transferPlayerToScene(player, teleportProps.build());
}
public boolean transferPlayerToScene(Player player, TeleportProperties teleportProperties) {
// Check if the teleport properties are valid.
if (teleportProperties.getTeleportTo() == null)
teleportProperties.setTeleportTo(player.getPosition());
// Call player teleport event.
PlayerTeleportEvent event =
new PlayerTeleportEvent(player, teleportProperties, player.getPosition());