aboutsummaryrefslogtreecommitdiff
path: root/features/dungeonSolvers/index.js
blob: f5e5584e41a8eea3e467e775b2754370424c6598 (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
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
/// <reference types="../../../CTAutocomplete" />
/// <reference lib="es2015" />
import Feature from "../../featureClass/class";
import * as renderUtils from "../../utils/renderUtils";
import HudTextElement from "../hud/HudTextElement";
import LocationSetting from "../settings/settingThings/location";
import ToggleSetting from "../settings/settingThings/toggle";

class DungeonSolvers extends Feature {
    constructor() {
        super()
    }

    onEnable(){
        this.initVariables()

        this.lividData = {}
        this.lividData.lividColor = {
            "Vendetta": "&f",
            "Crossed": "&d",
            "Hockey": "&c",
            "Doctor": "&7",
            "Frog": "&2",
            "Smile": "&a",
            "Scream": "&1",
            "Purple": "&5",
            "Arcade": "&e"
        }
        this.onWorldLoad()

        this.lividFindEnabled = new ToggleSetting("Correct livid finder", "Finds the real livid to kill in the f5 boss fight", true, "livid_find_enabled", this)
        this.lividFindHud = new ToggleSetting("Show Livid Hp", "Shows the nametag of the correct livid", true, "livid_hud_enabled", this).requires(this.lividFindEnabled)
        this.lividHpElement = new HudTextElement()
            .setToggleSetting(this.lividFindHud)
            .setLocationSetting(new LocationSetting("Correct Livid Hp Location", "Allows you to edit the location of the correct livid hp text", "livid_hp_location", this, [10, 50, 1, 1])
                .requires(this.lividFindHud)
                .editTempText("§r§e﴾ §c§lLivid§r §a7M§c❤ §e﴿§r"))

        this.lividFindChat = new ToggleSetting("Say correct livid in chat", "Sends the correct livid in chat", false, "livid_chat_enabled", this).requires(this.lividFindEnabled)
        this.lividFindBox = new ToggleSetting("Put a box around the correct livid", "This helps to locate it in the group", true, "livid_box_enabled", this).requires(this.lividFindEnabled)
        this.lividFindNametags = new ToggleSetting("Hide the nametags of incorrect livids", "This helps to locate it in the group", true, "livid_nametags_enabled", this).requires(this.lividFindEnabled)
        
        this.spiritBowDestroyTimer = new ToggleSetting("Timer for when the spirit bow will self destruct", "", true, "spirit_bow_destroy_timer", this)
        this.spiritBowDestroyElement = new HudTextElement()
        .setToggleSetting(this.spiritBowDestroyTimer)
        .setLocationSetting(new LocationSetting("Spirit bow destroy timer location", "Allows you to edit the location of the timer", "spirit_destroy_location", this, [10, 70, 3, 1])
            .requires(this.spiritBowDestroyTimer)
            .editTempText("&dBow Destroyed in: &c15s"))

        this.hudElements.push(this.spiritBowDestroyElement)
        
        this.spiritBowPickUps = []
        this.registerChat("&r&aYou picked up the &r&5Spirit Bow&r&a! Use it to attack &r&cThorn&r&a!&r", ()=>{
            this.spiritBowPickUps.push(Date.now())
        })
        
        this.registerStep(true, 2, this.step)
        this.registerEvent("worldLoad", this.onWorldLoad)
        
        this.registerEvent("renderOverlay", this.renderHud)
        this.registerEvent("renderWorld", this.renderWorld)
        // this.registerEvent("renderEntity", this.renderEntity)
        this.renderEntityEvent = undefined
    }

    renderWorld(ticks){
        if(this.lividFindBox.getValue()){
            if(this.lividData.correctLividEntity){
                renderUtils.drawBoxAtEntity(this.lividData.correctLividEntity, 255, 0, 0, 0.75, -2, ticks)
            }
        }
    }

    renderEntity(entity, position, ticks, event){
        if(this.lividFindNametags.getValue()){
            if(this.lividData.correctLividEntity){
                if(entity.getName().includes("Livid") && entity.getName().includes("❤") && entity.getUUID() !== this.lividData.correctLividEntity.getUUID()){
                    cancel(event)
                }
            }
        }
    }
    
    renderHud(){
        for(let element of this.hudElements){
            element.render()
        }
    }

    onWorldLoad(){
        this.lividData.correctLividColor = undefined
        this.lividData.correctLividColorHP = undefined
        this.lividData.sayLividColors = []
        this.lividData.sayLividColors2 = []
        this.lividData.correctLividEntity = undefined
        this.lividHpElement && this.lividHpElement.setText("")
    }

    step(){ //2fps
        if(this.lividFindEnabled.getValue() && (this.FeatureManager.features["dataLoader"].class.dungeonFloor === "F5")){ //TODO: fix on M5 (detect correct livid based on roof color)
            World.getAllEntities().forEach(entity => {
                let entityName = entity.getName()
				if (/(?:Vendetta|Crossed|Hockey|Doctor|Frog|Smile|Scream|Purple|Arcade) Livid/g.test(entityName)) {
					let lividName = entityName.replace(" Livid", "")

					if (!this.lividData.sayLividColors2.includes(lividName)) {
						this.lividData.sayLividColors2.push(lividName)
						if (this.lividData.sayLividColors2.length === 1) {
							this.lividData.correctLividColor = lividName
						}
						if (this.lividData.sayLividColors2.length === 9) {
                            if(this.lividFindChat.getValue()){
                                ChatLib.chat(this.FeatureManager.messagePrefix + "Correct livid is: " + this.lividData.lividColor[lividName] + lividName)
                            }
							this.lividData.correctLividColor = lividName
						}
					}
					return;
				}
                if (entityName.includes("Livid") && entityName.includes("❤")) {
                    if (!this.lividData.sayLividColors.includes(entityName.substr(0, 3))) {
                        this.lividData.sayLividColors.push(entityName.substr(0, 3))
                        if (this.lividData.sayLividColors.length === 9) {
                            this.lividData.correctLividColorHP = entityName.substr(0, 3)
                        }
                        if (this.lividData.sayLividColors.length === 1) {
                            this.lividData.correctLividColorHP = entityName.substr(0, 3)
                        }
                    }

                    if (this.lividData.sayLividColors.length === 1) {
                        if (entityName.includes("Livid") && entityName.includes("❤")) {
                            this.lividHpElement.setText(entityName)
                        }
                    } else {
                        if (this.lividData.correctLividColorHP !== undefined) {
                            // if (this.lividData.correctLividColor === "Arcade") {
                            //     this.lividHpElement.setText("Unknown Health (Yellow Livid)")
                            // } else {
                                if (entityName.includes(this.lividData.correctLividColorHP)) {
                                    this.lividHpElement.setText(entityName)
                                    this.lividData.correctLividEntity = entity
                                }
                            // }
                        }
                    }

                }
            })
        }

        if(this.lividData.correctLividEntity){
            if(!this.renderEntityEvent){
                this.renderEntityEvent = this.registerEvent("renderEntity", this.renderEntity)
            }
        }else{
            if(this.renderEntityEvent){
                this.unregisterEvent(this.renderEntityEvent)
            }
        }

        this.spiritBowPickUps = this.spiritBowPickUps.filter(pickUp => Date.now() - pickUp < 20000)
        if(this.spiritBowPickUps[0]){
            this.spiritBowDestroyElement.setText("&dBow Destroyed in: &c" + Math.round((this.spiritBowPickUps[0] + 20000 - Date.now()) / 1000) + "s")
        }else{
            this.spiritBowDestroyElement.setText("")
        }
        // this.spiritBowPickUps
    }

    initVariables(){
        this.lividFindEnabled = undefined
        this.lividData = undefined
        this.hudElements = []
    }

    onDisable(){
        this.initVariables()
    }
}

module.exports = {
    class: new DungeonSolvers()
}