aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/bazaar/BazaarApi.kt
blob: cbebe951c36c26f6f078cac494e967172a6e9928 (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
package at.hannibal2.skyhanni.bazaar

import at.hannibal2.skyhanni.utils.LorenzUtils

class BazaarApi {

    companion object {
        private val bazaarMap = mutableMapOf<String, BazaarData>()

        fun isBazaarInventory(inventoryName: String): Boolean {
            if (inventoryName.contains(" ➜ ") && !inventoryName.contains("Museum")) return true
            if (BazaarOrderHelper.isBazaarOrderInventory(inventoryName)) return true

            return when (inventoryName) {
                "Your Bazaar Orders" -> true
                "How many do you want?" -> true
                "How much do you want to pay?" -> true
                "Confirm Buy Order" -> true
                "Confirm Instant Buy" -> true
                "At what price are you selling?" -> true
                "Confirm Sell Offer" -> true
                "Order options" -> true

                else -> false
            }
        }

        fun getCleanBazaarName(name: String): String {
            if (name.endsWith(" Gemstone")) {
                return name.substring(6)
            }
            if (name.startsWith("§")) {
                return name.substring(2)
            }

            return name
        }

        fun getBazaarDataForName(name: String): BazaarData {
            if (bazaarMap.containsKey(name)) {
                val bazaarData = bazaarMap[name]
                if (bazaarData != null) {
                    return bazaarData
                }
                LorenzUtils.error("Bazaar data is null for item '$name'")
            }
            throw Error("no bz data found for name '$name'")
        }

        fun isBazaarItem(name: String): Boolean {
            val bazaarName = getCleanBazaarName(name)
            return bazaarMap.containsKey(bazaarName)
        }
    }

    init {
        BazaarDataGrabber(bazaarMap).start()
    }
}