搬运倒地的乌拉进维护
This commit is contained in:
@@ -147,8 +147,7 @@ namespace WulaFallenEmpire
|
||||
ticksRemaining = RequiredDuration(pawn);
|
||||
|
||||
// Move pawn inside
|
||||
pawn.DeSpawn();
|
||||
innerContainer.TryAdd(pawn, true);
|
||||
innerContainer.TryAddOrTransfer(pawn);
|
||||
}
|
||||
|
||||
private void CycleFinished()
|
||||
@@ -199,7 +198,10 @@ namespace WulaFallenEmpire
|
||||
|
||||
if (state == MaintenancePodState.Running)
|
||||
{
|
||||
sb.AppendLine("Contains".Translate() + ": " + Occupant.NameShortColored.Resolve());
|
||||
if (Occupant != null)
|
||||
{
|
||||
sb.AppendLine("Contains".Translate() + ": " + Occupant.NameShortColored.Resolve());
|
||||
}
|
||||
sb.AppendLine("TimeLeft".Translate() + ": " + ticksRemaining.ToStringTicksToPeriod());
|
||||
}
|
||||
|
||||
@@ -264,7 +266,7 @@ namespace WulaFallenEmpire
|
||||
private List<FloatMenuOption> GetPawnOptions()
|
||||
{
|
||||
List<FloatMenuOption> options = new List<FloatMenuOption>();
|
||||
foreach (Pawn p in parent.Map.mapPawns.FreeColonists.Where(pawn => pawn.def == ThingDefOf_WULA.Wula))
|
||||
foreach (Pawn p in parent.Map.mapPawns.FreeColonists.Where(pawn => pawn.def.defName == "WulaSpecies" || pawn.def.defName == "WulaSpeciesReal"))
|
||||
{
|
||||
if (p.health.hediffSet.HasHediff(Props.hediffToRemove))
|
||||
{
|
||||
@@ -274,8 +276,38 @@ namespace WulaFallenEmpire
|
||||
}
|
||||
else if (p.Downed)
|
||||
{
|
||||
// This is handled by the WorkGiver, but we can add a note here if we want.
|
||||
// options.Add(new FloatMenuOption(p.LabelShortCap + " (" + "Incapacitated".Translate() + ")", null));
|
||||
float required = RequiredComponents(p);
|
||||
if (refuelableComp.Fuel < required)
|
||||
{
|
||||
options.Add(new FloatMenuOption(p.LabelShortCap + " (" + "Incapacitated".Translate() + ", " + "WULA_MaintenancePod_NotEnoughComponents".Translate(required.ToString("F0")) + ")", null));
|
||||
}
|
||||
else
|
||||
{
|
||||
Action action = delegate
|
||||
{
|
||||
var potentialRescuers = parent.Map.mapPawns.FreeColonistsSpawned.Where(colonist =>
|
||||
!colonist.Downed && colonist.CanReserveAndReach(p, PathEndMode.OnCell, Danger.Deadly) && colonist.CanReserveAndReach(parent, PathEndMode.InteractionCell, Danger.Deadly));
|
||||
|
||||
if (!potentialRescuers.Any())
|
||||
{
|
||||
Messages.Message("WULA_MaintenancePod_NoRescuer".Translate(p.Named("PAWN")), MessageTypeDefOf.RejectInput);
|
||||
return;
|
||||
}
|
||||
|
||||
var rescuerOptions = new List<FloatMenuOption>();
|
||||
foreach (var rescuer in potentialRescuers)
|
||||
{
|
||||
rescuerOptions.Add(new FloatMenuOption(rescuer.LabelCap, delegate
|
||||
{
|
||||
var haulJob = JobMaker.MakeJob(JobDefOf_WULA.WULA_HaulToMaintenancePod, p, parent);
|
||||
haulJob.count = 1;
|
||||
rescuer.jobs.TryTakeOrderedJob(haulJob, JobTag.Misc);
|
||||
}));
|
||||
}
|
||||
Find.WindowStack.Add(new FloatMenu(rescuerOptions));
|
||||
};
|
||||
options.Add(new FloatMenuOption(p.LabelShortCap + " (" + "Incapacitated".Translate() + ")", action));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -6,8 +6,8 @@ namespace WulaFallenEmpire
|
||||
[DefOf]
|
||||
public static class JobDefOf_WULA
|
||||
{
|
||||
public static JobDef WULA_LoadComponentsToMaintenancePod;
|
||||
public static JobDef WULA_EnterMaintenancePod;
|
||||
|
||||
public static JobDef WULA_HaulToMaintenancePod;
|
||||
|
||||
static JobDefOf_WULA()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
using RimWorld;
|
||||
using System.Collections.Generic;
|
||||
using RimWorld;
|
||||
using Verse;
|
||||
using Verse.AI;
|
||||
|
||||
@@ -7,46 +7,50 @@ namespace WulaFallenEmpire
|
||||
{
|
||||
public class JobDriver_HaulToMaintenancePod : JobDriver
|
||||
{
|
||||
private const TargetIndex PatientIndex = TargetIndex.A;
|
||||
private const TargetIndex TakeeIndex = TargetIndex.A;
|
||||
private const TargetIndex PodIndex = TargetIndex.B;
|
||||
|
||||
protected Pawn Patient => (Pawn)job.GetTarget(PatientIndex).Thing;
|
||||
protected Building_Bed Pod => (Building_Bed)job.GetTarget(PodIndex).Thing;
|
||||
protected Pawn Takee => (Pawn)job.GetTarget(TakeeIndex).Thing;
|
||||
protected Building Pod => (Building)job.GetTarget(PodIndex).Thing;
|
||||
protected CompMaintenancePod PodComp => Pod.TryGetComp<CompMaintenancePod>();
|
||||
|
||||
public override bool TryMakePreToilReservations(bool errorOnFailed)
|
||||
{
|
||||
return pawn.Reserve(Patient, job, 1, -1, null, errorOnFailed) &&
|
||||
pawn.Reserve(Pod, job, 1, -1, null, errorOnFailed);
|
||||
return pawn.Reserve(Takee, job, 1, -1, null, errorOnFailed)
|
||||
&& pawn.Reserve(Pod, job, 1, -1, null, errorOnFailed);
|
||||
}
|
||||
|
||||
protected override IEnumerable<Toil> MakeNewToils()
|
||||
{
|
||||
this.FailOnDespawnedNullOrForbidden(PodIndex);
|
||||
this.FailOnDespawnedNullOrForbidden(PatientIndex);
|
||||
this.FailOnAggroMentalState(PatientIndex);
|
||||
this.FailOn(() => !Patient.Downed);
|
||||
// Standard failure conditions
|
||||
this.FailOnDestroyedOrNull(TakeeIndex);
|
||||
this.FailOnDestroyedOrNull(PodIndex);
|
||||
this.FailOnAggroMentalStateAndHostile(TakeeIndex);
|
||||
this.FailOn(() => PodComp == null); // Fail if the pod doesn't have our component
|
||||
this.FailOn(() => !pawn.CanReach(Pod, PathEndMode.InteractionCell, Danger.Deadly));
|
||||
this.FailOn(() => !Takee.Downed); // Can only haul downed pawns
|
||||
|
||||
var podComp = Pod.TryGetComp<CompMaintenancePod>();
|
||||
this.FailOn(() => podComp == null || podComp.State != MaintenancePodState.Idle || !podComp.PowerOn);
|
||||
// Go to the pawn to be rescued
|
||||
yield return Toils_Goto.GotoThing(TakeeIndex, PathEndMode.ClosestTouch)
|
||||
.FailOnDespawnedNullOrForbidden(TakeeIndex)
|
||||
.FailOnDespawnedNullOrForbidden(PodIndex)
|
||||
.FailOnSomeonePhysicallyInteracting(TakeeIndex);
|
||||
|
||||
// Go to the patient
|
||||
yield return Toils_Goto.GotoThing(PatientIndex, PathEndMode.OnCell);
|
||||
// Start carrying the pawn
|
||||
yield return Toils_Haul.StartCarryThing(TakeeIndex, false, true, false);
|
||||
|
||||
// Pick up the patient
|
||||
yield return Toils_Haul.StartCarryThing(PatientIndex);
|
||||
|
||||
// Carry the patient to the pod
|
||||
// Go to the maintenance pod
|
||||
yield return Toils_Goto.GotoThing(PodIndex, PathEndMode.InteractionCell);
|
||||
|
||||
// Place the patient in the pod
|
||||
yield return new Toil
|
||||
// Place the pawn inside the pod
|
||||
Toil placeInPod = ToilMaker.MakeToil("PlaceInPod");
|
||||
placeInPod.initAction = delegate
|
||||
{
|
||||
initAction = () =>
|
||||
{
|
||||
podComp.StartCycle(Patient);
|
||||
},
|
||||
defaultCompleteMode = ToilCompleteMode.Instant
|
||||
// The Comp will handle despawning the pawn and starting the cycle
|
||||
PodComp.StartCycle(Takee);
|
||||
};
|
||||
placeInPod.defaultCompleteMode = ToilCompleteMode.Instant;
|
||||
yield return placeInPod;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,6 @@ namespace WulaFallenEmpire
|
||||
public static class ThingDefOf_WULA
|
||||
{
|
||||
public static ThingDef WULA_MaintenancePod;
|
||||
public static ThingDef Wula;
|
||||
|
||||
static ThingDefOf_WULA()
|
||||
{
|
||||
|
||||
@@ -1,61 +0,0 @@
|
||||
using RimWorld;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Verse;
|
||||
using Verse.AI;
|
||||
|
||||
namespace WulaFallenEmpire
|
||||
{
|
||||
public class WorkGiver_HaulToMaintenancePod : WorkGiver_Scanner
|
||||
{
|
||||
public override ThingRequest PotentialWorkThingRequest => ThingRequest.ForDef(ThingDefOf_WULA.WULA_MaintenancePod);
|
||||
|
||||
public override IEnumerable<Thing> PotentialWorkThingsGlobal(Pawn pawn)
|
||||
{
|
||||
return pawn.Map.listerBuildings.AllBuildingsColonistOfDef(ThingDefOf_WULA.WULA_MaintenancePod);
|
||||
}
|
||||
|
||||
public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
|
||||
{
|
||||
if (!(t is Building pod) || !pawn.CanReserve(pod, 1, -1, null, forced))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var podComp = pod.GetComp<CompMaintenancePod>();
|
||||
if (podComp == null || podComp.State != MaintenancePodState.Idle || !podComp.PowerOn)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Pawn patient = FindPatientFor(pawn, podComp);
|
||||
return patient != null && pawn.CanReserve(patient, 1, -1, null, forced);
|
||||
}
|
||||
|
||||
public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
|
||||
{
|
||||
var pod = (Building)t;
|
||||
var podComp = pod.GetComp<CompMaintenancePod>();
|
||||
Pawn patient = FindPatientFor(pawn, podComp);
|
||||
if (patient == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
return JobMaker.MakeJob(JobDefOf_WULA.WULA_HaulToMaintenancePod, patient, pod);
|
||||
}
|
||||
|
||||
private Pawn FindPatientFor(Pawn rescuer, CompMaintenancePod podComp)
|
||||
{
|
||||
return rescuer.Map.mapPawns.AllPawnsSpawned
|
||||
.Where(p => p.def == ThingDefOf_WULA.Wula &&
|
||||
p.Faction == rescuer.Faction &&
|
||||
!p.IsForbidden(rescuer) &&
|
||||
p.Downed && // Key condition: pawn cannot walk
|
||||
p.health.hediffSet.HasHediff(podComp.Props.hediffToRemove) &&
|
||||
podComp.RequiredComponents(p) <= podComp.parent.GetComp<CompRefuelable>().Fuel &&
|
||||
rescuer.CanReserve(p))
|
||||
.OrderBy(p => p.Position.DistanceTo(rescuer.Position))
|
||||
.FirstOrDefault();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -136,7 +136,6 @@
|
||||
<Compile Include="Verb\Verb_ShootBeamExplosive.cs" />
|
||||
<Compile Include="Verb\VerbPropertiesExplosiveBeam.cs" />
|
||||
<Compile Include="WorkGiver_FeedWulaPatient.cs" />
|
||||
<Compile Include="WorkGiver_HaulToMaintenancePod.cs" />
|
||||
<Compile Include="WorkGiver_Warden_DeliverEnergy.cs" />
|
||||
<Compile Include="WorkGiver_Warden_FeedWula.cs" />
|
||||
<Compile Include="WorkGiverDefExtension_FeedWula.cs" />
|
||||
|
||||
Reference in New Issue
Block a user