-
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathDanmu.ts
87 lines (81 loc) · 2.45 KB
/
Danmu.ts
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import Team from "../Components/Team";
import User from "../Components/User";
import Game from "../Game/Game";
import { store } from "../store";
import { IParseDanmuData } from "./type";
function stopRunCode(msg = "stopRunCode") {
throw new Error(msg);
}
export default class Danmu {
static Apply(danmu: IParseDanmuData) {
if (Game.Core.isGameOver) return;
const user = Team.GetUserById(danmu.id);
if (user) {
try {
Danmu.ApplyTp(danmu, user);
Danmu.ApplyObedience(danmu, user);
Danmu.ApplyDraw(danmu, user);
if (danmu.faceId || danmu.text.length >= 2) {
Danmu.ApplyPowerUp(danmu, user);
}
} catch (error) {}
} else {
const team = Game.Core.teams.find((team) =>
team.hasJoinKeyword(danmu.text)
);
if (team) {
team.makeUser(danmu.id, danmu.name, danmu.face);
return;
}
}
}
static ApplyObedience(danmu: IParseDanmuData, user: User) {
if (!danmu.text.startsWith("投靠")) {
return;
}
let [, teamKeyword] = danmu.text.split(" ");
const team = Game.Core.teams.find((team) =>
team.hasJoinKeyword(teamKeyword)
);
if (team) {
user.obedience(team);
stopRunCode("投靠");
}
}
static ApplyTp(danmu: IParseDanmuData, user: User) {
const text = danmu.text.toLocaleLowerCase();
if (text === "tp" || text == "b") {
user.tp();
stopRunCode("tp");
}
}
static ApplyPowerUp(danmu: IParseDanmuData, user: User) {
let rand = Phaser.Math.Between(0, 100);
const { fansCard, liveId } = store.getState().config;
if (fansCard.enable && danmu.card) {
if (fansCard.level < danmu.card.level && danmu.card.liveId === liveId) {
rand = Phaser.Math.Between(
0,
Math.floor(Math.max(50, 100 - fansCard.level / 2 ** 2))
);
}
}
if (rand <= 8) {
user?.player.makeChild(1);
Game.Core?.toast?.showMessage(`${user.name} 获取了兵力+1`);
} else if (rand <= 18) {
user?.player.speedUp(0.2);
Game.Core?.toast?.showMessage(`${user.name} 获取了速度小幅提升`);
} else {
user?.player.speedUp(0.1);
Game.Core?.toast?.showMessage(`${user.name} 获取了速度微微提升了`);
}
}
static ApplyDraw(danmu: IParseDanmuData, user: User) {
if (danmu.text === "发兵") {
// 消耗所有积分
while (Game.Core.cardController?.draw(user)) {}
throw stopRunCode("发兵");
}
}
}