private void GiveEtherState(EtherState state) { var aspectTracker = Pawn.GetAspectTracker(); if (aspectTracker != null) { int stageNum; switch (state) { case EtherState.Broken: stageNum = 0; break; case EtherState.Bond: stageNum = 1; break; case EtherState.None: default: throw new ArgumentOutOfRangeException(nameof(state), state, null); } aspectTracker.Add(AspectDefOf.EtherState, stageNum); } }
private void Produce(int amount, float chance, ThingDef resource, ThingDef rareResource, ThoughtDef stageThought) { MemoryThoughtHandler thoughts = Pawn.needs?.mood?.thoughts?.memories; EtherState etherState = Pawn.GetEtherState(); HatchingTicker = 0; var thingCount = 0; var rareThingCount = 0; Aspect infusedAspect = Pawn.GetAspectTracker()?.GetAspect(AspectDefOf.MutagenInfused); int?sIndex = infusedAspect?.StageIndex; for (var i = 0; i < amount; i++) { bool shouldProduceRare; switch (sIndex) { case null: shouldProduceRare = Rand.RangeInclusive(0, 100) <= chance; break; case 0: shouldProduceRare = true; break; case 1: shouldProduceRare = false; break; case 2: return; //produce nothing default: throw new ArgumentOutOfRangeException(sIndex.Value.ToString()); } if (shouldProduceRare && rareResource != null) { rareThingCount++; } else { thingCount++; } } Thing thing = ThingMaker.MakeThing(resource); thing.stackCount = thingCount; Color?skinColor = Pawn.GetHighestInfluence()?.GetSkinColorOverride(Pawn); //dont want wool thats mostly human-skin colored if (resource.thingCategories.Contains(PMThingCategoryDefOf.Textiles) && resource.CompDefFor <CompColorable>() != null && skinColor.HasValue) { thing.SetColor(skinColor.Value); } if (thing.stackCount > 0) { GenPlace.TryPlaceThing(thing, Pawn.PositionHeld, Pawn.Map, ThingPlaceMode.Near); } if (rareResource != null) { Thing rareThing = ThingMaker.MakeThing(rareResource); rareThing.stackCount = rareThingCount; if (rareResource.thingCategories.Contains(PMThingCategoryDefOf.Textiles) && resource.CompDefFor <CompColorable>() != null && skinColor.HasValue) { thing.SetColor(skinColor.Value); } if (rareThing.stackCount > 0) { GenPlace.TryPlaceThing(rareThing, Pawn.PositionHeld, Pawn.Map, ThingPlaceMode.Near); } } if (etherState == EtherState.None) { if (Rand.RangeInclusive(0, 100) <= bondChance) { GiveEtherState(EtherState.Bond); etherState = EtherState.Bond; Find.LetterStack.ReceiveLetter( "LetterHediffFromEtherBondLabel".Translate(Pawn).CapitalizeFirst(), "LetterHediffFromEtherBond".Translate(Pawn).CapitalizeFirst(), LetterDefOf.NeutralEvent, Pawn); } else if (Rand.RangeInclusive(0, 100) <= brokenChance) { GiveEtherState(EtherState.Broken); etherState = EtherState.Broken; Find.LetterStack.ReceiveLetter( "LetterHediffFromEtherBrokenLabel".Translate(Pawn).CapitalizeFirst(), "LetterHediffFromEtherBroken".Translate(Pawn).CapitalizeFirst(), LetterDefOf.NeutralEvent, Pawn); } } if (stageThought != null) { thoughts?.TryGainMemory(stageThought); } ThoughtDef addThought; switch (etherState) { case EtherState.None: addThought = Props.genderAversion == Pawn.gender ? Props.wrongGenderThought ?? Props.thought : Props.thought; break; case EtherState.Broken: addThought = Props.etherBrokenThought; break; case EtherState.Bond: addThought = Props.etherBondThought; break; default: throw new ArgumentOutOfRangeException(); } if (addThought != null) { thoughts?.TryGainMemory(addThought); } if (etherState == EtherState.None) { brokenChance += 0.5f; bondChance += 0.2f; } totalProduced += rareThingCount + thingCount; }