|
| 1 | +package dev.robothanzo.werewolf.game.roles |
| 2 | + |
| 3 | +import dev.robothanzo.werewolf.database.documents.Player |
| 4 | +import dev.robothanzo.werewolf.database.documents.Session |
| 5 | +import dev.robothanzo.werewolf.game.model.* |
| 6 | +import dev.robothanzo.werewolf.game.roles.actions.* |
| 7 | +import org.junit.jupiter.api.Assertions.assertFalse |
| 8 | +import org.junit.jupiter.api.Assertions.assertTrue |
| 9 | +import org.junit.jupiter.api.BeforeEach |
| 10 | +import org.junit.jupiter.api.Test |
| 11 | + |
| 12 | +class WitchAntidoteTests { |
| 13 | + private lateinit var session: Session |
| 14 | + private lateinit var roleRegistry: RoleRegistry |
| 15 | + private lateinit var executor: RoleActionExecutor |
| 16 | + |
| 17 | + @BeforeEach |
| 18 | + fun setup() { |
| 19 | + session = Session() |
| 20 | + session.id = "test-session" |
| 21 | + session.day = 1 |
| 22 | + |
| 23 | + // Mock Roles |
| 24 | + val witchRole = object : BaseRole("女巫", Camp.GOD) { |
| 25 | + override fun getActions() = listOf(WitchAntidoteAction(), WitchPoisonAction()) |
| 26 | + } |
| 27 | + val werewolfRole = object : BaseRole("狼人", Camp.WEREWOLF) {} |
| 28 | + val villagerRole = object : BaseRole("平民", Camp.VILLAGER) {} |
| 29 | + val ghostRiderRole = object : BaseRole("惡靈騎士", Camp.WEREWOLF) {} |
| 30 | + |
| 31 | + roleRegistry = RoleRegistry( |
| 32 | + listOf(witchRole, werewolfRole, villagerRole, ghostRiderRole), |
| 33 | + listOf( |
| 34 | + WerewolfKillAction(), |
| 35 | + WitchAntidoteAction(), |
| 36 | + WitchPoisonAction(), |
| 37 | + GuardProtectAction(), |
| 38 | + DeathResolutionAction() |
| 39 | + ) |
| 40 | + ) |
| 41 | + executor = RoleActionExecutor(roleRegistry) |
| 42 | + |
| 43 | + // Setup Players |
| 44 | + session.players["1"] = Player(id = 1, roles = mutableListOf("狼人")) |
| 45 | + session.players["2"] = Player(id = 2, roles = mutableListOf("女巫")) |
| 46 | + session.players["3"] = Player(id = 3, roles = mutableListOf("平民")) |
| 47 | + session.players["4"] = Player(id = 4, roles = mutableListOf("惡靈騎士")) |
| 48 | + |
| 49 | + session.players.values.forEach { it.session = session } |
| 50 | + } |
| 51 | + |
| 52 | + @Test |
| 53 | + fun testWitchAntidoteSavesVillager() { |
| 54 | + val wolfKill = RoleActionInstance( |
| 55 | + actor = 1, |
| 56 | + actorRole = "狼人", |
| 57 | + actionDefinitionId = ActionDefinitionId.WEREWOLF_KILL, |
| 58 | + targets = mutableListOf(3), |
| 59 | + submittedBy = ActionSubmissionSource.PLAYER, |
| 60 | + status = ActionStatus.SUBMITTED |
| 61 | + ) |
| 62 | + val antidote = RoleActionInstance( |
| 63 | + actor = 2, |
| 64 | + actorRole = "女巫", |
| 65 | + actionDefinitionId = ActionDefinitionId.WITCH_ANTIDOTE, |
| 66 | + targets = mutableListOf(3), |
| 67 | + submittedBy = ActionSubmissionSource.PLAYER, |
| 68 | + status = ActionStatus.SUBMITTED |
| 69 | + ) |
| 70 | + |
| 71 | + val result = executor.executeActions(session, listOf(wolfKill, antidote)) |
| 72 | + |
| 73 | + assertFalse(result.deaths.values.flatten().contains(3), "Villager should be saved by Antidote") |
| 74 | + assertTrue(result.saved.contains(3), "Villager ID should be in saved list") |
| 75 | + } |
| 76 | + |
| 77 | + @Test |
| 78 | + fun testWitchAntidoteOnGhostRider() { |
| 79 | + // Wolves target GR (though they shouldn't usually, but for testing logic) |
| 80 | + val wolfKill = RoleActionInstance( |
| 81 | + actor = 1, |
| 82 | + actorRole = "狼人", |
| 83 | + actionDefinitionId = ActionDefinitionId.WEREWOLF_KILL, |
| 84 | + targets = mutableListOf(4), |
| 85 | + submittedBy = ActionSubmissionSource.PLAYER, |
| 86 | + status = ActionStatus.SUBMITTED |
| 87 | + ) |
| 88 | + // Witch tries to save GR |
| 89 | + val antidote = RoleActionInstance( |
| 90 | + actor = 2, |
| 91 | + actorRole = "女巫", |
| 92 | + actionDefinitionId = ActionDefinitionId.WITCH_ANTIDOTE, |
| 93 | + targets = mutableListOf(4), |
| 94 | + submittedBy = ActionSubmissionSource.PLAYER, |
| 95 | + status = ActionStatus.SUBMITTED |
| 96 | + ) |
| 97 | + |
| 98 | + val result = executor.executeActions(session, listOf(wolfKill, antidote)) |
| 99 | + |
| 100 | + // According to current logic: Witch targets GR -> Reflect! |
| 101 | + assertTrue(result.deaths[DeathCause.REFLECT]?.contains(2) == true, "Witch should be reflected") |
| 102 | + // The antidote should NOT have worked because reflection returns accumulatedState (skipping the action) |
| 103 | + assertFalse(result.saved.contains(4), "Antidote should have been skipped due to reflection") |
| 104 | + |
| 105 | + // GR is immune to wolf kill at night anyway |
| 106 | + assertFalse(result.deaths.values.flatten().contains(4), "Ghost Rider should be immune to wolf kill at night") |
| 107 | + } |
| 108 | +} |
0 commit comments