Grasscutter/src/main/java/emu/grasscutter/game/TeamInfo.java

80 lines
1.7 KiB
Java
Raw Normal View History

2022-04-17 12:43:07 +00:00
package emu.grasscutter.game;
import java.util.ArrayList;
import java.util.List;
import dev.morphia.annotations.Entity;
2022-04-17 12:43:07 +00:00
import emu.grasscutter.GenshinConstants;
import emu.grasscutter.Grasscutter;
2022-04-17 12:43:07 +00:00
import emu.grasscutter.game.avatar.GenshinAvatar;
@Entity
2022-04-17 12:43:07 +00:00
public class TeamInfo {
private String name;
private List<Integer> avatars;
public TeamInfo() {
this.name = "";
this.avatars = new ArrayList<>(Grasscutter.getConfig().getGameServerOptions().MaxAvatarsInTeam);
2022-04-17 12:43:07 +00:00
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public List<Integer> getAvatars() {
return avatars;
}
public int size() {
return avatars.size();
}
public boolean contains(GenshinAvatar avatar) {
return getAvatars().contains(avatar.getAvatarId());
}
public boolean addAvatar(GenshinAvatar avatar) {
if (size() >= Grasscutter.getConfig().getGameServerOptions().MaxAvatarsInTeam || contains(avatar)) {
2022-04-17 12:43:07 +00:00
return false;
}
getAvatars().add(avatar.getAvatarId());
return true;
}
public boolean removeAvatar(int slot) {
if (size() <= 1) {
return false;
}
getAvatars().remove(slot);
return true;
}
public void copyFrom(TeamInfo team) {
copyFrom(team, Grasscutter.getConfig().getGameServerOptions().MaxAvatarsInTeam);
2022-04-17 12:43:07 +00:00
}
public void copyFrom(TeamInfo team, int maxTeamSize) {
// Clone avatar ids from team to copy from
List<Integer> avatarIds = new ArrayList<>(team.getAvatars());
// Clear current avatar list first
2022-04-17 12:43:07 +00:00
this.getAvatars().clear();
// Copy from team
int len = Math.min(avatarIds.size(), maxTeamSize);
2022-04-17 12:43:07 +00:00
for (int i = 0; i < len; i++) {
int id = avatarIds.get(i);
2022-04-17 12:43:07 +00:00
this.getAvatars().add(id);
}
}
}