This commit is contained in:
2025-09-22 17:05:31 +08:00
parent db7e4393bc
commit 7da2bcc223
6 changed files with 89 additions and 103 deletions

View File

@@ -2,77 +2,17 @@ using RimWorld;
using RimWorld.Planet;
using UnityEngine;
using Verse;
using Verse.AI;
using Verse.Sound;
namespace ArachnaeSwarm
{
public class Verb_LaunchCatastropheMissile : Verb_Shoot
{
public override bool CanHitTargetFrom(IntVec3 root, LocalTargetInfo targ)
{
var silo = this.Caster as Building_CatastropheMissileSilo;
if (silo != null && silo.longTarget.IsValid)
{
return true;
}
return base.CanHitTargetFrom(root, targ);
}
// This verb is now only for local defense. The global launch is handled by the Building.
protected override bool TryCastShot()
{
var silo = this.Caster as Building_CatastropheMissileSilo;
if (silo != null && silo.longTarget.IsValid)
{
return this.TryCastGlobalShot(silo);
}
// If no long target, perform a normal local shot
return base.TryCastShot();
}
private bool TryCastGlobalShot(Building_CatastropheMissileSilo silo)
{
var refuelableComp = silo.TryGetComp<CompRefuelable>();
if (refuelableComp != null && !refuelableComp.HasFuel)
{
Messages.Message("NoMissileToLaunch".Translate(), silo, MessageTypeDefOf.RejectInput);
return false;
}
WorldObject_CatastropheMissile missile = (WorldObject_CatastropheMissile)WorldObjectMaker.MakeWorldObject(
DefDatabase<WorldObjectDef>.GetNamed("CatastropheMissile_Flying")
);
missile.Tile = silo.Map.Tile;
missile.destinationTile = silo.longTarget.Tile;
missile.destinationCell = silo.longTarget.Cell;
missile.Projectile = DefDatabase<ThingDef>.GetNamed("Projectile_CatastropheMissile");
Find.WorldObjects.Add(missile);
if(refuelableComp != null)
{
refuelableComp.ConsumeFuel(1);
}
SoundDef.Named("RocketLaunch").PlayOneShot(new TargetInfo(silo.Position, silo.Map));
// Reset target after launch
silo.longTarget = GlobalTargetInfo.Invalid;
// Manually reset cooldown
if (this.burstShotsLeft < this.verbProps.burstShotCount)
{
this.burstShotsLeft = 0;
}
if (this.verbProps.burstShotCount > 0)
{
this.ticksToNextBurstShot = this.verbProps.ticksBetweenBurstShots;
}
this.state = VerbState.Idle;
return true;
}
}
}