summaryrefslogtreewikicommitdiff
path: root/core/src/game/Glow.kt
blob: a2289ba32bb47b3e13753d826c3bf4d2513ff633 (plain)
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
package cat.freya.khs.game

class Glow(val game: Game) {

    @Volatile var timer: ULong = 0UL
    @Volatile var running: Boolean = true

    fun start() {
        running = true
        if (game.plugin.config.glow.stackable) {
            timer += game.plugin.config.glow.time
        } else {
            timer = game.plugin.config.glow.time
        }
    }

    fun reset() {
        running = false
        timer = 0UL
    }

    private fun sendPackets(glow: Boolean) {
        for (hider in game.hiderPlayers) for (seeker in game.seekerPlayers) hider.setGlow(
            seeker,
            glow,
        )
    }

    fun update() {
        if (!game.plugin.config.glow.enabled) return

        if (game.plugin.config.alwaysGlow) {
            sendPackets(true)
            return
        }

        if (!running) return

        if (timer >= 0UL) timer--

        if (timer == 0UL) {
            running = false
            sendPackets(false)
        } else {
            sendPackets(true)
        }
    }
}