2026-07-15 23:24:32 -05:00
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using RimWorld;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using Verse;
|
|
|
|
|
using Verse.AI;
|
|
|
|
|
|
|
|
|
|
namespace FCP.Core.Robotics
|
|
|
|
|
{
|
|
|
|
|
public class CompProperties_RobotUpgradeBench : CompProperties
|
|
|
|
|
{
|
|
|
|
|
public CompProperties_RobotUpgradeBench()
|
|
|
|
|
{
|
|
|
|
|
compClass = typeof(CompRobotUpgradeBench);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class CompRobotUpgradeBench : ThingComp
|
|
|
|
|
{
|
|
|
|
|
public CompProperties_RobotUpgradeBench Props => (CompProperties_RobotUpgradeBench)props;
|
|
|
|
|
|
|
|
|
|
public override IEnumerable<Gizmo> CompGetGizmosExtra()
|
|
|
|
|
{
|
|
|
|
|
yield return new Command_Action
|
|
|
|
|
{
|
|
|
|
|
defaultLabel = "FCP_UpgradeRobot_Gizmo".Translate(),
|
|
|
|
|
defaultDesc = "FCP_UpgradeRobot_GizmoDesc".Translate(),
|
|
|
|
|
icon = ContentFinder<Texture2D>.Get("Things/Items/Techprints/FCP_Techprint_Holotape_Orange"),
|
|
|
|
|
action = OpenUpgradeSelectMenu,
|
|
|
|
|
};
|
2026-07-25 09:01:02 -05:00
|
|
|
yield return new Command_Action
|
|
|
|
|
{
|
|
|
|
|
defaultLabel = "FCP_RobotInfo_Gizmo".Translate(),
|
|
|
|
|
defaultDesc = "FCP_RobotInfo_GizmoDesc".Translate(),
|
|
|
|
|
icon = TexButton.Info,
|
|
|
|
|
action = () => Find.WindowStack.Add(new Dialog_RobotInfo()),
|
|
|
|
|
};
|
2026-07-15 23:24:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OpenUpgradeSelectMenu()
|
|
|
|
|
{
|
|
|
|
|
List<FloatMenuOption> options = new List<FloatMenuOption>();
|
|
|
|
|
IEnumerable<Pawn> robots = parent.Map.mapPawns.AllPawnsSpawned
|
|
|
|
|
.Where(p => p.Faction == Faction.OfPlayer && RobotUtility.IsAnyRobot(p));
|
|
|
|
|
|
|
|
|
|
foreach (Pawn robot in robots)
|
|
|
|
|
{
|
|
|
|
|
IRobotTierProvider provider = RobotUtility.GetProvider(robot);
|
|
|
|
|
PawnKindDef nextTier = provider?.GetNextTier(robot.kindDef);
|
2026-07-19 00:57:55 -05:00
|
|
|
if (nextTier != null)
|
2026-07-15 23:24:32 -05:00
|
|
|
{
|
2026-07-19 00:57:55 -05:00
|
|
|
RobotTierExtension tierExt = nextTier.GetModExtension<RobotTierExtension>();
|
|
|
|
|
if (tierExt?.researchPrerequisite != null && !tierExt.researchPrerequisite.IsFinished)
|
|
|
|
|
{
|
|
|
|
|
options.Add(new FloatMenuOption($"{robot.LabelShort}: {"FCP_UpgradeRobot_NeedsResearch".Translate(tierExt.researchPrerequisite.LabelCap)}", null));
|
|
|
|
|
continue;
|
|
|
|
|
}
|
2026-07-15 23:24:32 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
options.Add(new FloatMenuOption(robot.LabelShort, () => CallToBench(robot)));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (options.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
options.Add(new FloatMenuOption("FCP_UpgradeRobot_NoneAvailable".Translate(), null));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Find.WindowStack.Add(new FloatMenu(options));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CallToBench(Pawn robot)
|
|
|
|
|
{
|
|
|
|
|
CompRobotUpgrade upgradeComp = robot.GetComp<CompRobotUpgrade>();
|
|
|
|
|
if (upgradeComp != null)
|
|
|
|
|
{
|
|
|
|
|
upgradeComp.PendingBench = parent;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public override IEnumerable<FloatMenuOption> CompFloatMenuOptions(Pawn selPawn)
|
|
|
|
|
{
|
|
|
|
|
if (!selPawn.CanReach(parent, PathEndMode.InteractionCell, Danger.Deadly))
|
|
|
|
|
{
|
|
|
|
|
yield return new FloatMenuOption("FCP_UpgradeRobot_Perform".Translate() + ": " + "NoPath".Translate(), null);
|
|
|
|
|
yield break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Pawn dockedRobot = FindDockedRobot();
|
|
|
|
|
if (dockedRobot == null)
|
|
|
|
|
{
|
|
|
|
|
yield break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IRobotTierProvider provider = RobotUtility.GetProvider(dockedRobot);
|
|
|
|
|
if (provider == null)
|
|
|
|
|
{
|
|
|
|
|
yield break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PawnKindDef nextTier = provider.GetNextTier(dockedRobot.kindDef);
|
|
|
|
|
if (nextTier == null)
|
|
|
|
|
{
|
|
|
|
|
yield break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
RobotTierExtension tierExt = nextTier.GetModExtension<RobotTierExtension>();
|
|
|
|
|
if (tierExt != null && !RobotUpgradeUtility.CanAffordCost(parent.Map, tierExt.upgradeCost))
|
|
|
|
|
{
|
|
|
|
|
yield return new FloatMenuOption("FCP_UpgradeRobot_Perform".Translate() + ": " + "FCP_UpgradeRobot_MissingMaterials".Translate(), null);
|
|
|
|
|
yield break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
yield return new FloatMenuOption("FCP_UpgradeRobot_Perform".Translate(), delegate
|
|
|
|
|
{
|
|
|
|
|
Job job = JobMaker.MakeJob(JobDefOf_Robotics.FCP_UpgradeRobot, parent, dockedRobot);
|
|
|
|
|
selPawn.jobs.TryTakeOrderedJob(job, JobTag.Misc);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Pawn FindDockedRobot()
|
|
|
|
|
{
|
|
|
|
|
foreach (Pawn p in parent.Map.mapPawns.AllPawnsSpawned)
|
|
|
|
|
{
|
|
|
|
|
if (RobotUtility.IsAnyRobot(p) && p.CurJobDef == JobDefOf_Robotics.FCP_RobotDock &&
|
|
|
|
|
p.CurJob.GetTarget(TargetIndex.A).Thing == parent)
|
|
|
|
|
{
|
|
|
|
|
return p;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|