Compare commits

...
Author SHA1 Message Date
Plastered_Crab 3f52585386 Changes to herding system for alphas 2026-03-25 13:34:22 -07:00
Plastered_Crab 9a2443f709 Changes to herding system for alphas 2026-03-25 13:05:36 -07:00
3 changed files with 25 additions and 10 deletions
@@ -46,6 +46,9 @@ class FindHerdLeaderTaskConfig : SingleTaskConfig {
): PokemonEntity? {
var bestLeader: PokemonEntity? = null
val (currentLeaderEntity, currentLeaderDefinition) = currentLeader ?: Pair(null, null)
if (currentLeaderEntity?.pokemon?.isAlpha == true) { // don't swap to a new alpha leader (I worry about mons constantly swapping between alphas if more are close by...)
return currentLeaderEntity
}
var bestTier = currentLeaderDefinition?.tier?.let { it + 1 } ?: 0 // Only upgrade to a higher tier leader
var bestDistance = Float.MAX_VALUE
nearbyEntities.findAll {
@@ -53,6 +56,7 @@ class FindHerdLeaderTaskConfig : SingleTaskConfig {
it != currentLeader &&
it.pokemon.storeCoordinates.get()?.store !is PartyStore &&
it.getHerdSize() < it.behaviour.herd.maxSize &&
//!it.brain.hasMemoryValue(CobblemonMemories.HERD_LEADER) &&
!it.brain.hasMemoryValue(CobblemonMemories.POKEMON_DROWSY)
}.forEach { possibleLeader ->
possibleLeader as PokemonEntity
@@ -65,13 +69,21 @@ class FindHerdLeaderTaskConfig : SingleTaskConfig {
val distance = entity.distanceTo(possibleLeader)
if (bestMatchingHerdLeader.tier < bestTier) {
return@forEach // No need to check further if this leader is worse than the best found so far
} else if ((distance > bestDistance && !possibleLeaderIsAlreadyALeader) && bestMatchingHerdLeader.tier == bestTier) {
return@forEach // No need to check further if this leader is farther than the best found so far, unless they are already a leader - I'd prefer to join a pack
} else {
bestLeader = possibleLeader
bestDistance = distance
bestTier = bestMatchingHerdLeader.tier
} else if (bestMatchingHerdLeader.tier == bestTier) {
if (possibleLeader.pokemon.isAlpha && bestLeader?.pokemon?.isAlpha == true) {
if (entity.random.nextBoolean()) { // choose random alpha if multiple are present
bestLeader = possibleLeader
bestDistance = distance
}
return@forEach
}
if (distance > bestDistance && !possibleLeaderIsAlreadyALeader) {
return@forEach // No need to check further if this leader is farther than the best found so far, unless they are already a leader - I'd prefer to join a pack
}
}
bestLeader = possibleLeader
bestDistance = distance
bestTier = bestMatchingHerdLeader.tier
}
return bestLeader ?: currentLeaderEntity
}
@@ -124,4 +136,4 @@ class FindHerdLeaderTaskConfig : SingleTaskConfig {
}
}
}
}
}
@@ -65,9 +65,8 @@ class MaintainHerdLeaderTaskConfig : SingleTaskConfig {
}
val leader = instance.get(herdLeader).let(UUID::fromString).let(world::getEntity) as? PokemonEntity
val currentLeaderDefinition = leader?.let { leader ->
entity.behaviour.herd.toleratedLeaders.find { it.pokemon.matches(leader) }
}
val currentLeaderDefinition = leader?.let {
entity.behaviour.herd.bestMatchLeader(entity, it) }
if (leader == null || currentLeaderDefinition == null) {
entity.brain.eraseMemory(CobblemonMemories.HERD_LEADER)
return@Trigger true // No leader, so we erase the memory
@@ -10,6 +10,7 @@ package com.cobblemon.mod.common.pokemon.ai
import com.bedrockk.molang.runtime.value.DoubleValue
import com.cobblemon.mod.common.api.molang.ObjectValue
import com.cobblemon.mod.common.api.pokemon.PokemonProperties
import com.cobblemon.mod.common.entity.pokemon.PokemonEntity
class HerdBehaviour {
@@ -39,6 +40,9 @@ class HerdBehaviour {
}
}
}
if (bestLeader != null && possibleLeader.pokemon.isAlpha) {
return ToleratedHerdLeader(PokemonProperties(), 9001, ignoresLevel = true) // WHAT?? OVER 9000???
}
return bestLeader
}