mirror of
https://github.com/Grasscutters/Grasscutter.git
synced 2025-01-12 04:42:53 +08:00
06101f1b9c
1. During the conversion of Morphia calls to the new API, some of the `Filter.eq()` calls had their `field` set to `playerId` due to a copy/paste typo. 2. Morphia 2 switches to the codec system, so anything that will be serialized in the pipeline requires the `@Entity` annotation.
80 lines
1.7 KiB
Java
80 lines
1.7 KiB
Java
package emu.grasscutter.game;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
|
|
import dev.morphia.annotations.Entity;
|
|
import emu.grasscutter.GenshinConstants;
|
|
import emu.grasscutter.Grasscutter;
|
|
import emu.grasscutter.game.avatar.GenshinAvatar;
|
|
|
|
@Entity
|
|
public class TeamInfo {
|
|
private String name;
|
|
private List<Integer> avatars;
|
|
|
|
public TeamInfo() {
|
|
this.name = "";
|
|
this.avatars = new ArrayList<>(Grasscutter.getConfig().getServerOptions().MaxAvatarsInTeam);
|
|
}
|
|
|
|
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().getServerOptions().MaxAvatarsInTeam || contains(avatar)) {
|
|
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().getServerOptions().MaxAvatarsInTeam);
|
|
}
|
|
|
|
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
|
|
this.getAvatars().clear();
|
|
|
|
// Copy from team
|
|
int len = Math.min(avatarIds.size(), maxTeamSize);
|
|
for (int i = 0; i < len; i++) {
|
|
int id = avatarIds.get(i);
|
|
this.getAvatars().add(id);
|
|
}
|
|
}
|
|
}
|