aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/itemabilities/abilitycooldown/ItemAbility.kt
blob: aca78fd0ac553ea024624a51c8481358cc84fafc (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
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
package at.hannibal2.skyhanni.features.itemabilities.abilitycooldown

import at.hannibal2.skyhanni.utils.LorenzUtils

enum class ItemAbility(
    val abilityName: String,
    val cooldownInSeconds: Long,
    vararg val itemNames: String,
    var lastClick: Long = 0L,
    var lastNewClick: Long = 0L,
    val actionBarDetection: Boolean = true,
) {
    //TODO add into repo

    HYPERION(5, "SCYLLA", "VALKYRIE", "ASTREA"),
    GYROKINETIC_WAND(30),
    GIANTS_SWORD(30),
    ICE_SPRAY_WAND(5),
    ATOMSPLIT_KATANA(4, "VORPAL_KATANA", "VOIDEDGE_KATANA"),


    // TODO replace old logic

    HEAL_1("Small Heal", 7, "Wand of Healing"),
    HEAL_2("Medium Heal", 7, "Wand of Mending"),
    HEAL_3("Big Heal", 7, "Wand of Restoration"),
    HEAL_4("Huge Heal", 7, "Wand of Atonement"),

    STAR_FALL("Starfall", 2, "Starlight Wand"),
    VODOO_DOLL("Acupuncture", 5, "Voodoo Doll"),
    INK_WAND("Ink Bomb", 30, "Ink Wand"),
    GOLEM_SWORD("Iron Punch", 3, "Golem Sword"),
    EMBER_ROD("Fire Blast", 30, "Ember Rod"),
    ENDER_BOW("Ender Warp", 30, "Ender Bow"),

    LIVID_DAGGER("Throw", 5, "Livid Dagger"),
    WEIRD_TUBA("Howl", 20, "Weird Tuba"),

    ENDSTONE_SWORD("Extreme Focus", 5, "End Stone Sword"),
    PIGMAN_SWORD("Burning Souls", 5, "Pigman Sword"),

    SOULWARD("Soulward", 20, "Soul Esoward"),
    ECHO("Echo", 3, "Ancestral Spade"),

    FIRE_VEIL("Fire Veil", 5, "Fire Veil Wand"),
    //TODO add new crimson isle weapons

    ;

    var newVariant = false
    var internalNames = mutableListOf<String>()

    constructor(cooldownInSeconds: Int, vararg alternateInternalNames: String) : this("no name", cooldownInSeconds.toLong(), actionBarDetection = false) {
        newVariant = true
        internalNames.addAll(alternateInternalNames)
        internalNames.add(name)
    }

    fun oldClick() {
        lastClick = System.currentTimeMillis()
    }

    fun isOnCooldown(): Boolean = lastClick + getCooldown() > System.currentTimeMillis()

    fun getCooldown(): Long = cooldownInSeconds * 1000

    fun getDurationText(): String {
        var duration: Long = lastClick + getCooldown() - System.currentTimeMillis()
        return if (duration < 1600) {
            duration /= 100
            var d = duration.toDouble()
            d /= 10.0
            LorenzUtils.formatDouble(d)
        } else {
            duration /= 1000
            duration++
            LorenzUtils.formatInteger(duration)
        }
    }

    fun newClick() {
//        println("newClick $this")
        lastNewClick = System.currentTimeMillis()
    }

    companion object {
        fun getByInternalName(internalName: String): ItemAbility? {
            return values().firstOrNull { it.newVariant && internalName in it.internalNames }
        }
    }

}