Fix Kanako building ownership bonuses

This commit is contained in:
daixiawu 2026-06-26 21:26:41 +08:00
parent a91ea6b1d0
commit 35dafd3c3c
5 changed files with 91 additions and 8 deletions

View File

@ -0,0 +1,49 @@
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."

View File

@ -30,11 +30,15 @@ namespace Logic.Skill
public override float GetAttackAdditionParam(MapData mapData, UnitData self, UnitData target = null)
{
if (mapData == null || self == null) return 0f;
var selfGrid = self.Grid(mapData);
if (selfGrid == null) return 0f;
var aroundBuf = RentAroundBuf();
mapData.GridMap.GetAroundGridData(1, 1, self.Grid(mapData), aroundBuf);
mapData.GridMap.GetAroundGridData(1, 1, selfGrid, aroundBuf);
float ret = 0f;
foreach(var grid in aroundBuf)
if (grid.Resource == ResourceType.Academy)
if (grid.Resource == ResourceType.Academy
&& MoriyaKanakoOwnershipUtil.IsGridInUnitUnionTerritory(mapData, grid, self))
ret += 0.5f;
ReturnAroundBuf();
return ret;

View File

@ -30,10 +30,14 @@ namespace Logic.Skill
public override float GetAttackAdditionParam(MapData mapData, UnitData self, UnitData target = null)
{
if (mapData == null || self == null) return 0f;
var selfGrid = self.Grid(mapData);
if (selfGrid == null) return 0f;
var aroundBuf = RentAroundBuf();
mapData.GridMap.GetAroundGridData(1, 1, self.Grid(mapData), aroundBuf);
mapData.GridMap.GetAroundGridData(1, 1, selfGrid, aroundBuf);
foreach(var grid in aroundBuf)
if (grid.Resource == ResourceType.Academy)
if (grid.Resource == ResourceType.Academy
&& MoriyaKanakoOwnershipUtil.IsGridInUnitUnionTerritory(mapData, grid, self))
{
ReturnAroundBuf();
return 0.5f;

View File

@ -30,11 +30,15 @@ namespace Logic.Skill
public override int GetExtraMoveRange(MapData map,UnitData self)
{
if (map == null || self == null) return 0;
var selfGrid = self.Grid(map);
if (selfGrid == null) return 0;
var aroundBuf = RentAroundBuf();
map.GridMap.GetAroundGridData(1, 1, self.Grid(map), aroundBuf);
map.GridMap.GetAroundGridData(1, 1, selfGrid, aroundBuf);
int ret = 0;
foreach(var grid in aroundBuf)
if (grid.Resource == ResourceType.MoriyaMilitary)
if (grid.Resource == ResourceType.MoriyaMilitary
&& MoriyaKanakoOwnershipUtil.IsGridInUnitUnionTerritory(map, grid, self))
ret++;
ReturnAroundBuf();
return ret;

View File

@ -14,6 +14,24 @@ using RuntimeData;
namespace Logic.Skill
{
public static class MoriyaKanakoOwnershipUtil
{
public static bool IsGridInUnitUnionTerritory(MapData mapData, GridData gridData, UnitData unitData)
{
if (mapData == null || gridData == null || unitData == null) return false;
if (!mapData.GetPlayerIdByUnitId(unitData.Id, out var unitPlayerId)) return false;
return mapData.GetPlayerDataByTerritoryGridId(gridData.Id, out var gridPlayerData)
&& mapData.SameUnion(gridPlayerData.Id, unitPlayerId);
}
public static bool HasUnitUnionBuildingOnGrid(MapData mapData, GridData gridData, UnitData unitData)
{
return gridData != null
&& gridData.HasBuilding()
&& IsGridInUnitUnionTerritory(mapData, gridData, unitData);
}
}
public partial class KanakoWindSkill : SkillBase
{
public KanakoWindSkill()
@ -30,10 +48,14 @@ namespace Logic.Skill
public override int GetExtraMoveRange(MapData map,UnitData self)
{
if (map == null || self == null) return 0;
var selfGrid = self.Grid(map);
if (selfGrid == null) return 0;
var aroundBuf = RentAroundBuf();
map.GridMap.GetAroundGridData(1, 1, self.Grid(map), aroundBuf);
map.GridMap.GetAroundGridData(1, 1, selfGrid, aroundBuf);
foreach(var grid in aroundBuf)
if (grid.Resource == ResourceType.MoriyaMilitary)
if (grid.Resource == ResourceType.MoriyaMilitary
&& MoriyaKanakoOwnershipUtil.IsGridInUnitUnionTerritory(map, grid, self))
{
ReturnAroundBuf();
return 1;