/// <summary> /// Gets the entries for the given pawn /// </summary> /// <param name="pawn">The pawn.</param> /// <returns></returns> public override IEnumerable <MutationEntry> GetEntries(Pawn pawn) { if (_cache.TryGetValue(pawn, out List <MutationEntry> lst)) { return(lst); } lst = new List <MutationEntry>(); Rand.PushState(pawn.thingIDNumber); try { var rMorph = AllMorphs.RandomElement(); foreach (MutationDef rMorphAllAssociatedMutation in rMorph.AllAssociatedMutations) //get all mutations from the randomly picked morph { var mEntry = new MutationEntry { addChance = rMorphAllAssociatedMutation.defaultAddChance, blocks = rMorphAllAssociatedMutation.defaultBlocks, mutation = rMorphAllAssociatedMutation }; lst.Add(mEntry); } _cache[pawn] = lst; //cache the results so we only have to do this once per pawn return(lst); } finally { Rand.PopState(); } }
private void AddMutations() { if (FinishedAddingMutations) { DecrementPartialComp(); //decrement only if we're finished adding mutations return; } if (!AnyMutationsInStage(CurStage)) { return; } if (_scratchDict.Count == 0) { ResetPossibleMutations(); } if (_curIndex < _checkList.Count) { AddPartMutations(); } else { //add whole body mutations int mutationsAdded = 0; for (var index = 0; index < _wholeBodyParts.Count; index++) { MutationEntry mutationEntry = _wholeBodyParts[index]; if (Rand.Value < mutationEntry.addChance) { MutationUtilities.AddMutation(pawn, mutationEntry.mutation); var mutagen = def.GetMutagenDef(); mutagen.TryApplyAspects(pawn); mutationsAdded++; } if (mutationsAdded >= MinMutationsPerCheck) { break; } } if (mutationsAdded > 0) { OnMutationsAdded(mutationsAdded); } } }
/// <summary> /// Gets the entries for the given pawn /// </summary> /// <param name="pawn">The pawn.</param> /// <param name="source"></param> /// <returns></returns> public override IEnumerable <MutationEntry> GetEntries(Pawn pawn, Hediff source) { if (_cache.TryGetValue(pawn, out List <MutationEntry> lst)) { return(lst); } lst = new List <MutationEntry>(); int seed; unchecked { seed = pawn.thingIDNumber + (Find.TickManager.TicksAbs / CYCLE_RATE); } Rand.PushState(seed); try { var rMorph = AllMorphs.RandomElement(); foreach (MutationDef rMorphAllAssociatedMutation in rMorph.AllAssociatedMutations) //get all mutations from the randomly picked morph { if (!allowRestricted && rMorphAllAssociatedMutation.IsRestricted) { continue; } var mEntry = new MutationEntry { addChance = rMorphAllAssociatedMutation.defaultAddChance, blocks = rMorphAllAssociatedMutation.defaultBlocks, mutation = rMorphAllAssociatedMutation }; lst.Add(mEntry); } _cache[pawn] = lst; //cache the results so we only have to do this once per pawn return(lst); } finally { Rand.PopState(); } }