/// <summary> /// Gets the skin color second override. /// </summary> /// <param name="def">The definition.</param> /// <param name="pawn">The pawn.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">def</exception> public static Color?GetSkinColorSecondOverride([NotNull] this MorphDef def, Pawn pawn = null) { if (def == null) { throw new ArgumentNullException(nameof(def)); } Color?aspectColor = pawn?.GetAspectTracker()?.GetAspect <Aspects.ColorationAspect>()?.ColorSet?.skinColorTwo; if (aspectColor.HasValue) { return(aspectColor); } if (def.ExplicitHybridRace == null) { HybridRaceSettings.GraphicsSettings gSettings = def.raceSettings?.graphicsSettings; if (pawn?.gender == Gender.Female && gSettings?.femaleSkinColorOverrideSecond != null) { return(gSettings.femaleSkinColorOverrideSecond); } return(gSettings?.skinColorOverrideSecond); } var hRace = def.ExplicitHybridRace as ThingDef_AlienRace; AlienPartGenerator generalSettingsAlienPartGenerator = hRace?.alienRace?.generalSettings?.alienPartGenerator; return(generalSettingsAlienPartGenerator?.GenerateRandomColor("skin", false, pawn?.thingIDNumber)); }
/// <summary> /// Generates the random color. /// </summary> /// <param name="generator">The generator.</param> /// <param name="channelName">Name of the channel.</param> /// <param name="first">if set to <c>true</c> [first].</param> /// <param name="seed">The seed.</param> /// <returns></returns> /// <exception cref="ArgumentNullException">generator</exception> public static Color?GenerateRandomColor([NotNull] this AlienPartGenerator generator, string channelName, bool first = true, int?seed = null) { if (generator == null) { throw new ArgumentNullException(nameof(generator)); } var channel = generator.colorChannels?.FirstOrDefault(c => c.name == channelName); var cGen = first ? channel?.first : channel?.second; if (cGen == null) { return(null); } if (seed != null) { try { Rand.PushState(seed.Value); return(cGen.NewRandomizedColor()); } finally { Rand.PopState(); } } return(cGen.NewRandomizedColor()); }
private void ChangeBodyType(Pawn pawn, BodyTypeDef bt) { AlienPartGenerator alienPartGenerator = alienRace.alienRace.generalSettings.alienPartGenerator; var storyTrv = Traverse.Create(pawn.story); var newStory = new Pawn_StoryTracker(pawn); var newStoryTrv = Traverse.Create(newStory); AccessTools.GetFieldNames(typeof(Pawn_StoryTracker)) .ForEach(f => newStoryTrv.Field(f).SetValue(storyTrv.Field(f).GetValue())); newStory.bodyType = bt; if (Props.colourSkinTwo || Props.colourSkin) { if (compAlien != null) { ColorChannelGenerator Alienskin = alienRace.alienRace.generalSettings.alienPartGenerator.colorChannels.Find(x => x.name == "skin"); AlienPartGenerator.ExposableValueTuple <UnityEngine.Color, UnityEngine.Color> skin; if (compAlien.ColorChannels.TryGetValue("skin", out skin)) { if (Props.colourSkin && Alienskin?.first != null) { skin.first = Alienskin.first.NewRandomizedColor(); } if (Props.colourSkinTwo && Alienskin?.second != null) { skin.second = Alienskin.second.NewRandomizedColor(); } compAlien.ColorChannels.SetOrAdd("skin", skin); } Traverse.Create(newStory).Field("SkinColor").SetValue(skin.first); Pawn.Notify_ColorChanged(); } } if (Props.changeHead) { List <string> heads = new List <string>(); if (!Props.crownType.NullOrEmpty()) { heads.Add(Props.crownType); } else { heads.AddRange(alienPartGenerator.aliencrowntypes); } compAlien.crownType = null; if (Pawn.story.HeadGraphicPath.Contains("Average")) { newStory.crownType = CrownType.Average; } else if (Pawn.story.HeadGraphicPath.Contains("Narrow")) { newStory.crownType = CrownType.Narrow; } } pawn.story = newStory; Traverse.Create(newStory).Field("headGraphicPath").SetValue(alienRace.alienRace.graphicPaths.GetCurrentGraphicPath(pawn.ageTracker.CurLifeStage).head.NullOrEmpty() ? "" : alienPartGenerator.RandomAlienHead(alienRace.alienRace.graphicPaths.GetCurrentGraphicPath(pawn.ageTracker.CurLifeStage).head, Pawn)); pawn.Drawer.renderer.graphics.ResolveAllGraphics(); Find.ColonistBar.drawer.Notify_RecachedEntries(); }
private static AlienPartGenerator GenerateHybridGenerator(AlienPartGenerator human, MorphDef morph, ThingDef_AlienRace impliedRace) { AlienPartGenerator gen = new AlienPartGenerator { alienbodytypes = human.alienbodytypes.MakeSafe().ToList(), aliencrowntypes = human.aliencrowntypes.MakeSafe().ToList(), bodyAddons = GenerateBodyAddons(human.bodyAddons, morph), alienProps = impliedRace }; return(gen); }
/// <inheritdoc/> public bool TryReassignBody(Pawn pawn) { if (!(pawn.def is ThingDef_AlienRace alienRace)) { return(false); } AlienPartGenerator generator = alienRace.alienRace.generalSettings.alienPartGenerator; if (generator.alienbodytypes.NullOrEmpty() || generator.alienbodytypes.Contains(pawn.story.bodyType)) { return(true); } List <BodyTypeDef> bodyTypes = generator.alienbodytypes.ListFullCopy(); if (bodyTypes.Count > 0) { switch (pawn.gender) { case Gender.Male: bodyTypes.Remove(BodyTypeDefOf.Female); break; case Gender.Female: bodyTypes.Remove(BodyTypeDefOf.Male); break; } } pawn.story.bodyType = bodyTypes.TryRandomElement(out BodyTypeDef newBody) ? newBody : BodyTypeDefOf.Thin; return(true); }
public static AlienRace InitializeAlienRace(ThingDef_AlienRace raceDef, Pawn p) { ThingDef_AlienRace.AlienSettings race = raceDef.alienRace; GeneralSettings generalSettings = race?.generalSettings; AlienPartGenerator alienPartGenerator = generalSettings?.alienPartGenerator; if (alienPartGenerator == null) { return(null); } List <GraphicPaths> graphicsPaths = race.graphicPaths; if (graphicsPaths == null) { return(null); } // We have enough to start putting together the result object, so we instantiate it now. AlienRace result = new AlienRace(); // Get the list of body types. List <BodyTypeDef> alienbodytypes = alienPartGenerator.alienbodytypes; if (alienbodytypes == null) { return(null); } List <BodyTypeDef> bodyTypes = new List <BodyTypeDef>(); if (alienbodytypes.Count > 0) { foreach (BodyTypeDef o in alienbodytypes) { bodyTypes.Add(o); } } result.BodyTypes = bodyTypes; // Determine if the alien races uses gender-specific heads. result.GenderSpecificHeads = alienPartGenerator.useGenderedHeads; result.CrownTypes = alienPartGenerator.aliencrowntypes; // Go through the graphics paths and find the heads path. string graphicsPathForHeads = null; foreach (GraphicPaths graphicsPath in graphicsPaths) { ICollection lifeStageCollection = GetFieldValueAsCollection(raceDef, graphicsPath, "lifeStageDefs"); if (lifeStageCollection == null || lifeStageCollection.Count == 0) { string path = GetFieldValueAsString(raceDef, graphicsPath, "head"); if (path != null) { graphicsPathForHeads = path; break; } } } result.GraphicsPathForHeads = graphicsPathForHeads; // Figure out colors. ColorGenerator primaryGenerator = alienPartGenerator.alienskincolorgen; result.UseMelaninLevels = true; if (primaryGenerator != null) { result.UseMelaninLevels = false; result.PrimaryColors = primaryGenerator.GetColorList(); } else { result.PrimaryColors = new List <Color>(); } ColorGenerator secondaryGenerator = alienPartGenerator.alienskinsecondcolorgen; result.HasSecondaryColor = false; if (secondaryGenerator != null) { result.HasSecondaryColor = true; result.SecondaryColors = secondaryGenerator.GetColorList(); } else { result.SecondaryColors = new List <Color>(); } // Hair properties. HairSettings hairSettings = race.hairSettings; result.HasHair = false; if (hairSettings != null) { result.HasHair = hairSettings.hasHair; if (hairSettings.hairTags.NullOrEmpty()) { result.HairTags = p.kindDef.defaultFactionType.hairTags; } else { result.HairTags = hairSettings.hairTags; } } ColorGenerator hairColorGenerator = alienPartGenerator.alienhaircolorgen; if (hairColorGenerator != null) { result.HairColors = primaryGenerator.GetColorList(); } else { result.HairColors = null; } return(result); }