This commit is contained in:
2025-10-01 12:26:49 +08:00
parent 73d9e0b453
commit b606ca4903
7 changed files with 75 additions and 136 deletions

Binary file not shown.

View File

@@ -141,7 +141,7 @@
<costList Inherit="False">
<ARA_Carapace>25</ARA_Carapace>
</costList>
<weaponTags>
<weaponTags Inherit="False">
<li>ARA_Armed_Organ</li>
<li>ARA_Armed_Organ_Ranged</li>
<li>ARA_Armed_Organ_T1</li>
@@ -234,7 +234,7 @@
<costList Inherit="False">
<ARA_Carapace>50</ARA_Carapace>
</costList>
<weaponTags>
<weaponTags Inherit="False">
<li>ARA_Armed_Organ</li>
<li>ARA_Armed_Organ_Ranged</li>
<li>ARA_Armed_Organ_T2</li>

View File

@@ -8,7 +8,7 @@
<descriptionHyperlinks>
<ThingDef>ARA_Cocoon_Weapon</ThingDef>
</descriptionHyperlinks>
<weaponTags>
<weaponTags Inherit="False">
<li>ARA_Armed_Organ</li>
<li>ARA_Armed_Organ_Melee</li>
<li>ARA_Armed_Organ_T1</li>
@@ -81,7 +81,7 @@
<descriptionHyperlinks>
<ThingDef>ARA_Cocoon_Weapon_1Stage</ThingDef>
</descriptionHyperlinks>
<weaponTags>
<weaponTags Inherit="False">
<li>ARA_Armed_Organ</li>
<li>ARA_Armed_Organ_Melee</li>
<li>ARA_Armed_Organ_T2</li>
@@ -164,7 +164,7 @@
<descriptionHyperlinks>
<ThingDef>ARA_Cocoon_Weapon_2Stage</ThingDef>
</descriptionHyperlinks>
<weaponTags>
<weaponTags Inherit="False">
<li>ARA_Armed_Organ</li>
<li>ARA_Armed_Organ_Melee</li>
<li>ARA_Armed_Organ_T3</li>
@@ -302,7 +302,7 @@
<costList Inherit="False">
<ARA_Carapace>25</ARA_Carapace>
</costList>
<weaponTags>
<weaponTags Inherit="False">
<li>ARA_Armed_Organ</li>
<li>ARA_Armed_Organ_Ranged</li>
<li>ARA_Armed_Organ_T1</li>
@@ -420,7 +420,7 @@
<costList Inherit="False">
<ARA_Carapace>25</ARA_Carapace>
</costList>
<weaponTags>
<weaponTags Inherit="False">
<li>ARA_Armed_Organ</li>
<li>ARA_Armed_Organ_Ranged</li>
<li>ARA_Armed_Organ_T2</li>
@@ -493,7 +493,7 @@
<costList Inherit="False">
<ARA_Carapace>25</ARA_Carapace>
</costList>
<weaponTags>
<weaponTags Inherit="False">
<li>ARA_Armed_Organ</li>
<li>ARA_Armed_Organ_Ranged</li>
<li>ARA_Armed_Organ_T2</li>
@@ -563,7 +563,7 @@
<costList Inherit="False">
<ARA_Carapace>50</ARA_Carapace>
</costList>
<weaponTags>
<weaponTags Inherit="False">
<li>ARA_Armed_Organ</li>
<li>ARA_Armed_Organ_Ranged</li>
<li>ARA_Armed_Organ_T2</li>
@@ -664,7 +664,7 @@
<costList Inherit="False">
<ARA_Carapace>50</ARA_Carapace>
</costList>
<weaponTags>
<weaponTags Inherit="False">
<li>ARA_Armed_Organ</li>
<li>ARA_Armed_Organ_Ranged</li>
<li>ARA_Armed_Organ_T1</li>
@@ -772,7 +772,7 @@
<costList Inherit="False">
<ARA_Carapace>50</ARA_Carapace>
</costList>
<weaponTags>
<weaponTags Inherit="False">
<li>ARA_Armed_Organ</li>
<li>ARA_Armed_Organ_Ranged</li>
<li>ARA_Armed_Organ_T2</li>
@@ -852,7 +852,7 @@
<costList Inherit="False">
<ARA_Carapace>50</ARA_Carapace>
</costList>
<weaponTags>
<weaponTags Inherit="False">
<li>ARA_Armed_Organ</li>
<li>ARA_Armed_Organ_Ranged</li>
<li>ARA_Armed_Organ_T2</li>
@@ -969,7 +969,7 @@
<costList Inherit="False">
<ARA_Carapace>50</ARA_Carapace>
</costList>
<weaponTags>
<weaponTags Inherit="False">
<li>ARA_Armed_Organ</li>
<li>ARA_Armed_Organ_Ranged</li>
<li>ARA_Armed_Organ_T1</li>
@@ -1045,7 +1045,7 @@
<defName>ARA_MW_Mimic_Niddle</defName>
<label>武装器官"拟线种毒针"</label>
<description>阿拉克涅虫群督虫使用基础近战武装器官,通过多根外露神经束与督虫的辅肢相连。这根毒针中藏有休眠中的阿拉克涅拟线种虫卵,攻击将感染受害者使其最终成为被拟线虫操控的寄生体。</description>
<weaponTags>
<weaponTags Inherit="False">
<li>ARA_Armed_Organ</li>
<li>ARA_Armed_Organ_Melee</li>
<li>ARA_Armed_Organ_T1</li>

View File

@@ -57,7 +57,7 @@
<costList Inherit="False">
<ARA_Carapace>50</ARA_Carapace>
</costList>
<weaponTags>
<weaponTags Inherit="False">
<li>ARA_Armed_Organ</li>
<li>ARA_Armed_Organ_Ranged</li>
<li>ARA_Armed_Organ_T1</li>

View File

@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="utf-8" ?>
<LanguageData>
<!-- Guardian Psy-Field Gizmo -->
<ARA_GuardianFieldGizmoLabel>守护者力场</ARA_GuardianFieldGizmoLabel>
</LanguageData>

View File

@@ -22,8 +22,8 @@ namespace ArachnaeSwarm
// Our comp is directly on the pawn, not on apparel
if (pawn.TryGetComp<ThingComp_GuardianPsyField>(out var interceptor))
{
// Call our custom intercept method
if (interceptor.TryIntercept(__instance))
// Call our custom intercept method, passing in the projectile's path
if (interceptor.TryIntercept(__instance, lastExactPos, newExactPos))
{
// If interception is successful, destroy the projectile
__instance.Destroy(DestroyMode.Vanish);

View File

@@ -5,7 +5,6 @@ using Verse.Sound;
namespace ArachnaeSwarm
{
// 1. Expanded CompProperties to match the user's example
public class CompProperties_GuardianPsyField : CompProperties
{
public float radius = 5.9f;
@@ -13,16 +12,12 @@ namespace ArachnaeSwarm
public int rechargeDelay = 3200; // Ticks after breaking
public int rechargeHitPointsIntervalTicks = 60; // Ticks to restore 1 HP
// New properties for psyfocus/entropy mechanics
public float psyfocusCostPerInterval = 0.001f; // e.g., 0.1% of max psyfocus per recharge interval
public float entropyGainPerDamage = 0.5f; // For self
// Removed entropyGainPerAllyDamage
public float hitPointsPctPerInterval = 0.01f; // Restore 1% of max HP per interval
public float psyfocusCostPerInterval = 0.001f;
public float entropyGainPerDamage = 0.5f;
public float hitPointsPctPerInterval = 0.01f;
public EffecterDef absorbEffecter;
// Removed transferAllyDamage
// Projectile interception properties
public bool interceptGroundProjectiles = false;
public bool interceptGroundProjectiles = true;
public bool interceptNonHostileProjectiles = false;
public bool interceptAirProjectiles = true;
@@ -41,19 +36,16 @@ namespace ArachnaeSwarm
[StaticConstructorOnStartup]
public class ThingComp_GuardianPsyField : ThingComp
{
// --- State Variables ---
private int lastInterceptTicks = -999999;
private int ticksToReset = 0; // Cooldown timer
private int ticksToReset = 0;
public int currentHitPoints;
private bool wasNotAtFullHp = false; // Tracks if shield was damaged before recharge
private bool wasNotAtFullHp = false;
// --- Properties ---
public CompProperties_GuardianPsyField Props => (CompProperties_GuardianPsyField)props;
private Pawn PawnOwner => parent as Pawn;
public bool IsOnCooldown => ticksToReset > 0;
public int HitPointsMax => Props.hitPoints;
// --- Visuals ---
private static readonly Material ForceFieldMat = MaterialPool.MatFrom("Other/ForceField", ShaderDatabase.MoteGlow);
private static readonly MaterialPropertyBlock MatPropertyBlock = new MaterialPropertyBlock();
@@ -61,15 +53,12 @@ namespace ArachnaeSwarm
{
get
{
// Shield is active if pawn is valid, hediff is present, not on cooldown, and has psyfocus.
// currentHitPoints <= 0 should NOT prevent activation for recharge.
if (PawnOwner == null || !PawnOwner.Spawned || PawnOwner.Dead || PawnOwner.Downed || IsOnCooldown)
return false;
var hediff = PawnOwner.health.hediffSet.GetFirstHediffOfDef(HediffDef.Named("ARA_GuardianPsyField"));
if (hediff == null) return false;
// Shield is only active if pawn has psyfocus
if (PawnOwner.psychicEntropy == null || PawnOwner.psychicEntropy.CurrentPsyfocus <= 0) return false;
return true;
@@ -103,134 +92,79 @@ namespace ArachnaeSwarm
Reset();
}
}
// Only allow recharge if the shield is 'Active' (i.e., has psyfocus) and not on cooldown
else if (Active && currentHitPoints < HitPointsMax)
{
// Check if there's enough psyfocus to pay for this interval's recharge
if (PawnOwner.psychicEntropy != null && PawnOwner.psychicEntropy.CurrentPsyfocus >= Props.psyfocusCostPerInterval)
{
wasNotAtFullHp = true; // Mark that the shield was damaged
wasNotAtFullHp = true;
if(this.parent.IsHashIntervalTick(Props.rechargeHitPointsIntervalTicks))
{
currentHitPoints += (int)(HitPointsMax * Props.hitPointsPctPerInterval);
if(currentHitPoints > HitPointsMax) currentHitPoints = HitPointsMax;
// Deduct psyfocus for this interval
PawnOwner.psychicEntropy.OffsetPsyfocusDirectly(-Props.psyfocusCostPerInterval);
}
}
else
{
// Not enough psyfocus to recharge, log for debugging
Log.Message($"[GuardianFieldComp] {PawnOwner.LabelShort} has insufficient psyfocus ({PawnOwner.psychicEntropy?.CurrentPsyfocus ?? 0}) to recharge shield (cost: {Props.psyfocusCostPerInterval}).");
}
}
// The full recharge psyfocus deduction is removed, as it's now gradual.
// The wasNotAtFullHp check is still useful for other potential effects when full.
else if (wasNotAtFullHp && currentHitPoints >= HitPointsMax)
{
wasNotAtFullHp = false; // Reset flag when full
wasNotAtFullHp = false;
}
}
// Projectile interception logic remains the same, as it's a separate Harmony patch
public bool TryIntercept(Projectile projectile)
// Helper method to apply costs
private void ApplyCosts(float damageAmount)
{
if (!Active) return false;
// Filter projectile types based on properties
if (projectile.def.projectile.flyOverhead && !Props.interceptAirProjectiles) return false;
if (!projectile.def.projectile.flyOverhead && !Props.interceptGroundProjectiles) return false;
if (projectile.Launcher != null && !projectile.Launcher.HostileTo(PawnOwner.Faction) && !Props.interceptNonHostileProjectiles) return false;
// --- Interception Success ---
lastInterceptTicks = Find.TickManager.TicksGame;
// Spawn effect at the point of interception, not the shield center
Props.interceptEffecter?.Spawn(projectile.ExactPosition.ToIntVec3(), PawnOwner.Map).Cleanup();
// No longer consuming hitpoints here, PostPreApplyDamage will handle it for self.
// The Harmony_DamageWorker for allies will handle it for allies.
return true;
}
// --- NEW: PostPreApplyDamage for self-protection (all damage types) ---
public override void PostPreApplyDamage(ref DamageInfo dinfo, out bool absorbed)
{
absorbed = false;
if (!Active || PawnOwner == null) return; // Only intercept if shield is active and for the owner
// We intercept ALL damage types for the owner
if (currentHitPoints < dinfo.Amount) return; // Not enough HP to absorb
// --- Absorption Success for self ---
Props.absorbEffecter?.Spawn(PawnOwner.Position, PawnOwner.Map).Cleanup(); // Effect at center for self-damage
// Add entropy based on damage taken for self
if (PawnOwner.psychicEntropy != null && Props.entropyGainPerDamage > 0)
{
PawnOwner.psychicEntropy.TryAddEntropy(dinfo.Amount * Props.entropyGainPerDamage, overLimit: true);
PawnOwner.psychicEntropy.TryAddEntropy(damageAmount * Props.entropyGainPerDamage, overLimit: true);
}
// Consume Hitpoints
currentHitPoints -= (int)dinfo.Amount;
currentHitPoints -= (int)damageAmount;
if (currentHitPoints <= 0)
{
Break();
}
absorbed = true; // Damage was absorbed
}
public bool TryIntercept(Projectile projectile, Vector3 lastExactPos, Vector3 newExactPos)
{
if (!Active) return false;
if (currentHitPoints <= 0) return false;
// --- REMOVED: Method for allies, called by Harmony patch ---
// public bool TryAbsorbDamageForAllyOnly(DamageInfo dinfo, Pawn allyPawn)
// {
// Log.Message($"[GuardianFieldComp] TryAbsorbDamageForAllyOnly for {allyPawn.LabelShort} (target) by {PawnOwner.LabelShort} (caster).");
// Log.Message($" - transferAllyDamage: {Props.transferAllyDamage}");
// Log.Message($" - Active: {Active}");
// Log.Message($" - allyPawn == PawnOwner: {allyPawn == PawnOwner}");
// Log.Message($" - allyPawn.Faction: {allyPawn.Faction?.Name ?? "Null"}, PawnOwner.Faction: {PawnOwner.Faction?.Name ?? "Null"}, FactionMatch: {allyPawn.Faction == PawnOwner.Faction}");
// Log.Message($" - InRange: {Vector3.Distance(allyPawn.TrueCenter(), PawnOwner.TrueCenter()) <= Props.radius}");
// Log.Message($" - HasHP: {currentHitPoints >= dinfo.Amount}");
if (!GenGeo.IntersectLineCircleOutline(PawnOwner.Position.ToVector2(), Props.radius, lastExactPos.ToVector2(), newExactPos.ToVector2()))
{
return false;
}
// // Check if ally damage transfer is enabled
// if (!Props.transferAllyDamage) { Log.Message(" -> transferAllyDamage is false."); return false; }
// // Shield must be active
// if (!Active) { Log.Message(" -> Shield is not Active."); return false; }
// // Cannot absorb damage for self (handled by PostPreApplyDamage)
// if (allyPawn == PawnOwner) { Log.Message(" -> Target is self."); return false; }
// // Only protect friendly pawns (same faction)
// if (allyPawn.Faction == null || PawnOwner.Faction == null || allyPawn.Faction != PawnOwner.Faction) { Log.Message(" -> Faction mismatch or null faction."); return false; }
// // Target must be in range
// if (Vector3.Distance(allyPawn.TrueCenter(), PawnOwner.TrueCenter()) > Props.radius) { Log.Message(" -> Target out of range."); return false; }
// // Check if shield has enough HP
// if (currentHitPoints < dinfo.Amount) { Log.Message(" -> Not enough HP to absorb damage."); return false; }
// // --- Absorption Success for ally ---
// Props.absorbEffecter?.Spawn(allyPawn.Position, allyPawn.Map).Cleanup();
// // Add entropy based on damage taken for ally
// if (PawnOwner.psychicEntropy != null && Props.entropyGainPerAllyDamage > 0)
// {
// PawnOwner.psychicEntropy.TryAddEntropy(dinfo.Amount * Props.entropyGainPerAllyDamage, overLimit: true);
// }
// // Consume Hitpoints
// currentHitPoints -= (int)dinfo.Amount;
// if (currentHitPoints <= 0)
// {
// Break();
// }
if (projectile.def.projectile.flyOverhead && !Props.interceptAirProjectiles) return false;
if (!projectile.def.projectile.flyOverhead && !Props.interceptGroundProjectiles) return false;
if (projectile.Launcher != null && !projectile.Launcher.HostileTo(PawnOwner.Faction) && !Props.interceptNonHostileProjectiles) return false;
// Log.Message(" -> Damage absorption successful!");
// return true; // Damage was absorbed
// }
lastInterceptTicks = Find.TickManager.TicksGame;
Props.interceptEffecter?.Spawn(projectile.ExactPosition.ToIntVec3(), PawnOwner.Map).Cleanup();
// Apply costs for intercepting projectile
ApplyCosts(projectile.DamageAmount);
return true;
}
public override void PostPreApplyDamage(ref DamageInfo dinfo, out bool absorbed)
{
absorbed = false;
if (!Active || PawnOwner == null) return;
// We only handle non-projectile damage here, as projectiles are handled by TryIntercept
if (dinfo.Def.isRanged) return;
if (currentHitPoints < dinfo.Amount) return;
Props.absorbEffecter?.Spawn(PawnOwner.Position, PawnOwner.Map).Cleanup();
// Apply costs for absorbing non-projectile damage
ApplyCosts(dinfo.Amount);
absorbed = true;
}
private void Break()
{
@@ -275,7 +209,6 @@ namespace ArachnaeSwarm
return Mathf.Max(idleAlpha, interceptAlpha);
}
// --- GIZMO ---
public override System.Collections.Generic.IEnumerable<Gizmo> CompGetGizmosExtra()
{
if (PawnOwner != null && Find.Selector.SingleSelectedThing == PawnOwner)
@@ -285,7 +218,6 @@ namespace ArachnaeSwarm
}
}
// Gizmo class copied from the user's example and adapted
[StaticConstructorOnStartup]
public class Gizmo_GuardianShieldStatus : Gizmo
{
@@ -304,7 +236,7 @@ namespace ArachnaeSwarm
Rect labelRect = rect2;
labelRect.height = rect.height / 2f;
Text.Font = GameFont.Tiny;
Widgets.Label(labelRect, "Guardian Field");
Widgets.Label(labelRect, "ARA_GuardianFieldGizmoLabel".Translate());
Rect barRect = rect2;
barRect.yMin = rect2.y + rect2.height / 2f;