mirror of
https://gitlab.com/cable-mc/cobblemon.git
synced 2026-10-24 08:06:24 -04:00
Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ebb429e97 |
@@ -87,6 +87,7 @@ import com.cobblemon.mod.common.config.constraint.IntConstraint
|
||||
import com.cobblemon.mod.common.config.starter.StarterConfig
|
||||
import com.cobblemon.mod.common.data.CobblemonDataProvider
|
||||
import com.cobblemon.mod.common.events.AdvancementHandler
|
||||
import com.cobblemon.mod.common.events.CaptureXpHandler
|
||||
import com.cobblemon.mod.common.events.ServerTickHandler
|
||||
import com.cobblemon.mod.common.item.PokeBallItem
|
||||
import com.cobblemon.mod.common.net.messages.client.settings.ServerSettingsPacket
|
||||
@@ -104,13 +105,7 @@ import com.cobblemon.mod.common.pokemon.properties.tags.PokemonFlagProperty
|
||||
import com.cobblemon.mod.common.pokemon.stat.CobblemonStatProvider
|
||||
import com.cobblemon.mod.common.starter.CobblemonStarterHandler
|
||||
import com.cobblemon.mod.common.trade.TradeManager
|
||||
import com.cobblemon.mod.common.util.DataKeys
|
||||
import com.cobblemon.mod.common.util.cobblemonResource
|
||||
import com.cobblemon.mod.common.util.ifDedicatedServer
|
||||
import com.cobblemon.mod.common.util.isLaterVersion
|
||||
import com.cobblemon.mod.common.util.party
|
||||
import com.cobblemon.mod.common.util.removeAmountIf
|
||||
import com.cobblemon.mod.common.util.server
|
||||
import com.cobblemon.mod.common.util.*
|
||||
import com.cobblemon.mod.common.world.feature.CobblemonPlacedFeatures
|
||||
import com.cobblemon.mod.common.world.feature.ore.CobblemonOrePlacedFeatures
|
||||
import com.cobblemon.mod.common.world.gamerules.CobblemonGameRules
|
||||
@@ -264,6 +259,12 @@ object Cobblemon {
|
||||
event.newFriendship = event.pokemon.friendship + increment.roundToInt()
|
||||
}
|
||||
|
||||
POKEMON_CAPTURED.subscribe { event ->
|
||||
if (event.player.isInBattle()) CaptureXpHandler.handleCaptureInBattle(event) else CaptureXpHandler.handleCaptureOutOfBattle(
|
||||
event
|
||||
)
|
||||
}
|
||||
|
||||
HeldItemProvider.register(CobblemonHeldItemManager, Priority.LOWEST)
|
||||
}
|
||||
|
||||
|
||||
+6
-1
@@ -10,6 +10,7 @@ package com.cobblemon.mod.common.api.pokemon.experience
|
||||
|
||||
import com.cobblemon.mod.common.api.battles.model.PokemonBattle
|
||||
import com.cobblemon.mod.common.battles.pokemon.BattlePokemon
|
||||
import com.cobblemon.mod.common.pokemon.Pokemon
|
||||
import net.minecraft.command.CommandSource
|
||||
import net.minecraft.item.ItemStack
|
||||
import net.minecraft.server.network.ServerPlayerEntity
|
||||
@@ -43,4 +44,8 @@ open class CommandExperienceSource(
|
||||
open class BattleExperienceSource(
|
||||
val battle: PokemonBattle,
|
||||
val facedPokemon: List<BattlePokemon>
|
||||
) : ExperienceSource
|
||||
) : ExperienceSource
|
||||
|
||||
open class CaptureExperienceSource(
|
||||
val capturedPokemon: Pokemon
|
||||
): ExperienceSource
|
||||
@@ -222,4 +222,7 @@ class CobblemonConfig {
|
||||
|
||||
@NodeCategory(Category.Debug)
|
||||
var enableDebugKeys = false
|
||||
|
||||
@NodeCategory(Category.Pokemon)
|
||||
val captureXpMultiplier = 1.0
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
/*
|
||||
* Copyright (C) 2023 Cobblemon Contributors
|
||||
*
|
||||
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||
*/
|
||||
|
||||
package com.cobblemon.mod.common.events
|
||||
|
||||
import com.cobblemon.mod.common.Cobblemon
|
||||
import com.cobblemon.mod.common.Cobblemon.config
|
||||
import com.cobblemon.mod.common.api.events.pokemon.PokemonCapturedEvent
|
||||
import com.cobblemon.mod.common.api.pokemon.experience.CaptureExperienceSource
|
||||
import com.cobblemon.mod.common.api.tags.CobblemonItemTags
|
||||
import com.cobblemon.mod.common.battles.pokemon.BattlePokemon
|
||||
|
||||
object CaptureXpHandler {
|
||||
fun handleCaptureInBattle(event: PokemonCapturedEvent) {
|
||||
val battle = Cobblemon.battleRegistry.getBattleByParticipatingPlayer(event.player) ?: return
|
||||
val caughtBattleMonActor = battle.actors.find { it.uuid == event.pokemon.uuid } ?: return
|
||||
val caughtBattleMon = caughtBattleMonActor.pokemonList.find { it.uuid == event.pokemon.uuid } ?: return
|
||||
|
||||
caughtBattleMonActor.getSide().getOppositeSide().actors.forEach { opponentActor ->
|
||||
opponentActor.pokemonList.filter {
|
||||
it.health > 0 && (caughtBattleMon.facedOpponents.contains(it) || it.effectedPokemon.heldItem()
|
||||
.isIn(CobblemonItemTags.EXPERIENCE_SHARE))
|
||||
}.forEach { opponentMon ->
|
||||
val xpShareOnly = !caughtBattleMon.facedOpponents.contains(opponentMon)
|
||||
val xpShareOnlyModifier =
|
||||
(if (xpShareOnly) config.experienceShareMultiplier else 1).toDouble()
|
||||
val experience = Cobblemon.experienceCalculator.calculate(
|
||||
opponentMon, caughtBattleMon, config.captureXpMultiplier * xpShareOnlyModifier
|
||||
)
|
||||
if (experience > 0) {
|
||||
opponentActor.awardExperience(opponentMon, experience)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun handleCaptureOutOfBattle(event: PokemonCapturedEvent) {
|
||||
val source = CaptureExperienceSource(event.pokemon)
|
||||
val playerParty = Cobblemon.storage.getParty(event.player)
|
||||
val first = playerParty.firstOrNull { it != event.pokemon && it.currentHealth > 0 } ?: return
|
||||
val targetMons = playerParty.filter {
|
||||
it != event.pokemon && it.currentHealth > 0 && (it.uuid == first.uuid || it.heldItem()
|
||||
.isIn(CobblemonItemTags.EXPERIENCE_SHARE))
|
||||
}
|
||||
targetMons.forEach { targetMon ->
|
||||
val xpShareOnly = targetMon.uuid != first.uuid
|
||||
val xpShareOnlyModifier = (if (xpShareOnly) config.experienceShareMultiplier else 1).toDouble()
|
||||
val experience = Cobblemon.experienceCalculator.calculate(
|
||||
BattlePokemon.safeCopyOf(targetMon),
|
||||
BattlePokemon.safeCopyOf(event.pokemon),
|
||||
config.captureXpMultiplier * xpShareOnlyModifier
|
||||
)
|
||||
targetMon.addExperienceWithPlayer(event.player, source, experience)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user