63 lines
2.5 KiB
C#
63 lines
2.5 KiB
C#
using Verse;
|
|
using Verse.AI;
|
|
using RimWorld;
|
|
|
|
namespace ArachnaeSwarm
|
|
{
|
|
public class FloatMenuOptionProvider_SuperCarry : FloatMenuOptionProvider
|
|
{
|
|
protected override bool Drafted => true;
|
|
protected override bool Undrafted => false;
|
|
protected override bool Multiselect => false;
|
|
protected override bool RequiresManipulation => true;
|
|
|
|
protected override bool AppliesInt(FloatMenuContext context)
|
|
{
|
|
var extension = context.FirstSelectedPawn.kindDef.GetModExtension<SuperCarryExtension>();
|
|
if (extension == null || !extension.canSuperCarry)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (extension.requiresFlight)
|
|
{
|
|
if (context.FirstSelectedPawn.flight == null || !context.FirstSelectedPawn.flight.Flying)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
protected override FloatMenuOption GetSingleOptionFor(Pawn clickedPawn, FloatMenuContext context)
|
|
{
|
|
Pawn carrier = context.FirstSelectedPawn;
|
|
var extension = carrier.kindDef.GetModExtension<SuperCarryExtension>();
|
|
|
|
if (clickedPawn == carrier) return null;
|
|
|
|
// 新增:检查是否允许携带敌对单位
|
|
if (clickedPawn.HostileTo(Faction.OfPlayer) && (extension == null || !extension.canCarryHostile))
|
|
{
|
|
return new FloatMenuOption("CannotCarry".Translate(clickedPawn) + ": " + "CarriedPawnHostile".Translate(), null);
|
|
}
|
|
|
|
if (!carrier.CanReach(clickedPawn, PathEndMode.ClosestTouch, Danger.Deadly))
|
|
{
|
|
return new FloatMenuOption("CannotCarry".Translate(clickedPawn) + ": " + "NoPath".Translate().CapitalizeFirst(), null);
|
|
}
|
|
if (!carrier.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))
|
|
{
|
|
return new FloatMenuOption("CannotCarry".Translate(carrier) + ": " + "Incapable".Translate().CapitalizeFirst(), null);
|
|
}
|
|
|
|
return FloatMenuUtility.DecoratePrioritizedTask(new FloatMenuOption("SuperCarry".Translate(clickedPawn.LabelShort, clickedPawn), delegate
|
|
{
|
|
Job job = JobMaker.MakeJob(DefDatabase<JobDef>.GetNamed("SuperCarry"), clickedPawn);
|
|
job.count = 1;
|
|
carrier.jobs.TryTakeOrderedJob(job, JobTag.Misc);
|
|
}), carrier, clickedPawn);
|
|
}
|
|
}
|
|
} |