hediff能量

This commit is contained in:
2025-07-22 19:31:18 +08:00
parent 15494e8a8e
commit 0dcebba343
8 changed files with 36 additions and 12 deletions

View File

@@ -29,7 +29,8 @@ namespace WulaFallenEmpire
protected override IEnumerable<Toil> MakeNewToils()
{
this.FailOnDespawnedNullOrForbidden(PatientInd);
this.FailOn(() => !FeedPatientUtility.ShouldBeFed(Patient));
// The job should fail if the patient is no longer in bed.
this.FailOn(() => !Patient.InBed());
if (pawn.inventory != null && pawn.inventory.Contains(Food))
{

View File

@@ -16,7 +16,7 @@ namespace WulaFallenEmpire
public override IEnumerable<Thing> PotentialWorkThingsGlobal(Pawn pawn)
{
return pawn.Map.mapPawns.AllPawns.Where(p => p.needs.TryGetNeed<Need_WulaEnergy>() != null && FeedPatientUtility.ShouldBeFed(p));
return pawn.Map.mapPawns.AllPawns.Where(p => p.needs.TryGetNeed<Need_WulaEnergy>() != null && p.InBed());
}
public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
@@ -39,12 +39,8 @@ namespace WulaFallenEmpire
return false;
}
if (!FeedPatientUtility.ShouldBeFed(patient))
{
return false;
}
if (WardenFeedUtility.ShouldBeFed(patient))
// A Wula patient should be fed if they are in bed. If the job is not forced, they must also be unable to move.
if (!patient.InBed() || (!forced && patient.health.capacities.CapableOf(PawnCapacityDefOf.Moving)))
{
return false;
}

View File

@@ -19,6 +19,11 @@ namespace WulaFallenEmpire
return null;
}
if (EnergyAvailableInRoomTo(prisoner))
{
return null;
}
if (!TryFindBestEnergySourceFor(pawn, prisoner, out Thing energySource, out _))
{
return null;
@@ -26,10 +31,27 @@ namespace WulaFallenEmpire
Job job = JobMaker.MakeJob(JobDefOf.DeliverFood, energySource, prisoner);
job.count = 1;
job.targetC = RCellFinder.SpotToChewStandingNear(prisoner, energySource);
return job;
}
private bool EnergyAvailableInRoomTo(Pawn prisoner)
{
if (prisoner.GetRoom() == null)
{
return false;
}
var allThings = prisoner.GetRoom().ContainedAndAdjacentThings;
foreach (Thing thing in allThings)
{
if (thing.def.GetModExtension<ThingDefExtension_EnergySource>() != null)
{
return true;
}
}
return false;
}
private bool TryFindBestEnergySourceFor(Pawn getter, Pawn eater, out Thing energySource, out ThingDef energyDef)
{
energySource = null;

View File

@@ -26,6 +26,12 @@ namespace WulaFallenEmpire
return null;
}
// The prisoner must be in bed to be fed by a warden. If the job is not forced, they must also be unable to move.
if (!prisoner.InBed() || (!forced && prisoner.health.capacities.CapableOf(PawnCapacityDefOf.Moving)))
{
return null;
}
if (!TryFindBestEnergySourceFor(pawn, prisoner, out Thing energySource, out _))
{
return null;

View File

@@ -81,7 +81,6 @@
<Compile Include="VerbPropertiesExplosiveBeam.cs" />
<Compile Include="HediffComp_WulaCharging.cs" />
<Compile Include="JobGiver_WulaGetEnergy.cs" />
<Compile Include="JobGiverDefExtension_WulaGetEnergy.cs" />
<Compile Include="JobGiver_WulaPackEnergy.cs" />
<Compile Include="JobGiverDefExtension_WulaPackEnergy.cs" />
</ItemGroup>