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

Fix: Crimson Isle Quest Parsing #3016

Merged
merged 3 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,13 @@ class CrimsonIsleReputationHelper(skyHanniMod: SkyHanniMod) {
var tabListQuestsMissing = false

/**
* c - Barbarian Not Accepted
* d - Mage Not Accepted
* e - Accepted
* a - Completed
* REGEX-TEST: §r§c✖ Rescue Mission
* REGEX-TEST: §r§a✔ Digested Mushrooms §r§8x20
* REGEX-TEST: §r§c✖ Slugfish §r§8x1
*/
val tabListQuestPattern by RepoPattern.pattern(
"crimson.reputation.tablist",
" §r§[cdea].*",
"crimson.reputationhelper.tablist.quest",
" (?:§.*)?(?<status>[✖✔]) (?<name>.+?)(?: (?:§.)*?x(?<amount>\\d+))?",
)

init {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,35 @@ class DailyQuestHelper(val reputationHelper: CrimsonIsleReputationHelper) {
val quests = mutableListOf<Quest>()
var greatSpook = false

val patternGroup = RepoPattern.group("crimson.reputationhelper.quest")

/**
* REGEX-TEST: §7Kill the §cAshfang §7miniboss §a2 §7times!
* REGEX-TEST: §7Kill the §cMage Outlaw §7miniboss §a1 §7time!
* REGEX-TEST: §7miniboss §a1 §7time!
*/
val minibossAmountPattern by RepoPattern.pattern(
"crimson.reputationhelper.quest.minibossamount",
val minibossAmountPattern by patternGroup.pattern(
"minibossamount",
"(?:§7Kill the §c.+ §7|.*)miniboss §a(?<amount>\\d) §7times?!",
)

/**
* REGEX-TEST: §eClick to start!
*/
val clickToStartPattern by patternGroup.pattern(
"clicktostart",
"(?:§.)*Click to start!",
)

/**
* REGEX-TEST: §a§lCOMPLETE
*/
val completedPattern by patternGroup.pattern(
"complete",
"(?:§.)*COMPLETE",
)


private val config get() = SkyHanniMod.feature.crimsonIsle.reputationHelper

@SubscribeEvent
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,19 @@ class QuestLoader(private val dailyQuestHelper: DailyQuestHelper) {
}

private fun readQuest(line: String) {
if (!dailyQuestHelper.reputationHelper.tabListQuestPattern.matches(line)) return
dailyQuestHelper.reputationHelper.tabListQuestPattern.matchMatcher(line) {
if (line.contains("The Great Spook")) {
dailyQuestHelper.greatSpook = true
dailyQuestHelper.update()
return
}

if (line.contains("The Great Spook")) {
dailyQuestHelper.greatSpook = true
dailyQuestHelper.update()
return
}
var text = line.substring(3)
val green = text.startsWith("§a")
text = text.substring(2)

val amount: Int
val name: String
// TODO use regex
if (text.contains(" §r§8x")) {
val split = text.split(" §r§8x")
name = split[0]
amount = split[1].toInt()
} else {
name = text
amount = 1
}
val name = group("name")
val amount = group("amount")?.toInt() ?: 1
val green = group("status") == "✔"

checkQuest(name, green, amount)
checkQuest(name, green, amount)
}
}

private fun checkQuest(name: String, green: Boolean, needAmount: Int) {
Expand Down Expand Up @@ -156,13 +145,13 @@ class QuestLoader(private val dailyQuestHelper: DailyQuestHelper) {
if (!categoryName.equals(name, ignoreCase = true)) continue
val stack = event.inventoryItems[22] ?: continue

val completed = stack.getLore().any { it.contains("Completed!") }
val completed = stack.getLore().any { dailyQuestHelper.completedPattern.matches(it) }
if (completed && quest.state != QuestState.COLLECTED) {
quest.state = QuestState.COLLECTED
dailyQuestHelper.update()
}

val accepted = !stack.getLore().any { it.contains("Click to start!") }
val accepted = !stack.getLore().any { dailyQuestHelper.clickToStartPattern.matches(it) }
if (accepted && quest.state == QuestState.NOT_ACCEPTED) {
quest.state = QuestState.ACCEPTED
dailyQuestHelper.update()
Expand Down
Loading