Skip to content
This repository has been archived by the owner on Nov 3, 2022. It is now read-only.

Commit

Permalink
PipeSystem: Add extractTime option to CompResourceStorage
Browse files Browse the repository at this point in the history
  • Loading branch information
KylianB committed Jul 19, 2022
1 parent 26f53ea commit 5b233dc
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 18 deletions.
Binary file modified 1.3/Assemblies/PipeSystem.dll
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public class ExtractOptions
public string labelKey;
public string descKey;

public int extractTime = 150;
public int extractAmount;
public ThingDef thing;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,29 +16,35 @@ protected override IEnumerable<Toil> MakeNewToils()
this.FailOnDespawnedOrNull(TargetIndex.A);
this.FailOn(() => Map.designationManager.DesignationOn(TargetThingA, PSDefOf.PS_Drain) == null);

ThingWithComps thingWithComps = (ThingWithComps)pawn.CurJob.targetA.Thing;
CompResourceStorage compRS = null;

for (int i = 0; i < thingWithComps.AllComps.Count; i++)
{
if (thingWithComps.AllComps[i] is CompResourceStorage cps)
compRS = cps;
}

this.FailOn(() => compRS == null);

yield return Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch);
yield return Toils_General.Wait(150).FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch).FailOnDestroyedOrNull(TargetIndex.A).WithProgressBarToilDelay(TargetIndex.A);
yield return Toils_General.Wait(compRS.Props.extractOptions.extractTime).FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch).FailOnDestroyedOrNull(TargetIndex.A).WithProgressBarToilDelay(TargetIndex.A);

Toil finalize = new Toil();
finalize.initAction = delegate
Toil finalize = new Toil
{
Pawn actor = finalize.actor;
ThingWithComps thingWithComps = (ThingWithComps)actor.CurJob.targetA.Thing;
for (int i = 0; i < thingWithComps.AllComps.Count; i++)
initAction = delegate
{
if (thingWithComps.AllComps[i] is CompResourceStorage cPS && cPS.extractResourceAmount <= cPS.AmountStored)
{
cPS.DrawResource(cPS.extractResourceAmount);

var opt = cPS.Props.extractOptions;
Thing createdThing = ThingMaker.MakeThing(opt.thing);
createdThing.stackCount = opt.extractAmount;
GenSpawn.Spawn(createdThing, pawn.Position, Map, WipeMode.VanishOrMoveAside);
}
}
Map.designationManager.DesignationOn(thingWithComps, PSDefOf.PS_Drain)?.Delete();
compRS.DrawResource(compRS.extractResourceAmount);

var opt = compRS.Props.extractOptions;
Thing createdThing = ThingMaker.MakeThing(opt.thing);
createdThing.stackCount = opt.extractAmount;
GenSpawn.Spawn(createdThing, pawn.Position, Map, WipeMode.VanishOrMoveAside);

Map.designationManager.DesignationOn(thingWithComps, PSDefOf.PS_Drain)?.Delete();
},
defaultCompleteMode = ToilCompleteMode.Instant
};
finalize.defaultCompleteMode = ToilCompleteMode.Instant;
yield return finalize;
}
}
Expand Down

0 comments on commit 5b233dc

Please sign in to comment.