Commit c919c9c9 authored by Melledy's avatar Melledy
Browse files

Limit co-op teams to 4 avatars max total

parent 7925d1cd
......@@ -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) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment