Suppress ready-to-join notification after province ownership change (#6751)

This commit is contained in:
2026-05-24 14:56:58 -04:00
committed by GitHub
parent 86d396c5f5
commit c08ed8c170
2 changed files with 73 additions and 8 deletions
@@ -150,6 +150,7 @@ class ActionResultApplierImpl(validator: Option[Validator]) extends ActionResult
): ActionResultT = {
val readyHeroes = newlyReadyToJoinHeroes(startingState, finalState)
.filterNot(heroHasQuestFulfilledNotification(result, _))
.filterNot(heroBecameReadyBecauseProvinceOwnershipChanged(startingState, _))
val notificationsAndRequests = readyHeroes.map {
case ReadyToJoinHero(heroId, provinceId, factionId) =>
@@ -199,6 +200,17 @@ class ActionResultApplierImpl(validator: Option[Validator]) extends ActionResult
}
}
private def heroBecameReadyBecauseProvinceOwnershipChanged(
startingState: GameState,
readyHero: ReadyToJoinHero
): Boolean =
startingState.provinces.get(readyHero.provinceId).exists { oldProvince =>
oldProvince.rulingFactionId != Some(readyHero.factionId) &&
oldProvince.unaffiliatedHeroes.exists { hero =>
hero.heroId == readyHero.heroId && hero.recruitmentInfo == RecruitmentInfo.WouldJoin
}
}
private def newlyReadyToJoinHeroes(
startingState: GameState,
finalState: GameState
@@ -250,7 +250,65 @@ class ActionResultApplierImplTest extends AnyFlatSpec with Matchers with BeforeA
} shouldBe empty
}
it should "add a notification when a ready hero becomes ready for a new ruling faction" in {
it should "add a notification when a ready hero moves into a ruled province" in {
val factionId = 11
val leaderId = 12
val heroId = 13
val oldProvinceId = 14
val newProvinceId = 15
val readyHero = UnaffiliatedHeroC(
heroId = heroId,
unaffiliatedHeroType = UnaffiliatedHeroType.Resident,
recruitmentInfo = RecruitmentInfo.WouldJoin
)
val oldProvince = ProvinceC(
id = oldProvinceId,
rulingFactionId = None,
unaffiliatedHeroes = Vector(readyHero)
)
val newProvince = ProvinceC(
id = newProvinceId,
rulingFactionId = Some(factionId),
unaffiliatedHeroes = Vector.empty
)
val startingState = baseGameState.copy(
provinces = Map(oldProvinceId -> oldProvince, newProvinceId -> newProvince),
factions = Map(
factionId -> FactionC(
id = factionId,
factionHeadId = leaderId,
name = "Test Faction",
leaderIds = Vector(leaderId)
)
),
heroes = Map(leaderId -> HeroC(id = leaderId, factionId = Some(factionId)), heroId -> HeroC(id = heroId))
)
val actionResult = ActionResultC(
actionResultType = ActionResultType.UnknownActionUnspecified,
changedProvinces = Vector(
ChangedProvinceC(
provinceId = oldProvinceId,
removedUnaffiliatedHeroIds = Vector(heroId)
),
ChangedProvinceC(
provinceId = newProvinceId,
newUnaffiliatedHeroes = Vector(readyHero)
)
)
)
val result = applier.applyActionResult(startingState, actionResult)
result.actionResult.newNotifications.head.details.shouldBe(
NotificationDetails.HeroReadyToJoin(
heroId = heroId,
provinceId = newProvinceId,
factionId = factionId
)
)
}
it should "not add a notification when a ready hero's province becomes ruled by a new faction" in {
val oldFactionId = 10
val newFactionId = 11
val oldLeaderId = 12
@@ -302,13 +360,8 @@ class ActionResultApplierImplTest extends AnyFlatSpec with Matchers with BeforeA
val result = applier.applyActionResult(startingState, actionResult)
result.actionResult.newNotifications.head.details.shouldBe(
NotificationDetails.HeroReadyToJoin(
heroId = heroId,
provinceId = provinceId,
factionId = newFactionId
)
)
result.actionResult.newNotifications shouldBe empty
result.actionResult.newGeneratedTextRequests shouldBe empty
}
"a result with a new round id" should "change the round ID in the game state" in {