Skip to content

Commit 1952a1b

Browse files
authored
HA Reversion after Mega and Ogerpon Tweaks (#106)
* Fixed Mega causing HA to not revert properly Also tweaked Ogerpon details to support future Tera implementation * Ogerpon ability fixes to enable future tera * Fixed Megas not reverting if not active in battle For loop was exiting early lol facepalm
1 parent 12135e8 commit 1952a1b

5 files changed

Lines changed: 166 additions & 128 deletions

File tree

Lines changed: 144 additions & 122 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,144 @@
1-
package generations.gg.generations.core.generationscore.common.battle
2-
3-
import com.cobblemon.mod.common.api.battles.interpreter.BattleMessage
4-
import com.cobblemon.mod.common.api.battles.model.PokemonBattle
5-
import com.cobblemon.mod.common.api.battles.model.actor.BattleActor
6-
import com.cobblemon.mod.common.api.pokemon.feature.FlagSpeciesFeature
7-
import com.cobblemon.mod.common.api.pokemon.feature.SpeciesFeature
8-
import com.cobblemon.mod.common.api.pokemon.feature.StringSpeciesFeature
9-
import com.cobblemon.mod.common.api.pokemon.feature.SynchronizedSpeciesFeature
10-
import com.cobblemon.mod.common.battles.ShowdownActionRequest
11-
import com.cobblemon.mod.common.battles.ShowdownMoveset
12-
import com.cobblemon.mod.common.battles.pokemon.BattlePokemon
13-
import com.cobblemon.mod.common.pokemon.Pokemon
14-
import com.cobblemon.mod.common.util.cobblemonResource
15-
import com.cobblemon.mod.common.util.hasKeyItem
16-
import com.mojang.datafixers.util.Unit
17-
import generations.gg.generations.core.generationscore.common.util.getProviderOrNull
18-
19-
object GenerationsInstructionProcessor {
20-
@JvmStatic
21-
fun processDetailsChange(battle: PokemonBattle, message: BattleMessage) {
22-
val s1 = message.argumentAt(1) ?: return
23-
val s2 = s1.split(",".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
24-
if (s2.isEmpty()) return
25-
val s3 = s2[0].lowercase().split("-".toRegex(), 2).dropLastWhile { it.isEmpty() }.toTypedArray()
26-
27-
if (s3.size < 2) return
28-
29-
val battlePokemon = message.battlePokemon(0, battle) ?: return
30-
31-
val name = s3[1]
32-
33-
var pair: Pair<String, Any> = when(name) {
34-
"mega" -> "mega" to true
35-
"mega-x" -> "mega_x" to true
36-
"mega-y" -> "mega_y" to true
37-
"sunshine" -> "sunny" to true
38-
"school" -> "schooling" to true
39-
"primal" -> "primal" to true
40-
"ash" -> "ash" to true
41-
"wellspring", "hearthflame", "cornerstone", "teal" -> s3.getOrNull(2)?.takeIf { it == "Tera" }.let { "terastal" to true } ?: null
42-
43-
else -> name to true
44-
} ?: let {
45-
battlePokemon.originalPokemon.removeBattleFeature()
46-
battlePokemon.effectedPokemon.removeBattleFeature()
47-
return
48-
}
49-
50-
pair.let {
51-
when (it.second) {
52-
is String -> it.let { StringSpeciesFeature(it.first, it.second as String) }
53-
is Boolean -> it.let { FlagSpeciesFeature(it.first, it.second as Boolean) }
54-
else -> null
55-
}
56-
}?.let {
57-
battle.dispatchGo {
58-
battlePokemon.entity
59-
battlePokemon.originalPokemon.applyBattleFeature(it)
60-
battlePokemon.effectedPokemon.applyBattleFeature(it)
61-
}
62-
}
63-
64-
65-
// ?.let {
66-
// battle.dispatchGo {
67-
// FlagSpeciesFeature(it, true).also {
68-
// it.apply(battlePokemon.originalPokemon)
69-
// it.apply(battlePokemon.effectedPokemon)
70-
// }
71-
// }
72-
// }
73-
}
74-
75-
@JvmStatic
76-
fun processBattleEnd(battle: PokemonBattle) {
77-
battle.actors.forEach { actor ->
78-
if (!actor.getPlayerUUIDs().iterator().hasNext()) return@forEach
79-
actor.pokemonList.forEach { battlePokemon ->
80-
battlePokemon.originalPokemon.removeBattleFeature()
81-
battlePokemon.effectedPokemon.removeBattleFeature()
82-
83-
// sequenceOf("mega", "mega_x", "mega_y", "primal", "stellar", "terastal", "hero", "hangry", "meteor", "blade", "pirouette", "sunny", "schooling", "ash", "busted").forEach { name ->
84-
// battlePokemon.effectedPokemon.features.removeIf { it.name == name }
85-
// battlePokemon.originalPokemon.features.removeIf { it.name == name }
86-
// }
87-
//
88-
// battlePokemon.effectedPokemon.updateAspects()
89-
}
90-
}
91-
}
92-
93-
94-
}
95-
96-
private fun Pokemon.removeBattleFeature() {
97-
val data = this.persistentData
98-
val name = if(data.contains("form_name")) data.getString("form_name").also { data.remove("form_name") } else return
99-
val value = if(data.contains("form_value")) data.getString("form_value").also { data.remove("form_value") } else null
100-
101-
if(value == null) {
102-
features.removeIf { it.name == name }
103-
} else {
104-
val feature = features.firstOrNull { it.name == name } ?: return
105-
106-
if(feature is StringSpeciesFeature) {
107-
feature.value = value
108-
}
109-
}
110-
111-
updateAspects()
112-
}
113-
114-
private fun Pokemon.applyBattleFeature(feature: SpeciesFeature) {
115-
this.persistentData.putString("form_name", feature.name)
116-
if(feature is StringSpeciesFeature) {
117-
this.persistentData.putString("form_value", feature.value)
118-
feature.apply(this)
119-
} else {
120-
(feature as FlagSpeciesFeature).apply(this)
121-
}
122-
}
1+
package generations.gg.generations.core.generationscore.common.battle
2+
3+
import com.cobblemon.mod.common.api.abilities.Ability
4+
import com.cobblemon.mod.common.api.battles.interpreter.BattleMessage
5+
import com.cobblemon.mod.common.api.battles.model.PokemonBattle
6+
import com.cobblemon.mod.common.api.battles.model.actor.BattleActor
7+
import com.cobblemon.mod.common.api.pokemon.feature.FlagSpeciesFeature
8+
import com.cobblemon.mod.common.api.pokemon.feature.SpeciesFeature
9+
import com.cobblemon.mod.common.api.pokemon.feature.StringSpeciesFeature
10+
import com.cobblemon.mod.common.api.pokemon.feature.SynchronizedSpeciesFeature
11+
import com.cobblemon.mod.common.battles.ShowdownActionRequest
12+
import com.cobblemon.mod.common.battles.ShowdownMoveset
13+
import com.cobblemon.mod.common.battles.pokemon.BattlePokemon
14+
import com.cobblemon.mod.common.pokemon.Pokemon
15+
import com.cobblemon.mod.common.util.cobblemonResource
16+
import com.cobblemon.mod.common.util.hasKeyItem
17+
import com.mojang.datafixers.util.Unit
18+
import generations.gg.generations.core.generationscore.common.util.getProviderOrNull
19+
20+
object GenerationsInstructionProcessor {
21+
private var originalAbility: Ability? = null
22+
23+
@JvmStatic
24+
fun processDetailsChange(battle: PokemonBattle, message: BattleMessage) {
25+
val s1 = message.argumentAt(1) ?: return
26+
val s2 = s1.split(",".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
27+
if (s2.isEmpty()) return
28+
val s3 = s2[0].lowercase().split("-".toRegex(), 2).dropLastWhile { it.isEmpty() }.toTypedArray()
29+
30+
if (s3.size < 2) return
31+
32+
val battlePokemon = message.battlePokemon(0, battle) ?: return
33+
34+
val name = s3[1]
35+
36+
originalAbility = battlePokemon.originalPokemon.ability
37+
38+
var pair: Pair<String, Any> = when(name) {
39+
"mega" -> "mega" to true
40+
"mega-x" -> "mega_x" to true
41+
"mega-y" -> "mega_y" to true
42+
"sunshine" -> "sunny" to true
43+
"school" -> "schooling" to true
44+
"primal" -> "primal" to true
45+
"ash" -> "ash" to true
46+
"wellspring-tera", "hearthflame-tera", "cornerstone-tera", "teal-tera" -> "embody-aspect" to true
47+
48+
else -> name to true
49+
} ?: let {
50+
battlePokemon.originalPokemon.removeBattleFeature()
51+
battlePokemon.effectedPokemon.removeBattleFeature()
52+
return
53+
}
54+
55+
pair.let {
56+
when (it.second) {
57+
is String -> it.let { StringSpeciesFeature(it.first, it.second as String) }
58+
is Boolean -> it.let { FlagSpeciesFeature(it.first, it.second as Boolean) }
59+
else -> null
60+
}
61+
}?.let {
62+
battle.dispatchGo {
63+
battlePokemon.entity
64+
battlePokemon.originalPokemon.applyBattleFeature(it)
65+
battlePokemon.effectedPokemon.applyBattleFeature(it)
66+
}
67+
}
68+
69+
70+
// ?.let {
71+
// battle.dispatchGo {
72+
// FlagSpeciesFeature(it, true).also {
73+
// it.apply(battlePokemon.originalPokemon)
74+
// it.apply(battlePokemon.effectedPokemon)
75+
// }
76+
// }
77+
// }
78+
}
79+
80+
@JvmStatic
81+
fun processBattleEnd(battle: PokemonBattle) {
82+
battle.actors.forEach { actor ->
83+
if (!actor.getPlayerUUIDs().iterator().hasNext()) return@forEach
84+
actor.pokemonList.forEach { battlePokemon ->
85+
val tempAbility = battlePokemon.originalPokemon.ability
86+
val data = battlePokemon.effectedPokemon.persistentData
87+
val name = if(data.contains("form_name")) data.getString("form_name") else ""
88+
battlePokemon.originalPokemon.removeBattleFeature()
89+
battlePokemon.effectedPokemon.removeBattleFeature()
90+
91+
battlePokemon.originalPokemon.restoreAbility(tempAbility, originalAbility, name)
92+
93+
// sequenceOf("mega", "mega_x", "mega_y", "primal", "stellar", "terastal", "hero", "hangry", "meteor", "blade", "pirouette", "sunny", "schooling", "ash", "busted").forEach { name ->
94+
// battlePokemon.effectedPokemon.features.removeIf { it.name == name }
95+
// battlePokemon.originalPokemon.features.removeIf { it.name == name }
96+
// }
97+
//
98+
// battlePokemon.effectedPokemon.updateAspects()
99+
}
100+
}
101+
}
102+
103+
104+
}
105+
106+
private fun Pokemon.removeBattleFeature() {
107+
val data = this.persistentData
108+
val name = if(data.contains("form_name")) data.getString("form_name").also { data.remove("form_name") } else return
109+
val value = if(data.contains("form_value")) data.getString("form_value").also { data.remove("form_value") } else null
110+
111+
if(value == null) {
112+
features.removeIf { it.name == name }
113+
} else {
114+
val feature = features.firstOrNull { it.name == name } ?: return
115+
116+
if(feature is StringSpeciesFeature) {
117+
feature.value = value
118+
}
119+
}
120+
121+
updateAspects()
122+
}
123+
124+
private fun Pokemon.applyBattleFeature(feature: SpeciesFeature) {
125+
this.persistentData.putString("form_name", feature.name)
126+
if(feature is StringSpeciesFeature) {
127+
this.persistentData.putString("form_value", feature.value)
128+
feature.apply(this)
129+
} else {
130+
(feature as FlagSpeciesFeature).apply(this)
131+
}
132+
}
133+
134+
private fun Pokemon.restoreAbility(tempAbility: Ability, originalAbility: Ability?, name: String) {
135+
if (name == "mega" || name == "mega_x" || name == "mega_y") {
136+
if (tempAbility != originalAbility) {
137+
originalAbility?.let { ability ->
138+
this.updateAbility(ability)
139+
} ?: run {
140+
println("Original Ability is null")
141+
}
142+
}
143+
}
144+
}

common/src/main/resources/data/cobblemon/species/generation9/ogerpon.json

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,9 @@
100100
"gen9",
101101
"legendary"
102102
],
103-
"aspects": [],
103+
"aspects": [
104+
"teal"
105+
],
104106
"height": 12,
105107
"weight": 398,
106108
"evolutions": [],
@@ -274,7 +276,8 @@
274276
"legendary"
275277
],
276278
"aspects": [
277-
"teal-tera"
279+
"embody-aspect",
280+
"teal"
278281
],
279282
"height": 12,
280283
"weight": 398,
@@ -318,7 +321,8 @@
318321
"legendary"
319322
],
320323
"aspects": [
321-
"wellspring-tera"
324+
"embody-aspect",
325+
"wellspring"
322326
],
323327
"height": 12,
324328
"weight": 398,
@@ -362,7 +366,8 @@
362366
"legendary"
363367
],
364368
"aspects": [
365-
"hearthflame-tera"
369+
"embody-aspect",
370+
"hearthflame"
366371
],
367372
"height": 12,
368373
"weight": 398,
@@ -406,7 +411,8 @@
406411
"legendary"
407412
],
408413
"aspects": [
409-
"cornerstone-tera"
414+
"embody-aspect",
415+
"cornerstone"
410416
],
411417
"height": 12,
412418
"weight": 398,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
{
2+
"pokemon": ["ogerpon"],
3+
"features": ["embody-aspect"]
4+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"type": "flag",
3+
"keys": ["embody-aspect"],
4+
"default": false,
5+
"isAspect": true
6+
}

common/src/main/resources/data/generations_core/species_features/ogerpon_mask.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"type": "choice",
33
"keys": ["ogerpon_mask"],
4-
"default": "false",
4+
"default": "teal",
55
"choices": [
66
"teal",
77
"wellspring",

0 commit comments

Comments
 (0)