This commit is contained in:
2025-09-21 15:21:22 +08:00
parent 5d2d2c5e4d
commit 4fb30a03aa
6 changed files with 104 additions and 39 deletions

Binary file not shown.

View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8" ?>
<Defs>
<JobDef>
<defName>ARA_DeployWormhole</defName>
<driverClass>ArachnaeSwarm.JobDriver_DeployWormhole</driverClass>
<reportString>deploying wormhole.</reportString>
<allowOpportunisticPrefix>true</allowOpportunisticPrefix>
</JobDef>
</Defs>

View File

@@ -209,6 +209,7 @@
<Compile Include="Wormhole\Building_WormholePortal_A.cs" />
<Compile Include="Wormhole\Building_WormholePortal_B.cs" />
<Compile Include="Wormhole\CompLaunchableWormhole.cs" />
<Compile Include="Wormhole\JobDriver_DeployWormhole.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- 自定义清理任务删除obj文件夹中的临时文件 -->

View File

@@ -2,6 +2,7 @@ using RimWorld;
using RimWorld.Planet;
using System.Collections.Generic;
using Verse;
using Verse.AI;
namespace ArachnaeSwarm
{
@@ -136,6 +137,50 @@ namespace ArachnaeSwarm
}
}
public override IEnumerable<FloatMenuOption> GetFloatMenuOptions(Pawn selPawn)
{
foreach (var option in base.GetFloatMenuOptions(selPawn))
{
yield return option;
}
if (status == WormholePortalStatus.Linked)
{
yield break;
}
if (!selPawn.CanReach(this, PathEndMode.Touch, Danger.Deadly))
{
yield return new FloatMenuOption("CannotUseNoPath".Translate(), null);
yield break;
}
var compLaunchable = this.GetComp<CompLaunchableWormhole>();
var compRefuelable = this.GetComp<CompRefuelable>();
if (compRefuelable.Fuel < compLaunchable.Props.fuelNeededToLaunch)
{
yield return new FloatMenuOption("CommandDeployWormholePortalB_Pilot".Translate() + " (" + "NotEnoughFuel".Translate() + ")", null);
yield break;
}
// TODO: Create ARA_DeployWormhole JobDef
var jobDef = DefDatabase<JobDef>.GetNamed("ARA_DeployWormhole", false);
if (jobDef == null)
{
yield return new FloatMenuOption("DEV: JobDef ARA_DeployWormhole not found", null);
yield break;
}
void action()
{
var job = JobMaker.MakeJob(jobDef, this);
selPawn.jobs.TryTakeOrderedJob(job, JobTag.Misc);
}
yield return new FloatMenuOption("CommandDeployWormholePortalB_Pilot".Translate(), action);
}
public override string GetInspectString()
{
string text = base.GetInspectString();

View File

@@ -21,45 +21,8 @@ namespace ArachnaeSwarm
public override IEnumerable<Gizmo> CompGetGizmosExtra()
{
if (PortalA?.status == WormholePortalStatus.Linked)
{
yield break;
}
Command_Action launchCommand = new Command_Action();
launchCommand.defaultLabel = "CommandDeployWormholePortalB_Pilot".Translate();
launchCommand.defaultDesc = "CommandDeployWormholePortalB_PilotDesc".Translate();
launchCommand.icon = ContentFinder<Texture2D>.Get("UI/Commands/LaunchShip");
if (refuelableComp.Fuel < this.Props.fuelNeededToLaunch)
{
launchCommand.Disable("NotEnoughFuel".Translate());
}
launchCommand.action = delegate
{
var targetingParameters = new TargetingParameters
{
canTargetPawns = true,
canTargetBuildings = false,
mapObjectTargetsMustBeAutoAttackable = false,
validator = (TargetInfo target) =>
{
if (!target.HasThing) return false;
Pawn p = target.Thing as Pawn;
return p != null && p.IsColonistPlayerControlled && !p.Downed && !p.IsBurning();
}
};
Find.Targeter.BeginTargeting(targetingParameters, (LocalTargetInfo target) =>
{
Pawn pilot = target.Pawn;
if (pilot != null)
{
StartChoosingDestination(pilot);
}
});
};
yield return launchCommand;
// The gizmo is now replaced by a float menu option.
yield break;
}
public void StartChoosingDestination(Pawn pilot)

View File

@@ -0,0 +1,45 @@
using System.Collections.Generic;
using Verse;
using Verse.AI;
namespace ArachnaeSwarm
{
public class JobDriver_DeployWormhole : JobDriver
{
private Building_WormholePortal_A PortalA => (Building_WormholePortal_A)job.targetA.Thing;
public override bool TryMakePreToilReservations(bool errorOnFailed)
{
return pawn.Reserve(job.targetA, job, 1, -1, null, errorOnFailed);
}
protected override IEnumerable<Toil> MakeNewToils()
{
this.FailOnDespawnedOrNull(TargetIndex.A);
this.FailOn(() => PortalA.status == WormholePortalStatus.Linked);
// Go to Portal A
yield return Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch);
// Wait a bit to simulate 'entering'
Toil waitToil = Toils_General.Wait(120).WithProgressBarToilDelay(TargetIndex.A);
waitToil.FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch);
yield return waitToil;
// Start the deployment process
Toil deployToil = new Toil();
deployToil.initAction = delegate
{
var comp = PortalA.GetComp<CompLaunchableWormhole>();
if (comp != null)
{
// This will open the world map targeting UI
// The actual teleportation of the pilot happens inside StartChoosingDestination -> ChoseWorldTarget -> Deploy
comp.StartChoosingDestination(pawn);
}
};
deployToil.defaultCompleteMode = ToilCompleteMode.Instant;
yield return deployToil;
}
}
}