From 07e038343d86b913c184d175d48f6017f2cc7b4c Mon Sep 17 00:00:00 2001 From: KingRainbow44 Date: Wed, 10 May 2023 20:54:25 -0400 Subject: [PATCH] Fix teleporting errors --- .gitignore | 3 +++ .../grasscutter/game/player/TeamManager.java | 6 ++---- .../emu/grasscutter/game/world/Scene.java | 2 +- .../emu/grasscutter/game/world/World.java | 20 +++++++++++++++++-- .../send/PacketPlayerEnterSceneNotify.java | 8 ++++---- 5 files changed, 28 insertions(+), 11 deletions(-) diff --git a/.gitignore b/.gitignore index 0a2881741..73478426d 100644 --- a/.gitignore +++ b/.gitignore @@ -86,3 +86,6 @@ src/main/resources/handbook.html # Hotswap Agent hotswap-agent.properties + +# Debug patches +patches/*.patch diff --git a/src/main/java/emu/grasscutter/game/player/TeamManager.java b/src/main/java/emu/grasscutter/game/player/TeamManager.java index cd9039018..0c1efd20f 100644 --- a/src/main/java/emu/grasscutter/game/player/TeamManager.java +++ b/src/main/java/emu/grasscutter/game/player/TeamManager.java @@ -7,7 +7,6 @@ import dev.morphia.annotations.Transient; import emu.grasscutter.GameConstants; import emu.grasscutter.Grasscutter; import emu.grasscutter.data.GameData; -import emu.grasscutter.data.binout.config.fields.ConfigAbilityData; import emu.grasscutter.data.excels.avatar.AvatarSkillDepotData; import emu.grasscutter.game.avatar.Avatar; import emu.grasscutter.game.entity.EntityAvatar; @@ -980,7 +979,7 @@ public final class TeamManager extends BasePlayerDataManager { // any } - for (ConfigAbilityData abilities : config.getAvatarAbilities()) { + for (var abilities : config.getAvatarAbilities()) { avatarData.getAbilities().add(Utils.abilityHash(abilities.getAbilityName())); } } @@ -1123,8 +1122,7 @@ public final class TeamManager extends BasePlayerDataManager { */ public void removeTrialAvatar(List trialAvatarIds) { // Check if the player is using a trial team. - if (!this.isUsingTrialTeam()) - throw new IllegalStateException("Player is not using trial team."); + if (!this.isUsingTrialTeam()) return; this.getPlayer() .sendPacket( diff --git a/src/main/java/emu/grasscutter/game/world/Scene.java b/src/main/java/emu/grasscutter/game/world/Scene.java index 50cc30c2a..b9e074fd6 100644 --- a/src/main/java/emu/grasscutter/game/world/Scene.java +++ b/src/main/java/emu/grasscutter/game/world/Scene.java @@ -373,7 +373,7 @@ public final class Scene { } } - public synchronized void removeEntities(List entity, VisionType visionType) { + public void removeEntities(List entity, VisionType visionType) { var toRemove = entity.stream() .filter(Objects::nonNull) diff --git a/src/main/java/emu/grasscutter/game/world/World.java b/src/main/java/emu/grasscutter/game/world/World.java index 416c99ab7..d28c8f3ca 100644 --- a/src/main/java/emu/grasscutter/game/world/World.java +++ b/src/main/java/emu/grasscutter/game/world/World.java @@ -271,7 +271,7 @@ public final class World implements Iterable { .teleportType(teleportType) .enterReason(enterReason) .teleportTo(teleportTo) - .enterType(EnterType.ENTER_TYPE_GOTO); + .enterType(EnterType.ENTER_TYPE_JUMP); val sceneData = GameData.getSceneDataMap().get(sceneId); if (dungeonData != null) { @@ -301,29 +301,37 @@ public final class World implements Iterable { // Call event & check if it was canceled. event.call(); if (event.isCanceled()) { + System.out.println("Teleport was canceled"); return false; // Teleport was canceled. } if (GameData.getSceneDataMap().get(teleportProperties.getSceneId()) == null) { + System.out.println("Scene data is null"); return false; } Scene oldScene = null; - if (player.getScene() != null) { oldScene = player.getScene(); + System.out.println("Old scene is not null"); // Don't deregister scenes if the player is going to tp back into them if (oldScene.getId() == teleportProperties.getSceneId()) { oldScene.setDontDestroyWhenEmpty(true); + System.out.println("don't destroy when empty is set"); } oldScene.removePlayer(player); + System.out.println("remove player was called"); } var newScene = this.getSceneById(teleportProperties.getSceneId()); + System.out.printf("new scene is %s%n", newScene.getId()); newScene.addPlayer(player); + System.out.println("player was added to new scene"); + player.getTeamManager().applyAbilities(newScene); + System.out.println("new abilities applied"); // Dungeon // Dungeon system is handling this already @@ -336,31 +344,39 @@ public final class World implements Iterable { if (teleportProperties.getTeleportTo() == null && config != null) { if (config.born_pos != null) { teleportProperties.setTeleportTo(config.born_pos); + System.out.printf("setting pos to %s%n", config.born_pos); } if (config.born_rot != null) { teleportProperties.setTeleportRot(config.born_rot); + System.out.printf("setting rot to %s%n", config.born_rot); } } // Set player position and rotation if (teleportProperties.getTeleportTo() != null) { player.getPosition().set(teleportProperties.getTeleportTo()); + System.out.printf("moving player to %s%n", teleportProperties.getTeleportTo()); } if (teleportProperties.getTeleportRot() != null) { player.getRotation().set(teleportProperties.getTeleportRot()); + System.out.printf("rotating player to %s%n", teleportProperties.getTeleportRot()); } if (oldScene != null && newScene != oldScene) { newScene.setPrevScene(oldScene.getId()); + System.out.printf("new scene's prev is %s%n", newScene.getPrevScene()); oldScene.setDontDestroyWhenEmpty(false); + System.out.println("old scene's dont destroy when empty is false"); } // Teleport packet player.sendPacket(new PacketPlayerEnterSceneNotify(player, teleportProperties)); + System.out.println("packet was sent to player"); if (teleportProperties.getTeleportType() != TeleportType.INTERNAL && teleportProperties.getTeleportType() != SCRIPT) { player.getQuestManager().queueEvent(QuestContent.QUEST_CONTENT_ANY_MANUAL_TRANSPORT); + System.out.println("transport event called"); } return true; diff --git a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerEnterSceneNotify.java b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerEnterSceneNotify.java index 786193f17..ea870dd16 100644 --- a/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerEnterSceneNotify.java +++ b/src/main/java/emu/grasscutter/server/packet/send/PacketPlayerEnterSceneNotify.java @@ -100,10 +100,10 @@ public class PacketPlayerEnterSceneNotify extends BasePacket { + "-" + 18402); - // INVESTIGATE: The brokenness of scene reloading. - // if (teleportProperties.getDungeonId() != 0) { - // proto.setDungeonId(teleportProperties.getDungeonId()); - // } + // Apply the dungeon ID to the packet if it's a dungeon. + if (teleportProperties.getDungeonId() != 0) { + proto.setDungeonId(teleportProperties.getDungeonId()); + } this.setData(proto); }