Skip to content
Open
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
Binary file added app/src/main/assets/En/skill_strengthened.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/En/skill_unstrengthened.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added app/src/main/assets/Jp/skill_strengthened.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ private fun AutoBattle.ExitReason.text(): String = when (this) {
AutoBattle.ExitReason.FirstClearRewards -> stringResource(R.string.first_clear_rewards)
AutoBattle.ExitReason.Paused -> stringResource(R.string.script_paused)
AutoBattle.ExitReason.StopAfterThisRun -> stringResource(R.string.stop_after_this_run)
is AutoBattle.ExitReason.StrengthenedSkillEmpty -> stringResource(R.string.strengthened_skill_empty, skill, requirement)
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,23 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.layout.size
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.AlertDialog
import androidx.compose.material3.Card
import androidx.compose.material3.CardDefaults
import androidx.compose.material3.CardDefaults.cardElevation
import androidx.compose.material3.Icon
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.rememberCoroutineScope
import androidx.compose.runtime.setValue
import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier
import androidx.compose.ui.platform.LocalContext
import androidx.compose.ui.res.painterResource
import androidx.compose.ui.res.stringResource
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
Expand Down Expand Up @@ -71,6 +76,21 @@ private fun PreferredSupport(
val prefServants by config.preferredServants.remember()
val prefCEs by config.preferredCEs.remember()

// todo: remove this note later when the feature is working fine on all servers
var showStrengthenedNote by androidx.compose.runtime.remember { mutableStateOf(false) }
if (showStrengthenedNote) {
AlertDialog(
onDismissRequest = { showStrengthenedNote = false },
confirmButton = {
TextButton(onClick = { showStrengthenedNote = false }) {
Text(stringResource(android.R.string.ok))
}
},
// title = { Text(stringResource(R.string.note)) },
text = { Text(stringResource(R.string.p_strengthened_skills_note)) }
)
}

LazyColumn {
item {
Heading(stringResource(R.string.p_support_mode_preferred))
Expand Down Expand Up @@ -124,6 +144,34 @@ private fun PreferredSupport(
)
)
}
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.padding(16.dp)
) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.weight(1f)
) {
Text(stringResource(R.string.p_strengthened_skills))
Icon(
painter = painterResource(R.drawable.ic_info),
contentDescription = "Info",
modifier = Modifier
.padding(start = 8.dp)
.size(20.dp)
.clickable { showStrengthenedNote = true },
tint = MaterialTheme.colorScheme.secondary
)
}

StrengthenedSkills(
strengthenedSkills = listOf(
config.skill1Strengthened,
config.skill2Strengthened,
config.skill3Strengthened
)
)
}
}
}
}
Expand Down Expand Up @@ -289,4 +337,37 @@ private fun MaxSkills(
}
}
}
}

@Composable
private fun StrengthenedSkills(
strengthenedSkills: List<Pref<Int>>
) {
Row(verticalAlignment = Alignment.CenterVertically) {
strengthenedSkills.forEachIndexed { index, pref ->
if (index != 0) {
Text("/", modifier = Modifier.padding(horizontal = 8.dp))
}

var strengthened by pref.remember()

Card(
elevation = cardElevation(5.dp),
colors = CardDefaults.cardColors(
containerColor = if (strengthened > 0) MaterialTheme.colorScheme.secondary else MaterialTheme.colorScheme.surfaceVariant,
contentColor = if (strengthened > 0) MaterialTheme.colorScheme.onSecondary else MaterialTheme.colorScheme.onSurfaceVariant
)
) {
Box(
contentAlignment = Alignment.Center,
// change to '(rankUp + 1) % 4' in future if there's 3 rank up quests on the same skill
modifier = Modifier
.clickable { strengthened = (strengthened + 1) % 3 }
.size(40.dp)
) {
Text(strengthened.toString())
}
}
}
}
}
3 changes: 3 additions & 0 deletions app/src/main/res/values/localized.xml
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ Skills"</string>
<string name="p_battle_config_support_friend_name_hint">"Friend name images can be added using 'Support Image Maker' script"</string>
<string name="p_battle_config_support_also_check_all">"Also check All"</string>
<string name="p_max_skills">"Max Skills"</string>
<string name="p_strengthened_skills">"Strengthened Skills"</string>
<string name="p_strengthened_skills_note">"This feature has been tested on JP and NA servers. Contact GitHub/Discord if it is not working on your server."</string>
<string name="strengthened_skill_empty">"Strengthening %2$d may not be available for Skill %1$d. Please check your configuration."</string>
<string name="p_game_server">"Game Server"</string>
<string name="p_game_server_auto_detect">"Auto-detect"</string>
<string name="p_spam_summary">"Danger mode requires Auto-targeting"</string>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@ internal class SupportPreferences(
override val skill2Max by prefs.skill2Max
override val skill3Max by prefs.skill3Max

override val skill1Strengthened by prefs.skill1Strengthened
override val skill2Strengthened by prefs.skill2Strengthened
override val skill3Strengthened by prefs.skill3Strengthened

override val grandServant by prefs.grandServant
override val bondCEEffect by prefs.bondCEEffect
override val requireBothNormalAndRewardMatch by prefs.requireBothNormalAndRewardMatch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ class SupportPrefsCore(
val skill2Max = maker.bool("support_skill_max_2")
val skill3Max = maker.bool("support_skill_max_3")

val skill1Strengthened = maker.int("support_skill_strengthened_1")
val skill2Strengthened = maker.int("support_skill_strengthened_2")
val skill3Strengthened = maker.int("support_skill_strengthened_3")

val grandServant = maker.bool("support_grand_servant")
val bondCEEffect = maker.enum(
"support_bond_ce_effect",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,4 +94,6 @@ enum class Images(val path: String) {
GrandCeLabel("grand_ce_label.png"),
BondCeEffectDefault("bond_ce_effect_default.png"),
BondCeEffectNP("bond_ce_effect_np.png"),
SkillStrengthened("skill_strengthened.png"),
SkillUnstrengthened("skill_unstrengthened.png"),
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ class AutoBattle @Inject constructor(
class CardPriorityParseError(val msg: String) : ExitReason()
data object Paused : ExitReason()
data object StopAfterThisRun : ExitReason()
// Inside sealed class ExitReason
class StrengthenedSkillEmpty(val skill: Int, val requirement: Int) : ExitReason()
}

internal class BattleExitException(val reason: ExitReason) : Exception(reason.cause)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,8 @@ class SupportScreenLocations @Inject constructor(
val listSwipeStart = Location(-59, if (canLongSwipe) 1000 else 1190) + supportOffset
val listSwipeEnd = Location(-89, if (canLongSwipe) 300 else 660) + supportOffset

val strengthenedSkillRegion = Region(0, 0, 24, 24) + supportOffset

fun locate(supportClass: SupportClass) = when (supportClass) {
SupportClass.None -> 0
SupportClass.All -> 184
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ interface ISupportPreferences {
val skill2Max: Boolean
val skill3Max: Boolean

val skill1Strengthened: Int
val skill2Strengthened: Int
val skill3Strengthened: Int

val grandServant: Boolean
val bondCEEffect: BondCEEffectEnum
val requireBothNormalAndRewardMatch: Boolean
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import io.github.fate_grand_automata.scripts.IFgoAutomataApi
import io.github.fate_grand_automata.scripts.Images
import io.github.fate_grand_automata.scripts.ScriptLog
import io.github.fate_grand_automata.scripts.prefs.ISupportPreferences
import io.github.fate_grand_automata.scripts.entrypoints.AutoBattle
import io.github.lib_automata.Location
import io.github.lib_automata.Pattern
import io.github.lib_automata.Region
Expand Down Expand Up @@ -49,6 +50,17 @@ class ServantSelection @Inject constructor(
!skillCheckNeeded || checkMaxedSkills(needMaxedSkills, whichSkillsAreMaxed(bounds.region))
}

.filter {
val needStrengthenedSkills = listOf(
supportPrefs.skill1Strengthened.coerceIn(0..2),
supportPrefs.skill2Strengthened.coerceIn(0..2),
supportPrefs.skill3Strengthened.coerceIn(0..2)
)

val skillStrengthenedCheckNeeded = needStrengthenedSkills.any { it > 0}
!skillStrengthenedCheckNeeded || checkStrengthenedSkills(bounds.region, needStrengthenedSkills).all{ it }
}

return matched.isNotEmpty()
}

Expand Down Expand Up @@ -102,7 +114,7 @@ class ServantSelection @Inject constructor(
skillRegion.exists(images[Images.SkillTen], similarity = 0.68)
}
}

private fun checkMaxedSkills(expectedSkills: List<Boolean>, actualSkills: List<Boolean>): Boolean {
val result = expectedSkills
.zip(actualSkills) { expected, actual ->
Expand All @@ -118,4 +130,38 @@ class ServantSelection @Inject constructor(

return result.all { it }
}
}

/**
* Check if the skill is strengthened(rank-up quest cleared)
* Currently restricted to level 2 (2 rank-up quests) for each skill, can modify in UI to allow more
*/
private fun checkStrengthenedSkills(bounds: Region, needStrengthenedSkills: List<Int>): List<Boolean> {
val skillMargin = 90
val rankUpMargin = 18

/**
* When the servant portrait is found near the bottom of the screen
* return false to skip detection of 'Images.SkillUnstrengthened'
* to avoid false exception
*/
if (bounds.y > 1000) return List(needStrengthenedSkills.size) { false }

return needStrengthenedSkills.mapIndexed { index, requirement ->
if (requirement <= 0) return@mapIndexed true

val strengthenedSkillLocation = Location(
bounds.x + 1650 + index * skillMargin,
bounds.y + 351 - (requirement - 1) * rankUpMargin
)
val strengthenedSkillRegion = locations.support.strengthenedSkillRegion.copy(x = strengthenedSkillLocation.x, y = strengthenedSkillLocation.y)
when{
strengthenedSkillRegion.exists(images[Images.SkillStrengthened], similarity = 0.68) -> true
strengthenedSkillRegion.exists(images[Images.SkillUnstrengthened], similarity = 0.68) -> false
else -> throw AutoBattle.BattleExitException(
// 'Images.SkillUnstrengthened' not found, exit script and prompt user to check configuration
AutoBattle.ExitReason.StrengthenedSkillEmpty(index + 1, requirement)
)
}
}
}
}
Loading