mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-12-18 18:05:05 +01:00
Fix double adding of avatar entities
This commit is contained in:
@@ -9,7 +9,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
public class TeamInfo {
|
public final class TeamInfo {
|
||||||
private String name;
|
private String name;
|
||||||
private final List<Integer> avatars;
|
private final List<Integer> avatars;
|
||||||
|
|
||||||
|
|||||||
@@ -131,6 +131,30 @@ public final class TeamManager extends BasePlayerDataManager {
|
|||||||
return avatars;
|
return avatars;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the active team.
|
||||||
|
* If there are errors with the team, they can be fixed.
|
||||||
|
*
|
||||||
|
* @param fix If true, the team will be fixed.
|
||||||
|
* @return The active team.
|
||||||
|
*/
|
||||||
|
public List<EntityAvatar> getActiveTeam(boolean fix) {
|
||||||
|
if (!fix) return this.getActiveTeam();
|
||||||
|
|
||||||
|
// Remove duplicate avatars.
|
||||||
|
var avatars = this.getActiveTeam();
|
||||||
|
var avatarIds = new HashSet<Long>();
|
||||||
|
for (var entityAvatar : new ArrayList<>(avatars)) {
|
||||||
|
if (avatarIds.contains(entityAvatar.getAvatar().getGuid())) {
|
||||||
|
avatars.remove(entityAvatar);
|
||||||
|
} else {
|
||||||
|
avatarIds.add(entityAvatar.getAvatar().getGuid());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return avatars; // Return the fixed team.
|
||||||
|
}
|
||||||
|
|
||||||
public EntityAvatar getCurrentAvatarEntity() {
|
public EntityAvatar getCurrentAvatarEntity() {
|
||||||
if (this.currentCharacterIndex >= this.getActiveTeam().size()) {
|
if (this.currentCharacterIndex >= this.getActiveTeam().size()) {
|
||||||
this.currentCharacterIndex = 0; // Reset to the first character.
|
this.currentCharacterIndex = 0; // Reset to the first character.
|
||||||
@@ -557,8 +581,6 @@ public final class TeamManager extends BasePlayerDataManager {
|
|||||||
} else {
|
} else {
|
||||||
// Restores all avatars from the player's avatar storage.
|
// Restores all avatars from the player's avatar storage.
|
||||||
// If the avatar is already in the team, it will not be added.
|
// If the avatar is already in the team, it will not be added.
|
||||||
// TODO: Fix order in which avatars are added.
|
|
||||||
// Currently, they are added from last to first.
|
|
||||||
var avatars = this.getCurrentTeamInfo().getAvatars();
|
var avatars = this.getCurrentTeamInfo().getAvatars();
|
||||||
for (var index = 0; index < avatars.size(); index++) {
|
for (var index = 0; index < avatars.size(); index++) {
|
||||||
var avatar = avatars.get(index);
|
var avatar = avatars.get(index);
|
||||||
@@ -804,7 +826,7 @@ public final class TeamManager extends BasePlayerDataManager {
|
|||||||
// return;
|
// return;
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
player
|
this.getPlayer()
|
||||||
.getStaminaManager()
|
.getStaminaManager()
|
||||||
.stopSustainedStaminaHandler(); // prevent drowning immediately after respawn
|
.stopSustainedStaminaHandler(); // prevent drowning immediately after respawn
|
||||||
|
|
||||||
@@ -813,7 +835,7 @@ public final class TeamManager extends BasePlayerDataManager {
|
|||||||
entity.setFightProperty(
|
entity.setFightProperty(
|
||||||
FightProperty.FIGHT_PROP_CUR_HP,
|
FightProperty.FIGHT_PROP_CUR_HP,
|
||||||
entity.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP) * .4f);
|
entity.getFightProperty(FightProperty.FIGHT_PROP_MAX_HP) * .4f);
|
||||||
player.getSatiationManager().removeSatiationDirectly(entity.getAvatar(), 15000);
|
this.getPlayer().getSatiationManager().removeSatiationDirectly(entity.getAvatar(), 15000);
|
||||||
this.getPlayer()
|
this.getPlayer()
|
||||||
.sendPacket(
|
.sendPacket(
|
||||||
new PacketAvatarFightPropUpdateNotify(
|
new PacketAvatarFightPropUpdateNotify(
|
||||||
@@ -829,10 +851,10 @@ public final class TeamManager extends BasePlayerDataManager {
|
|||||||
this.getPlayer(),
|
this.getPlayer(),
|
||||||
EnterType.ENTER_TYPE_SELF,
|
EnterType.ENTER_TYPE_SELF,
|
||||||
EnterReason.Revival,
|
EnterReason.Revival,
|
||||||
player.getSceneId(),
|
this.getPlayer().getSceneId(),
|
||||||
getRespawnPosition()));
|
this.getRespawnPosition()));
|
||||||
player.getPosition().set(getRespawnPosition());
|
this.getPlayer().getPosition().set(this.getRespawnPosition());
|
||||||
} catch (Exception e) {
|
} catch (Exception ignored) {
|
||||||
this.getPlayer()
|
this.getPlayer()
|
||||||
.sendPacket(
|
.sendPacket(
|
||||||
new PacketPlayerEnterSceneNotify(
|
new PacketPlayerEnterSceneNotify(
|
||||||
@@ -841,7 +863,7 @@ public final class TeamManager extends BasePlayerDataManager {
|
|||||||
EnterReason.Revival,
|
EnterReason.Revival,
|
||||||
3,
|
3,
|
||||||
GameConstants.START_POSITION));
|
GameConstants.START_POSITION));
|
||||||
player
|
this.getPlayer()
|
||||||
.getPosition()
|
.getPosition()
|
||||||
.set(GameConstants.START_POSITION); // If something goes wrong, the resurrection is here
|
.set(GameConstants.START_POSITION); // If something goes wrong, the resurrection is here
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import emu.grasscutter.net.proto.SceneTeamAvatarOuterClass.SceneTeamAvatar;
|
|||||||
import emu.grasscutter.net.proto.SceneTeamUpdateNotifyOuterClass.SceneTeamUpdateNotify;
|
import emu.grasscutter.net.proto.SceneTeamUpdateNotifyOuterClass.SceneTeamUpdateNotify;
|
||||||
|
|
||||||
public class PacketSceneTeamUpdateNotify extends BasePacket {
|
public class PacketSceneTeamUpdateNotify extends BasePacket {
|
||||||
|
|
||||||
public PacketSceneTeamUpdateNotify(Player player) {
|
public PacketSceneTeamUpdateNotify(Player player) {
|
||||||
super(PacketOpcodes.SceneTeamUpdateNotify);
|
super(PacketOpcodes.SceneTeamUpdateNotify);
|
||||||
|
|
||||||
@@ -16,7 +15,7 @@ public class PacketSceneTeamUpdateNotify extends BasePacket {
|
|||||||
.setIsInMp(player.getWorld().isMultiplayer());
|
.setIsInMp(player.getWorld().isMultiplayer());
|
||||||
|
|
||||||
for (var p : player.getWorld().getPlayers()) {
|
for (var p : player.getWorld().getPlayers()) {
|
||||||
for (var entityAvatar : p.getTeamManager().getActiveTeam()) {
|
for (var entityAvatar : p.getTeamManager().getActiveTeam(true)) {
|
||||||
var avatarProto =
|
var avatarProto =
|
||||||
SceneTeamAvatar.newBuilder()
|
SceneTeamAvatar.newBuilder()
|
||||||
.setPlayerUid(p.getUid())
|
.setPlayerUid(p.getUid())
|
||||||
|
|||||||
Reference in New Issue
Block a user