DungeonChallenge.java 2.52 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
package emu.grasscutter.game.dungeons;

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

import emu.grasscutter.data.GameData;
import emu.grasscutter.data.def.MonsterData;
import emu.grasscutter.game.entity.EntityMonster;
import emu.grasscutter.game.entity.GameEntity;
import emu.grasscutter.game.world.Scene;
import emu.grasscutter.net.proto.VisionTypeOuterClass.VisionType;
Melledy's avatar
Melledy committed
12
import emu.grasscutter.scripts.constants.EventType;
13
14
import emu.grasscutter.scripts.data.SceneGroup;
import emu.grasscutter.scripts.data.SceneMonster;
Melledy's avatar
Melledy committed
15
import emu.grasscutter.server.packet.send.PacketChallengeDataNotify;
16
17
18
19
20
21
22
23
24
25
import emu.grasscutter.server.packet.send.PacketDungeonChallengeBeginNotify;
import emu.grasscutter.server.packet.send.PacketDungeonChallengeFinishNotify;
import emu.grasscutter.server.packet.send.PacketSceneEntityAppearNotify;

public class DungeonChallenge {
	private final Scene scene;
	private final SceneGroup group;
	
	private int challengeIndex;
	private int challengeId;
26
27
	private boolean success;
	private boolean progress;
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
	
	private int score;
	private int objective = 0;
	
	public DungeonChallenge(Scene scene, SceneGroup group) {
		this.scene = scene;
		this.group = group;
		
		objective += group.monsters.size();
	}

	public Scene getScene() {
		return scene;
	}

	public SceneGroup getGroup() {
		return group;
	}
	
	public int getChallengeIndex() {
		return challengeIndex;
	}

	public void setChallengeIndex(int challengeIndex) {
		this.challengeIndex = challengeIndex;
	}

	public int getChallengeId() {
		return challengeId;
	}

	public void setChallengeId(int challengeId) {
		this.challengeId = challengeId;
	}

	public boolean isSuccess() {
64
		return success;
65
66
67
	}

	public void setSuccess(boolean isSuccess) {
68
69
70
71
72
		this.success = isSuccess;
	}
	
	public boolean inProgress() {
		return progress;
73
74
	}

Melledy's avatar
Melledy committed
75
76
77
78
	public int getScore() {
		return score;
	}

79
	public void start() {
80
		this.progress = true;
81
82
83
84
		getScene().broadcastPacket(new PacketDungeonChallengeBeginNotify(this));
	}
	
	public void finish() {
85
		this.progress = false;
86
87
88
		getScene().broadcastPacket(new PacketDungeonChallengeFinishNotify(this));
		
		if (this.isSuccess()) {
Melledy's avatar
Melledy committed
89
			this.getScene().getScriptManager().callEvent(EventType.EVENT_CHALLENGE_SUCCESS, null);
90
		} else {
Melledy's avatar
Melledy committed
91
			this.getScene().getScriptManager().callEvent(EventType.EVENT_CHALLENGE_FAIL, null);
92
93
94
95
		}
	}

	public void onMonsterDie(EntityMonster entity) {
Melledy's avatar
Melledy committed
96
97
98
		score = getScore() + 1;
		
		getScene().broadcastPacket(new PacketChallengeDataNotify(this, 1, getScore()));
99
		
Melledy's avatar
Melledy committed
100
		if (getScore() >= objective) {
101
102
103
104
105
			this.setSuccess(true);
			finish();
		}
	}
}