-
-
Notifications
You must be signed in to change notification settings - Fork 329
fix: Add OCR cooldown guard to prevent skill spam false positives #2195
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
Changes from 2 commits
f9a5c41
61c7ebf
8926ddc
9b584a2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -8,6 +8,7 @@ import io.github.fate_grand_automata.scripts.models.SkillSpamTarget | |
| import io.github.fate_grand_automata.scripts.models.SpamConfigPerTeamSlot | ||
| import io.github.fate_grand_automata.scripts.models.battle.BattleState | ||
| import io.github.fate_grand_automata.scripts.models.skills | ||
| import io.github.lib_automata.Pattern | ||
| import io.github.lib_automata.dagger.ScriptScope | ||
| import javax.inject.Inject | ||
| import kotlin.time.Duration.Companion.seconds | ||
|
|
@@ -22,6 +23,8 @@ class SkillSpam @Inject constructor( | |
| ) : IFgoAutomataApi by api { | ||
| companion object { | ||
| val skillSpamDelay = 0.25.seconds | ||
| val skillReadyRecheckDelay = 0.1.seconds | ||
| val cooldownRegex = Regex("""\d+""") | ||
| } | ||
|
|
||
| fun spamSkills() { | ||
|
|
@@ -42,7 +45,7 @@ class SkillSpam @Inject constructor( | |
| // Some delay for skill icon to be loaded | ||
| skillSpamDelay.wait() | ||
|
|
||
| if (skillImage in locations.battle.imageRegion(skill)) { | ||
| if (isReadyForSpam(skill, skillImage)) { | ||
| val target = skillSpamConfig.determineTarget(servantSlot) | ||
|
|
||
| caster.castServantSkill(skill, target) | ||
|
|
@@ -68,4 +71,36 @@ class SkillSpam @Inject constructor( | |
| SkillSpamTarget.Left -> ServantTarget.Left | ||
| SkillSpamTarget.Right -> ServantTarget.Right | ||
| } | ||
| } | ||
|
|
||
| private fun isReadyForSpam(skill: io.github.fate_grand_automata.scripts.models.Skill.Servant, skillImage: Pattern): Boolean { | ||
| val isReady = useSameSnapIn { | ||
| skillImage in locations.battle.imageRegion(skill) && !hasCooldownText(skill) | ||
| } | ||
|
|
||
| if (!isReady) { | ||
| return false | ||
| } | ||
|
|
||
| skillReadyRecheckDelay.wait() | ||
|
|
||
| return useSameSnapIn { | ||
| skillImage in locations.battle.imageRegion(skill) && !hasCooldownText(skill) | ||
| } | ||
| } | ||
|
|
||
| private fun hasCooldownText(skill: io.github.fate_grand_automata.scripts.models.Skill.Servant): Boolean { | ||
| val text = locations.battle.cooldownTextRegion(skill) | ||
| .detectText(outlinedText = true) | ||
| .replace('O', '0') | ||
| .replace('o', '0') | ||
|
||
| .replace('I', '1') | ||
| .replace('l', '1') | ||
|
|
||
| val cooldown = cooldownRegex | ||
|
||
| .find(text) | ||
| ?.value | ||
| ?.toIntOrNull() | ||
|
|
||
| return cooldown != null && cooldown > 0 | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Already addressed in 61c7ebf — the hardcoded
skillReadySimilarity = 0.9constant was removed and the calls were reverted to theinoperator (Region.contains), which passessimilarity = nulland defers toplatformImpl.prefs.minSimilarity. This is consistent with how the rest of the codebase handles image matching.