TeamInfo.java 1.68 KB
Newer Older
Melledy's avatar
Melledy committed
1
2
3
4
5
package emu.grasscutter.game;

import java.util.ArrayList;
import java.util.List;

6
import dev.morphia.annotations.Entity;
Melledy's avatar
Melledy committed
7
import emu.grasscutter.GenshinConstants;
8
import emu.grasscutter.Grasscutter;
Melledy's avatar
Melledy committed
9
10
import emu.grasscutter.game.avatar.GenshinAvatar;

11
@Entity
Melledy's avatar
Melledy committed
12
13
14
15
16
17
public class TeamInfo {
	private String name;
	private List<Integer> avatars;
	
	public TeamInfo() {
		this.name = "";
18
		this.avatars = new ArrayList<>(Grasscutter.getConfig().getGameServerOptions().MaxAvatarsInTeam);
Melledy's avatar
Melledy committed
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
	}

	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) {
42
		if (size() >= Grasscutter.getConfig().getGameServerOptions().MaxAvatarsInTeam || contains(avatar)) {
Melledy's avatar
Melledy committed
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
			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) {
62
		copyFrom(team, Grasscutter.getConfig().getGameServerOptions().MaxAvatarsInTeam);
Melledy's avatar
Melledy committed
63
64
65
	}
	
	public void copyFrom(TeamInfo team, int maxTeamSize) {
66
67
68
69
		// Clone avatar ids from team to copy from
		List<Integer> avatarIds = new ArrayList<>(team.getAvatars());
		
		// Clear current avatar list first
Melledy's avatar
Melledy committed
70
71
72
		this.getAvatars().clear();
		
		// Copy from team
73
		int len = Math.min(avatarIds.size(), maxTeamSize);
Melledy's avatar
Melledy committed
74
		for (int i = 0; i < len; i++) {
75
			int id = avatarIds.get(i);
Melledy's avatar
Melledy committed
76
77
78
79
			this.getAvatars().add(id);
		}
	}
}