Пример #1
0
        public override Color GetColor(Pawn pawn, List <string> options)
        {
            List <Pair <Color, float> > list = new List <Pair <Color, float> >();

            foreach (var option in options)
            {
                var          arg = option.Replace(" ", "");
                List <float> num = new List <float>();
                foreach (Match match in Regex.Matches(arg, @"(\d{1,}\.\d{1,}|\d{1,})"))
                {
                    num.Add(float.Parse(match.Value));
                }
                if (num.Count() != 3)
                {
                    RaceAddon.Notify("Parsing failed! => " + option, true);
                }
                float randomNum = Rand.RangeInclusive((int)num[0], (int)num[1]) / 255f;
                Color color     = new Color(randomNum, randomNum, randomNum);
                list.Add(new Pair <Color, float>(color, num[2]));
            }
            if (list.Count == 0)
            {
                RaceAddon.Notify("Color generation failed! => " + pawn.Name.ToStringFull, true);
                return(Color.white);
            }
            return(list.RandomElementByWeight(x => x.Second).First);
        }
Пример #2
0
        public void CheckAgeSetting()
        {
            var thingDef      = pawn.def as RaceAddonThingDef;
            var newAgeSetting = thingDef.raceAddonSettings.ageSettings.GetPresent(pawn);

            if (presentAgeSetting != newAgeSetting)
            {
                presentAgeSetting = newAgeSetting;
                AppearanceDef appearanceDef = presentAgeSetting.appearances?.GetAppearanceDef(pawn, true);
                if (appearanceDef != null && !presentAgeSetting.keepAppearance)
                {
                    RaceAddon.SetAppearance(pawn, racomp, thingDef, appearanceDef);
                }
                racomp.raceAddonGraphicSet = new RaceAddonGraphicSet(pawn, racomp);
                pawn.Drawer.renderer.graphics.ResolveAllGraphics();
                if (pawn.IsColonist)
                {
                    Find.LetterStack.ReceiveLetter("RaceAddon_GrowUp_Label".Translate(pawn.Name.ToStringShort), "RaceAddon_GrowUp_String".Translate(), LetterDefOf.PositiveEvent);
                }

                /*
                 * if (presentAgeSetting.ageBackstory != null && thingDef.raceAddonSettings.ageSettings[thingDef.raceAddonSettings.ageSettings.IndexOf(presentAgeSetting) - 1].ageBackstory.Backstory == pawn.story.childhood)
                 * {
                 *  pawn.story.childhood = presentAgeSetting.ageBackstory.Backstory;
                 *
                 *  if (presentAgeSetting.ageBackstory.skillGains.Count > 0)
                 *  {
                 *      foreach (SkillGain skillGain in presentAgeSetting.ageBackstory.skillGains)
                 *      {
                 *          pawn.skills.Learn(skillGain.skill, skillGain.xp, true);
                 *          pawn.skills.skills.ForEach(x => x.Level += x.def == skillGain.skill ? skillGain.xp : 0);
                 *      }
                 *  }
                 *  if (presentAgeSetting.ageBackstory.forcedHediffs.Count > 0)
                 *  {
                 *      foreach (var set in presentAgeSetting.ageBackstory.forcedHediffs)
                 *      {
                 *          Hediff hediff = HediffMaker.MakeHediff(set.hediffDef, pawn, set.targetPart.GetBodyPartRecord(pawn.def.race.body));
                 *          hediff.Severity = set.severity;
                 *          pawn.health.AddHediff(hediff);
                 *      }
                 *  }
                 *
                 *  pawn.workSettings = new Pawn_WorkSettings(pawn);
                 *  pawn.workSettings.EnableAndInitialize();
                 * }
                 */
            }
        }
Пример #3
0
        public RaceAddonGraphicSet(Pawn pawn, RaceAddonComp racomp)
        {
            if (pawn.def is RaceAddonThingDef thingDef)
            {
                this.pawn   = pawn;
                this.racomp = racomp;

                presentAgeSetting = thingDef.raceAddonSettings.ageSettings.GetPresent(pawn);

                headMeshSet = new GraphicMeshSet((1.5f * presentAgeSetting.drawSize.head.x) * racomp.drawSizeDeviation, (1.5f * presentAgeSetting.drawSize.head.y) * racomp.drawSizeDeviation);
                bodyMeshSet = new GraphicMeshSet((1.5f * presentAgeSetting.drawSize.body.x) * racomp.drawSizeDeviation, (1.5f * presentAgeSetting.drawSize.body.y) * racomp.drawSizeDeviation);
                //equipmentMeshSet = new GraphicMeshSet(presentAgeSetting.drawSize.equipment.x, presentAgeSetting.drawSize.equipment.y);
                racomp.cachedDrawLocCorrection = 0f;
                if (thingDef.raceAddonSettings.graphicSetting.footPositionCorrection_DrawSize)
                {
                    racomp.cachedDrawLocCorrection += (1.5f - (1.5f * presentAgeSetting.drawSize.body.y)) / 2f;
                }
                if (thingDef.raceAddonSettings.graphicSetting.footPositionCorrection_DrawSizeCurve)
                {
                    racomp.cachedDrawLocCorrection += (1.5f - (1.5f * racomp.drawSizeDeviation)) / 2f;
                }

                eyeBlinker   = thingDef.raceAddonSettings.graphicSetting.eyeBlink ? new EyeBlinker() : null;
                headRotator  = thingDef.raceAddonSettings.graphicSetting.headAnimation ? new HeadRotator() : null;
                headTargeter = thingDef.raceAddonSettings.graphicSetting.headTargeting ? new HeadTargeter(pawn) : null;

                upperFaceGraphic = racomp.upperFaceDef == null ? null : new FaceGraphicRecord(pawn, racomp.upperFaceDef, racomp.faceColor_Main, racomp.faceColor_Sub, thingDef.raceAddonSettings.graphicSetting.fixedUpperFace);
                lowerFaceGraphic = racomp.lowerFaceDef == null ? null : new FaceGraphicRecord(pawn, racomp.lowerFaceDef, racomp.faceColor_Main, racomp.faceColor_Sub, thingDef.raceAddonSettings.graphicSetting.fixedLowerFace);
                foreach (var addonData in racomp.addonDatas)
                {
                    var linkedBodyPart = addonData.addonDef.linkedBodyPart.GetBodyPartRecord(pawn.def.race.body);
                    addonGraphics.Add(new AddonGraphicRecord(addonData, linkedBodyPart, thingDef.raceAddonSettings.graphicSetting.rottingColor));
                }
            }
            else
            {
                RaceAddon.Notify("RaceAddonGraphicSet Init failure, Unkown ThingDef => " + pawn.Name.ToStringShort, true);
            }
        }
 public override void PostSpawnSetup(bool respawningAfterLoad)
 {
     base.PostSpawnSetup(respawningAfterLoad);
     Pawn = parent as Pawn;
     RaceAddon.OldVersionBugFixes(Pawn);
 }
        public override void ResolveReferences()
        {
            base.ResolveReferences();

            WorkTags workDisables = WorkTags.None;

            if (this.workDisables != null)
            {
                this.workDisables.ForEach(x => workDisables |= x);
            }

            WorkTags requiredWorkTags = WorkTags.None;

            if (this.requiredWorkTags != null)
            {
                this.requiredWorkTags.ForEach(x => requiredWorkTags |= x);
            }

            List <TraitEntry> forcedTraits = new List <TraitEntry>();

            if (this.forcedTraits != null)
            {
                this.forcedTraits.ForEach(x => forcedTraits.Add(new TraitEntry(x.traitDef, x.degree)));
            }

            List <TraitEntry> disallowedTraits = new List <TraitEntry>();

            if (this.disallowedTraits != null)
            {
                this.disallowedTraits.ForEach(x => disallowedTraits.Add(new TraitEntry(x.traitDef, x.degree)));
            }

            Dictionary <SkillDef, int> skillGainsResolved = new Dictionary <SkillDef, int>();

            if (skillGains != null)
            {
                skillGains.ForEach(x => skillGainsResolved.Add(x.skill, x.xp));
            }

            Backstory = new Backstory
            {
                identifier = defName,

                slot            = backstoryInfo.slot,
                title           = backstoryInfo.title,
                titleShort      = backstoryInfo.titleShort,
                baseDesc        = backstoryInfo.description,
                spawnCategories = spawnCategories,

                workDisables       = workDisables,
                requiredWorkTags   = requiredWorkTags,
                forcedTraits       = forcedTraits,
                disallowedTraits   = disallowedTraits,
                skillGainsResolved = skillGainsResolved
            };
            Traverse.Create(Backstory).Field("bodyTypeMaleResolved").SetValue(BodyTypeDefOf.Male);
            Traverse.Create(Backstory).Field("bodyTypeFemaleResolved").SetValue(BodyTypeDefOf.Female);
            Backstory.ResolveReferences();
            Backstory.PostLoad();
            Backstory.identifier = defName;

            IEnumerable <string> errors = Backstory.ConfigErrors(false);

            if (errors.Any())
            {
                RaceAddon.Notify("BackstoryDef has errors! => " + defName + string.Join("\n", errors.ToArray()), true);
            }
            else
            {
                BackstoryDatabase.AddBackstory(Backstory);
            }
        }
        public override void ResolveReferences()
        {
            base.ResolveReferences();

            RaceAddon.AllRaceAddonThingDefs.Add(this);

            if (!raceAddonSettings.healthSetting.rottingCorpse)
            {
                race.corpseDef.comps.RemoveAll((CompProperties x) => x is CompProperties_Rottable);
                race.corpseDef.comps.RemoveAll((CompProperties x) => x is CompProperties_SpawnerFilth);
            }

            if (raceAddonSettings.workGiverRestrictionSetting.allAllow)
            {
                foreach (WorkGiverDef def in raceAddonSettings.workGiverRestrictionSetting.allAllow_Exceptions)
                {
                    if (!DisabledWorkGivers.Contains(def))
                    {
                        DisabledWorkGivers.Add(def);
                    }
                }
            }
            else
            {
                foreach (WorkGiverDef def in DefDatabase <WorkGiverDef> .AllDefs)
                {
                    if (!raceAddonSettings.workGiverRestrictionSetting.allAllow_Exceptions.Contains(def))
                    {
                        if (!DisabledWorkGivers.Contains(def))
                        {
                            DisabledWorkGivers.Add(def);
                        }
                    }
                }
            }
            foreach (WorkGiverDef def in raceAddonSettings.workGiverRestrictionSetting.raceSpecifics)
            {
                if (!RaceAddon.WorkGiverRestrictions.Contains(def))
                {
                    RaceAddon.WorkGiverRestrictions.Add(def);
                }
            }
            if (raceAddonSettings.characterizationSetting.workDisables != null)
            {
                WorkTags workTags = WorkTags.None;
                foreach (WorkTags tag in raceAddonSettings.characterizationSetting.workDisables)
                {
                    workTags |= tag;
                }
                DisabledWorkTags = workTags;


                foreach (WorkTypeDef def in DefDatabase <WorkTypeDef> .AllDefsListForReading.FindAll(x => (DisabledWorkTags & x.workTags) != 0))
                {
                    if (!DisabledWorkTypes.Contains(def))
                    {
                        DisabledWorkTypes.Add(def);
                    }
                }
            }

            foreach (var obj in raceAddonSettings.apparelRestrictionSetting.raceSpecifics)
            {
                if (!RaceAddon.ApparelRestrictions.Contains(obj))
                {
                    RaceAddon.ApparelRestrictions.Add(obj);
                }
            }
            foreach (var obj in raceAddonSettings.weaponRestrictionSetting.raceSpecifics)
            {
                if (!RaceAddon.WeaponRestrictions.Contains(obj))
                {
                    RaceAddon.WeaponRestrictions.Add(obj);
                }
            }
            foreach (var obj in raceAddonSettings.workGiverRestrictionSetting.raceSpecifics)
            {
                if (!RaceAddon.WorkGiverRestrictions.Contains(obj))
                {
                    RaceAddon.WorkGiverRestrictions.Add(obj);
                }
            }
            foreach (var obj in raceAddonSettings.traitRestrictionSetting.raceSpecifics)
            {
                if (!RaceAddon.TraitRestrictions.Contains(new Trait(obj.traitDef, obj.degree)))
                {
                    RaceAddon.TraitRestrictions.Add(new Trait(obj.traitDef, obj.degree));
                }
            }
            foreach (var obj in raceAddonSettings.hediffRestrictionSetting.raceSpecifics)
            {
                if (!RaceAddon.HediffRestrictions.Contains(obj))
                {
                    RaceAddon.HediffRestrictions.Add(obj);
                }
            }
            foreach (var obj in raceAddonSettings.thoughtRestrictionSetting.raceSpecifics)
            {
                if (!RaceAddon.ThoughtRestrictions.Contains(obj))
                {
                    RaceAddon.ThoughtRestrictions.Add(obj);
                }
            }
            foreach (var obj in raceAddonSettings.buildingRestrictionSetting.raceSpecifics)
            {
                if (!RaceAddon.BuildingRestrictions.Contains(obj))
                {
                    RaceAddon.BuildingRestrictions.Add(obj);
                }
            }
            foreach (var obj in raceAddonSettings.foodRestrictionSetting.raceSpecifics)
            {
                if (!RaceAddon.FoodRestrictions.Contains(obj))
                {
                    RaceAddon.FoodRestrictions.Add(obj);
                }
            }
            foreach (var obj in raceAddonSettings.plantRestrictionSetting.raceSpecifics)
            {
                if (!RaceAddon.PlantRestrictions.Contains(obj))
                {
                    RaceAddon.PlantRestrictions.Add(obj);
                }
            }
            foreach (var obj in raceAddonSettings.animalRestrictionSetting.raceSpecifics)
            {
                if (!RaceAddon.AnimalRestrictions.Contains(obj))
                {
                    RaceAddon.AnimalRestrictions.Add(obj);
                }
            }
            foreach (var obj in raceAddonSettings.recipeRestrictionSetting.raceSpecifics)
            {
                if (!RaceAddon.RecipeRestrictions.Contains(obj))
                {
                    RaceAddon.RecipeRestrictions.Add(obj);
                }
            }
            foreach (var obj in raceAddonSettings.researchRestrictionSetting.raceSpecifics)
            {
                if (!RaceAddon.ResearchRestrictions.Contains(obj))
                {
                    RaceAddon.ResearchRestrictions.Add(obj);
                }
            }

            if (comps.Any(x => x.compClass == typeof(RaceAddonComp)))
            {
                RaceAddon.Notify(defName + " has a duplicate RaceAddonComp!");
            }
            else
            {
                comps.Add(new CompProperties(typeof(RaceAddonComp)));
            }
        }