TH1/Tools/CheckMoriyaKanakoOwnershipGuard.ps1

50 lines
2.2 KiB
PowerShell

param(
[string]$Root = (Resolve-Path "$PSScriptRoot\..").Path
)
$ErrorActionPreference = "Stop"
function Read-Text([string]$RelativePath) {
$path = Join-Path $Root $RelativePath
if (-not (Test-Path -LiteralPath $path)) {
throw "Missing required file: $RelativePath"
}
return Get-Content -LiteralPath $path -Raw
}
$playerLogic = Read-Text "Unity/Assets/Scripts/TH1_Logic/Player/PlayerLogic.cs"
$ownershipUtil = Read-Text "Unity/Assets/Scripts/TH1_Logic/Skill/AllSkill/KanakoWindSkill.cs"
if ($ownershipUtil -notmatch 'public\s+static\s+bool\s+IsGridInUnitUnionTerritory\s*\(') {
throw "MoriyaKanakoOwnershipUtil must expose IsGridInUnitUnionTerritory for ownership-safe grid checks."
}
if ($ownershipUtil -notmatch 'public\s+static\s+bool\s+HasUnitUnionBuildingOnGrid\s*\(') {
throw "MoriyaKanakoOwnershipUtil must expose HasUnitUnionBuildingOnGrid for Moriya road checks."
}
if ($ownershipUtil -notmatch '(?s)GetPlayerIdByUnitId\s*\(\s*unitData\.Id.*?GetPlayerDataByTerritoryGridId\s*\(\s*gridData\.Id.*?SameUnion\s*\(') {
throw "MoriyaKanakoOwnershipUtil.IsGridInUnitUnionTerritory must prove unit owner and grid territory are in the same union."
}
if ($playerLogic -notmatch '(?s)SkillType\.MORIYAROAD.*?gridData\.Feature\s*==\s*TerrainFeature\.Mountain.*?MoriyaKanakoOwnershipUtil\.HasUnitUnionBuildingOnGrid\s*\(\s*mapData\s*,\s*gridData\s*,\s*unitData\s*\)') {
throw "MORIYAROAD mountain-building road bonus must require unit-union building ownership."
}
$skillFiles = @(
"Unity/Assets/Scripts/TH1_Logic/Skill/AllSkill/KanakoWindSkill.cs",
"Unity/Assets/Scripts/TH1_Logic/Skill/AllSkill/KanakoWindProSkill.cs",
"Unity/Assets/Scripts/TH1_Logic/Skill/AllSkill/KanakoWarSkill.cs",
"Unity/Assets/Scripts/TH1_Logic/Skill/AllSkill/KanakoWarProSkill.cs"
)
foreach ($relativePath in $skillFiles) {
$text = Read-Text $relativePath
if ($text -match 'ResourceType\.(MoriyaMilitary|Academy)' -and
$text -notmatch 'MoriyaKanakoOwnershipUtil\.IsGridInUnitUnionTerritory\s*\(') {
throw "$relativePath checks Kanako building resources without unit-union ownership."
}
}
Write-Host "Moriya/Kanako ownership guard passed."