Improve team respawn (#1752)

* Pull request made after merging the latest version

* Update src/main/resources/languages/ja-JP.json

* first commit

* TeamRespawn_BigWorld

* Improving scene Loading

* Final commit

* optimize import

* optimize

* Update TeamManager.java

* Update src/main/java/emu/grasscutter/game/player/TeamManager.java
This commit is contained in:
Kawaa 2022-09-12 21:55:10 +08:00 committed by GitHub
parent 72c16d7ecb
commit 070edd263a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -3,10 +3,10 @@ package emu.grasscutter.game.player;
import static emu.grasscutter.config.Configuration.*;
import java.util.*;
import dev.morphia.annotations.Entity;
import dev.morphia.annotations.Transient;
import emu.grasscutter.GameConstants;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.excels.AvatarSkillDepotData;
import emu.grasscutter.game.avatar.Avatar;
import emu.grasscutter.game.entity.EntityAvatar;
@ -37,6 +37,8 @@ import emu.grasscutter.server.packet.send.PacketRemoveCustomTeamRsp;
import emu.grasscutter.server.packet.send.PacketSceneTeamUpdateNotify;
import emu.grasscutter.server.packet.send.PacketSetUpAvatarTeamRsp;
import emu.grasscutter.server.packet.send.PacketWorldPlayerDieNotify;
import emu.grasscutter.utils.Position;
import emu.grasscutter.utils.Utils;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
@ -623,17 +625,30 @@ public class TeamManager extends BasePlayerDataManager {
this.getPlayer().sendPacket(new PacketAvatarLifeStateChangeNotify(entity.getAvatar()));
}
// Teleport player
// Teleport player and set player position
try{
this.getPlayer().sendPacket(new PacketPlayerEnterSceneNotify(this.getPlayer(), EnterType.ENTER_TYPE_SELF, EnterReason.Revival, player.getSceneId(), getRespawnPosition()));
player.getPosition().set(getRespawnPosition());
}catch(Exception e){
this.getPlayer().sendPacket(new PacketPlayerEnterSceneNotify(this.getPlayer(), EnterType.ENTER_TYPE_SELF, EnterReason.Revival, 3, GameConstants.START_POSITION));
// Set player position
player.setSceneId(3);
player.getPosition().set(GameConstants.START_POSITION);
player.getPosition().set(GameConstants.START_POSITION); // If something goes wrong, the resurrection is here
}
// Packets
this.getPlayer().sendPacket(new BasePacket(PacketOpcodes.WorldPlayerReviveRsp));
}
public Position getRespawnPosition() {
var deathPos = this.getPlayer().getPosition();
int sceneId = this.getPlayer().getSceneId();
// Get the closest trans point to where the player died.
var respawnPoint = this.getPlayer().getUnlockedScenePoints(sceneId).stream()
.map(pointId -> GameData.getScenePointEntryById(sceneId, pointId))
.filter(point -> point.getPointData().getType().equals("SceneTransPoint"))
.min((Comparator.comparingDouble(pos -> Utils.getDist(pos.getPointData().getTranPos(), deathPos))));
return respawnPoint.get().getPointData().getTranPos();
}
public void saveAvatars() {
// Save all avatars from active team
for (EntityAvatar entity : this.getActiveTeam()) {