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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
package cat.freya.khs.game
import cat.freya.khs.Khs
import java.util.UUID
import kotlin.math.roundToInt
const val DISABLED_IDENT = "KHS_DISABLED_FILTER_ME_OUT"
interface Board {
fun setText(title: String, text: List<String>)
fun display(uuid: UUID)
interface Team {
var prefix: String
// options
var canCollide: Boolean
var nameTagsVisible: Boolean
// players
var players: Set<UUID>
}
// seeker/hider display
fun getTeam(name: String): Board.Team
}
fun updateTeams(plugin: Khs, board: Board) {
val hider = board.getTeam("Hider")
val seeker = board.getTeam("Seeker")
hider.players = plugin.game.hiderUUIDs
seeker.players = plugin.game.seekerUUIDs
hider.nameTagsVisible = plugin.config.nametagsVisible
seeker.nameTagsVisible = plugin.config.nametagsVisible
hider.canCollide = false
seeker.canCollide = false
hider.prefix = plugin.locale.game.team.hider
seeker.prefix = plugin.locale.game.team.seeker
}
fun getLobbyBoard(plugin: Khs, uuid: UUID): Board? {
return plugin.shim.getBoard("lobby-$uuid")
}
fun reloadLobbyBoard(plugin: Khs, uuid: UUID) {
val timer = plugin.game.timer
val countdown =
when {
timer != null -> plugin.boardConfig.countdown.startingIn.with(timer)
else -> plugin.boardConfig.countdown.waiting
}
val count = plugin.game.size
val seekerPercent = (plugin.game.getSeekerChance(uuid) * 100).roundToInt()
val hiderPercent = 100 - seekerPercent
val map = plugin.game.map?.name ?: ""
val board = getLobbyBoard(plugin, uuid) ?: return
updateTeams(plugin, board)
val title = plugin.boardConfig.lobby.title
board.setText(
title,
plugin.boardConfig.lobby.content.map {
it.replace("{COUNTDOWN}", countdown)
.replace("{COUNT}", count.toString())
.replace("{SEEKER%}", seekerPercent.toString())
.replace("{HIDER%}", hiderPercent.toString())
.replace("{MAP}", map)
},
)
board.display(uuid)
}
fun getGameBoard(plugin: Khs, uuid: UUID): Board? {
return plugin.shim.getBoard("game-$uuid")
}
private fun getBorderLocale(plugin: Khs): String {
val config = plugin.game.map?.config?.worldBorder
val border = plugin.game.border
if (config?.enabled != true || border.expired) return DISABLED_IDENT
if (border.state == Border.State.SHRINKING) return plugin.boardConfig.border.shrinking
val m = border.timer / 60UL
val s = border.timer % 60UL
return plugin.boardConfig.border.timer.with(m, s)
}
private fun getTauntLocale(plugin: Khs): String {
val config = plugin.config.taunt
val taunt = plugin.game.taunt
if (!config.enabled || taunt.expired) return DISABLED_IDENT
if (taunt.running) return plugin.boardConfig.taunt.active
val m = taunt.timer / 60UL
val s = taunt.timer % 60UL
return plugin.boardConfig.taunt.timer.with(m, s)
}
private fun getGlowLocale(plugin: Khs): String {
val config = plugin.config.glow
val always = plugin.config.alwaysGlow
val glow = plugin.game.glow
if (always || !config.enabled) return DISABLED_IDENT
if (glow.running) return plugin.boardConfig.glow.active
else return plugin.boardConfig.glow.disabled
}
fun reloadGameBoard(plugin: Khs, uuid: UUID) {
val timer = plugin.game.timer
val time = plugin.boardConfig.countdown.timer.with((timer ?: 0UL) / 60UL, (timer ?: 0UL) % 60UL)
val team =
when (plugin.game.getTeam(uuid)) {
Game.Team.HIDER -> plugin.locale.game.team.hider
Game.Team.SEEKER -> plugin.locale.game.team.seeker
else -> plugin.locale.game.team.spectator
}
// border event
val border = getBorderLocale(plugin)
val taunt = getTauntLocale(plugin)
val glow = getGlowLocale(plugin)
val numSeeker = plugin.game.seekerSize
val numHider = plugin.game.hiderSize
val map = plugin.game.map?.name ?: ""
val board = getGameBoard(plugin, uuid) ?: return
updateTeams(plugin, board)
val title = plugin.boardConfig.game.title
board.setText(
title,
plugin.boardConfig.game.content
.map {
it.replace("{TIME}", time)
.replace("{TEAM}", team)
.replace("{BORDER}", border)
.replace("{TAUNT}", taunt)
.replace("{GLOW}", glow)
.replace("{#SEEKER}", numSeeker.toString())
.replace("{#HIDER}", numHider.toString())
.replace("{MAP}", map)
}
.filter { !it.contains(DISABLED_IDENT) },
)
board.display(uuid)
}
|