TH1/Tools/CheckAttackGroundPeaceSemantics.ps1

104 lines
4.2 KiB
PowerShell

param()
$ErrorActionPreference = "Stop"
$repoRoot = Resolve-Path (Join-Path $PSScriptRoot "..")
$failures = @()
function Add-Failure {
param([string]$Message)
$script:failures += $Message
}
function Read-RepoText {
param([string]$RelativePath)
$path = Join-Path $repoRoot $RelativePath
if (-not (Test-Path -LiteralPath $path)) {
Add-Failure "Missing file: $RelativePath"
return ""
}
return Get-Content -LiteralPath $path -Raw
}
$skillBase = Read-RepoText "Unity/Assets/Scripts/TH1_Logic/Skill/SkillBase.cs"
$unitData = Read-RepoText "Unity/Assets/Scripts/TH1_Data/UnitData.cs"
$actionLogic = Read-RepoText "Unity/Assets/Scripts/TH1_Logic/Action/ActionLogic.cs"
$hakureiNorwayHeroSkill = Read-RepoText "Unity/Assets/Scripts/TH1_Logic/Skill/AllSkill/HakureiNorwayHeroSkill.cs"
if ($skillBase -notmatch "public bool AttackGroundCountsAsActiveAttack\(MapData map,UnitData self, GridData target\);") {
Add-Failure "ISkill must expose AttackGroundCountsAsActiveAttack."
}
if ($skillBase -notmatch "public virtual bool AttackGroundCountsAsActiveAttack\(MapData map, UnitData self, GridData target\)\s*\{\s*return true;\s*\}") {
Add-Failure "SkillBase default AttackGroundCountsAsActiveAttack must remain true."
}
if ($unitData -notmatch "out bool countsAsActiveAttack") {
Add-Failure "UnitData.AttackGroundExecute must return countsAsActiveAttack."
}
if ($unitData -notmatch "skill\.AttackGroundCountsAsActiveAttack\(map, this, target\)") {
Add-Failure "UnitData.AttackGroundExecute must read skill-level active-attack semantics before executing."
}
if ($actionLogic -notmatch "out skillAttackGroundCountsAsActiveAttack") {
Add-Failure "UnitAttackGroundAction must receive the skill active-attack semantic result."
}
if ($actionLogic -notmatch "if \(skillAttackGroundCountsAsActiveAttack\)\s*ActiveAttackActionRecorder\.MarkStarted") {
Add-Failure "UnitAttackGroundAction must only reset peace progress for skill ground actions that count as active attacks."
}
if ($actionLogic -notmatch "if \(!handledBySkillAttackGround && hasSuwakoAttack\)" -or
$actionLogic -notmatch "(?s)targetGrid\.RealUnit\(actionParams\.MapData, out var targetGridUnit\).*?ActiveAttackActionRecorder\.MarkStarted" -or
$actionLogic -notmatch "(?s)unit1\.ClearActionPoint\(\).*?actionParams\.MapData\.AddUnitData") {
Add-Failure "Suwako occupied-grid interaction and empty-grid summon paths must stay separated."
}
$skillFiles = Get-ChildItem -LiteralPath (Join-Path $repoRoot "Unity/Assets/Scripts/TH1_Logic/Skill/AllSkill") -Recurse -Filter "*.cs"
foreach ($file in $skillFiles) {
$text = Get-Content -LiteralPath $file.FullName -Raw
if ($text -notmatch "override\s+bool\s+AttackGroundExecute\s*\(") {
continue
}
if ($text -notmatch "override\s+bool\s+AttackGroundCountsAsActiveAttack\s*\(") {
$relative = [System.IO.Path]::GetRelativePath($repoRoot, $file.FullName)
Add-Failure "$relative overrides AttackGroundExecute but does not explicitly declare AttackGroundCountsAsActiveAttack."
}
}
$expectedFalseSkills = @(
"SumirekoOccultOrbOwnerSkill",
"KasenBeastGuideReserveSkill"
)
foreach ($className in $expectedFalseSkills) {
$pattern = "(?s)class\s+$className\b.*?override\s+bool\s+AttackGroundCountsAsActiveAttack\s*\([^)]*\)\s*\{\s*return\s+false;\s*\}"
if ($hakureiNorwayHeroSkill -notmatch $pattern) {
Add-Failure "$className must declare ground targeting as non-attack so peace wonder progress is preserved."
}
}
$expectedTrueSkills = @(
"SuikaFallingSplashSkill",
"SuikaThrowReadySkill"
)
foreach ($className in $expectedTrueSkills) {
$pattern = "(?s)class\s+$className\b.*?override\s+bool\s+AttackGroundCountsAsActiveAttack\s*\([^)]*\)\s*\{\s*return\s+true;\s*\}"
if ($hakureiNorwayHeroSkill -notmatch $pattern) {
Add-Failure "$className must explicitly declare ground targeting as active attack."
}
}
if ($failures.Count -gt 0) {
Write-Host "AttackGround peace semantics check failed:" -ForegroundColor Red
foreach ($failure in $failures) {
Write-Host " - $failure" -ForegroundColor Red
}
exit 1
}
Write-Host "AttackGround peace semantics checks passed."