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

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

6
import dev.morphia.annotations.Entity;
7
import emu.grasscutter.game.avatar.Avatar;
Melledy's avatar
Melledy committed
8

9
10
import static emu.grasscutter.Configuration.*;

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<>(GAME_OPTIONS.avatarLimits.singlePlayerTeam);
Melledy's avatar
Melledy committed
19
20
	}

Akka's avatar
Akka committed
21
22
23
24
25
	public TeamInfo(List<Integer> avatars) {
		this.name = "";
		this.avatars = avatars;
	}

Melledy's avatar
Melledy committed
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();
	}
	
42
	public boolean contains(Avatar avatar) {
Melledy's avatar
Melledy committed
43
44
45
		return getAvatars().contains(avatar.getAvatarId());
	}

46
	public boolean addAvatar(Avatar avatar) {
47
		if (size() >= GAME_OPTIONS.avatarLimits.singlePlayerTeam || contains(avatar)) {
Melledy's avatar
Melledy committed
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
			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) {
67
		copyFrom(team, GAME_OPTIONS.avatarLimits.singlePlayerTeam);
Melledy's avatar
Melledy committed
68
69
70
	}
	
	public void copyFrom(TeamInfo team, int maxTeamSize) {
71
72
73
74
		// 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
75
76
77
		this.getAvatars().clear();
		
		// Copy from team
78
		int len = Math.min(avatarIds.size(), maxTeamSize);
Melledy's avatar
Melledy committed
79
		for (int i = 0; i < len; i++) {
80
			int id = avatarIds.get(i);
Melledy's avatar
Melledy committed
81
82
83
84
			this.getAvatars().add(id);
		}
	}
}