From fc78d64f62fd79d1ebdc8e7725485e7efd2774ff Mon Sep 17 00:00:00 2001 From: Segfault Guy Date: Wed, 5 Apr 2023 00:45:19 -0400 Subject: [PATCH] Add handlers for |-sidestart|, |-sideend|, and |-fieldactivate| instructions --- .../mod/common/battles/BattleSide.kt | 5 + .../mod/common/battles/ShowdownInterpreter.kt | 119 ++++++++++++++---- .../assets/cobblemon/lang/en_us.json | 48 +++++-- 3 files changed, 132 insertions(+), 40 deletions(-) diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/battles/BattleSide.kt b/common/src/main/kotlin/com/cobblemon/mod/common/battles/BattleSide.kt index 7e3ac99910..ee812ee87c 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/battles/BattleSide.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/battles/BattleSide.kt @@ -10,6 +10,7 @@ package com.cobblemon.mod.common.battles import com.cobblemon.mod.common.api.battles.model.PokemonBattle import com.cobblemon.mod.common.api.battles.model.actor.BattleActor +import net.minecraft.text.Text /** * Unlike the Showdown side.ts, this can represent multiple actors. @@ -23,4 +24,8 @@ class BattleSide(vararg val actors: BattleActor) { lateinit var battle: PokemonBattle fun getOppositeSide() = if (this == battle.side1) battle.side2 else battle.side1 + + fun broadcastChatMessage(component: Text) { + return this.actors.forEach { it.sendMessage(component) } + } } \ No newline at end of file diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/battles/ShowdownInterpreter.kt b/common/src/main/kotlin/com/cobblemon/mod/common/battles/ShowdownInterpreter.kt index 4a2e5739ce..a0dd51fdae 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/battles/ShowdownInterpreter.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/battles/ShowdownInterpreter.kt @@ -55,6 +55,7 @@ import java.util.concurrent.CompletableFuture import kotlin.math.roundToInt import net.minecraft.entity.LivingEntity import net.minecraft.server.world.ServerWorld +import net.minecraft.text.MutableText import net.minecraft.text.Text object ShowdownInterpreter { @@ -62,7 +63,7 @@ object ShowdownInterpreter { private val sideUpdateInstructions = mutableMapOf Unit>() private val splitUpdateInstructions = mutableMapOf Unit>() // Stores a reference to the previous move message in a battle so a minor action can refer back to it (Battle UUID : Move message) - private val lastMover = mutableMapOf() + private val lastMover = mutableMapOf() init { // Note '-cureteam' is a legacy thing that is only used in generation 2 and 4 mods for heal bell and aromatherapy respectively as such we can just ignore that @@ -119,6 +120,9 @@ object ShowdownInterpreter { updateInstructions["|-hitcount|"] = this::handleHitCountInstruction updateInstructions["|-item|"] = this::handleItemInstruction updateInstructions["|-enditem|"] = this::handleEndItemInstruction + updateInstructions["|-sidestart|"] = this::handleSideStartInstructions + updateInstructions["|-sideend|"] = this::handleSideEndInstructions + updateInstructions["|-fieldactivate|"] = this::handleFieldActivateInstructions sideUpdateInstructions["|request|"] = this::handleRequestInstruction splitUpdateInstructions["|switch|"] = this::handleSwitchInstruction @@ -563,8 +567,8 @@ object ShowdownInterpreter { // |move|p1a: Charizard|Tackle|p2a: Magikarp private fun handleMoveInstruction(battle: PokemonBattle, rawMessage: String, remainingLines: MutableList) { battle.dispatchGo { - this.lastMover[battle.battleId] = rawMessage val message = BattleMessage(rawMessage) + this.lastMover[battle.battleId] = message val userPokemon = message.actorAndActivePokemon(0, battle)?.second ?: return@dispatchGo val targetPokemon = message.actorAndActivePokemon(2, battle)?.second @@ -685,9 +689,7 @@ object ShowdownInterpreter { battle.dispatch { battle.broadcastChatMessage(battleLang("crit")) this.lastMover[battle.battleId]?.let { message -> - val editMessaged = message.replace("|move|", "") - val userPNX = editMessaged.split("|")[0].split(":")[0].trim() - val battlePokemon = battle.getActorAndActiveSlotFromPNX(userPNX).second.battlePokemon ?: return@let + val battlePokemon = message.getBattlePokemon(0, battle) ?: return@let battlePokemon.criticalHits++ } GO @@ -746,23 +748,27 @@ object ShowdownInterpreter { } } - private fun handleStartInstructions(battle: PokemonBattle, message: String, remainingLines: MutableList){ - battle.dispatch { - val pnx = message.split("|-start|")[1].substring(0, 3) - val (_, pokemon) = battle.getActorAndActiveSlotFromPNX(pnx) - if (message.contains("|confusion")){ - battle.broadcastChatMessage(battleLang("confusion_start",pokemon.battlePokemon?.getName() ?: "")) + private fun handleStartInstructions(battle: PokemonBattle, rawMessage: String, remainingLines: MutableList){ + battle.dispatchWaiting() { + val message = BattleMessage(rawMessage) + val pokemon = message.getBattlePokemon(0, battle) ?: return@dispatchWaiting + val effect = message.effectAt(1) ?: return@dispatchWaiting + if (message.hasOptionalArgument("silent")) { + LOGGER.debug("Received silent: {}", message.rawMessage) } - if (message.contains("|protect")){ - battle.broadcastChatMessage(battleLang("protect_start",pokemon.battlePokemon?.getName() ?: "")) + else { + val lang = when (effect.id) { + "confusion" -> battleLang("start.confusion", pokemon.getName()) + "protect" -> battleLang("start.protect", pokemon.getName()) + "bide" -> battleLang("start.bide", pokemon.getName()) + "yawn" -> battleLang("start.yawn", pokemon.getName()) + // ignore 3 to prevent clutter (-fieldactivate already announces perish) + "perish3" -> return@dispatchWaiting + "perish2", "perish1", "perish0" -> battleLang("start.perish_count", pokemon.getName(), effect.id.last().digitToInt()) + else -> battle.createUnimplemented(message) + } + battle.broadcastChatMessage(lang) } - if (message.contains("move: Bide")){ - battle.broadcastChatMessage(battleLang("bide_start",pokemon.battlePokemon?.getName() ?: "")) - } - if (message.contains("move: Yawn")){ - battle.broadcastChatMessage(battleLang("yawn_start",pokemon.battlePokemon?.getName() ?: "")) - } - WaitDispatch(2F) } } @@ -828,10 +834,10 @@ object ShowdownInterpreter { return@dispatchGo } val lang = when(effect.id) { - "protect" -> battleLang("protect_activate", pokemonName) + "protect" -> battleLang("activate.protect", pokemonName) // Includes a 3rd argument being the magnitude level as a number - "magnitude" -> battleLang("magnitude_level", message.argumentAt(2)?.toIntOrNull() ?: 1) - "bide" -> battleLang("bide_activate", pokemonName) + "magnitude" -> battleLang("activate.magnitude", message.argumentAt(2)?.toIntOrNull() ?: 1) + "bide" -> battleLang("activate.bide", pokemonName) "gravity" -> battleLang("activate.gravity", pokemonName) "focusband" -> battleLang("item.hung_on.end", pokemonName, CobblemonItems.FOCUS_BAND.get().name) "mistyterrain" -> battleLang("activate.misty_terrain", pokemonName) @@ -845,6 +851,8 @@ object ShowdownInterpreter { "guardsplit" -> battleLang("activate.guard_split", pokemonName) "spite" -> battleLang("activate.spite", pokemonName, message.argumentAt(2)!!, message.argumentAt(3)!!) "wrap" -> battleLang("activate.wrap", pokemonName, message.actorAndActivePokemonFromOptional(battle)?.second?.battlePokemon?.getName() ?: return@dispatchGo) + "shedskin" -> battleLang("activate.shed_skin", pokemonName) + "destinybond" -> battleLang("activate.destiny_bond", pokemonName) else -> battle.createUnimplemented(message) } battle.broadcastChatMessage(lang) @@ -901,6 +909,18 @@ object ShowdownInterpreter { } } + private fun handleFieldActivateInstructions(battle: PokemonBattle, rawMessage: String, remainingLines: MutableList){ + battle.dispatchWaiting { + val message = BattleMessage(rawMessage) + val effect = message.effectAt(0) ?: return@dispatchWaiting + val lang = when (effect.id) { + "perishsong" -> battleLang("field_activate.perish_song") + else -> battle.createUnimplemented(message) + } + battle.broadcastChatMessage(lang) + } + } + private fun handleAbilityInstructions(battle: PokemonBattle, rawMessage: String, remainingLines: MutableList) { battle.dispatchGo { val message = BattleMessage(rawMessage) @@ -981,10 +1001,11 @@ object ShowdownInterpreter { } else { val feedback = when (effect.id) { - "confusion" -> battleLang("confusion_snapped", pokemonName) - "bide" -> battleLang("bide_end", pokemonName) - "bind" -> battleLang("end.bide", pokemonName) + "confusion" -> battleLang("end.confusion", pokemonName) + "bide" -> battleLang("end.bide", pokemonName) + "bind" -> battleLang("end.bind", pokemonName) "wrap" -> battleLang("end.wrap", pokemonName) + "yawn" -> lang("status.sleep.apply", pokemonName) else -> battle.createUnimplemented(message) } battle.broadcastChatMessage(feedback) @@ -992,6 +1013,50 @@ object ShowdownInterpreter { } } + private fun handleSideStartInstructions(battle: PokemonBattle, rawMessage: String, remainingLines: MutableList){ + battle.dispatchWaiting { + val message = BattleMessage(rawMessage) + val side = if (message.argumentAt(0)?.get(1) == '1') battle.side1 else battle.side2 + battle.sides.forEach { + val subject = if (it == side) battleLang("side_subject.ally") else battleLang("side_subject.opponent") + val lang = when (message.argumentAt(1)) { + "move: Stealth Rock" -> battleLang("side_start.stealth_rock", subject) + "Spikes" -> battleLang("side_start.spikes", subject) + "move: Toxic Spikes" -> battleLang("side_start.toxic_spikes", subject) + "move: Sticky Web" -> battleLang("side_start.sticky_web", subject) + "move: Reflect" -> battleLang("side_start.reflect", subject) + "move: Light Screen" -> battleLang("side_start.light_screen", subject) + "move: Aurora Veil" -> battleLang("side_start.aurora_veil", subject) + "move: Tailwind" -> battleLang("side_start.tailwind", subject) + else -> battle.createUnimplemented(message) + } + it.broadcastChatMessage(lang) + } + } + } + + private fun handleSideEndInstructions(battle: PokemonBattle, rawMessage: String, remainingLines: MutableList){ + battle.dispatchWaiting { + val message = BattleMessage(rawMessage) + val side = if (message.argumentAt(0)?.get(1) == '1') battle.side1 else battle.side2 + battle.sides.forEach { + val subject = if (it == side) battleLang("side_subject.ally") else battleLang("side_subject.opponent") + val lang = when (message.argumentAt(1)) { + "move: Stealth Rock" -> battleLang("side_end.stealth_rock", subject) + "Spikes" -> battleLang("side_end.spikes", subject) + "move: Toxic Spikes" -> battleLang("side_end.toxic_spikes", subject) + "move: Sticky Web" -> battleLang("side_end.sticky_web", subject) + "move: Reflect" -> battleLang("side_end.reflect", subject) + "move: Light Screen" -> battleLang("side_end.light_screen", subject) + "move: Aurora Veil" -> battleLang("side_end.aurora_veil", subject) + "move: Tailwind" -> battleLang("side_end.tailwind", subject) + else -> battle.createUnimplemented(message) + } + it.broadcastChatMessage(lang) + } + } + } + /** * Format: * |request|REQUEST @@ -1169,7 +1234,7 @@ object ShowdownInterpreter { battle.sendSidedUpdate(actor, BattleHealthChangePacket(pnx, remainingHealth.toFloat()), BattleHealthChangePacket(pnx, newHealthRatio)) if (cause != null) { when (cause) { - "confusion" -> battle.broadcastChatMessage(battleLang("confusion_activate", activePokemon.battlePokemon?.getName()!!)) + "confusion" -> battle.broadcastChatMessage(battleLang("hurt.confusion", activePokemon.battlePokemon?.getName()!!)) } } WaitDispatch(1F) 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 e689577fd7..2e85ebfcee 100644 --- a/common/src/main/resources/assets/cobblemon/lang/en_us.json +++ b/common/src/main/resources/assets/cobblemon/lang/en_us.json @@ -410,7 +410,8 @@ "cobblemon.capture.not_single": "You can only capture wild Pokémon in a 1v1 battle.", "cobblemon.you_in_battle": "You can't do that while in a battle!", "cobblemon.battle.turn": "It is now turn %1$s", - + "cobblemon.battle.side_subject.ally": "your", + "cobblemon.battle.side_subject.opponent": "the opposing", "cobblemon.battle.rain_dance": "It started to rain!", "cobblemon.battle.rain_dance_upkeep": "Rain continues to fall.", @@ -424,16 +425,11 @@ "cobblemon.battle.hail_buffeted": "%1$s was buffeted by hail.", "cobblemon.battle.no_weather": "The weather clears up.", - "cobblemon.battle.confusion_start": "%1$s is confused!", - "cobblemon.battle.confusion_activate": "It hurt itself in confusion!", - "cobblemon.battle.confusion_snapped": "%1$s snapped out of its confusion!", - "cobblemon.battle.protect_start": "%1$s starts protecting itself!", - "cobblemon.battle.protect_activate": "%1$s protected itself!", - "cobblemon.battle.magnitude_level": "Magnitude %1$s!", - "cobblemon.battle.bide_start": "%1$s begins storing energy!", - "cobblemon.battle.bide_activate": "%1$s is storing energy!", - "cobblemon.battle.bide_end": "%1$s unleashed its energy!", - "cobblemon.battle.yawn_start": "%1$s grew drowsy!", + "cobblemon.battle.start.confusion": "%1$s is confused!", + "cobblemon.battle.start.protect": "%1$s starts protecting itself!", + "cobblemon.battle.start.bide": "%1$s begins storing energy!", + "cobblemon.battle.start.yawn": "%1$s grew drowsy!", + "cobblemon.battle.start.perish_count": "%1$s's perish count fell to %2$s.", "cobblemon.battle.field_start.electric_terrain": "An electric current ran across the battlefield!", "cobblemon.battle.field_start.grassy_terrain": "Grass grew to cover the battlefield!", @@ -457,6 +453,26 @@ "cobblemon.battle.field_end.water_sport": "The effects of Water Sport have faded.", "cobblemon.battle.field_end.wonder_room": "Wonder Room wore off, and Defense and Sp. Def stats returned to normal!", + "cobblemon.battle.field_activate.perish_song": "All Pokémon that heard the song will faint in three turns!", + + "cobblemon.battle.side_start.stealth_rock": "Polished stones float in the air around %1$s team!", + "cobblemon.battle.side_start.spikes": "Spikes were scattered on the ground all around %1$s team!", + "cobblemon.battle.side_start.toxic_spikes": "Poison spikes were scattered on the ground all around %1$s team!", + "cobblemon.battle.side_start.sticky_web": "A sticky web has been laid on the ground around %1$s team!", + "cobblemon.battle.side_start.reflect": "Reflect made %1$s team stronger against physical moves!", + "cobblemon.battle.side_start.light_screen": "Light Screen made %1$s team stronger against special moves!", + "cobblemon.battle.side_start.aurora_veil": "Aurora Veil made %1$s team stronger against physical and special moves!", + "cobblemon.battle.side_start.tailwind": "The Tailwind blew from behind %1$s team!", + + "cobblemon.battle.side_end.stealth_rock": "The pointed stones disappeared from around %1$s team!", + "cobblemon.battle.side_end.spikes": "The spikes disappeared from the ground around %1$s team!", + "cobblemon.battle.side_end.toxic_spikes": "The poison spikes disappeared from the ground around %1$s team!", + "cobblemon.battle.side_end.sticky_web": "The sticky web has disappeared from the ground around %1$s team", + "cobblemon.battle.side_end.reflect": "%1$s team's Reflect wore off!", + "cobblemon.battle.side_end.light_screen": "%1$s team's Light Screen wore off!", + "cobblemon.battle.side_end.aurora_veil": "%1$s team's Aurora Veil wore off!", + "cobblemon.battle.side_end.tailwind": "%1$s team's Tailwind petered out!", + "cobblemon.battle.cant.generic_block": "%1$s can't use %2$s!", "cobblemon.battle.cant.truant": "%1$s is loafing around!", "cobblemon.battle.cant.flinched": "%1$s flinched and couldn't move!", @@ -483,6 +499,11 @@ "cobblemon.battle.activate.court_change": "%1$s swapped the battle effects affecting each side of the field!", "cobblemon.battle.activate.guard_split": "%1$s shared its guard with the target!", "cobblemon.battle.activate.spite": "It reduced the PP of %1$s's %2$s by %3$s!", + "cobblemon.battle.activate.shed_skin": "%1$s was cured of its status!", + "cobblemon.battle.activate.bide": "%1$s is storing energy!", + "cobblemon.battle.activate.protect": "%1$s protected itself!", + "cobblemon.battle.activate.magnitude": "Magnitude %1$s!", + "cobblemon.battle.activate.destiny_bond": "%1$s took its attacker down with it!", "cobblemon.battle.prepare.bounce": "%1$s sprang up!", "cobblemon.battle.prepare.dig": "%1$s burrowed its way under the ground!", @@ -528,11 +549,12 @@ "cobblemon.battle.singlemove.rage": "%1$s goes into a rage!", "cobblemon.battle.hurt.wrap": "%1$s was hurt by wrap!", + "cobblemon.battle.hurt.confusion": "It hurt itself in confusion!", "cobblemon.battle.end.bind": "%1$s is no longer being squeezed!", "cobblemon.battle.end.wrap": "%1$s was freed from wrap!", - - + "cobblemon.battle.end.bide": "%1$s unleashed its energy!", + "cobblemon.battle.end.confusion": "%1$s snapped out of its confusion!", "cobblemon.battle.set_hp.pain_split": "The battlers shared their pain!",