Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Added Primal Fear solvers #2771

Merged
merged 13 commits into from
Oct 22, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public static class RepositoryLocation {
public String user = "hannibal002";

@Expose
@ConfigOption(name = "Repository Name", desc = "The Repository Name, default: SkyHanni-Repo")
@ConfigOption(name = "Repository Name", desc = "The Repository Name, default: SkyHanni-REPO")
@ConfigEditorText
public String name = "SkyHanni-REPO";

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import at.hannibal2.skyhanni.config.FeatureToggle;
import at.hannibal2.skyhanni.config.core.config.Position;
import com.google.gson.annotations.Expose;
import io.github.notenoughupdates.moulconfig.annotations.Accordion;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean;
import io.github.notenoughupdates.moulconfig.annotations.ConfigLink;
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;
Expand Down Expand Up @@ -47,4 +48,8 @@ public class GreatSpookConfig {
@ConfigLink(owner = GreatSpookConfig.class, field = "greatSpookTimeLeft")
public Position positionTimeLeft = new Position(40, 40, false, true);

@ConfigOption(name = "Primal Fear Solvers", desc = "Solvers for the Primal Fears.")
@Accordion
@Expose
public PrimalFearSolverConfig primalFearSolver = new PrimalFearSolverConfig();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package at.hannibal2.skyhanni.config.features.event;

import at.hannibal2.skyhanni.config.FeatureToggle;
import com.google.gson.annotations.Expose;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorBoolean;
import io.github.notenoughupdates.moulconfig.annotations.ConfigEditorKeybind;
import io.github.notenoughupdates.moulconfig.annotations.ConfigOption;
import org.lwjgl.input.Keyboard;

public class PrimalFearSolverConfig {
@Expose
@ConfigOption(name = "Math", desc = "Sends a clickable message with the solution in chat.")
@ConfigEditorBoolean
@FeatureToggle
public boolean math = false;

@Expose
@ConfigOption(name = "Public Speaking", desc = "Sends a clickable message with a random string in chat.")
@ConfigEditorBoolean
@FeatureToggle
public boolean publicSpeaking = false;
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,20 @@ package at.hannibal2.skyhanni.features.event.spook
import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.data.model.SkyblockStat
import at.hannibal2.skyhanni.events.GuiRenderEvent
import at.hannibal2.skyhanni.events.LorenzChatEvent
import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.DelayedRun
import at.hannibal2.skyhanni.utils.HypixelCommands
import at.hannibal2.skyhanni.utils.LorenzUtils
import at.hannibal2.skyhanni.utils.NEUCalculator
import at.hannibal2.skyhanni.utils.RegexUtils.matchMatcher
import at.hannibal2.skyhanni.utils.RenderUtils.renderString
import at.hannibal2.skyhanni.utils.SoundUtils
import at.hannibal2.skyhanni.utils.StringUtils
import at.hannibal2.skyhanni.utils.TabListData
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent

@SkyHanniModule
Expand All @@ -22,11 +30,11 @@ object TheGreatSpook {

@SubscribeEvent
fun onSecondPassed(event: SecondPassedEvent) {
if (isAllDisabled()) return
if (!LorenzUtils.inSkyBlock) return

if (isTimerEnabled() || isNotificationEnabled()) displayTimer = checkTabList(" §r§cPrimal Fears§r§7: ")
if (isTimeLeftEnabled()) displayTimeLeft = checkTabList(" §r§dEnds In§r§7: ")
if (isNotificationEnabled()) {
if (config.primalFearTimer || config.primalFearNotification) displayTimer = checkTabList(" §r§cPrimal Fears§r§7: ")
if (config.greatSpookTimeLeft) displayTimeLeft = checkTabList(" §r§dEnds In§r§7: ")
if (config.primalFearNotification) {
if (displayTimer.endsWith("READY!!")) {
if (notificationSeconds > 0) {
SoundUtils.playBeepSound()
Expand All @@ -44,20 +52,77 @@ object TheGreatSpook {

@SubscribeEvent
fun onRenderOverlay(event: GuiRenderEvent.GuiOverlayRenderEvent) {
if (isTimerEnabled()) config.positionTimer.renderString(displayTimer, posLabel = "Primal Fear Timer")
if (isFearStatEnabled()) {
if (!LorenzUtils.inSkyBlock) return

if (config.primalFearTimer) config.positionTimer.renderString(displayTimer, posLabel = "Primal Fear Timer")
if (config.fearStatDisplay) {
SkyblockStat.FEAR.displayValue?.let {
config.positionFear.renderString(it, posLabel = "Fear Stat Display")
}
}
if (isTimeLeftEnabled()) config.positionTimeLeft.renderString(displayTimeLeft, posLabel = "Time Left Display")
if (config.greatSpookTimeLeft) config.positionTimeLeft.renderString(displayTimeLeft, posLabel = "Time Left Display")
}

/**
* REGEX-TEST: §d§lQUICK MATHS! §r§7Solve: §r§e(10*2)+12*5
*/
private val mathFearMessagePattern by RepoPattern.pattern(
"chat.math",
"§d§lQUICK MATHS! §r§7Solve: §r§e(?<math>.*)",
KeinsWolfi marked this conversation as resolved.
Show resolved Hide resolved
)

/**
* REGEX-TEST: §4[FEAR] Public Speaking Demon§r§f: Speak PlasticEating!
*/
private val speakingFearMessagePattern by RepoPattern.pattern(
"chat.speaking",
"§4\\[FEAR] Public Speaking Demon§r§f: (Speak|Say something interesting) (?<name>.*)!",
)

private fun mathSolver(query: String?) {
val answer = query?.let { NEUCalculator.calculateOrNull(it)?.toInt() } ?: run {
ChatUtils.userError("Failed to solve $query!")
return
}
ChatUtils.clickToActionOrDisable(
"The answer is: $answer",
config.primalFearSolver::math,
actionName = "Send the answer",
action = {
HypixelCommands.allChat(answer.toString())
},
)
}

private fun publicSpeakingSolver() {
ChatUtils.clickToActionOrDisable(
"Click to complete the Primal Fear",
config.primalFearSolver::publicSpeaking,
actionName = "send a random string.",
action = {
HypixelCommands.allChat("I looove SkyHanni! ${StringUtils.generateRandomString(4)}")
},
)
}

private fun isTimerEnabled(): Boolean = LorenzUtils.inSkyBlock && config.primalFearTimer
@SubscribeEvent
fun onChat(event: LorenzChatEvent) {
if (!LorenzUtils.inSkyBlock) return

private fun isNotificationEnabled(): Boolean = LorenzUtils.inSkyBlock && config.primalFearNotification
private fun isFearStatEnabled(): Boolean = LorenzUtils.inSkyBlock && config.fearStatDisplay
private fun isTimeLeftEnabled(): Boolean = LorenzUtils.inSkyBlock && config.greatSpookTimeLeft
if (config.primalFearSolver.math) {
mathFearMessagePattern.matchMatcher(event.message) {
DelayedRun.runNextTick {
mathSolver(group("math"))
}
}
}

private fun isAllDisabled(): Boolean = !isTimeLeftEnabled() && !isTimerEnabled() && !isFearStatEnabled() && !isNotificationEnabled()
if (config.primalFearSolver.publicSpeaking) {
speakingFearMessagePattern.matchMatcher(event.message) {
DelayedRun.runNextTick {
publicSpeakingSolver()
}
}
}
}
}
7 changes: 7 additions & 0 deletions src/main/java/at/hannibal2/skyhanni/utils/StringUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,13 @@ object StringUtils {

fun generateRandomId() = UUID.randomUUID().toString()

private const val CHARS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"
fun generateRandomString(length: Int): String {
var res: String = ""
repeat(length) { res += CHARS.random() }
return res
}

fun String.insert(pos: Int, chars: CharSequence): String = this.substring(0, pos) + chars + this.substring(pos)

fun String.insert(pos: Int, char: Char): String = this.substring(0, pos) + char + this.substring(pos)
Expand Down
Loading