diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/api/battles/model/PokemonBattle.kt b/common/src/main/kotlin/com/cobblemon/mod/common/api/battles/model/PokemonBattle.kt index 6de5e88286..46605d1bc5 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/api/battles/model/PokemonBattle.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/api/battles/model/PokemonBattle.kt @@ -137,6 +137,9 @@ open class PokemonBattle( val captureActions = mutableListOf() val majorBattleActions = hashMapOf() + + /** Monotonically increasing counter to track faint ordering within this battle. */ + var faintCounter = 0 val minorBattleActions = hashMapOf() val contextManager = ContextManager() @@ -244,12 +247,23 @@ open class PokemonBattle( fun end() { ended = true + val awardToFainted = Cobblemon.config.awardExperienceToFaintedPokemon + val awardOnLoss = Cobblemon.config.awardExperienceOnBattleLoss this.actors.forEach { actor -> val faintedPokemons = actor.pokemonList.filter { it.health <= 0 } actor.getSide().getOppositeSide().actors.forEach { opponent -> - val opponentNonFaintedPokemons = opponent.pokemonList.filter { it.health > 0 } + val opponentPokemons = if (awardToFainted) opponent.pokemonList else opponent.pokemonList.filter { it.health > 0 } faintedPokemons.forEach { faintedPokemon -> - for (opponentPokemon in opponentNonFaintedPokemons) { + for (opponentPokemon in opponentPokemons) { + // Faint-order check: if awarding XP to fainted pokemon, only award for enemies that fainted before this pokemon did + if (awardToFainted) { + val enemyFaintedAt = faintedPokemon.faintedAt ?: continue + val opponentFaintedAt = opponentPokemon.faintedAt + if (opponentFaintedAt != null && opponentFaintedAt <= enemyFaintedAt) { + continue + } + } + val facedFainted = opponentPokemon.facedOpponents.contains(faintedPokemon) val pokemon = opponentPokemon.effectedPokemon if (facedFainted) { @@ -270,7 +284,8 @@ open class PokemonBattle( else -> continue } val experience = Cobblemon.experienceCalculator.calculate(opponentPokemon, faintedPokemon, multiplier) - if (experience > 0 && actor.pokemonList.all { it.health <= 0 }) { + val enemyTeamWiped = actor.pokemonList.all { it.health <= 0 } + if (experience > 0 && (enemyTeamWiped || awardOnLoss)) { opponent.awardExperience(opponentPokemon, experience) } Cobblemon.evYieldCalculator.calculate(opponentPokemon, faintedPokemon).forEach { (stat, amount) -> diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/battles/interpreter/instructions/FaintInstruction.kt b/common/src/main/kotlin/com/cobblemon/mod/common/battles/interpreter/instructions/FaintInstruction.kt index 5ecad11776..6ba0ef00e7 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/battles/interpreter/instructions/FaintInstruction.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/battles/interpreter/instructions/FaintInstruction.kt @@ -51,6 +51,7 @@ class FaintInstruction(battle: PokemonBattle, val message: BattleMessage) : Inte preamble.thenAccept { faintingPokemon.effectedPokemon.currentHealth = 0 + faintingPokemon.faintedAt = battle.faintCounter++ faintingPokemon.sendUpdate() CobblemonEvents.BATTLE_FAINTED.post(BattleFaintedEvent(battle, pokemon, context, pnx)) battle.getActorAndActiveSlotFromPNX(pnx).second.battlePokemon = null diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/battles/pokemon/BattlePokemon.kt b/common/src/main/kotlin/com/cobblemon/mod/common/battles/pokemon/BattlePokemon.kt index 05c0ae285f..cc50470ad7 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/battles/pokemon/BattlePokemon.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/battles/pokemon/BattlePokemon.kt @@ -110,6 +110,9 @@ open class BattlePokemon( /** A set of all the BattlePokemon that they faced during the battle (for exp purposes) */ val facedOpponents = mutableSetOf() + /** The faint sequence number within the battle, or null if this pokemon has not fainted. */ + var faintedAt: Int? = null + /** * The [HeldItemManager] backing this [BattlePokemon]. */ diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/config/CobblemonConfig.kt b/common/src/main/kotlin/com/cobblemon/mod/common/config/CobblemonConfig.kt index d5b1476244..c0db6fa7ed 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/config/CobblemonConfig.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/config/CobblemonConfig.kt @@ -146,6 +146,12 @@ class CobblemonConfig { @CobblemonConfigField(Category.Battles, lang = "experience_share_multiplier", SERVER) var experienceShareMultiplier = .5 + @CobblemonConfigField(Category.Battles, lang = "award_experience_to_fainted_pokemon", SERVER) + var awardExperienceToFaintedPokemon = false + + @CobblemonConfigField(Category.Battles, lang = "award_experience_on_battle_loss", SERVER) + var awardExperienceOnBattleLoss = false + @CobblemonConfigField(Category.Battles, lang = "lucky_egg_multiplier", SERVER) var luckyEggMultiplier = 1.5 diff --git a/common/src/main/resources/assets/cobblemon/lang/en_us.json b/common/src/main/resources/assets/cobblemon/lang/en_us.json index 14c613bfdf..7da98ac3ef 100644 --- a/common/src/main/resources/assets/cobblemon/lang/en_us.json +++ b/common/src/main/resources/assets/cobblemon/lang/en_us.json @@ -2494,6 +2494,10 @@ "cobblemon.config.ui.allow_experience_from_pvp.tooltip": "Whether to allow Exp. gain from PvP battles.", "cobblemon.config.ui.experience_share_multiplier": "Experience Share Multiplier", "cobblemon.config.ui.experience_share_multiplier.tooltip": "Multiplier of how much of the total Exp is given to a Pokémon holding an Exp. Share.", + "cobblemon.config.ui.award_experience_to_fainted_pokemon": "Award Exp. to Fainted Pokémon", + "cobblemon.config.ui.award_experience_to_fainted_pokemon.tooltip": "Whether fainted Pokémon receive Exp. for opponents they helped defeat before fainting.", + "cobblemon.config.ui.award_experience_on_battle_loss": "Award Exp. on Battle Loss", + "cobblemon.config.ui.award_experience_on_battle_loss.tooltip": "Whether Pokémon receive Exp. for opponents they defeated even if the battle is lost. Requires 'Award Exp. to Fainted Pokémon' to be enabled for fainted Pokémon to benefit.", "cobblemon.config.ui.lucky_egg_multiplier": "Lucky Egg Multiplier", "cobblemon.config.ui.lucky_egg_multiplier.tooltip": "Multiplier of how much of the total Exp is given to a Pokémon holding a Lucky Egg.", "cobblemon.config.ui.allow_spectating": "Allow Spectating",