Files
RickGrymes f84841be45 Merge modules into core and add robotics
Consolidates Enlist, Laser, and PresettablePocketMap code into FCP_Core and removes their separate projects/assemblies. Adds a full robotics feature set (robot control terminal, modes, hacking, docking/upgrading, loadouts, quest integration, derelict/wild robot behavior, and supporting defs/jobs), plus biome-restricted raid support and dedicated trader-character spawning updates. Also expands game content with new weapon/melee sound defs and assets, many new site map icons, a new Fusion Core item, lunchbox loot table additions, and several compatibility/bug fixes for updated RimWorld APIs and edge cases.
2026-07-15 23:24:32 -05:00

69 lines
2.2 KiB
C#

using System.Collections.Generic;
using RimWorld;
using Verse;
using Verse.AI;
namespace FCP.Core.Robotics
{
public class JobDriver_UpgradeRobot : JobDriver
{
private const int WorkTicks = 320;
private Thing Bench => job.GetTarget(TargetIndex.A).Thing;
private Pawn Robot => (Pawn)job.GetTarget(TargetIndex.B).Thing;
public override bool TryMakePreToilReservations(bool errorOnFailed)
{
return pawn.Reserve(Bench, job, 1, -1, null, errorOnFailed) && pawn.Reserve(Robot, job, 1, -1, null, errorOnFailed);
}
protected override IEnumerable<Toil> MakeNewToils()
{
this.FailOnDestroyedOrNull(TargetIndex.A);
this.FailOnDestroyedOrNull(TargetIndex.B);
this.FailOn(() => Robot.CurJobDef != JobDefOf_Robotics.FCP_RobotDock);
yield return Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.InteractionCell);
Toil work = Toils_General.Wait(WorkTicks);
work.WithProgressBarToilDelay(TargetIndex.A);
work.FailOnCannotTouch(TargetIndex.A, PathEndMode.InteractionCell);
yield return work;
yield return new Toil
{
initAction = FinishUpgrade,
defaultCompleteMode = ToilCompleteMode.Instant,
};
}
private void FinishUpgrade()
{
IRobotTierProvider provider = RobotUtility.GetProvider(Robot);
PawnKindDef nextTier = provider?.GetNextTier(Robot.kindDef);
if (nextTier == null)
{
return;
}
RobotTierExtension tierExt = nextTier.GetModExtension<RobotTierExtension>();
if (tierExt != null && !RobotUpgradeUtility.TryConsumeCost(pawn.Map, tierExt.upgradeCost))
{
return;
}
provider.UpgradeTo(Robot, nextTier);
CompRobotUpgrade upgradeComp = Robot.GetComp<CompRobotUpgrade>();
if (upgradeComp != null)
{
upgradeComp.PendingBench = null;
}
if (Robot.CurJobDef == JobDefOf_Robotics.FCP_RobotDock)
{
Robot.jobs.EndCurrentJob(JobCondition.InterruptForced);
}
}
}
}