修友伤没有了

This commit is contained in:
2025-08-17 21:10:51 +08:00
parent f509e7191a
commit 9cc3334884
3 changed files with 32 additions and 6 deletions

View File

@@ -65,6 +65,7 @@
<li Class="WulaFallenEmpire.Wula_PathPierce_Extension"> <li Class="WulaFallenEmpire.Wula_PathPierce_Extension">
<maxHits>-1</maxHits> <!-- 无限穿透 --> <maxHits>-1</maxHits> <!-- 无限穿透 -->
<damageFalloff>0</damageFalloff> <!-- 无伤害衰减 --> <damageFalloff>0</damageFalloff> <!-- 无伤害衰减 -->
<preventFriendlyFire>false</preventFriendlyFire> <!-- 是否阻止友方火力 -->
</li> </li>
</modExtensions> </modExtensions>
<tickerType>Normal</tickerType> <tickerType>Normal</tickerType>

View File

@@ -12,6 +12,8 @@ namespace WulaFallenEmpire
public int maxHits = 3; public int maxHits = 3;
// The percentage of damage lost per hit. 0.25 means 25% damage loss per hit. // The percentage of damage lost per hit. 0.25 means 25% damage loss per hit.
public float damageFalloff = 0.25f; public float damageFalloff = 0.25f;
// If true, this projectile will never cause friendly fire, regardless of game settings.
public bool preventFriendlyFire = false;
} }
public class Projectile_WulaLineAttack : Projectile public class Projectile_WulaLineAttack : Projectile
@@ -40,6 +42,8 @@ namespace WulaFallenEmpire
this.lastTickPosition = origin; this.lastTickPosition = origin;
this.alreadyDamaged.Clear(); this.alreadyDamaged.Clear();
this.hitCounter = 0; this.hitCounter = 0;
// Friendly fire is prevented if EITHER the game setting is true OR the XML extension is true.
this.preventFriendlyFire = preventFriendlyFire || (Props?.preventFriendlyFire ?? false);
} }
protected override void Tick() protected override void Tick()
@@ -92,11 +96,32 @@ namespace WulaFallenEmpire
foreach (Thing thing in thingsInCell) foreach (Thing thing in thingsInCell)
{ {
if (thing is Pawn pawn && pawn != this.launcher && !alreadyDamaged.Contains(pawn) && GenHostility.HostileTo(pawn, this.launcher.Faction)) if (thing is Pawn pawn && pawn != this.launcher && !alreadyDamaged.Contains(pawn))
{ {
ApplyPathDamage(pawn); bool shouldDamage = false;
if (!infinitePenetration && hitCounter >= maxHits) break;
} // Case 1: Always damage the intended target if it's a pawn. This allows hunting.
if (this.intendedTarget.Thing == pawn)
{
shouldDamage = true;
}
// Case 2: Always damage hostile pawns in the path.
else if (pawn.HostileTo(this.launcher))
{
shouldDamage = true;
}
// Case 3: Damage non-hostiles (friendlies, neutrals) if the shot itself isn't marked to prevent friendly fire.
else if (!this.preventFriendlyFire)
{
shouldDamage = true;
}
if (shouldDamage)
{
ApplyPathDamage(pawn);
if (!infinitePenetration && hitCounter >= maxHits) break;
}
}
} }
} }
} }