mirror of
https://gitlab.com/cable-mc/cobblemon.git
synced 2026-11-25 01:28:54 -05:00
Implemented action-effect driven temporary form reversion and custom Schedulables in action effects
This commit is contained in:
1 parent
bbb692f521
commit
e850253d88
21 files changed
+164
-79
No files matched your search
+25
-1
@@ -10,8 +10,12 @@ package com.cobblemon.mod.common.api.moves.animations
|
||||
|
||||
import com.bedrockk.molang.runtime.MoLangRuntime
|
||||
import com.cobblemon.mod.common.api.molang.ExpressionLike
|
||||
import com.cobblemon.mod.common.api.molang.MoLangFunctions.addStandardFunctions
|
||||
import com.cobblemon.mod.common.api.moves.animations.keyframes.ActionEffectKeyframe
|
||||
import com.cobblemon.mod.common.api.scheduling.Schedulable
|
||||
import com.cobblemon.mod.common.api.scheduling.ServerTaskTracker
|
||||
import com.cobblemon.mod.common.entity.npc.NPCEntity
|
||||
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||
import com.cobblemon.mod.common.util.asExpressionLike
|
||||
import com.cobblemon.mod.common.util.resolveBoolean
|
||||
import java.util.concurrent.CompletableFuture
|
||||
@@ -76,8 +80,28 @@ class ActionEffectContext(
|
||||
var interrupted: Boolean = false,
|
||||
var currentKeyframes: MutableList<ActionEffectKeyframe> = mutableListOf(),
|
||||
var level: Level? = null,
|
||||
var holdRemovalCallbacks: MutableMap<String, () -> Unit> = mutableMapOf()
|
||||
var holdRemovalCallbacks: MutableMap<String, () -> Unit> = mutableMapOf(),
|
||||
var tracker: Schedulable = ServerTaskTracker
|
||||
) {
|
||||
companion object {
|
||||
fun fromPokemonEntity(
|
||||
actionEffect: ActionEffectTimeline,
|
||||
pokemonEntity: PokemonEntity,
|
||||
runtime: MoLangRuntime = MoLangRuntime().also { it.environment.query.addStandardFunctions() },
|
||||
holds: Collection<String> = emptySet(),
|
||||
holdRemovalCallbacks: Map<String, () -> Unit> = emptyMap()
|
||||
): ActionEffectContext {
|
||||
return ActionEffectContext(
|
||||
actionEffect = actionEffect,
|
||||
providers = mutableListOf(UsersProvider(listOf(pokemonEntity))),
|
||||
holdRemovalCallbacks = holdRemovalCallbacks.toMutableMap(),
|
||||
holds = holds.toMutableSet(),
|
||||
runtime = runtime,
|
||||
level = pokemonEntity.level()
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
lateinit var future: CompletableFuture<Unit>
|
||||
inline fun <reified T> findOneProvider() = providers.filterIsInstance<T>().firstOrNull()
|
||||
|
||||
|
||||
+1
-1
@@ -49,6 +49,6 @@ class AnimationActionEffectKeyframe : ConditionalActionEffectKeyframe(), EntityC
|
||||
players.forEach { it.sendPacket(pkt) }
|
||||
}
|
||||
|
||||
return delayedFuture(seconds = delay.resolveFloat(context.runtime))
|
||||
return delayedFuture(seconds = delay.resolveFloat(context.runtime), tracker = context.tracker)
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -46,6 +46,6 @@ class EntityMoLangActionEffectKeyframe : ConditionalActionEffectKeyframe(), Enti
|
||||
players.forEach { it.sendPacket(pkt) }
|
||||
}
|
||||
|
||||
return delayedFuture(seconds = delay.resolveFloat(context.runtime))
|
||||
return delayedFuture(seconds = delay.resolveFloat(context.runtime), context.tracker)
|
||||
}
|
||||
}
|
||||
+1
-2
@@ -18,7 +18,6 @@ import com.cobblemon.mod.common.entity.PosableEntity
|
||||
import com.cobblemon.mod.common.net.messages.client.effect.SpawnSnowstormEntityParticlePacket
|
||||
import com.cobblemon.mod.common.util.asExpressionLike
|
||||
import com.cobblemon.mod.common.util.asIdentifierDefaultingNamespace
|
||||
import net.minecraft.commands.arguments.EntityArgument.getPlayers
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import net.minecraft.server.level.ServerLevel
|
||||
|
||||
@@ -79,6 +78,6 @@ class EntityParticlesActionEffectKeyframe : ConditionalActionEffectKeyframe(), E
|
||||
}
|
||||
}
|
||||
|
||||
return delayedFuture(seconds = delay.resolveFloat(context.runtime))
|
||||
return delayedFuture(seconds = delay.resolveFloat(context.runtime), context.tracker)
|
||||
}
|
||||
}
|
||||
+2
-2
@@ -15,8 +15,8 @@ import com.cobblemon.mod.common.api.moves.animations.UsersProvider
|
||||
import com.cobblemon.mod.common.api.scheduling.delayedFuture
|
||||
import com.cobblemon.mod.common.util.asExpressionLike
|
||||
import com.cobblemon.mod.common.util.asIdentifierDefaultingNamespace
|
||||
import net.minecraft.core.registries.Registries
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import net.minecraft.core.registries.Registries
|
||||
|
||||
/**
|
||||
* An action effect keyframe that plays a positioned sound for all matching entities.
|
||||
@@ -45,6 +45,6 @@ class EntitySoundActionEffectKeyframe : ConditionalActionEffectKeyframe(), Entit
|
||||
entity.playSound(soundEvent, 1f, 1f)
|
||||
}
|
||||
|
||||
return delayedFuture(seconds = delay.resolveFloat(context.runtime))
|
||||
return delayedFuture(seconds = delay.resolveFloat(context.runtime), context.tracker)
|
||||
}
|
||||
}
|
||||
+1
-3
@@ -8,8 +8,6 @@
|
||||
|
||||
package com.cobblemon.mod.common.api.moves.animations.keyframes
|
||||
|
||||
import com.bedrockk.molang.runtime.struct.QueryStruct
|
||||
import com.cobblemon.mod.common.Cobblemon
|
||||
import com.cobblemon.mod.common.api.molang.ExpressionLike
|
||||
import com.cobblemon.mod.common.api.moves.animations.ActionEffectContext
|
||||
import com.cobblemon.mod.common.api.scheduling.delayedFuture
|
||||
@@ -27,6 +25,6 @@ class MoLangActionEffectKeyframe : ActionEffectKeyframe {
|
||||
val delay: ExpressionLike = "0".asExpressionLike()
|
||||
override fun play(context: ActionEffectContext): CompletableFuture<Unit> {
|
||||
expressions.resolve(context.runtime)
|
||||
return delayedFuture(seconds = delay.resolveFloat(context.runtime))
|
||||
return delayedFuture(seconds = delay.resolveFloat(context.runtime), context.tracker)
|
||||
}
|
||||
}
|
||||
+1
-2
@@ -13,7 +13,6 @@ import com.cobblemon.mod.common.api.moves.animations.ActionEffectTimeline
|
||||
import com.cobblemon.mod.common.api.moves.animations.ActionEffects
|
||||
import com.cobblemon.mod.common.api.moves.animations.TargetsProvider
|
||||
import com.cobblemon.mod.common.api.moves.animations.UsersProvider
|
||||
import com.cobblemon.mod.common.api.scheduling.afterOnServer
|
||||
import com.cobblemon.mod.common.entity.ai.OmniPathNavigation.NavigationContext
|
||||
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||
import com.cobblemon.mod.common.util.asExpressionLike
|
||||
@@ -61,7 +60,7 @@ class MoveToTargetActionEffectKeyframe : ActionEffectKeyframe {
|
||||
}
|
||||
)
|
||||
|
||||
afterOnServer(seconds = timeout.resolveFloat(context.runtime)) {
|
||||
context.tracker.after(seconds = timeout.resolveFloat(context.runtime)) {
|
||||
if (!future.isDone && !timedOut) {
|
||||
timedOut = true
|
||||
timeoutEffect.run(context).thenApply { future.complete(Unit) }
|
||||
|
||||
+1
-1
@@ -14,5 +14,5 @@ import com.cobblemon.mod.common.util.asExpressionLike
|
||||
|
||||
class PauseActionEffectKeyframe : ConditionalActionEffectKeyframe() {
|
||||
val pause = "1".asExpressionLike()
|
||||
override fun playWhenTrue(context: ActionEffectContext) = delayedFuture(seconds = pause.resolveFloat(context.runtime))
|
||||
override fun playWhenTrue(context: ActionEffectContext) = delayedFuture(seconds = pause.resolveFloat(context.runtime), context.tracker)
|
||||
}
|
||||
+2
-3
@@ -13,13 +13,12 @@ import com.cobblemon.mod.common.api.moves.animations.ActionEffectContext
|
||||
import com.cobblemon.mod.common.api.moves.animations.ActionEffectTimeline
|
||||
import com.cobblemon.mod.common.api.moves.animations.ActionEffects
|
||||
import com.cobblemon.mod.common.api.moves.animations.UsersProvider
|
||||
import com.cobblemon.mod.common.api.scheduling.after
|
||||
import com.cobblemon.mod.common.entity.ai.OmniPathNavigation.NavigationContext
|
||||
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
|
||||
import com.cobblemon.mod.common.util.asExpressionLike
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import net.minecraft.resources.ResourceLocation
|
||||
import net.minecraft.world.phys.Vec3
|
||||
import java.util.concurrent.CompletableFuture
|
||||
|
||||
class ReturnToPositionActionEffectKeyframe : ActionEffectKeyframe {
|
||||
val speed = 1F
|
||||
@@ -56,7 +55,7 @@ class ReturnToPositionActionEffectKeyframe : ActionEffectKeyframe {
|
||||
}
|
||||
)
|
||||
|
||||
after(seconds = timeout.resolveFloat(context.runtime)) {
|
||||
context.tracker.after(seconds = timeout.resolveFloat(context.runtime)) {
|
||||
if (!future.isDone && !timedOut) {
|
||||
timedOut = true
|
||||
timeoutEffect.run(context).thenApply { future.complete(Unit) }
|
||||
|
||||
-8
@@ -39,14 +39,6 @@ interface TransformationController<T : TransformationLike> : MutableSet<T> {
|
||||
*/
|
||||
fun canStart(): Boolean
|
||||
|
||||
/**
|
||||
* Validates the [TransformationLike] currently active for this controller's [pokemon] and determines whether it can be
|
||||
* reverted and if the pokemon is capable of reverting right now.
|
||||
*
|
||||
* @return whether the transformation can be reverted.
|
||||
*/
|
||||
fun canRevert(): Boolean
|
||||
|
||||
/**
|
||||
* Retrieves the [TransformationLike] in this controller that matches the provided id.
|
||||
*
|
||||
|
||||
+2
-4
@@ -9,8 +9,6 @@
|
||||
package com.cobblemon.mod.common.api.scheduling
|
||||
|
||||
import java.util.concurrent.CompletableFuture
|
||||
import com.cobblemon.mod.common.util.runOnServer
|
||||
import net.minecraft.world.TickRateManager
|
||||
import net.minecraft.world.level.Level
|
||||
|
||||
@Deprecated("Use afterOnServer or afterOnClient; ambiguous side is not good for your health")
|
||||
@@ -52,9 +50,9 @@ fun lerpOnServer(seconds: Float = 0F, action: (Float) -> Unit) = ServerTaskTrack
|
||||
fun lerpOnClient(seconds: Float = 0F, action: (Float) -> Unit) = ClientTaskTracker.lerp(seconds = seconds, action = action)
|
||||
fun taskBuilder() = ScheduledTask.Builder()
|
||||
|
||||
fun delayedFuture(seconds: Float): CompletableFuture<Unit> {
|
||||
fun delayedFuture(seconds: Float, tracker: Schedulable = ServerTaskTracker): CompletableFuture<Unit> {
|
||||
val future = CompletableFuture<Unit>()
|
||||
afterOnServer(seconds = seconds) {
|
||||
tracker.after(seconds = seconds) {
|
||||
future.complete(Unit)
|
||||
}
|
||||
return future
|
||||
|
||||
+16
-3
@@ -12,6 +12,7 @@ import com.cobblemon.mod.common.Cobblemon
|
||||
import com.cobblemon.mod.common.advancement.CobblemonCriteria
|
||||
import com.cobblemon.mod.common.api.events.CobblemonEvents
|
||||
import com.cobblemon.mod.common.api.events.pokemon.PokemonGainedEvent
|
||||
import com.cobblemon.mod.common.api.moves.animations.ActionEffectContext
|
||||
import com.cobblemon.mod.common.api.pokemon.feature.TickingSpeciesFeature
|
||||
import com.cobblemon.mod.common.api.pokemon.transformation.trigger.PassiveTrigger
|
||||
import com.cobblemon.mod.common.api.storage.pc.PCStore
|
||||
@@ -22,6 +23,7 @@ import com.cobblemon.mod.common.pokemon.activestate.ShoulderedState
|
||||
import com.cobblemon.mod.common.pokemon.transformation.form.TemporaryForm
|
||||
import com.cobblemon.mod.common.util.DataKeys
|
||||
import com.cobblemon.mod.common.util.getPlayer
|
||||
import com.cobblemon.mod.common.util.isBusy
|
||||
import com.cobblemon.mod.common.util.isPokemonEntity
|
||||
import com.cobblemon.mod.common.util.lang
|
||||
import com.cobblemon.mod.common.util.server
|
||||
@@ -152,9 +154,20 @@ open class PlayerPartyStore(
|
||||
|
||||
// Reevaluate active form
|
||||
val form = pokemon.form
|
||||
if (form is TemporaryForm && !form.reevaluate(pokemon)) {
|
||||
form.revert(pokemon)
|
||||
} // TODO check locks?
|
||||
if (form is TemporaryForm && !form.reevaluate(pokemon) && !player.isBusy() && pokemon.entity?.isBusy != true) {
|
||||
val entity = pokemon.entity
|
||||
if (entity == null) {
|
||||
form.revert(pokemon)
|
||||
} else {
|
||||
form.performRevert(
|
||||
pokemonEntity = entity,
|
||||
context =ActionEffectContext.fromPokemonEntity(
|
||||
actionEffect = form.revertActionEffect,
|
||||
pokemonEntity = entity
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// Reevaluate transformation requirements and remove invalid transformations from the controller
|
||||
pokemon.formProxy.server().reevaluate()
|
||||
|
||||
+29
-20
@@ -14,7 +14,6 @@ import com.cobblemon.mod.common.api.battles.model.PokemonBattle
|
||||
import com.cobblemon.mod.common.api.events.CobblemonEvents
|
||||
import com.cobblemon.mod.common.api.events.battles.instruction.FormeChangeEvent
|
||||
import com.cobblemon.mod.common.api.moves.animations.ActionEffectContext
|
||||
import com.cobblemon.mod.common.api.moves.animations.UsersProvider
|
||||
import com.cobblemon.mod.common.battles.ShowdownInterpreter
|
||||
import com.cobblemon.mod.common.battles.dispatch.ActionEffectInstruction
|
||||
import com.cobblemon.mod.common.battles.dispatch.GO
|
||||
@@ -64,26 +63,36 @@ class FormChangeInstruction(val message: BattleMessage): ActionEffectInstruction
|
||||
|
||||
override fun runActionEffect(battle: PokemonBattle, runtime: MoLangRuntime) {
|
||||
battle.dispatch {
|
||||
if (form is TemporaryForm) {
|
||||
val actionEffect = (form as TemporaryForm).actionEffect
|
||||
val providers = mutableListOf<Any>(battle)
|
||||
val pokemon = message.battlePokemon(0, battle) ?: return@dispatch GO
|
||||
pokemon.effectedPokemon.entity?.let { UsersProvider(it) }?.let(providers::add)
|
||||
val context = ActionEffectContext(
|
||||
actionEffect = actionEffect,
|
||||
runtime = runtime,
|
||||
providers = providers,
|
||||
level = battle.players.firstOrNull()?.level()
|
||||
)
|
||||
(form as TemporaryForm).perform(battlePokemon.effectedPokemon.entity!!, context)
|
||||
UntilDispatch { context.future.isDone }
|
||||
} else {
|
||||
val form = battlePokemon.effectedPokemon.form
|
||||
if (form is TemporaryForm) {
|
||||
form.revert(battlePokemon.effectedPokemon)
|
||||
}
|
||||
val entity = battlePokemon.effectedPokemon.entity
|
||||
val currentForm = battlePokemon.effectedPokemon.form
|
||||
if (entity == null) {
|
||||
battlePokemon.effectedPokemon.form = form
|
||||
return@dispatch GO
|
||||
}
|
||||
return@dispatch GO
|
||||
|
||||
val form = form
|
||||
val actionEffect = if (form is TemporaryForm) {
|
||||
form.actionEffect
|
||||
} else if (currentForm is TemporaryForm) {
|
||||
currentForm.revertActionEffect
|
||||
} else {
|
||||
battlePokemon.effectedPokemon.form = form
|
||||
return@dispatch GO // This should never happen tbh
|
||||
}
|
||||
|
||||
val context = ActionEffectContext.fromPokemonEntity(
|
||||
actionEffect = actionEffect,
|
||||
runtime = runtime,
|
||||
pokemonEntity = entity
|
||||
)
|
||||
|
||||
if (form is TemporaryForm) {
|
||||
form.perform(entity, context)
|
||||
} else {
|
||||
(currentForm as TemporaryForm).performRevert(entity, context)
|
||||
}
|
||||
|
||||
return@dispatch UntilDispatch { context.future.isDone }
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -23,7 +23,6 @@ import com.cobblemon.mod.common.client.render.drawScaledText
|
||||
import com.cobblemon.mod.common.client.render.models.blockbench.FloatingState
|
||||
import com.cobblemon.mod.common.pokemon.FormData
|
||||
import com.cobblemon.mod.common.pokemon.Pokemon
|
||||
import com.cobblemon.mod.common.pokemon.transformation.controller.ClientTransformationController
|
||||
import com.cobblemon.mod.common.pokemon.transformation.proxies.TransformationProxy
|
||||
import com.cobblemon.mod.common.util.cobblemonResource
|
||||
import com.cobblemon.mod.common.util.math.fromEulerXYZDegrees
|
||||
@@ -87,7 +86,7 @@ abstract class EvolutionSelectScreen<C : TransformationDisplay, S : Transformati
|
||||
clickAction = {
|
||||
Minecraft.getInstance().player?.clientSideCloseContainer()
|
||||
playSound(CobblemonSounds.GUI_CLICK)
|
||||
val controller = getProxy(pokemon).client() as ClientTransformationController
|
||||
val controller = getProxy(pokemon).client()
|
||||
if (controller.canStart(this.display)) {
|
||||
CobblemonNetwork.sendToServer(controller.acceptPacket(this.pokemon, this.display))
|
||||
}
|
||||
|
||||
+10
-3
@@ -8,19 +8,26 @@
|
||||
|
||||
package com.cobblemon.mod.common.net.serverhandling
|
||||
|
||||
import com.cobblemon.mod.common.api.moves.animations.ActionEffectContext
|
||||
import com.cobblemon.mod.common.api.net.ServerNetworkPacketHandler
|
||||
import com.cobblemon.mod.common.net.messages.server.pokemon.update.form.RevertFormPacket
|
||||
import com.cobblemon.mod.common.pokemon.transformation.form.TemporaryForm
|
||||
import com.cobblemon.mod.common.util.isBusy
|
||||
import com.cobblemon.mod.common.util.party
|
||||
import net.minecraft.server.MinecraftServer
|
||||
import net.minecraft.server.level.ServerPlayer
|
||||
|
||||
object RevertFormHandler : ServerNetworkPacketHandler<RevertFormPacket> {
|
||||
override fun handle(packet: RevertFormPacket, server: MinecraftServer, player: ServerPlayer) {
|
||||
val pokemon = player.party().get(packet.pokemonUUID) ?: return
|
||||
val pokemon = player.party()[packet.pokemonUUID] ?: return
|
||||
val form = pokemon.form
|
||||
if (form is TemporaryForm) {
|
||||
form.revert(pokemon)
|
||||
if (form is TemporaryForm && form.toggleable && !pokemon.isBusy() && !player.isBusy()) {
|
||||
val entity = pokemon.entity
|
||||
if (entity != null) {
|
||||
form.performRevert(pokemonEntity = entity, context = ActionEffectContext.fromPokemonEntity(actionEffect = form.revertActionEffect, pokemonEntity = entity))
|
||||
} else {
|
||||
form.revert(pokemon)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+10
@@ -10,6 +10,7 @@ package com.cobblemon.mod.common.pokemon.transformation.controller
|
||||
|
||||
import com.cobblemon.mod.common.api.net.NetworkPacket
|
||||
import com.cobblemon.mod.common.api.pokemon.transformation.TransformationDisplay
|
||||
import com.cobblemon.mod.common.api.pokemon.transformation.TransformationLike
|
||||
import com.cobblemon.mod.common.api.pokemon.transformation.controller.TransformationController
|
||||
import com.cobblemon.mod.common.client.CobblemonClient
|
||||
import com.cobblemon.mod.common.pokemon.Pokemon
|
||||
@@ -44,6 +45,15 @@ abstract class ClientTransformationController<T : TransformationDisplay>(
|
||||
this.canStart() &&
|
||||
this.any { it === transformation }
|
||||
|
||||
|
||||
/**
|
||||
* Validates the [TransformationLike] currently active for this controller's [pokemon] and determines whether it can be
|
||||
* reverted and if the pokemon is capable of reverting right now.
|
||||
*
|
||||
* @return whether the transformation can be reverted.
|
||||
*/
|
||||
abstract fun canRevert(): Boolean
|
||||
|
||||
// FROM MutableSet ------------------------------------------------------------------------------------------------
|
||||
|
||||
override fun add(element: T): Boolean {
|
||||
|
||||
-1
@@ -37,7 +37,6 @@ class ServerEvolutionController(
|
||||
override fun addPacket(transformation: Evolution) = AddEvolutionPacket(this.pokemon, transformation)
|
||||
override fun clearPacket() = ClearEvolutionsPacket { this.pokemon }
|
||||
override fun removePacket(transformation: Evolution) = RemoveEvolutionPacket(this.pokemon, transformation)
|
||||
override fun canRevert() = false // TODO evolutions are currently one-way, but modders may appreciate reversion support
|
||||
override fun isDuplicate(element: Evolution) = this.find { element.result.matches(it.result) } != null
|
||||
|
||||
override fun start(transformation: Evolution) {
|
||||
|
||||
-1
@@ -38,7 +38,6 @@ class ServerFormController(
|
||||
override fun clearPacket() = ClearFormsPacket { this.pokemon }
|
||||
override fun removePacket(transformation: TemporaryForm) = RemoveFormPacket(this.pokemon, transformation)
|
||||
override fun isDuplicate(element: TemporaryForm) = this.find { it.name == element.name } != null
|
||||
override fun canRevert(): Boolean = pokemon.form is TemporaryForm && (pokemon.form as TemporaryForm).toggleable
|
||||
|
||||
override fun start(transformation: TemporaryForm) {
|
||||
if (!canStart(transformation)) return
|
||||
|
||||
+27
-21
@@ -8,16 +8,13 @@
|
||||
|
||||
package com.cobblemon.mod.common.pokemon.transformation.form
|
||||
|
||||
import com.bedrockk.molang.runtime.MoLangRuntime
|
||||
import com.cobblemon.mod.common.api.events.CobblemonEvents
|
||||
import com.cobblemon.mod.common.api.events.pokemon.form.FormCompleteEvent
|
||||
import com.cobblemon.mod.common.api.events.pokemon.form.FormDisplayEvent
|
||||
import com.cobblemon.mod.common.api.events.pokemon.form.FormTestedEvent
|
||||
import com.cobblemon.mod.common.api.molang.MoLangFunctions.addStandardFunctions
|
||||
import com.cobblemon.mod.common.api.moves.animations.ActionEffectContext
|
||||
import com.cobblemon.mod.common.api.moves.animations.ActionEffectTimeline
|
||||
import com.cobblemon.mod.common.api.moves.animations.ActionEffects
|
||||
import com.cobblemon.mod.common.api.moves.animations.UsersProvider
|
||||
import com.cobblemon.mod.common.api.pokemon.PokemonSpecies
|
||||
import com.cobblemon.mod.common.api.pokemon.transformation.Transformation
|
||||
import com.cobblemon.mod.common.api.pokemon.transformation.evolution.PreEvolution
|
||||
@@ -72,7 +69,10 @@ open class TemporaryForm (
|
||||
?: ActionEffects.actionEffects["generic_form".asIdentifierDefaultingNamespace()]
|
||||
?: throw Exception()
|
||||
|
||||
|
||||
val revertActionEffect: ActionEffectTimeline
|
||||
get() = ActionEffects.actionEffects[actionEffectIdentifier?.withPath { "revert" } ?: cobblemonResource("form_${name.lowercase()}_revert")]
|
||||
?: ActionEffects.actionEffects["generic_form_revert".asIdentifierDefaultingNamespace()]
|
||||
?: throw Exception()
|
||||
|
||||
/* Temporary forms DO NOT have their own preevo/evolutions/forms and have to fallback on the parent. Because parentForm
|
||||
is not initialized until AFTER species registration, none of these properties are safe to access until [PokemonSpecies.observable] */
|
||||
@@ -138,42 +138,48 @@ open class TemporaryForm (
|
||||
pokemon.recall()
|
||||
}
|
||||
|
||||
val pokemonEntity = pokemon.entity
|
||||
if (pokemonEntity != null) {
|
||||
val runtime = MoLangRuntime()
|
||||
runtime.environment.query.addStandardFunctions()
|
||||
val providers: MutableList<Any> = mutableListOf(UsersProvider(pokemonEntity))
|
||||
val context = ActionEffectContext(
|
||||
actionEffect = actionEffect,
|
||||
runtime = runtime,
|
||||
providers = providers,
|
||||
level = pokemonEntity.level()
|
||||
)
|
||||
this.perform(pokemonEntity, context)
|
||||
} else {
|
||||
val pokemonEntity = pokemon.entity ?: run {
|
||||
pokemon.form = this
|
||||
fulfill(pokemon)
|
||||
return
|
||||
}
|
||||
|
||||
val context = ActionEffectContext.fromPokemonEntity(
|
||||
actionEffect = actionEffect,
|
||||
pokemonEntity = pokemonEntity
|
||||
)
|
||||
|
||||
this.perform(pokemonEntity, context)
|
||||
}
|
||||
|
||||
override fun fulfill(pokemon: Pokemon) {
|
||||
super.fulfill(pokemon)
|
||||
pokemon.form = this
|
||||
pokemon.entity?.entityData?.set(PokemonEntity.TRANSFORMATION_STARTED, false)
|
||||
CobblemonEvents.FORM_COMPLETE.post(FormCompleteEvent(pokemon, this))
|
||||
}
|
||||
|
||||
fun perform(pokemonEntity: PokemonEntity, context: ActionEffectContext) {
|
||||
private fun doActionEffect(pokemonEntity: PokemonEntity, context: ActionEffectContext, afterAction: () -> Unit) {
|
||||
context.tracker = pokemonEntity // Bind all of this to an entity so recalling the entity just kills all of this
|
||||
pokemonEntity.entityData.set(PokemonEntity.TRANSFORMATION_STARTED, true)
|
||||
val finishTransformation: () -> Unit = {
|
||||
if (pokemonEntity.isTransforming) {
|
||||
fulfill(pokemonEntity.pokemon)
|
||||
afterAction()
|
||||
pokemonEntity.entityData.set(PokemonEntity.TRANSFORMATION_STARTED, false)
|
||||
}
|
||||
}
|
||||
context.holdRemovalCallbacks["transformation"] = finishTransformation
|
||||
val future = actionEffect.run(context)
|
||||
val future = context.actionEffect.run(context)
|
||||
future.thenRun(finishTransformation)
|
||||
}
|
||||
|
||||
fun perform(pokemonEntity: PokemonEntity, context: ActionEffectContext) {
|
||||
doActionEffect(pokemonEntity, context) { fulfill(pokemonEntity.pokemon) }
|
||||
}
|
||||
|
||||
fun performRevert(pokemonEntity: PokemonEntity, context: ActionEffectContext) {
|
||||
doActionEffect(pokemonEntity, context) { revert(pokemonEntity.pokemon) }
|
||||
}
|
||||
|
||||
fun revert(pokemon: Pokemon) {
|
||||
if (toggleable) {
|
||||
pokemon.form = parentForm
|
||||
|
||||
+26
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"timeline": [
|
||||
{
|
||||
"type": "add_holds",
|
||||
"holds": ["transformation"]
|
||||
},
|
||||
{
|
||||
"type": "entity_particles",
|
||||
"effect": "cobblemon:statdown_actor",
|
||||
"delay": 0.1,
|
||||
"locators": ["root"]
|
||||
},
|
||||
{
|
||||
"type": "pause",
|
||||
"pause": 1.0
|
||||
},
|
||||
{
|
||||
"type": "remove_holds",
|
||||
"holds": ["transformation"]
|
||||
},
|
||||
{
|
||||
"type": "pause",
|
||||
"pause": 2.0
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"timeline": [
|
||||
{
|
||||
"type": "remove_holds",
|
||||
"holds": ["transformation"]
|
||||
}
|
||||
]
|
||||
}
|
||||
Reference in new issue
Block a user