BattlePassMission.java 1.79 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
package emu.grasscutter.game.battlepass;

import dev.morphia.annotations.Entity;
import dev.morphia.annotations.Transient;
import emu.grasscutter.data.GameData;
import emu.grasscutter.data.excels.BattlePassMissionData;
import emu.grasscutter.game.props.BattlePassMissionStatus;

@Entity
public class BattlePassMission {
	private int id;
	private int progress;
	private BattlePassMissionStatus status;
	
	@Transient
	private BattlePassMissionData data;
	
	@Deprecated // Morphia only
	public BattlePassMission() {}
	
	public BattlePassMission(int id) {
		this.id = id;
	}

	public int getId() {
		return id;
	}

	public BattlePassMissionData getData() {
		if (this.data == null) {
			this.data = GameData.getBattlePassMissionDataMap().get(getId());
		}
		return this.data;
	}

	public int getProgress() {
		return progress;
	}

	public void addProgress(int addProgress, int maxProgress) {
		this.progress = Math.min(addProgress + this.progress, maxProgress);
	}

	public BattlePassMissionStatus getStatus() {
		if (status == null) status = BattlePassMissionStatus.MISSION_STATUS_UNFINISHED;
		return status;
	}

	public void setStatus(BattlePassMissionStatus status) {
		this.status = status;
	}

	public boolean isFinshed() {
		return getStatus().getValue() >= 2;
	}

	public emu.grasscutter.net.proto.BattlePassMissionOuterClass.BattlePassMission toProto() {
		var protoBuilder = emu.grasscutter.net.proto.BattlePassMissionOuterClass.BattlePassMission.newBuilder();
		
		protoBuilder
			.setMissionId(getId())
			.setCurProgress(getProgress())
			.setTotalProgress(getData().getProgress())
			.setRewardBattlePassPoint(getData().getAddPoint())
			.setMissionStatus(getStatus().getMissionStatus())
			.setMissionType(getData().getRefreshType() == null ? 0 : getData().getRefreshType().getValue());
		
		return protoBuilder.build();
	}
}