Add Building_CumBucket.StoredStackCount attribute

This commit is contained in:
amevarashi 2022-05-23 22:07:31 +05:00
parent 5130c70655
commit 877bea1eb6
2 changed files with 39 additions and 14 deletions

View File

@ -1,23 +1,52 @@
using RimWorld; using RimWorld;
using System.Linq;
using System.Text;
using Verse; using Verse;
namespace RJWSexperience // Used in Menstruation with this namespace namespace RJWSexperience // Used in Menstruation with this namespace
{ {
public class Building_CumBucket : Building_Storage public class Building_CumBucket : Building_Storage
{ {
protected float storedcum = 0f; protected float storedDecimalRemainder = 0f;
protected float totalgathered = 0f; protected float totalGathered = 0f;
public int StoredStackCount
{
get
{
if (!slotGroup.HeldThings.Any())
return 0;
return slotGroup.HeldThings.Select(thing => thing.stackCount).Aggregate((sum, x) => sum + x);
}
}
public override void ExposeData() public override void ExposeData()
{ {
Scribe_Values.Look(ref storedcum, "storedcum", storedcum, true); Scribe_Values.Look(ref storedDecimalRemainder, "storedcum", 0f);
Scribe_Values.Look(ref totalgathered, "totalgathered", totalgathered, true); Scribe_Values.Look(ref totalGathered, "totalgathered", 0f);
base.ExposeData(); base.ExposeData();
} }
public override string GetInspectString() public override string GetInspectString()
{ {
return Keyed.RSTotalGatheredCum + string.Format("{0:0.##}ml", totalgathered); StringBuilder stringBuilder = new StringBuilder();
string baseString = base.GetInspectString();
if (!baseString.NullOrEmpty())
{
stringBuilder.AppendLine(baseString);
}
stringBuilder.Append(Keyed.RSTotalGatheredCum).AppendFormat("{0:0.##}ml", totalGathered);
if (SexperienceMod.Settings.Debug.DevMode)
{
stringBuilder.AppendLine();
stringBuilder.AppendLine($"[Debug] stored: {StoredStackCount}");
stringBuilder.Append($"[Debug] storedDecimalRemainder: {storedDecimalRemainder}");
}
return stringBuilder.ToString();
} }
public void AddCum(float amount) public void AddCum(float amount)
@ -33,16 +62,16 @@ namespace RJWSexperience // Used in Menstruation with this namespace
public void AddCum(float amount, Thing cum) public void AddCum(float amount, Thing cum)
{ {
storedcum += amount; storedDecimalRemainder += amount;
totalgathered += amount; totalGathered += amount;
int num = (int)storedcum; int num = (int)storedDecimalRemainder;
cum.stackCount = num; cum.stackCount = num;
if (cum.stackCount > 0 && !GenPlace.TryPlaceThing(cum, PositionHeld, Map, ThingPlaceMode.Direct, out Thing res)) if (cum.stackCount > 0 && !GenPlace.TryPlaceThing(cum, PositionHeld, Map, ThingPlaceMode.Direct, out Thing res))
{ {
FilthMaker.TryMakeFilth(PositionHeld, Map, VariousDefOf.FilthCum, num); FilthMaker.TryMakeFilth(PositionHeld, Map, VariousDefOf.FilthCum, num);
} }
storedcum -= num; storedDecimalRemainder -= num;
} }
} }
} }

View File

@ -22,11 +22,7 @@ namespace RJWSexperience.Cum
if (!(t is Building_CumBucket bucket)) if (!(t is Building_CumBucket bucket))
return false; return false;
List<Thing> thingsInBucket = bucket.Map.thingGrid.ThingsListAt(bucket.Position); return bucket.StoredStackCount < VariousDefOf.GatheredCum.stackLimit;
int stackInBucket = thingsInBucket.Select(thing => thing.stackCount).Aggregate((sum, x) => sum + x);
return stackInBucket < VariousDefOf.GatheredCum.stackLimit;
} }
public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false) public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)