mirror of
https://github.com/Melledy/Grasscutter.git
synced 2024-11-25 10:51:47 +00:00
Limit co-op teams to 4 avatars max total
This commit is contained in:
parent
7925d1cda3
commit
c919c9c9eb
@ -60,13 +60,16 @@ public class TeamInfo {
|
||||
}
|
||||
|
||||
public void copyFrom(TeamInfo team, int maxTeamSize) {
|
||||
// Clear
|
||||
// Clone avatar ids from team to copy from
|
||||
List<Integer> avatarIds = new ArrayList<>(team.getAvatars());
|
||||
|
||||
// Clear current avatar list first
|
||||
this.getAvatars().clear();
|
||||
|
||||
// Copy from team
|
||||
int len = Math.min(team.getAvatars().size(), maxTeamSize);
|
||||
int len = Math.min(avatarIds.size(), maxTeamSize);
|
||||
for (int i = 0; i < len; i++) {
|
||||
int id = team.getAvatars().get(i);
|
||||
int id = avatarIds.get(i);
|
||||
this.getAvatars().add(id);
|
||||
}
|
||||
}
|
||||
|
@ -166,7 +166,7 @@ public class TeamManager {
|
||||
|
||||
// Methods
|
||||
|
||||
public void updateTeamResonances() {
|
||||
private void updateTeamResonances() {
|
||||
Int2IntOpenHashMap map = new Int2IntOpenHashMap();
|
||||
|
||||
this.getTeamResonances().clear();
|
||||
@ -196,7 +196,7 @@ public class TeamManager {
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTeamEntities(GenshinPacket responsePacket) {
|
||||
public void updateTeamEntities(GenshinPacket responsePacket) {
|
||||
// Sanity check - Should never happen
|
||||
if (this.getCurrentTeamInfo().getAvatars().size() <= 0) {
|
||||
return;
|
||||
@ -241,7 +241,7 @@ public class TeamManager {
|
||||
// Set new selected character index
|
||||
if (prevSelectedAvatarIndex == -1) {
|
||||
// Previous selected avatar is not in the same spot, we will select the current one in the prev slot
|
||||
prevSelectedAvatarIndex = Math.min(this.currentCharacterIndex, getCurrentTeamInfo().getAvatars().size() - 1);
|
||||
prevSelectedAvatarIndex = Math.min(this.currentCharacterIndex, this.getActiveTeam().size() - 1);
|
||||
}
|
||||
this.currentCharacterIndex = prevSelectedAvatarIndex;
|
||||
|
||||
|
@ -28,7 +28,6 @@ import emu.grasscutter.server.packet.send.PacketPlayerEnterSceneNotify;
|
||||
import emu.grasscutter.server.packet.send.PacketSceneEntityAppearNotify;
|
||||
import emu.grasscutter.server.packet.send.PacketSceneEntityDisappearNotify;
|
||||
import emu.grasscutter.server.packet.send.PacketScenePlayerInfoNotify;
|
||||
import emu.grasscutter.server.packet.send.PacketSceneTeamUpdateNotify;
|
||||
import emu.grasscutter.server.packet.send.PacketSyncScenePlayTeamEntityNotify;
|
||||
import emu.grasscutter.server.packet.send.PacketSyncTeamEntityNotify;
|
||||
import emu.grasscutter.server.packet.send.PacketWorldPlayerInfoNotify;
|
||||
@ -169,7 +168,7 @@ public class World implements Iterable<GenshinPlayer> {
|
||||
player.setPeerId(this.getNextPeerId());
|
||||
player.getTeamManager().setEntityId(getNextEntityId(EntityIdType.TEAM));
|
||||
|
||||
// TODO Update team of all players
|
||||
// Setup team avatars
|
||||
this.setupPlayerAvatars(player);
|
||||
|
||||
// Info packet for other players
|
||||
@ -212,18 +211,23 @@ public class World implements Iterable<GenshinPlayer> {
|
||||
|
||||
private void updatePlayerInfos(GenshinPlayer paramPlayer) {
|
||||
for (GenshinPlayer player : getPlayers()) {
|
||||
// Dont send packets if player is loading in
|
||||
// Dont send packets if player is loading in and filter out joining player
|
||||
if (!player.hasSentAvatarDataNotify() || player.getSceneLoadState().getValue() < SceneLoadState.INIT.getValue() || player == paramPlayer) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Update team of all players since max players has been changed - Probably not the best way to do it
|
||||
if (this.isMultiplayer()) {
|
||||
player.getTeamManager().getMpTeam().copyFrom(player.getTeamManager().getMpTeam(), player.getTeamManager().getMaxTeamSize());
|
||||
player.getTeamManager().updateTeamEntities(null);
|
||||
}
|
||||
|
||||
// World player info packets
|
||||
player.getSession().send(new PacketWorldPlayerInfoNotify(this));
|
||||
player.getSession().send(new PacketScenePlayerInfoNotify(this));
|
||||
player.getSession().send(new PacketWorldPlayerRTTNotify(this));
|
||||
|
||||
// Team packets
|
||||
player.getSession().send(new PacketSceneTeamUpdateNotify(player));
|
||||
player.getSession().send(new PacketSyncTeamEntityNotify(player));
|
||||
player.getSession().send(new PacketSyncScenePlayTeamEntityNotify(player));
|
||||
}
|
||||
@ -283,6 +287,11 @@ public class World implements Iterable<GenshinPlayer> {
|
||||
EntityAvatar entity = new EntityAvatar(this, player.getAvatars().getAvatarById(avatarId));
|
||||
player.getTeamManager().getActiveTeam().add(entity);
|
||||
}
|
||||
|
||||
// Limit character index in case its out of bounds
|
||||
if (player.getTeamManager().getCurrentCharacterIndex() >= player.getTeamManager().getActiveTeam().size() || player.getTeamManager().getCurrentCharacterIndex() < 0) {
|
||||
player.getTeamManager().setCurrentCharacterIndex(player.getTeamManager().getCurrentCharacterIndex() - 1);
|
||||
}
|
||||
}
|
||||
|
||||
private void removePlayerAvatars(GenshinPlayer player) {
|
||||
|
Loading…
Reference in New Issue
Block a user