diff --git a/1.6/Assemblies/WulaFallenEmpire.dll b/1.6/Assemblies/WulaFallenEmpire.dll index 85be7978..526fd317 100644 Binary files a/1.6/Assemblies/WulaFallenEmpire.dll and b/1.6/Assemblies/WulaFallenEmpire.dll differ diff --git a/1.6/Defs/EventDefs/EventDef_Examples.xml b/1.6/Defs/EventDefs/EventDef_Examples.xml index d0a955c9..78615cba 100644 --- a/1.6/Defs/EventDefs/EventDef_Examples.xml +++ b/1.6/Defs/EventDefs/EventDef_Examples.xml @@ -8,7 +8,14 @@
  • - +
  • + + Mechanoid +
  • +
  • 来自乌拉帝国 大教堂的进攻 diff --git a/1.6/Defs/HediffDefs/Hediffs_WULA_Maintenance.xml b/1.6/Defs/HediffDefs/Hediffs_WULA_Maintenance.xml index 83a942da..52cd2b90 100644 --- a/1.6/Defs/HediffDefs/Hediffs_WULA_Maintenance.xml +++ b/1.6/Defs/HediffDefs/Hediffs_WULA_Maintenance.xml @@ -9,7 +9,7 @@ false 0 0 - 2 + 1
  • @@ -59,16 +59,6 @@
  • -
  • - - 2.0 - -
  • - Consciousness - 0.1 -
  • - - \ No newline at end of file diff --git a/1.6/Defs/JobDefs/WULA_JobDefs.xml b/1.6/Defs/JobDefs/WULA_JobDefs.xml index 68ba56d1..fa9d8530 100644 --- a/1.6/Defs/JobDefs/WULA_JobDefs.xml +++ b/1.6/Defs/JobDefs/WULA_JobDefs.xml @@ -22,6 +22,7 @@ true + WULA_HaulToMaintenancePod WulaFallenEmpire.JobDriver_HaulToMaintenancePod diff --git a/1.6/Defs/Misc/FactionExists_Example.xml b/1.6/Defs/Misc/FactionExists_Example.xml deleted file mode 100644 index 902e348d..00000000 --- a/1.6/Defs/Misc/FactionExists_Example.xml +++ /dev/null @@ -1,45 +0,0 @@ - - - - - - MyCustomEvent_RequiresMechanoids - - 一个只有在机械族存在时才会发生的特殊事件。 - - - - - -
  • - - Mechanoid -
  • - - - -
    - - - -
    - -
    \ No newline at end of file diff --git a/1.6/Defs/Misc/LetterDefs/EventLetter.xml b/1.6/Defs/WulaMiscSettingDefs/LetterDefs/EventLetter.xml similarity index 100% rename from 1.6/Defs/Misc/LetterDefs/EventLetter.xml rename to 1.6/Defs/WulaMiscSettingDefs/LetterDefs/EventLetter.xml diff --git a/1.6/Defs/Misc/LifeStageDefs/LifeStages_WULA.xml b/1.6/Defs/WulaMiscSettingDefs/LifeStageDefs/LifeStages_WULA.xml similarity index 100% rename from 1.6/Defs/Misc/LifeStageDefs/LifeStages_WULA.xml rename to 1.6/Defs/WulaMiscSettingDefs/LifeStageDefs/LifeStages_WULA.xml diff --git a/Source/WulaFallenEmpire/CompMaintenancePod.cs b/Source/WulaFallenEmpire/CompMaintenancePod.cs index 43217cee..891b0d47 100644 --- a/Source/WulaFallenEmpire/CompMaintenancePod.cs +++ b/Source/WulaFallenEmpire/CompMaintenancePod.cs @@ -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 GetPawnOptions() { List options = new List(); - 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(); + 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 { diff --git a/Source/WulaFallenEmpire/JobDefOf_WULA.cs b/Source/WulaFallenEmpire/JobDefOf_WULA.cs index 253d8ae7..917ffc15 100644 --- a/Source/WulaFallenEmpire/JobDefOf_WULA.cs +++ b/Source/WulaFallenEmpire/JobDefOf_WULA.cs @@ -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() diff --git a/Source/WulaFallenEmpire/JobDriver_HaulToMaintenancePod.cs b/Source/WulaFallenEmpire/JobDriver_HaulToMaintenancePod.cs index 6046a391..1a0e6fbd 100644 --- a/Source/WulaFallenEmpire/JobDriver_HaulToMaintenancePod.cs +++ b/Source/WulaFallenEmpire/JobDriver_HaulToMaintenancePod.cs @@ -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(); 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 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(); - 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; } } } \ No newline at end of file diff --git a/Source/WulaFallenEmpire/ThingDefOf_WULA.cs b/Source/WulaFallenEmpire/ThingDefOf_WULA.cs index 60f5e417..4f61ed19 100644 --- a/Source/WulaFallenEmpire/ThingDefOf_WULA.cs +++ b/Source/WulaFallenEmpire/ThingDefOf_WULA.cs @@ -7,7 +7,6 @@ namespace WulaFallenEmpire public static class ThingDefOf_WULA { public static ThingDef WULA_MaintenancePod; - public static ThingDef Wula; static ThingDefOf_WULA() { diff --git a/Source/WulaFallenEmpire/WorkGiver_HaulToMaintenancePod.cs b/Source/WulaFallenEmpire/WorkGiver_HaulToMaintenancePod.cs deleted file mode 100644 index 95d56697..00000000 --- a/Source/WulaFallenEmpire/WorkGiver_HaulToMaintenancePod.cs +++ /dev/null @@ -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 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(); - 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(); - 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().Fuel && - rescuer.CanReserve(p)) - .OrderBy(p => p.Position.DistanceTo(rescuer.Position)) - .FirstOrDefault(); - } - } -} \ No newline at end of file diff --git a/Source/WulaFallenEmpire/WulaFallenEmpire.csproj b/Source/WulaFallenEmpire/WulaFallenEmpire.csproj index 6fc2e370..12426e5b 100644 --- a/Source/WulaFallenEmpire/WulaFallenEmpire.csproj +++ b/Source/WulaFallenEmpire/WulaFallenEmpire.csproj @@ -136,7 +136,6 @@ -