This commit is contained in:
2025-11-25 12:01:49 +08:00
parent f73f4f55e3
commit e833245d0a
10 changed files with 498 additions and 108 deletions

View File

@@ -16,11 +16,13 @@ namespace WulaFallenEmpire
{
if (map == null)
yield break;
if (Find.TickManager.TicksGame - lastUpdateTick > UPDATE_INTERVAL_TICKS)
{
UpdateShieldCache();
lastUpdateTick = Find.TickManager.TicksGame;
}
if (activeShieldsByMap.TryGetValue(map, out var shields))
{
foreach (var shield in shields)
@@ -30,36 +32,57 @@ namespace WulaFallenEmpire
}
}
}
private static void UpdateShieldCache()
{
activeShieldsByMap.Clear();
foreach (var map in Find.Maps)
{
if (map == null) continue;
var shieldSet = new HashSet<ThingComp_AreaShield>();
// 搜索装备上的护盾
foreach (var pawn in map.mapPawns.AllPawnsSpawned)
{
if (pawn?.apparel == null || pawn.Destroyed)
continue;
foreach (var apparel in pawn.apparel.WornApparel)
{
if (apparel == null || apparel.Destroyed)
continue;
var shield = apparel.TryGetComp<ThingComp_AreaShield>();
// 修改:只有立定且激活的护盾才加入缓存
if (shield != null && shield.Active && !shield.IsWearerMoving)
if (shield != null && shield.Active && !shield.IsHolderMoving)
{
shieldSet.Add(shield);
}
}
}
// 搜索固定物品上的护盾(新增)
foreach (var thing in map.listerThings.AllThings)
{
if (thing == null || thing.Destroyed || thing is Apparel)
continue;
var shield = thing.TryGetComp<ThingComp_AreaShield>();
if (shield != null && shield.Active)
{
shieldSet.Add(shield);
}
}
activeShieldsByMap[map] = shieldSet;
}
}
public static void NotifyShieldStateChanged(ThingComp_AreaShield shield)
{
if (shield?.Wearer?.Map != null)
if (shield?.Holder?.Map != null)
{
lastUpdateTick = 0;
}