Compare commits

...
Author SHA1 Message Date
tmetcalfe89 f7ccdeeb7d switched from shedinja to wonderguard
also scope creep, but ability on a pokemon can be null (probably in initialization before the ability info has been loaded?), so I optional'd it. it is *not* the solution, but it is a solution for right now.
2024-08-14 13:10:27 -07:00
tmetcalfe89 4677c691c6 abstracted stat overrides 2024-08-14 12:37:02 -07:00
2 changed files with 17 additions and 8 deletions
@@ -402,7 +402,7 @@ open class PokemonProperties {
friendship?.takeIf { it != pokemon.friendship }?.let { return false }
pokeball?.takeIf { it != pokemon.caughtBall.name.toString() }?.let { return false }
nature?.takeIf { it != pokemon.nature.name.toString() }?.let { return false }
ability?.takeIf { it != pokemon.ability.name }?.let { return false }
ability?.takeIf { it != pokemon.ability?.name }?.let { return false }
status?.takeIf { it != pokemon.status?.status?.showdownName }?.let { return false }
ivs?.forEach{ stat ->
if (stat.value != pokemon.ivs[stat.key]) { return false }
@@ -8,6 +8,7 @@
package com.cobblemon.mod.common.pokemon.stat
import com.cobblemon.mod.common.api.pokemon.PokemonProperties
import com.cobblemon.mod.common.api.pokemon.stats.Stat
import com.cobblemon.mod.common.api.pokemon.stats.StatProvider
import com.cobblemon.mod.common.api.pokemon.stats.StatTypeAdapter
@@ -39,6 +40,12 @@ object CobblemonStatProvider : StatProvider {
private val ordinalToStat = Stats.values().associateBy { it.ordinal }
private val identifierToOrdinal = Stats.values().associate { it.identifier to it.ordinal }
val statOverrides = mapOf(
"ability=wonderguard" to mapOf(
Stats.HP to 1
)
)
override fun all(): Collection<Stat> = Stats.ALL
override fun ofType(type: Stat.Type): Collection<Stat> = when(type) {
@@ -86,19 +93,21 @@ object CobblemonStatProvider : StatProvider {
}
override fun getStatForPokemon(pokemon: Pokemon, stat: Stat): Int {
val override =
statOverrides.entries.find { (props) -> PokemonProperties.parse(props).matches(pokemon) }?.value?.get(stat)
if (override != null) {
return override
}
val stats = pokemon.form.baseStats
val iv = pokemon.ivs.getOrDefault(stat)
val base = pokemon.form.baseStats[stat]!!
val ev = pokemon.evs.getOrDefault(stat)
val level = pokemon.level
return if (stat == Stats.HP) {
if (pokemon.species.resourceIdentifier == Pokemon.SHEDINJA) {
1
} else {
// Why does showdown have the + 100 inside the numerator instead of + level at the end? It's the same mathematically but odd choice.
// modStats['hp'] = tr(tr(2 * stat + set.ivs['hp'] + tr(set.evs['hp'] / 4) + 100) * set.level / 100 + 10);
truncate(truncate(2.0 * base + iv + truncate(ev / 4.0) + 100) * level / 100.0 + 10).toInt()
}
// Why does showdown have the + 100 inside the numerator instead of + level at the end? It's the same mathematically but odd choice.
// modStats['hp'] = tr(tr(2 * stat + set.ivs['hp'] + tr(set.evs['hp'] / 4) + 100) * set.level / 100 + 10);
truncate(truncate(2.0 * base + iv + truncate(ev / 4.0) + 100) * level / 100.0 + 10).toInt()
} else {
pokemon.effectiveNature.modifyStat(stat, ((2 * base + iv + (ev / 4)) * level) / 100 + 5)
}