summaryrefslogtreewikicommitdiff
path: root/core/src/game/Taunt.kt
blob: 60b5c5c49e793dbfd4f002a74d3ee32ad5789485 (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
49
50
51
52
53
54
55
package cat.freya.khs.game

import java.util.UUID

class Taunt(val game: Game) {

    @Volatile var timer: ULong = 0UL
    @Volatile var running: Boolean = true
    @Volatile var taunted: UUID? = null
    @Volatile var last: UUID? = null

    val expired: Boolean
        get() = (game.hiderSize <= 1UL && game.plugin.config.taunt.disableForLastHider)

    fun reset() {
        running = false
        timer = game.plugin.config.taunt.delay
        last = taunted
        taunted = null
    }

    fun update() {
        if (!game.plugin.config.taunt.enabled || expired) return

        if (timer != 0UL) {
            timer--
            return
        }

        // running means we are to taunt!
        if (running) {
            // if player left, well, damn
            if (taunted?.let { game.hasPlayer(it) } != true) {
                reset()
                return
            }

            val player = taunted?.let { game.plugin.shim.getPlayer(it) }
            player?.taunt()

            game.broadcast(game.plugin.locale.prefix.taunt + game.plugin.locale.taunt.activate)
            reset()
            return
        }

        // select a hider to taunt
        val hider = game.hiderPlayers.filter { it.uuid != last }.randomOrNull() ?: return

        game.broadcast(game.plugin.locale.prefix.taunt + game.plugin.locale.taunt.warning)
        hider.message(game.plugin.locale.taunt.chosen)
        timer = 30UL
        running = true
        taunted = hider.uuid
    }
}