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

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

import emu.grasscutter.GenshinConstants;
7
import emu.grasscutter.Grasscutter;
Melledy's avatar
Melledy committed
8
9
10
11
12
13
14
15
import emu.grasscutter.game.avatar.GenshinAvatar;

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

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