Fix teleporting errors

This commit is contained in:
KingRainbow44 2023-05-10 20:54:25 -04:00
parent 510e6bfa78
commit 07e038343d
No known key found for this signature in database
GPG Key ID: FC2CB64B00D257BE
5 changed files with 28 additions and 11 deletions

3
.gitignore vendored
View File

@ -86,3 +86,6 @@ src/main/resources/handbook.html
# Hotswap Agent # Hotswap Agent
hotswap-agent.properties hotswap-agent.properties
# Debug patches
patches/*.patch

View File

@ -7,7 +7,6 @@ import dev.morphia.annotations.Transient;
import emu.grasscutter.GameConstants; 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.binout.config.fields.ConfigAbilityData;
import emu.grasscutter.data.excels.avatar.AvatarSkillDepotData; import emu.grasscutter.data.excels.avatar.AvatarSkillDepotData;
import emu.grasscutter.game.avatar.Avatar; import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.entity.EntityAvatar; import emu.grasscutter.game.entity.EntityAvatar;
@ -980,7 +979,7 @@ public final class TeamManager extends BasePlayerDataManager {
// any // any
} }
for (ConfigAbilityData abilities : config.getAvatarAbilities()) { for (var abilities : config.getAvatarAbilities()) {
avatarData.getAbilities().add(Utils.abilityHash(abilities.getAbilityName())); avatarData.getAbilities().add(Utils.abilityHash(abilities.getAbilityName()));
} }
} }
@ -1123,8 +1122,7 @@ public final class TeamManager extends BasePlayerDataManager {
*/ */
public void removeTrialAvatar(List<Integer> trialAvatarIds) { public void removeTrialAvatar(List<Integer> trialAvatarIds) {
// Check if the player is using a trial team. // Check if the player is using a trial team.
if (!this.isUsingTrialTeam()) if (!this.isUsingTrialTeam()) return;
throw new IllegalStateException("Player is not using trial team.");
this.getPlayer() this.getPlayer()
.sendPacket( .sendPacket(

View File

@ -373,7 +373,7 @@ public final class Scene {
} }
} }
public synchronized void removeEntities(List<GameEntity> entity, VisionType visionType) { public void removeEntities(List<GameEntity> entity, VisionType visionType) {
var toRemove = var toRemove =
entity.stream() entity.stream()
.filter(Objects::nonNull) .filter(Objects::nonNull)

View File

@ -271,7 +271,7 @@ public final class World implements Iterable<Player> {
.teleportType(teleportType) .teleportType(teleportType)
.enterReason(enterReason) .enterReason(enterReason)
.teleportTo(teleportTo) .teleportTo(teleportTo)
.enterType(EnterType.ENTER_TYPE_GOTO); .enterType(EnterType.ENTER_TYPE_JUMP);
val sceneData = GameData.getSceneDataMap().get(sceneId); val sceneData = GameData.getSceneDataMap().get(sceneId);
if (dungeonData != null) { if (dungeonData != null) {
@ -301,29 +301,37 @@ public final class World implements Iterable<Player> {
// Call event & check if it was canceled. // Call event & check if it was canceled.
event.call(); event.call();
if (event.isCanceled()) { if (event.isCanceled()) {
System.out.println("Teleport was canceled");
return false; // Teleport was canceled. return false; // Teleport was canceled.
} }
if (GameData.getSceneDataMap().get(teleportProperties.getSceneId()) == null) { if (GameData.getSceneDataMap().get(teleportProperties.getSceneId()) == null) {
System.out.println("Scene data is null");
return false; return false;
} }
Scene oldScene = null; Scene oldScene = null;
if (player.getScene() != null) { if (player.getScene() != null) {
oldScene = player.getScene(); 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 // Don't deregister scenes if the player is going to tp back into them
if (oldScene.getId() == teleportProperties.getSceneId()) { if (oldScene.getId() == teleportProperties.getSceneId()) {
oldScene.setDontDestroyWhenEmpty(true); oldScene.setDontDestroyWhenEmpty(true);
System.out.println("don't destroy when empty is set");
} }
oldScene.removePlayer(player); oldScene.removePlayer(player);
System.out.println("remove player was called");
} }
var newScene = this.getSceneById(teleportProperties.getSceneId()); var newScene = this.getSceneById(teleportProperties.getSceneId());
System.out.printf("new scene is %s%n", newScene.getId());
newScene.addPlayer(player); newScene.addPlayer(player);
System.out.println("player was added to new scene");
player.getTeamManager().applyAbilities(newScene); player.getTeamManager().applyAbilities(newScene);
System.out.println("new abilities applied");
// Dungeon // Dungeon
// Dungeon system is handling this already // Dungeon system is handling this already
@ -336,31 +344,39 @@ public final class World implements Iterable<Player> {
if (teleportProperties.getTeleportTo() == null && config != null) { if (teleportProperties.getTeleportTo() == null && config != null) {
if (config.born_pos != null) { if (config.born_pos != null) {
teleportProperties.setTeleportTo(config.born_pos); teleportProperties.setTeleportTo(config.born_pos);
System.out.printf("setting pos to %s%n", config.born_pos);
} }
if (config.born_rot != null) { if (config.born_rot != null) {
teleportProperties.setTeleportRot(config.born_rot); teleportProperties.setTeleportRot(config.born_rot);
System.out.printf("setting rot to %s%n", config.born_rot);
} }
} }
// Set player position and rotation // Set player position and rotation
if (teleportProperties.getTeleportTo() != null) { if (teleportProperties.getTeleportTo() != null) {
player.getPosition().set(teleportProperties.getTeleportTo()); player.getPosition().set(teleportProperties.getTeleportTo());
System.out.printf("moving player to %s%n", teleportProperties.getTeleportTo());
} }
if (teleportProperties.getTeleportRot() != null) { if (teleportProperties.getTeleportRot() != null) {
player.getRotation().set(teleportProperties.getTeleportRot()); player.getRotation().set(teleportProperties.getTeleportRot());
System.out.printf("rotating player to %s%n", teleportProperties.getTeleportRot());
} }
if (oldScene != null && newScene != oldScene) { if (oldScene != null && newScene != oldScene) {
newScene.setPrevScene(oldScene.getId()); newScene.setPrevScene(oldScene.getId());
System.out.printf("new scene's prev is %s%n", newScene.getPrevScene());
oldScene.setDontDestroyWhenEmpty(false); oldScene.setDontDestroyWhenEmpty(false);
System.out.println("old scene's dont destroy when empty is false");
} }
// Teleport packet // Teleport packet
player.sendPacket(new PacketPlayerEnterSceneNotify(player, teleportProperties)); player.sendPacket(new PacketPlayerEnterSceneNotify(player, teleportProperties));
System.out.println("packet was sent to player");
if (teleportProperties.getTeleportType() != TeleportType.INTERNAL if (teleportProperties.getTeleportType() != TeleportType.INTERNAL
&& teleportProperties.getTeleportType() != SCRIPT) { && teleportProperties.getTeleportType() != SCRIPT) {
player.getQuestManager().queueEvent(QuestContent.QUEST_CONTENT_ANY_MANUAL_TRANSPORT); player.getQuestManager().queueEvent(QuestContent.QUEST_CONTENT_ANY_MANUAL_TRANSPORT);
System.out.println("transport event called");
} }
return true; return true;

View File

@ -100,10 +100,10 @@ public class PacketPlayerEnterSceneNotify extends BasePacket {
+ "-" + "-"
+ 18402); + 18402);
// INVESTIGATE: The brokenness of scene reloading. // Apply the dungeon ID to the packet if it's a dungeon.
// if (teleportProperties.getDungeonId() != 0) { if (teleportProperties.getDungeonId() != 0) {
// proto.setDungeonId(teleportProperties.getDungeonId()); proto.setDungeonId(teleportProperties.getDungeonId());
// } }
this.setData(proto); this.setData(proto);
} }