mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-10 12:33:21 +08:00
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:
parent
72c16d7ecb
commit
070edd263a
@ -3,10 +3,10 @@ package emu.grasscutter.game.player;
|
|||||||
import static emu.grasscutter.config.Configuration.*;
|
import static emu.grasscutter.config.Configuration.*;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import dev.morphia.annotations.Entity;
|
import dev.morphia.annotations.Entity;
|
||||||
import dev.morphia.annotations.Transient;
|
import dev.morphia.annotations.Transient;
|
||||||
import emu.grasscutter.GameConstants;
|
import emu.grasscutter.GameConstants;
|
||||||
|
import emu.grasscutter.data.GameData;
|
||||||
import emu.grasscutter.data.excels.AvatarSkillDepotData;
|
import emu.grasscutter.data.excels.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;
|
||||||
@ -37,6 +37,8 @@ import emu.grasscutter.server.packet.send.PacketRemoveCustomTeamRsp;
|
|||||||
import emu.grasscutter.server.packet.send.PacketSceneTeamUpdateNotify;
|
import emu.grasscutter.server.packet.send.PacketSceneTeamUpdateNotify;
|
||||||
import emu.grasscutter.server.packet.send.PacketSetUpAvatarTeamRsp;
|
import emu.grasscutter.server.packet.send.PacketSetUpAvatarTeamRsp;
|
||||||
import emu.grasscutter.server.packet.send.PacketWorldPlayerDieNotify;
|
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.Int2ObjectMap;
|
||||||
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||||
@ -623,17 +625,30 @@ public class TeamManager extends BasePlayerDataManager {
|
|||||||
this.getPlayer().sendPacket(new PacketAvatarLifeStateChangeNotify(entity.getAvatar()));
|
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));
|
this.getPlayer().sendPacket(new PacketPlayerEnterSceneNotify(this.getPlayer(), EnterType.ENTER_TYPE_SELF, EnterReason.Revival, 3, GameConstants.START_POSITION));
|
||||||
|
player.getPosition().set(GameConstants.START_POSITION); // If something goes wrong, the resurrection is here
|
||||||
// Set player position
|
}
|
||||||
player.setSceneId(3);
|
|
||||||
player.getPosition().set(GameConstants.START_POSITION);
|
|
||||||
|
|
||||||
// Packets
|
// Packets
|
||||||
this.getPlayer().sendPacket(new BasePacket(PacketOpcodes.WorldPlayerReviveRsp));
|
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() {
|
public void saveAvatars() {
|
||||||
// Save all avatars from active team
|
// Save all avatars from active team
|
||||||
for (EntityAvatar entity : this.getActiveTeam()) {
|
for (EntityAvatar entity : this.getActiveTeam()) {
|
||||||
|
Loading…
Reference in New Issue
Block a user