This commit is contained in:
2025-09-07 17:27:06 +08:00
parent 7a6d5380e1
commit b28594c604
5 changed files with 17 additions and 12 deletions

Binary file not shown.

View File

@@ -39,6 +39,9 @@
<inertiaDistance>6</inertiaDistance>
<collisionDamageDef>Blunt</collisionDamageDef>
<flyerDef>ARA_Flyer_TrackingCharge</flyerDef>
<maxFlightTicks>600</maxFlightTicks> <!-- 7.5 seconds timeout -->
<collisionRadius>2.5</collisionRadius> <!-- Larger collision radius -->
<impactSound>Pawn_Melee_BigBash_HitPawn</impactSound>
</li>
</comps>
</AbilityDef>

View File

@@ -11,6 +11,9 @@ namespace ArachnaeSwarm
public float inertiaDistance = 3f;
public DamageDef collisionDamageDef;
public ThingDef flyerDef;
public int maxFlightTicks = 300; // Default 5 seconds timeout
public float collisionRadius = 1.5f;
public SoundDef impactSound;
public CompProperties_TrackingCharge()
{

View File

@@ -5,6 +5,7 @@ using System.Reflection;
using System.Linq;
using Verse.AI;
using System.Collections.Generic;
using Verse.Sound;
namespace ArachnaeSwarm
{
@@ -18,6 +19,8 @@ namespace ArachnaeSwarm
public DamageDef collisionDamageDef;
public LocalTargetInfo primaryTarget;
public int maxFlightTicks;
public float collisionRadius;
public SoundDef impactSound;
// --- Internal state ---
private Vector3 currentSpeed;
@@ -114,8 +117,12 @@ namespace ArachnaeSwarm
float calculatedDamage = this.initialDamage + (this.distanceTraveled * this.damagePerTile);
var dinfo = new DamageInfo(this.collisionDamageDef, calculatedDamage, 1f, -1, this.FlyingPawn);
if (!hasHitPrimaryTarget && homing && primaryTarget.HasThing && primaryTarget.Thing.Spawned && (this.exactPosition - primaryTarget.Thing.DrawPos).sqrMagnitude < 1.5f * 1.5f)
if (!hasHitPrimaryTarget && homing && primaryTarget.HasThing && primaryTarget.Thing.Spawned && (this.exactPosition - primaryTarget.Thing.DrawPos).sqrMagnitude < this.collisionRadius * this.collisionRadius)
{
if (this.impactSound != null)
{
SoundStarter.PlayOneShot(this.impactSound, new TargetInfo(this.exactPosition.ToIntVec3(), this.Map));
}
hasHitPrimaryTarget = true; // Mark as hit to prevent re-triggering
primaryTarget.Thing.TakeDamage(dinfo);
homing = false;

View File

@@ -46,17 +46,9 @@ namespace ArachnaeSwarm
trackingCharge.inertiaDistance = props.inertiaDistance;
trackingCharge.collisionDamageDef = props.collisionDamageDef;
trackingCharge.primaryTarget = this.currentTarget;
// --- Dynamic Timeout Calculation ---
float flightSpeed = props.flyerDef.pawnFlyer.flightSpeed;
if (flightSpeed <= 0)
{
Log.Error("flyerDef has no flightSpeed, cannot calculate timeout.");
return false;
}
// Timeout is twice the time it would take to fly the max range in a straight line
int maxTicks = (int)((this.verbProps.range / flightSpeed) * 2.0f);
trackingCharge.maxFlightTicks = maxTicks;
trackingCharge.maxFlightTicks = props.maxFlightTicks;
trackingCharge.collisionRadius = props.collisionRadius;
trackingCharge.impactSound = props.impactSound;
// Setup and spawn
trackingCharge.StartFlight(this.CasterPawn, this.currentTarget.Cell);