为乌拉族引入了新的“机体维护”需求,通过`WULA_Maintenance_Neglect`健康状况(Hediff)体现。该状况会随时间推移而恶化,影响角色能力。 新增建筑“维护舱”(`WULA_MaintenancePod`),乌拉族成员可进入其中进行维护,以清除“维护疏忽”的负面效果。维护过程需要消耗电力和零部件,所需零部件数量与负面效果的严重程度相关。 实现了配套的自动化工作逻辑: - 当维护需求达到阈值时,角色会自动进入维护舱。 - 当维护舱缺少零部件时,搬运工会自动为其装填。 此外,事件系统中增加了一个新的条件 `Condition_FactionExists`。
66 lines
2.3 KiB
C#
66 lines
2.3 KiB
C#
using RimWorld;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using Verse;
|
|
using Verse.AI;
|
|
|
|
namespace WulaFallenEmpire
|
|
{
|
|
public class WorkGiver_LoadComponents : WorkGiver_Scanner
|
|
{
|
|
public override ThingRequest PotentialWorkThingRequest => ThingRequest.ForDef(ThingDef.Named("WULA_MaintenancePod"));
|
|
|
|
public override PathEndMode PathEndMode => PathEndMode.Touch;
|
|
|
|
public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
|
|
{
|
|
if (!(t is Building building) || !building.Spawned || building.IsForbidden(pawn) || !pawn.CanReserve(building, 1, -1, null, forced))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
var podComp = building.GetComp<CompMaintenancePod>();
|
|
if (podComp == null || podComp.State != MaintenancePodState.Idle)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
// We define a "needed" threshold. Let's say we want to keep at least 10 components stocked.
|
|
// This prevents pawns from hauling one component at a time.
|
|
const int desiredStockpile = 10;
|
|
if (podComp.storedComponents >= desiredStockpile)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (FindBestComponent(pawn, podComp) == null)
|
|
{
|
|
JobFailReason.Is("WULA_NoComponentsToLoad".Translate());
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
|
|
{
|
|
var podComp = t.GetComp<CompMaintenancePod>();
|
|
Thing component = FindBestComponent(pawn, podComp);
|
|
if (component == null)
|
|
{
|
|
return null;
|
|
}
|
|
return JobMaker.MakeJob(JobDefOf.WULA_LoadComponentsToMaintenancePod, t, component);
|
|
}
|
|
|
|
private Thing FindBestComponent(Pawn pawn, CompMaintenancePod pod)
|
|
{
|
|
ThingDef componentDef = pod.Props.componentDef;
|
|
if (componentDef == null) return null;
|
|
|
|
Predicate<Thing> validator = (Thing x) => !x.IsForbidden(pawn) && pawn.CanReserve(x);
|
|
return GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(componentDef), PathEndMode.ClosestTouch, TraverseParms.For(pawn), 9999f, validator);
|
|
}
|
|
}
|
|
} |