aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/features/dungeon/DungeonCopilot.kt
blob: 663079a901f3259466f72d6416c51467ba11f4bf (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
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
package at.hannibal2.skyhanni.features.dungeon

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.events.*
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.RenderUtils.renderString
import at.hannibal2.skyhanni.utils.StringUtils.matchRegex
import net.minecraft.client.Minecraft
import net.minecraft.entity.item.EntityArmorStand
import net.minecraftforge.client.event.RenderGameOverlayEvent
import net.minecraftforge.event.world.WorldEvent
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

class DungeonCopilot {

    var nextStep = ""
    var searchForKey = false

    @SubscribeEvent
    fun onChatMessage(event: LorenzChatEvent) {
        if (!isEnabled()) return

        val message = event.message

        if (message.matchRegex("(.*) has started the dungeon countdown. The dungeon will begin in 1 minute.")) {
            changeNextStep("Ready up")
        }
        if (message.endsWith("§a is now ready!")) {
            var name = Minecraft.getMinecraft().thePlayer.name
            if (message.contains(name)) {
                changeNextStep("Wait for the dungeon to start!")
            }
        }

        var foundKeyOrDoor = false

        //key pickup
        if (message.matchRegex("(.*) §r§ehas obtained §r§a§r§6§r§8Wither Key§r§e!") ||
            message == "§eA §r§a§r§6§r§8Wither Key§r§e was picked up!"
        ) {
            changeNextStep("Open Wither Door")
            foundKeyOrDoor = true

        }
        if (message.matchRegex("(.*) §r§ehas obtained §r§a§r§c§r§cBlood Key§r§e!") ||
            message == "§eA §r§a§r§c§r§cBlood Key§r§e was picked up!"
        ) {
            changeNextStep("Open Blood Door")
            foundKeyOrDoor = true
        }


        if (message.matchRegex("(.*) opened a §r§8§lWITHER §r§adoor!")) {
            changeNextStep("Clear next room")
            searchForKey = true
            foundKeyOrDoor = true
        }

        if (message == "§cThe §r§c§lBLOOD DOOR§r§c has been opened!") {
            changeNextStep("Wait for Blood Room to fully spawn")
            foundKeyOrDoor = true
        }

        if (foundKeyOrDoor && SkyHanniMod.feature.dungeon.messageFilterKeysAndDoors) {
            event.blockedReason = "dungeon_keys_and_doors"
        }


        if (message == "§c[BOSS] The Watcher§r§f: That will be enough for now.") {
            changeNextStep("Clear Blood Room")
        }

        if (message == "§c[BOSS] The Watcher§r§f: You have proven yourself. You may pass.") {
            event.blockedReason = "dungeon copilot"
            changeNextStep("Enter Boss Room")
        }
    }

    private fun changeNextStep(step: String) {
        nextStep = step
    }

    @SubscribeEvent
    fun onCheckRender(event: CheckRenderEntityEvent<*>) {
        if (!LorenzUtils.inDungeons) return

        val entity = event.entity
        if (entity !is EntityArmorStand) return

        if (!searchForKey) return

        if (entity.name == "§6§8Wither Key") {
            changeNextStep("Pick up Wither Key")
            searchForKey = false
        }
        if (entity.name == "§c§cBlood Key") {
            changeNextStep("Pick up Blood Key")
            searchForKey = false
        }
    }

    @SubscribeEvent
    fun onDungeonStart(event: DungeonStartEvent) {
        changeNextStep("Clear first room")
        searchForKey = true
    }

    @SubscribeEvent
    fun onDungeonStart(event: DungeonEnterEvent) {
        changeNextStep("Talk to Mort")
        searchForKey = true
    }

    @SubscribeEvent
    fun onDungeonBossRoomEnter(event: DungeonBossRoomEnterEvent) {
        changeNextStep("Defeat the boss! Good luck :)")
    }

    @SubscribeEvent
    fun onWorldChange(event: WorldEvent.Load) {
        changeNextStep("")
    }

    private fun isEnabled(): Boolean {
        return LorenzUtils.inDungeons && SkyHanniMod.feature.dungeon.copilotEnabled
    }

    @SubscribeEvent
    fun onRenderOverlay(event: RenderGameOverlayEvent.Post) {
        if (event.type != RenderGameOverlayEvent.ElementType.ALL) return
        if (!isEnabled()) return

        SkyHanniMod.feature.dungeon.copilotPos.renderString(nextStep)
    }
}