diff --git a/1.6/Assemblies/WulaFallenEmpire.dll b/1.6/Assemblies/WulaFallenEmpire.dll index f177ec77..80439592 100644 Binary files a/1.6/Assemblies/WulaFallenEmpire.dll and b/1.6/Assemblies/WulaFallenEmpire.dll differ diff --git a/1.6/Defs/JobDefs/WULA_Jobs_Maintenance.xml b/1.6/Defs/JobDefs/WULA_Jobs_Maintenance.xml deleted file mode 100644 index 29f026db..00000000 --- a/1.6/Defs/JobDefs/WULA_Jobs_Maintenance.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - WULA_LoadComponentsToMaintenancePod - WulaFallenEmpire.JobDriver_LoadComponents - 正在为维护舱装填零部件。 - ToCellNonStorage - - - - WULA_EnterMaintenancePod - WulaFallenEmpire.JobDriver_EnterMaintenancePod - 正在进入维护舱。 - - - \ No newline at end of file diff --git a/1.6/Defs/ThingDefs_Buildings/WULA_Buildings_Maintenance.xml b/1.6/Defs/ThingDefs_Buildings/WULA_Buildings_Maintenance.xml index 6241a359..24d78ad0 100644 --- a/1.6/Defs/ThingDefs_Buildings/WULA_Buildings_Maintenance.xml +++ b/1.6/Defs/ThingDefs_Buildings/WULA_Buildings_Maintenance.xml @@ -42,13 +42,6 @@ BuildingDestroyed_Metal_Big 1800 - - - -
  • ComponentIndustrial
  • -
    -
    -
    Misc MinifiedThing @@ -79,9 +72,6 @@
  • PlaceWorker_PreventInteractionSpotOverlap
  • - -
  • ITab_Storage
  • -
    \ No newline at end of file diff --git a/1.6/Defs/WorkGiverDefs/WULA_WorkGivers.xml b/1.6/Defs/WorkGiverDefs/WULA_WorkGivers.xml deleted file mode 100644 index dd5a0365..00000000 --- a/1.6/Defs/WorkGiverDefs/WULA_WorkGivers.xml +++ /dev/null @@ -1,27 +0,0 @@ - - - - - WULA_LoadComponentsToMaintenancePod - - WulaFallenEmpire.WorkGiver_LoadComponents - Hauling - 装填 - 装填于 - 110 - -
  • Manipulation
  • -
    -
    - - - WULA_EnterMaintenancePod - - WulaFallenEmpire.WorkGiver_EnterMaintenancePod - Patient - 进行维护 - 进行维护于 - 100 - - -
    \ No newline at end of file diff --git a/Source/WulaFallenEmpire/CompMaintenancePod.cs b/Source/WulaFallenEmpire/CompMaintenancePod.cs index 32a17baa..ba82b2c9 100644 --- a/Source/WulaFallenEmpire/CompMaintenancePod.cs +++ b/Source/WulaFallenEmpire/CompMaintenancePod.cs @@ -6,6 +6,7 @@ using System.Text; using UnityEngine; using Verse; using Verse.AI; +using Verse.Sound; namespace WulaFallenEmpire { @@ -31,14 +32,12 @@ namespace WulaFallenEmpire } [StaticConstructorOnStartup] - public class CompMaintenancePod : ThingComp, IThingHolder, IStoreSettingsParent + public class CompMaintenancePod : ThingComp, IThingHolder { // ===================== Fields ===================== private ThingOwner innerContainer; private CompPowerTrader powerComp; - private StorageSettings allowedComponentSettings; - - public float storedComponents = 0f; + private CompRefuelable refuelableComp; private int ticksRemaining; private MaintenancePodState state = MaintenancePodState.Idle; @@ -64,36 +63,20 @@ namespace WulaFallenEmpire innerContainer = new ThingOwner(this, false, LookMode.Deep); } - public override void Initialize(CompProperties props) - { - base.Initialize(props); - // Setup allowed thing filter for components - allowedComponentSettings = new StorageSettings(this); - if (parent.def.building.defaultStorageSettings != null) - { - allowedComponentSettings.CopyFrom(parent.def.building.defaultStorageSettings); - } - else if (Props.componentDef != null) - { - allowedComponentSettings.filter = new ThingFilter(); - allowedComponentSettings.filter.SetAllow(Props.componentDef, true); - } - } public override void PostSpawnSetup(bool respawningAfterLoad) { base.PostSpawnSetup(respawningAfterLoad); powerComp = parent.TryGetComp(); + refuelableComp = parent.TryGetComp(); } public override void PostExposeData() { base.PostExposeData(); Scribe_Values.Look(ref state, "state", MaintenancePodState.Idle); - Scribe_Values.Look(ref storedComponents, "storedComponents", 0f); Scribe_Values.Look(ref ticksRemaining, "ticksRemaining", 0); Scribe_Deep.Look(ref innerContainer, "innerContainer", this); - Scribe_Deep.Look(ref allowedComponentSettings, "allowedComponentSettings", this); } // ===================== IThingHolder Implementation ===================== @@ -107,13 +90,6 @@ namespace WulaFallenEmpire return innerContainer; } - // ===================== IStoreSettingsParent Implementation ===================== - public StorageSettings GetStoreSettings() => allowedComponentSettings; - public StorageSettings GetParentStoreSettings() => parent.def.building.fixedStorageSettings; - public void Notify_SettingsChanged() { } - public bool StorageTabVisible => true; - - // ===================== Core Logic ===================== public override void CompTick() { @@ -143,13 +119,13 @@ namespace WulaFallenEmpire public void StartCycle(Pawn pawn) { float required = RequiredComponents(pawn); - if (storedComponents < required) + if (refuelableComp == null || refuelableComp.Fuel < required) { Log.Error($"[WulaFallenEmpire] Tried to start maintenance cycle for {pawn.LabelShort} without enough components. This should have been checked earlier."); return; } - storedComponents -= required; + refuelableComp.ConsumeFuel(required); state = MaintenancePodState.Running; ticksRemaining = Props.durationTicks; @@ -174,7 +150,7 @@ namespace WulaFallenEmpire Hediff hediff = occupant.health.hediffSet.GetFirstHediffOfDef(Props.hediffToRemove); if (hediff != null) { - occupant.health.RemoveHediff(hediff); + hediff.Severity = 0.01f; Messages.Message("WULA_MaintenanceComplete".Translate(occupant.Named("PAWN")), occupant, MessageTypeDefOf.PositiveEvent); } } @@ -190,19 +166,13 @@ namespace WulaFallenEmpire GenPlace.TryPlaceThing(occupant, parent.InteractionCell, parent.Map, ThingPlaceMode.Near); if (Props.exitSound != null) { - Props.exitSound.PlayOneShot(new TargetInfo(parent.Position, parent.Map)); + SoundStarter.PlayOneShot(Props.exitSound, new TargetInfo(parent.Position, parent.Map)); } } innerContainer.Clear(); state = MaintenancePodState.Idle; } - public void AddComponents(Thing components) - { - int count = components.stackCount; - storedComponents += count; - components.Destroy(); - } // ===================== UI & Gizmos ===================== public override string CompInspectStringExtra() @@ -216,7 +186,10 @@ namespace WulaFallenEmpire sb.AppendLine("TimeLeft".Translate() + ": " + ticksRemaining.ToStringTicksToPeriod()); } - sb.AppendLine("WULA_MaintenancePod_StoredComponents".Translate() + ": " + storedComponents.ToString("F0")); + if (refuelableComp != null) + { + sb.AppendLine("WULA_MaintenancePod_StoredComponents".Translate() + ": " + refuelableComp.Fuel.ToString("F0") + " / " + refuelableComp.Props.fuelCapacity.ToString("F0")); + } if (!PowerOn) { @@ -244,12 +217,12 @@ namespace WulaFallenEmpire if (p.health.hediffSet.HasHediff(Props.hediffToRemove)) { float required = RequiredComponents(p); - if (storedComponents >= required) + if (refuelableComp != null && refuelableComp.Fuel >= required) { options.Add(new FloatMenuOption(p.LabelShort, () => { - // TODO: Create and assign job - Messages.Message("This needs a JobDriver.", MessageTypeDefOf.RejectInput); + Job job = JobMaker.MakeJob(JobDefOf_WULA.WULA_EnterMaintenancePod, parent); + p.jobs.TryTakeOrderedJob(job, JobTag.Misc); })); } else diff --git a/Source/WulaFallenEmpire/JobDefOf_WULA.cs b/Source/WulaFallenEmpire/JobDefOf_WULA.cs new file mode 100644 index 00000000..ed0e0d28 --- /dev/null +++ b/Source/WulaFallenEmpire/JobDefOf_WULA.cs @@ -0,0 +1,17 @@ +using RimWorld; +using Verse; + +namespace WulaFallenEmpire +{ + [DefOf] + public static class JobDefOf_WULA + { + public static JobDef WULA_LoadComponentsToMaintenancePod; + public static JobDef WULA_EnterMaintenancePod; + + static JobDefOf_WULA() + { + DefOfHelper.EnsureInitializedInCtor(typeof(JobDefOf_WULA)); + } + } +} \ No newline at end of file diff --git a/Source/WulaFallenEmpire/JobDriver_LoadComponents.cs b/Source/WulaFallenEmpire/JobDriver_LoadComponents.cs deleted file mode 100644 index 8dbfbd38..00000000 --- a/Source/WulaFallenEmpire/JobDriver_LoadComponents.cs +++ /dev/null @@ -1,53 +0,0 @@ -using RimWorld; -using System; -using System.Collections.Generic; -using Verse; -using Verse.AI; - -namespace WulaFallenEmpire -{ - public class JobDriver_LoadComponents : JobDriver - { - private const TargetIndex PodIndex = TargetIndex.A; - private const TargetIndex ComponentIndex = TargetIndex.B; - - protected Thing Pod => job.GetTarget(PodIndex).Thing; - protected Thing Component => job.GetTarget(ComponentIndex).Thing; - - public override bool TryMakePreToilReservations(bool errorOnFailed) - { - if (pawn.Reserve(Pod, job, 1, -1, null, errorOnFailed)) - { - return pawn.Reserve(Component, job, 1, -1, null, errorOnFailed); - } - return false; - } - - protected override IEnumerable MakeNewToils() - { - this.FailOnDespawnedNullOrForbidden(PodIndex); - this.FailOnBurningImmobile(PodIndex); - - var podComp = Pod.TryGetComp(); - this.FailOn(() => podComp == null || podComp.State != MaintenancePodState.Idle); - - // Go and get the components - yield return Toils_Goto.GotoThing(ComponentIndex, PathEndMode.OnCell).FailOnSomeonePhysicallyInteracting(ComponentIndex); - yield return Toils_Haul.StartCarryThing(ComponentIndex); - - // Carry them to the pod - yield return Toils_Goto.GotoThing(PodIndex, PathEndMode.InteractionCell); - - // Load the components - yield return Toils_General.WaitWith(60, TargetIndex.A, true, true, false, PodIndex); - yield return new Toil - { - initAction = () => - { - podComp.AddComponents(this.GetActor().carryTracker.CarriedThing); - }, - defaultCompleteMode = ToilCompleteMode.Instant - }; - } - } -} \ No newline at end of file diff --git a/Source/WulaFallenEmpire/Job_Maintenance.cs b/Source/WulaFallenEmpire/Job_Maintenance.cs index 160c7a5b..46cd988c 100644 --- a/Source/WulaFallenEmpire/Job_Maintenance.cs +++ b/Source/WulaFallenEmpire/Job_Maintenance.cs @@ -4,10 +4,6 @@ using Verse.AI; namespace WulaFallenEmpire { - public class JobDriver_EnterMaintenancePod : JobDriver_EnterBiosculpterPod - { - } - public class WorkGiver_DoMaintenance : WorkGiver_Scanner { public override ThingRequest PotentialWorkThingRequest => ThingRequest.ForDef(ThingDef.Named("WULA_MaintenancePod")); diff --git a/Source/WulaFallenEmpire/WorkGiver_EnterMaintenancePod.cs b/Source/WulaFallenEmpire/WorkGiver_EnterMaintenancePod.cs deleted file mode 100644 index 7966c1fa..00000000 --- a/Source/WulaFallenEmpire/WorkGiver_EnterMaintenancePod.cs +++ /dev/null @@ -1,62 +0,0 @@ -using RimWorld; -using System; -using System.Collections.Generic; -using System.Linq; -using Verse; -using Verse.AI; - -namespace WulaFallenEmpire -{ - public class WorkGiver_EnterMaintenancePod : WorkGiver_Scanner - { - public override ThingRequest PotentialWorkThingRequest => ThingRequest.ForDef(ThingDef.Named("WULA_MaintenancePod")); - - public override PathEndMode PathEndMode => PathEndMode.InteractionCell; - - // This method now checks the severity of the hediff. - public override bool ShouldSkip(Pawn pawn, bool forced = false) - { - var podDef = ThingDef.Named("WULA_MaintenancePod"); - var podProps = podDef.GetCompProperties(); - if (podProps?.hediffToRemove == null) return true; - - Hediff hediff = pawn.health.hediffSet.GetFirstHediffOfDef(podProps.hediffToRemove); - - // Skip if no hediff or if severity is below the configured threshold. - if (hediff == null || hediff.Severity < podProps.minSeverityToMaintain) - { - return true; - } - - return false; - } - - 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(); - if (podComp == null || podComp.State != MaintenancePodState.Idle || !podComp.PowerOn) - { - return false; - } - - float requiredComponents = podComp.RequiredComponents(pawn); - if (podComp.storedComponents < requiredComponents) - { - JobFailReason.Is("WULA_MaintenancePod_NotEnoughComponents".Translate(requiredComponents.ToString("F0"))); - return false; - } - - return true; - } - - public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false) - { - return JobMaker.MakeJob(JobDefOf.WULA_EnterMaintenancePod, t); - } - } -} \ No newline at end of file diff --git a/Source/WulaFallenEmpire/WorkGiver_LoadComponents.cs b/Source/WulaFallenEmpire/WorkGiver_LoadComponents.cs deleted file mode 100644 index e823a16e..00000000 --- a/Source/WulaFallenEmpire/WorkGiver_LoadComponents.cs +++ /dev/null @@ -1,66 +0,0 @@ -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(); - 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(); - 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 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); - } - } -} \ No newline at end of file diff --git a/Source/WulaFallenEmpire/WulaFallenEmpire.csproj b/Source/WulaFallenEmpire/WulaFallenEmpire.csproj index f3ae8ec9..94759690 100644 --- a/Source/WulaFallenEmpire/WulaFallenEmpire.csproj +++ b/Source/WulaFallenEmpire/WulaFallenEmpire.csproj @@ -72,6 +72,7 @@ + @@ -98,9 +99,11 @@ + + @@ -140,7 +143,7 @@ - +