Use keyed lookups for unaffiliated hero action (#7942)

This commit is contained in:
2026-06-23 13:59:30 -07:00
committed by GitHub
parent bae90633a5
commit b7cd003b4c
@@ -25,11 +25,16 @@ case class EndUnaffiliatedHeroActionsPhaseAction(
heroes: Vector[HeroT],
factions: Vector[FactionT]
) extends ProtolessSequentialResultsAction {
private lazy val factionsById: Map[FactionId, FactionT] =
factions.map(faction => faction.id -> faction).toMap
private lazy val heroesById: Map[HeroId, HeroT] =
heroes.map(hero => hero.id -> hero).toMap
private def requiredFaction(fid: FactionId): FactionT =
factions.find(_.id == fid).getOrElse(throw new IllegalArgumentException(s"No faction found for id $fid"))
factionsById.getOrElse(fid, throw new IllegalArgumentException(s"No faction found for id $fid"))
private def requiredHero(hid: HeroId): HeroT =
heroes.find(_.id == hid).getOrElse(throw new IllegalArgumentException(s"No hero found for id $hid"))
heroesById.getOrElse(hid, throw new IllegalArgumentException(s"No hero found for id $hid"))
private def heroRejoinResults: Vector[ActionResultT] =
(for {
@@ -78,7 +83,7 @@ case class EndUnaffiliatedHeroActionsPhaseAction(
)
}
}
.getOrElse(Vector())
.getOrElse(Vector.empty)
override def results: Vector[ActionResultT] = {
val cpsAndLlmRequests = provinces.map { p =>