public static void DestroyApparel(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn) { if (comp.ChosenItem.redressNewPawn.destroyApparel) { newPawn.apparel.DestroyAll(); } }
public static void SetName(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn) { if (comp.ChosenItem.copyParent.name) { newPawn.Name = comp.Pawn.Name; } }
public static void DestroyInventory(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn) { if (comp.ChosenItem.redressNewPawn.destroyInventory) { newPawn.inventory.innerContainer.ClearAndDestroyContents(); } }
public static void SetAge(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn) { ThingSettings TS = comp.ChosenItem; if (TS.IsCopier && TS.copyParent.age) { LifeStageDef LSDef = comp.Pawn.ageTracker.CurLifeStage; LifeStageAge LSAge = comp.Pawn.def.race.lifeStageAges.Where(LS => LS.def == LSDef).FirstOrFallback(); if (LSAge == null) { return; } newPawn.ageTracker.AgeBiologicalTicks = (long)(LSAge.minAge * MyDefs.OneYearTicks); newPawn.ageTracker.AgeChronologicalTicks = Math.Max(comp.Pawn.ageTracker.AgeBiologicalTicks, comp.Pawn.ageTracker.AgeChronologicalTicks); return; } /* * else if (TS.HasAgeRange) * { * if(TS.HasBiologicalAgeRange) * newPawn.ageTracker.AgeBiologicalTicks = MyDefs.OneYearTicks * TS.biologicalAgeRange.RandomInRange; * if (TS.HasChronologicalAgeRange) * newPawn.ageTracker.AgeBiologicalTicks = MyDefs.OneYearTicks * TS.chronologicalAgeRange.RandomInRange; * } */ newPawn.ageTracker.AgeBiologicalTicks = MyDefs.OneYearTicks * TS.biologicalAgeRange.RandomInRange; newPawn.ageTracker.AgeChronologicalTicks = MyDefs.OneYearTicks * TS.chronologicalAgeRange.RandomInRange + newPawn.ageTracker.AgeBiologicalTicks; }
public static void SetBodyType(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn) { if (comp.ChosenItem.copyParent.bodyType) { newPawn.story.bodyType = comp.Pawn.story.bodyType; } }
public static void SetHairColor(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn) { if (comp.ChosenItem.copyParent.hairColor) { newPawn.story.hairColor = comp.Pawn.story.hairColor; } }
public static MentalStateDef GetWeightedRandomMentalState(this HediffComp_RandySpawnUponDeath comp) { if (!(comp.HasChosenPawn && comp.ChosenItem.HasMentalStateParams)) { return(null); } List <MentalStateOption> MSOL = comp.ChosenItem.mentalState; float DiceThrow = Rand.Range(0, MSOL.MSTotalWeight()); for (int i = 0; i < MSOL.Count; i++) { if ((DiceThrow -= MSOL[i].weight) < 0) { if (comp.MyDebug) { Log.Warning("GetWeightedRandomIndex : returning " + i); } return(MSOL[i].mentalDef); } } if (comp.MyDebug) { Log.Warning("GetWeightedRandomMentalState : failed to return proper index, returning null"); } return(null); }
public static bool FulfilsRequirement(this HediffComp_RandySpawnUponDeath comp, out Thing closestThing) { closestThing = null; if (!comp.HasRequirement) { return(true); } if (comp.HasHediffRequirement && !comp.FulfilsSeverityRequirement()) { if (comp.MyDebug) { Log.Warning("hediff requirements not fulfiled"); } return(false); } if (comp.HasThingRequirement && !comp.FulfilsThingRequirement(comp.Pawn.Corpse, out closestThing)) { if (comp.MyDebug) { Log.Warning("thing requirements not fulfiled"); } return(false); } return(true); }
public static FactionDef GetFactionDef(this HediffComp_RandySpawnUponDeath comp, FactionPickerParameters FPP) { Pawn p = comp.Pawn; if (FPP.HasInheritedFaction && p.Faction != null) { return(p.Faction.def); } else if (FPP.HasForcedFaction) { return(FPP.forcedFaction); } else if (FPP.HasPlayerFaction) { return(Faction.OfPlayer.def); } else if (FPP.HasNoFaction) { return(null); } else if (FPP.HasDefaultPawnKindFaction) { return(comp.ChosenItem.pawnKindToSpawn?.defaultFactionType ?? null); } return(null); }
public static bool TryDoSpawn(this HediffComp_RandySpawnUponDeath comp, Thing thing, int randomQuantity) { if (thing.Negligible()) { if (comp.MyDebug) { Log.Warning("TryDoSpawn - negligeable"); } return(false); } if (comp.HasChosenPawn) { if (comp.MyDebug) { Log.Warning("TryDoSpawn -> TrySpawnPawn"); } return(comp.TrySpawnPawn(thing, randomQuantity)); } else if (comp.HasChosenThing) { if (comp.MyDebug) { Log.Warning("TryDoSpawn -> TrySpawnPawn"); } return(comp.TrySpawnThing(thing, randomQuantity)); } return(false); }
public static void SetGender(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn) { if (comp.ChosenItem.copyParent.gender) { newPawn.gender = comp.Pawn.gender; } }
public static void ComputeRandomFaction(this HediffComp_RandySpawnUponDeath comp) { if (!comp.ChosenItem.HasFactionParams) { return; } int FactionIndex = comp.GetWeightedRandomFaction(); if (FactionIndex == -1) { if (comp.MyDebug) { Log.Warning("ComputeRandomFaction - found no index"); } return; } //comp.newBorn = comp.CurIP.factionPickerParameters[FactionIndex].newBorn; FactionPickerParameters FPP = comp.ChosenItem.faction[FactionIndex]; if (comp.MyDebug) { FPP.Dump(); } comp.RandomFaction = comp.GetFaction(FPP); if (comp.MyDebug) { Log.Warning("ComputeRandomFaction - found:" + comp.RandomFaction?.GetCallLabel()); } }
public static int GetWeightedRandomFaction(this HediffComp_RandySpawnUponDeath comp) { if (!(comp.HasChosenPawn && comp.ChosenItem.HasFactionParams)) { return(-1); } List <FactionPickerParameters> RFP = comp.ChosenItem.faction; float DiceThrow = Rand.Range(0, RFP.FactionTotalWeight()); for (int i = 0; i < RFP.Count; i++) { if ((DiceThrow -= RFP[i].weight) < 0) { if (comp.MyDebug) { Log.Warning("GetWeightedRandomIndex : returning " + i); } return(i); } } if (comp.MyDebug) { Log.Warning("GetWeightedRandomFaction : failed to return proper index, returning -1"); } return(-1); }
public static void ComputeRandomMentalState(this HediffComp_RandySpawnUponDeath comp) { if (!comp.ChosenItem.HasMentalStateParams) { return; } MentalStateDef msd = comp.GetWeightedRandomMentalState(); if (msd == null) { if (comp.MyDebug) { Log.Warning("ComputeRandomMentalState - found no MentalStateDef"); } return; } comp.RandomMS = msd; if (comp.MyDebug) { Log.Warning("ComputeRandomFaction - found:" + comp.RandomFaction?.GetCallLabel()); } }
public static void SetMelanin(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn) { if (comp.ChosenItem.copyParent.melanin) { newPawn.story.melanin = comp.Pawn.story.melanin; } }
public static void TrySpawnAllFilth(this HediffComp_RandySpawnUponDeath comp, Thing refThing, bool debug = false) { if (debug) { Log.Warning(comp.Pawn.LabelShort + " - TrySpawnAllFilth"); } if (!comp.HasFilth) { if (debug) { Log.Warning("no filth found"); } return; } int randFilthNum = comp.FilthNum.RandomInRange; for (int i = 0; i < randFilthNum; i++) { if (debug) { Log.Warning( "filth " + i + "/" + randFilthNum + " - fDef:" + comp.FilthToSpawn + " - pos:" + refThing.Position + " - map null?" + (refThing.Map == null) ); } TrySpawnFilth(refThing, comp.FilthRadius.RandomInRange, comp.FilthToSpawn); } }
public static void DestroyEquipment(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn) { if (comp.ChosenItem.redressNewPawn.destroyEquipment) { newPawn.equipment.DestroyAllEquipment(); } }
public static float ThingsTotalWeight(this HediffComp_RandySpawnUponDeath comp, List <ThingSettings> TSList) { string debugStr = comp.MyDebug ? comp.Pawn.LabelShort + " ThingsTotalWeight " : ""; if (comp.MyDebug) { Log.Warning(debugStr + " searching total weights thing list"); } float total = 0; for (int i = 0; i < TSList.Count; i++) { total += TSList[i].weight; } if (comp.MyDebug) { Log.Warning(debugStr + " found: " + total); } return(total); }
public static void LoseSkill(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn, int wantedLevel, int index, bool debug = false) { string myDebugSr = newPawn.LabelShort + " - LoseSkill - "; if (debug) { Log.Warning(myDebugSr + "Entering"); } int loopBreaker = 20; while (wantedLevel < newPawn.skills.skills[index].levelInt && loopBreaker > 0) { float xpInjected = -(newPawn.skills.skills[index].levelInt * 1000); if (debug) { Log.Warning( myDebugSr + " loop: " + loopBreaker + " xpInjected: " + xpInjected + " ori: " + comp.Pawn.skills.skills[index].levelInt + " new: " + newPawn.skills.skills[index].levelInt ); } newPawn.skills.skills[index].Learn(xpInjected, true); loopBreaker--; } }
public static void UpdateDisabilities(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn) { if (newPawn.skills == null) { return; } newPawn.skills.Notify_SkillDisablesChanged(); }
public static void SetSkills(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn, bool debug = false) { if (!comp.ChosenItem.copyParent.skills) { return; } string myDebugSr = newPawn.LabelShort + " - SetSkills - "; for (int i = 0; i < newPawn.skills.skills.Count; i++) { float decayRatio = comp.ChosenItem.copyParent.skillDecay.RandomInRange; int wantedLevel = (int)(comp.Pawn.skills.skills[i].levelInt * decayRatio); if (debug) { Log.Warning( myDebugSr + " browsing " + comp.Pawn.skills.skills[i].def.defName + " ori: " + comp.Pawn.skills.skills[i].levelInt + " new: " + newPawn.skills.skills[i].levelInt + " decayRatio: " + decayRatio + " wantedSkill: " + wantedLevel //" rememberSkillTracker: " + comp.rememberSkillTracker.skills[i].levelInt ); } if (wantedLevel > newPawn.skills.skills[i].levelInt) { if (debug) { Log.Warning(myDebugSr + "Calling gainskill"); } comp.GainSkill(newPawn, wantedLevel, i, debug); } else if (wantedLevel < newPawn.skills.skills[i].levelInt) { if (debug) { Log.Warning(myDebugSr + "Calling loseskill"); } comp.LoseSkill(newPawn, wantedLevel, i, debug); } if (debug) { Log.Warning( myDebugSr + " copied skill [" + i + "]:" + comp.Pawn.skills.skills[i].def.defName + " new: " + newPawn.skills.skills[i].levelInt ); } //newSkill.xpSinceLastLevel = originalSkill.xpSinceLastLevel; } }
public static bool TryFindSpawnCell(this HediffComp_RandySpawnUponDeath comp, Thing refThing, int randomQuantity, Map map, out IntVec3 result) { ThingDef thingDef = comp.ChosenItem.thingToSpawn; if (refThing.Negligible()) { result = IntVec3.Invalid; if (comp.MyDebug) { Log.Warning("TryFindSpawnCell Null - pawn null"); } return(false); } foreach (IntVec3 current in GenAdj.CellsAdjacent8Way(refThing).InRandomOrder(null)) { if (current.Walkable(map)) { Building edifice = current.GetEdifice(map); if (edifice == null || !thingDef.IsEdifice()) { if (!(edifice is Building_Door building_Door) || building_Door.FreePassage) { if (GenSight.LineOfSight(refThing.Position, current, map, false, null, 0, 0)) { bool flag = false; List <Thing> thingList = current.GetThingList(map); for (int i = 0; i < thingList.Count; i++) { Thing thing = thingList[i]; if (thing.def.category == ThingCategory.Item) { if (thing.def != thingDef || thing.stackCount > thingDef.stackLimit - randomQuantity) { flag = true; break; } } } if (!flag) { result = current; return(true); } } } } } } if (comp.MyDebug) { Log.Warning("TryFindSpawnCell Null - no spawn cell found"); } result = IntVec3.Invalid; return(false); }
public static int GetWeightedRandomIndex(this HediffComp_RandySpawnUponDeath comp, List <int> AlreadyPickedOptions) { if (!comp.Props.settings.HasSomethingToSpawn) { return(-1); } List <ThingSettings> TSList; if (comp.HasColorCondition) { TSList = comp.ThingSettingsWithColor(); } else { TSList = comp.FullOptionList; } if (!AlreadyPickedOptions.NullOrEmpty()) { TSList = comp.ThingSettingsWithExclusion(TSList, AlreadyPickedOptions); } float DiceThrow = Rand.Range(0, comp.ThingsTotalWeight(TSList)); for (int i = 0; i < TSList.Count; i++) { if ((DiceThrow -= TSList[i].weight) < 0) { if (comp.MyDebug) { Log.Warning("GetWeightedRandomIndex : returning thing " + i); } if (AlreadyPickedOptions.NullOrEmpty() && !comp.HasColorCondition) { return(i); } else { int normalizedIndex = comp.Props.settings.things.IndexOf(TSList[i]); if (comp.MyDebug) { Log.Warning("GetWeightedRandomIndex : returning thing " + i + " normalized:" + normalizedIndex); } return(normalizedIndex); } } } if (comp.MyDebug) { Log.Warning("GetWeightedRandomIndex : failed to return proper index, returning -1"); } return(-1); }
public static Faction GetFaction(this HediffComp_RandySpawnUponDeath comp, FactionPickerParameters FPP) { FactionDef fDef = comp.GetFactionDef(FPP); if (fDef == null) { return(null); } return(Find.FactionManager.AllFactions.Where(F => F.def == fDef).FirstOrFallback()); }
public static int ComputeSpawnCount(this HediffComp_RandySpawnUponDeath comp) { float answer = comp.NumberToSpawn; if (comp.WeightedSpawn) { answer *= comp.Pawn.CompletudeRatio(); } return((int)answer); }
public static void SetBackstories(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn) { if (comp.ChosenItem.copyParent.childBS) { newPawn.story.childhood = comp.Pawn.story.childhood; } if (comp.ChosenItem.copyParent.adultBS) { newPawn.story.adulthood = comp.Pawn.story.adulthood; } }
public static bool DestroyCorpse(this HediffComp_RandySpawnUponDeath comp, Corpse corpse) { bool DidIt = false; if (comp.Props.HasParentRedress && comp.Props.redressParent.destroyCorpse && !corpse.Negligible()) { DidIt = true; corpse.DeSpawn(); } return(DidIt); }
public static List <ThingSettings> ThingSettingsWithExclusion(this HediffComp_RandySpawnUponDeath comp, List <ThingSettings> TSList, List <int> AlreadyPickedOptions) { List <ThingSettings> answer = new List <ThingSettings>(); answer = comp.Props.settings.things.ListFullCopy(); foreach (int i in AlreadyPickedOptions) { answer.RemoveAt(i); } return(answer); }
public static void SetPassions(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn, bool debug = false) { if (!comp.ChosenItem.copyParent.passions) { return; } for (int i = 0; i < newPawn.skills.skills.Count; i++) { newPawn.skills.skills[i].passion = comp.Pawn.skills.skills[i].passion; } }
public static void SetTraits(this HediffComp_RandySpawnUponDeath comp, Pawn newPawn) { if (!comp.ChosenItem.copyParent.traits) { return; } for (int i = newPawn.story.traits.allTraits.Count - 1; i >= 0; i--) { newPawn.story.traits.allTraits.RemoveAt(i); } newPawn.story.traits.allTraits = comp.Pawn.story.traits.allTraits.ListFullCopy(); }