コード例 #1
0
        // 与Color.HSVToRGB重复

        /*
         * public static Color hsb2rgb(float h, float s, float v, float a = 1f)
         * {
         *  //if ()
         *  //{
         *  //    throw new ArgumentOutOfRangeException();
         *  //}
         *  h = Math.Max(Math.Min(h, 360f), 0f);
         *  s = Math.Max(Math.Min(s, 1f), 0f);
         *  v = Math.Max(Math.Min(v, 1f), 0f);
         *
         *  float r = 0, g = 0, b = 0;
         *  int i = (int)((h / 60) % 6);
         *  float f = (h / 60) - i;
         *  float p = v * (1 - s);
         *  float q = v * (1 - f * s);
         *  float t = v * (1 - (1 - f) * s);
         *  switch (i)
         *  {
         *      case 0:
         *          r = v;
         *          g = t;
         *          b = p;
         *          break;
         *      case 1:
         *          r = q;
         *          g = v;
         *          b = p;
         *          break;
         *      case 2:
         *          r = p;
         *          g = v;
         *          b = t;
         *          break;
         *      case 3:
         *          r = p;
         *          g = q;
         *          b = v;
         *          break;
         *      case 4:
         *          r = t;
         *          g = p;
         *          b = v;
         *          break;
         *      case 5:
         *          r = v;
         *          g = p;
         *          b = q;
         *          break;
         *      default:
         *          break;
         *  }
         *  return new Color(r, g, b);
         * }
         */

        /*
         * BodyPartRecord partRecHead = CentaurBodyDef.AllParts.First(d => d.def == BodyPartDefOf.Head);
         * BodyPartRecord partRecWaist = CentaurBodyDef.AllParts.First(d => d?.groups?.Contains(DefDatabase<BodyPartGroupDef>.GetNamed("Waist")) ?? false);
         * if (apparel != null &&
         *      (apparel?.defaultOutfitTags?.Contains("CentaurOutfit") == true
         *    / *|| apparel?.CoversBodyPart(partRecHead) == true
         || apparel?.CoversBodyPart(partRecWaist) == true
         || allDef2.apparel?.bodyPartGroups.Contains(BodyPartGroupDefOf.UpperHead) == true
         || allDef2.apparel?.bodyPartGroups.Contains(BodyPartGroupDefOf.FullHead) == true
         || allDef2.apparel?.bodyPartGroups.Contains(DefDatabase<BodyPartGroupDef>.GetNamed("Waist")) == true
         || allDef2.apparel?.layers.Contains(ApparelLayerDefOf.Overhead) == true
         || allDef2.apparel?.layers.Contains(ApparelLayerDefOf.Belt) == true* /
         ||     )
         || )
         || return true;
         */
        /**
         * <summary>
         * 检测物品是否为合法的半人马服装。
         * </summary>
         * <param name="thing">需要被检测的物品。</param>
         * <returns>该物品是否为合法的半人马服装。</returns>
         */
        public static bool VaildCentaurApparelPredicate(ThingDef thing)
        {
            ApparelProperties apparel = thing?.apparel;

            if (apparel == null)
            {
                return(false);
            }
            if (apparel?.defaultOutfitTags?.Contains("CentaurOutfit") == true)
            {
                return(true);
            }

            if (apparel.bodyPartGroups?.Any() == true)
            {
                foreach (BodyPartGroupDef bpg in apparel.bodyPartGroups)
                {
                    if (!CentaurBodyPartGroups.Contains(bpg)) // || bpg == BodyPartGroupDefOf.Torso)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
コード例 #2
0
        public static int ToPawnLayerIndex(ApparelProperties apparelProperties)
        {
            ApparelLayer layer = apparelProperties.LastLayer;

            if (layer == ApparelLayer.OnSkin && apparelProperties.bodyPartGroups.Count == 1 && apparelProperties.bodyPartGroups[0].Equals(BodyPartGroupDefOf.Legs))
            {
                return(Pants);
            }
            else
            {
                switch (layer)
                {
                case ApparelLayer.OnSkin:
                    return(BottomClothingLayer);

                case ApparelLayer.Middle:
                    return(MiddleClothingLayer);

                case ApparelLayer.Shell:
                    return(TopClothingLayer);

                case ApparelLayer.Accessory:
                    return(Accessory);

                case ApparelLayer.Overhead:
                    return(Hat);

                default:
                {
                    Log.Warning("Cannot find matching layer for apparel.  Last layer: " + apparelProperties.LastLayer);
                    return(-1);
                }
                }
            }
        }
コード例 #3
0
ファイル: Utilities.cs プロジェクト: rheirman/WhatTheHack
 public static bool IsBelt(ApparelProperties apparel)
 {
     //Apparel is a belt when it can only be attached to a waist and nothing else.
     if (apparel != null && apparel.layers.Contains(ApparelLayerDefOf.Belt))
     {
         return(true);
     }
     return(false);
 }
コード例 #4
0
ファイル: Utilities.cs プロジェクト: Roffelchen/WhatTheHack
 public static bool IsBelt(ApparelProperties apparel)
 {
     //Apparel is a belt when it can only be attached to a waist and nothing else.
     if (apparel != null && apparel.bodyPartGroups.Count == 1 && apparel.bodyPartGroups[0] == WTH_DefOf.Waist)
     {
         return(true);
     }
     return(false);
 }
コード例 #5
0
            static string apparelOkayToWear(Pawn pawn, Apparel apparel)
            {
                ApparelProperties app = apparel.def.apparel;

                if (!pawn.kindDef.apparelRequired.NullOrEmpty() && pawn.kindDef.apparelRequired.Contains(apparel.def))
                {
                    return("OK");
                }
                if (!app.CorrectGenderForWearing(pawn.gender))
                {
                    return("Wrong gender.");
                }
                List <SpecificApparelRequirement> specificApparelRequirements = pawn.kindDef.specificApparelRequirements;

                if (specificApparelRequirements != null)
                {
                    for (int i = 0; i < specificApparelRequirements.Count; i++)
                    {
                        if (PawnApparelGenerator.ApparelRequirementHandlesThing(specificApparelRequirements[i], apparel.def) && PawnApparelGenerator.ApparelRequirementTagsMatch(specificApparelRequirements[i], apparel.def))
                        {
                            return("OK");
                        }
                    }
                }
                if (!pawn.kindDef.apparelTags.NullOrEmpty())
                {
                    if (!app.tags.Any((string tag) => pawn.kindDef.apparelTags.Contains(tag)))
                    {
                        return("Required tag missing.");
                    }
                    if ((pawn.royalty == null || pawn.royalty.MostSeniorTitle == null) && app.tags.Contains("Royal") && !pawn.kindDef.apparelTags.Any((string tag) => app.tags.Contains(tag)))
                    {
                        return("Royal apparel on non-royal pawn.");
                    }
                }
                if (!pawn.kindDef.apparelDisallowTags.NullOrEmpty() && pawn.kindDef.apparelDisallowTags.Any((string t) => app.tags.Contains(t)))
                {
                    return("Has a disallowed tag.");
                }
                if (pawn.royalty != null && pawn.royalty.AllTitlesInEffectForReading.Any())
                {
                    RoyalTitle mostSeniorTitle = pawn.royalty.MostSeniorTitle;
                    if (apparel.TryGetQuality(out var qc) && (int)qc < (int)mostSeniorTitle.def.requiredMinimumApparelQuality)
                    {
                        return("Quality too low.");
                    }
                }
                return("OK");
            }
コード例 #6
0
        public ApparelPropertiesStats(ApparelProperties a)
        {
            this.wornGraphicPath               = a.wornGraphicPath;
            this.wearPerDay                    = a.wearPerDay;
            this.careIfWornByCorpse            = a.careIfWornByCorpse;
            this.hatRenderedFrontOfFace        = a.hatRenderedFrontOfFace;
            this.useDeflectMetalEffect         = a.useDeflectMetalEffect;
            this.useWornGraphicMask            = a.useWornGraphicMask;
            this.canBeGeneratedToSatisfyWarmth = a.canBeGeneratedToSatisfyWarmth;
            this.gender = a.gender;

            this.tags = Util.CreateList(a.tags);
            this.defaultOutfitTags = Util.CreateList(a.defaultOutfitTags);
            this.bodyPartGroups    = Util.CreateDefStatList(a.bodyPartGroups);
            this.layers            = Util.CreateDefStatList(a.layers);
        }
コード例 #7
0
 public static bool IsHeadwear(ApparelProperties apparelProperties)
 {
     if (apparelProperties.LastLayer == ApparelLayerDefOf.Overhead)
     {
         return(true);
     }
     for (int i = 0; i < apparelProperties.bodyPartGroups.Count; ++i)
     {
         var group = apparelProperties.bodyPartGroups[i];
         if (group == BodyPartGroupDefOf.FullHead || group == BodyPartGroupDefOf.UpperHead || group == BodyPartGroupDefOf.Eyes)
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #8
0
        public PawnLayer FindLayerForApparel(ApparelProperties apparelProperties)
        {
            ApparelLayerDef layer = apparelProperties.LastLayer;

            if (layer == ApparelLayerDefOf.OnSkin && apparelProperties.bodyPartGroups.Count == 1)
            {
                if (apparelProperties.bodyPartGroups[0].Equals(BodyPartGroupDefOf.Legs))
                {
                    return(pantsLayer);
                }
                else if (apparelProperties.bodyPartGroups[0].defName == "Hands")
                {
                    return(null);
                }
                else if (apparelProperties.bodyPartGroups[0].defName == "Feet")
                {
                    return(null);
                }
            }
            if (layer == ApparelLayerDefOf.OnSkin)
            {
                return(bottomClothingLayer);
            }
            else if (layer == ApparelLayerDefOf.Middle)
            {
                return(middleClothingLayer);
            }
            else if (layer == ApparelLayerDefOf.Shell)
            {
                return(topClothingLayer);
            }
            else if (layer == ApparelLayerDefOf.Overhead)
            {
                return(hatLayer);
            }
            else if (layer == ApparelLayerDefOf.Belt)
            {
                return(accessoryLayer);
            }
            else
            {
                Log.Warning("Cannot find matching layer for apparel.  Last layer: " + apparelProperties.LastLayer);
                return(null);
            }
        }
コード例 #9
0
        public PawnLayer FindLayerForApparel(ApparelProperties apparelProperties)
        {
            ApparelLayerDef layer = apparelProperties.LastLayer;

            if (layer == ApparelLayerDefOf.OnSkin)
            {
                if (apparelProperties.bodyPartGroups.Any(x => x.Equals(BodyPartGroupDefOf.Legs)))
                {
                    if (apparelProperties.bodyPartGroups.Count == 1 ||
                        // YAYO's Combat 3 added Feet as a body part to pants, breaking this mod, so this fixes it
                        (apparelProperties.bodyPartGroups.Count == 2 && apparelProperties.bodyPartGroups.Any(x => x.defName == "Feet")))
                    {
                        return(pantsLayer);
                    }
                    // would have returned bottomClothingLayer here, but it's redundant.
                }
                // checks if not gloves or socks (1 body part, which is either hands or feet)
                else if (apparelProperties.bodyPartGroups.Count == 1 && apparelProperties.bodyPartGroups.All(x => x.defName == "Hands" || x.defName == "Feet"))
                {
                    return(null);
                }
                return(bottomClothingLayer);
            }
            else if (layer == ApparelLayerDefOf.Middle)
            {
                return(middleClothingLayer);
            }
            else if (layer == ApparelLayerDefOf.Shell)
            {
                return(topClothingLayer);
            }
            else if (layer == ApparelLayerDefOf.Overhead)
            {
                return(hatLayer);
            }
            else if (layer == ApparelLayerDefOf.Belt)
            {
                return(accessoryLayer);
            }
            else
            {
                Logger.Warning("Cannot find matching layer for apparel.  Last layer: " + apparelProperties.LastLayer);
                return(null);
            }
        }
コード例 #10
0
 public static bool IsHeadwear(ApparelProperties apparelProperties)
 {
     if (apparelProperties == null)
     {
         return(false);
     }
     if (apparelProperties.LastLayer == ApparelLayerDefOf.Overhead || apparelProperties.LastLayer == ApparelLayerDefOf.EyeCover)
     {
         return(true);
     }
     foreach (var g in apparelProperties.bodyPartGroups)
     {
         if (g == BodyPartGroupDefOf.FullHead || g == BodyPartGroupDefOf.UpperHead || g == BodyPartGroupDefOf.Eyes)
         {
             return(true);
         }
     }
     return(false);
 }
コード例 #11
0
        public void ApplyStats(ApparelProperties to)
        {
            to.wornGraphicPath               = this.wornGraphicPath;
            to.wearPerDay                    = this.wearPerDay;
            to.careIfWornByCorpse            = this.careIfWornByCorpse;
            to.hatRenderedFrontOfFace        = this.hatRenderedFrontOfFace;
            to.useDeflectMetalEffect         = this.useDeflectMetalEffect;
            to.useWornGraphicMask            = this.useWornGraphicMask;
            to.canBeGeneratedToSatisfyWarmth = this.canBeGeneratedToSatisfyWarmth;
            to.gender = this.gender;

            Util.Populate(out to.tags, this.tags, false);
            Util.Populate(out to.defaultOutfitTags, this.defaultOutfitTags, false);
            Util.Populate(out to.bodyPartGroups, this.bodyPartGroups, (v) => v.Def, false);
            Util.Populate(out to.layers, this.layers, (v) => v.Def, false);

            typeof(ApparelProperties).GetField("cachedHumanBodyCoverage", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(to, -1);
            typeof(ApparelProperties).GetField("interferingBodyPartGroups", BindingFlags.NonPublic | BindingFlags.Instance).SetValue(to, null);

            ApparelProperties.ResetStaticData();
        }
コード例 #12
0
        public ApparelPropertiesWidget(ApparelProperties apparelProperties)
        {
            this.apparelProperties = apparelProperties;

            this.inputWidgets = new List <IInputWidget>()
            {
                // this.useWornGraphicMask == s.useWornGraphicMask &&
                //    this.canBeGeneratedToSatisfyWarmth == s.canBeGeneratedToSatisfyWarmth &&
                //    this.gender == s.gender &&
                new FloatInputWidget <ApparelProperties>(this.apparelProperties, "Wear Per Day", s => s.wearPerDay, (s, v) => s.wearPerDay = v),
                new BoolInputWidget <ApparelProperties>(this.apparelProperties, "Care If Worn By Corpse", s => s.careIfWornByCorpse, (s, v) => s.careIfWornByCorpse            = v),
                new BoolInputWidget <ApparelProperties>(this.apparelProperties, "Hat Rendered Front OfFace", s => s.hatRenderedFrontOfFace, (s, v) => s.hatRenderedFrontOfFace = v),
                new BoolInputWidget <ApparelProperties>(this.apparelProperties, "Use Deflect Metal Effect", s => s.useDeflectMetalEffect, (s, v) => s.useDeflectMetalEffect    = v),
                new BoolInputWidget <ApparelProperties>(this.apparelProperties, "Use Worn Graphic Mask", s => s.useWornGraphicMask, (s, b) => s.useWornGraphicMask             = b),
                new BoolInputWidget <ApparelProperties>(this.apparelProperties, "Can Be Generated for Warmth", s => s.canBeGeneratedToSatisfyWarmth, (s, b) => s.canBeGeneratedToSatisfyWarmth = b),
                new EnumInputWidget <ApparelProperties, Gender>(this.apparelProperties, "Gender", 100f, s => s.gender, (s, v) => s.gender = v),
                new TextPlusMinusInputWidget("Tags", 100f, () => this.apparelProperties.tags)
            };

            this.bodyPartGroupArgs = new WindowUtil.PlusMinusArgs <BodyPartGroupDef>()
            {
                allItems       = DefDatabase <BodyPartGroupDef> .AllDefs,
                beingUsed      = () => this.apparelProperties?.bodyPartGroups,
                onAdd          = v => this.apparelProperties.bodyPartGroups.Add(v),
                onRemove       = v => this.apparelProperties.bodyPartGroups.Remove(v),
                getDisplayName = v => Util.GetLabel(v),
            };

            this.apparelLayerArgs = new WindowUtil.PlusMinusArgs <ApparelLayerDef>()
            {
                allItems       = DefDatabase <ApparelLayerDef> .AllDefs,
                beingUsed      = () => this.apparelProperties?.layers,
                onAdd          = v => this.apparelProperties.layers.Add(v),
                onRemove       = v => this.apparelProperties.layers.Remove(v),
                getDisplayName = v => Util.GetLabel(v),
            };
        }
コード例 #13
0
 private static void DoPlayLoad()
 {
     GraphicDatabase.Clear();
     DeepProfiler.Start("Load all active mods.");
     try
     {
         LoadedModManager.LoadAllActiveMods();
     }
     finally
     {
         DeepProfiler.End();
     }
     DeepProfiler.Start("Load language metadata.");
     try
     {
         LanguageDatabase.LoadAllMetadata();
     }
     finally
     {
         DeepProfiler.End();
     }
     LongEventHandler.SetCurrentEventText("LoadingDefs".Translate());
     DeepProfiler.Start("Copy all Defs from mods to global databases.");
     try
     {
         foreach (Type item in typeof(Def).AllSubclasses())
         {
             GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item, "AddAllInMods");
         }
     }
     finally
     {
         DeepProfiler.End();
     }
     DeepProfiler.Start("Resolve cross-references between non-implied Defs.");
     try
     {
         DirectXmlCrossRefLoader.ResolveAllWantedCrossReferences(FailMode.Silent);
     }
     finally
     {
         DeepProfiler.End();
     }
     DeepProfiler.Start("Rebind defs (early).");
     try
     {
         DefOfHelper.RebindAllDefOfs(true);
     }
     finally
     {
         DeepProfiler.End();
     }
     DeepProfiler.Start("Generate implied Defs (pre-resolve).");
     try
     {
         DefGenerator.GenerateImpliedDefs_PreResolve();
     }
     finally
     {
         DeepProfiler.End();
     }
     DeepProfiler.Start("Resolve cross-references between Defs made by the implied defs.");
     try
     {
         DirectXmlCrossRefLoader.ResolveAllWantedCrossReferences(FailMode.LogErrors);
     }
     finally
     {
         DeepProfiler.End();
     }
     DeepProfiler.Start("Rebind DefOfs (final).");
     try
     {
         DefOfHelper.RebindAllDefOfs(false);
     }
     finally
     {
         DeepProfiler.End();
     }
     DeepProfiler.Start("Other def binding, resetting and global operations.");
     try
     {
         PlayerKnowledgeDatabase.ReloadAndRebind();
         LessonAutoActivator.Reset();
         CostListCalculator.Reset();
         PawnApparelGenerator.Reset();
         RestUtility.Reset();
         ThoughtUtility.Reset();
         PawnWeaponGenerator.Reset();
         ThinkTreeKeyAssigner.Reset();
         ThingCategoryNodeDatabase.FinalizeInit();
         TrainableUtility.Reset();
         HaulAIUtility.Reset();
         GenConstruct.Reset();
         WorkGiver_FillFermentingBarrel.Reset();
         WorkGiver_DoBill.Reset();
         Pawn.Reset();
         WorkGiver_InteractAnimal.Reset();
         WorkGiver_Warden_DoExecution.Reset();
         WorkGiver_GrowerSow.Reset();
         WorkGiver_Miner.Reset();
         MedicalCareUtility.Reset();
         InspectPaneUtility.Reset();
         GraphicDatabaseHeadRecords.Reset();
         DateReadout.Reset();
         ResearchProjectDef.GenerateNonOverlappingCoordinates();
         WorkGiver_FixBrokenDownBuilding.CacheTranslations();
         ItemCollectionGeneratorUtility.Reset();
         BaseGen.Reset();
         HealthUtility.Reset();
         ResourceCounter.ResetDefs();
         WildSpawner.Reset();
         ApparelProperties.Reset();
     }
     finally
     {
         DeepProfiler.End();
     }
     DeepProfiler.Start("Resolve references.");
     try
     {
         foreach (Type item2 in typeof(Def).AllSubclasses())
         {
             if (item2 != typeof(ThingDef))
             {
                 GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item2, "ResolveAllReferences", true);
             }
         }
         DefDatabase <ThingDef> .ResolveAllReferences(true);
     }
     finally
     {
         DeepProfiler.End();
     }
     DeepProfiler.Start("Generate implied Defs (post-resolve).");
     try
     {
         DefGenerator.GenerateImpliedDefs_PostResolve();
     }
     finally
     {
         DeepProfiler.End();
     }
     if (Prefs.DevMode)
     {
         DeepProfiler.Start("Error check all defs.");
         try
         {
             foreach (Type item3 in typeof(Def).AllSubclasses())
             {
                 GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item3, "ErrorCheckAllDefs");
             }
         }
         finally
         {
             DeepProfiler.End();
         }
     }
     LongEventHandler.SetCurrentEventText("Initializing".Translate());
     DeepProfiler.Start("Load keyboard preferences.");
     try
     {
         KeyPrefs.Init();
     }
     finally
     {
         DeepProfiler.End();
     }
     DeepProfiler.Start("Short hash giving.");
     try
     {
         ShortHashGiver.GiveAllShortHashes();
     }
     finally
     {
         DeepProfiler.End();
     }
     LongEventHandler.ExecuteWhenFinished(delegate
     {
         DeepProfiler.Start("Load backstories.");
         try
         {
             BackstoryDatabase.ReloadAllBackstories();
         }
         finally
         {
             DeepProfiler.End();
         }
     });
     LongEventHandler.ExecuteWhenFinished(delegate
     {
         DeepProfiler.Start("Inject selected language data into game data.");
         try
         {
             LanguageDatabase.activeLanguage.InjectIntoData();
             GenLabel.ClearCache();
         }
         finally
         {
             DeepProfiler.End();
         }
     });
     LongEventHandler.ExecuteWhenFinished(delegate
     {
         StaticConstructorOnStartupUtility.CallAll();
         if (Prefs.DevMode)
         {
             StaticConstructorOnStartupUtility.ReportProbablyMissingAttributes();
         }
     });
 }
コード例 #14
0
        private static void PawnKindApparelCheck()
        {
            List <DebugMenuOption> list = new List <DebugMenuOption>();

            foreach (PawnKindDef item in from kd in DefDatabase <PawnKindDef> .AllDefs
                     where kd.race == ThingDefOf.Human
                     orderby kd.defName
                     select kd)
            {
                PawnKindDef localKindDef = item;
                list.Add(new DebugMenuOption(localKindDef.defName, DebugMenuOptionMode.Action, delegate
                {
                    Faction faction = FactionUtility.DefaultFactionFrom(localKindDef.defaultFactionType);
                    bool flag       = false;
                    for (int k = 0; k < 100; k++)
                    {
                        Pawn pawn2 = PawnGenerator.GeneratePawn(localKindDef, faction);
                        if (pawn2.royalty != null)
                        {
                            RoyalTitle mostSeniorTitle2 = pawn2.royalty.MostSeniorTitle;
                            if (mostSeniorTitle2 != null && !mostSeniorTitle2.def.requiredApparel.NullOrEmpty())
                            {
                                for (int l = 0; l < mostSeniorTitle2.def.requiredApparel.Count; l++)
                                {
                                    if (!mostSeniorTitle2.def.requiredApparel[l].IsMet(pawn2))
                                    {
                                        Log.Error(localKindDef + " (" + mostSeniorTitle2.def.label + ")  does not have its title requirements met. index=" + l + logApparel(pawn2));
                                        flag = true;
                                    }
                                }
                            }
                        }
                        List <Apparel> wornApparel2 = pawn2.apparel.WornApparel;
                        for (int m = 0; m < wornApparel2.Count; m++)
                        {
                            string text = apparelOkayToWear(pawn2, wornApparel2[m]);
                            if (text != "OK")
                            {
                                Log.Error(text + " - " + wornApparel2[m].Label + logApparel(pawn2));
                                flag = true;
                            }
                        }
                        Find.WorldPawns.PassToWorld(pawn2, PawnDiscardDecideMode.Discard);
                    }
                    if (!flag)
                    {
                        Log.Message("No errors for " + localKindDef.defName);
                    }
                }));
            }
            Find.WindowStack.Add(new Dialog_DebugOptionListLister(list));
            string apparelOkayToWear(Pawn pawn, Apparel apparel)
            {
                ApparelProperties app = apparel.def.apparel;

                if (!pawn.kindDef.apparelRequired.NullOrEmpty() && pawn.kindDef.apparelRequired.Contains(apparel.def))
                {
                    return("OK");
                }
                if (!app.CorrectGenderForWearing(pawn.gender))
                {
                    return("Wrong gender.");
                }
                List <SpecificApparelRequirement> specificApparelRequirements = pawn.kindDef.specificApparelRequirements;

                if (specificApparelRequirements != null)
                {
                    for (int i = 0; i < specificApparelRequirements.Count; i++)
                    {
                        if (PawnApparelGenerator.ApparelRequirementHandlesThing(specificApparelRequirements[i], apparel.def) && PawnApparelGenerator.ApparelRequirementTagsMatch(specificApparelRequirements[i], apparel.def))
                        {
                            return("OK");
                        }
                    }
                }
                if (!pawn.kindDef.apparelTags.NullOrEmpty())
                {
                    if (!app.tags.Any((string tag) => pawn.kindDef.apparelTags.Contains(tag)))
                    {
                        return("Required tag missing.");
                    }
                    if ((pawn.royalty == null || pawn.royalty.MostSeniorTitle == null) && app.tags.Contains("Royal") && !pawn.kindDef.apparelTags.Any((string tag) => app.tags.Contains(tag)))
                    {
                        return("Royal apparel on non-royal pawn.");
                    }
                }
                if (!pawn.kindDef.apparelDisallowTags.NullOrEmpty() && pawn.kindDef.apparelDisallowTags.Any((string t) => app.tags.Contains(t)))
                {
                    return("Has a disallowed tag.");
                }
                if (pawn.royalty != null && pawn.royalty.AllTitlesInEffectForReading.Any())
                {
                    RoyalTitle mostSeniorTitle = pawn.royalty.MostSeniorTitle;
                    if (apparel.TryGetQuality(out QualityCategory qc) && (int)qc < (int)mostSeniorTitle.def.requiredMinimumApparelQuality)
                    {
                        return("Quality too low.");
                    }
                }
                return("OK");
            }

            string logApparel(Pawn p)
            {
                StringBuilder stringBuilder = new StringBuilder();

                stringBuilder.AppendLine();
                stringBuilder.AppendLine($"Apparel of {p.LabelShort}:");
                List <Apparel> wornApparel = p.apparel.WornApparel;

                for (int j = 0; j < wornApparel.Count; j++)
                {
                    stringBuilder.AppendLine("  - " + wornApparel[j].Label);
                }
                return(stringBuilder.ToString());
            }
        }
コード例 #15
0
ファイル: PlayDataLoader.cs プロジェクト: KraigXu/GameProject
        private static void DoPlayLoad()
        {
            DeepProfiler.Start("GraphicDatabase.Clear()");
            try
            {
                GraphicDatabase.Clear();
            }
            finally
            {
                DeepProfiler.End();
            }
            DeepProfiler.Start("Load all active mods.");
            try
            {
                LoadedModManager.LoadAllActiveMods();
            }
            finally
            {
                DeepProfiler.End();
            }
            DeepProfiler.Start("Load language metadata.");
            try
            {
                LanguageDatabase.InitAllMetadata();
            }
            finally
            {
                DeepProfiler.End();
            }
            LongEventHandler.SetCurrentEventText("LoadingDefs".Translate());
            DeepProfiler.Start("Copy all Defs from mods to global databases.");
            try
            {
                foreach (Type item in typeof(Def).AllSubclasses())
                {
                    GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item, "AddAllInMods");
                }
            }
            finally
            {
                DeepProfiler.End();
            }
            DeepProfiler.Start("Resolve cross-references between non-implied Defs.");
            try
            {
                DirectXmlCrossRefLoader.ResolveAllWantedCrossReferences(FailMode.Silent);
            }
            finally
            {
                DeepProfiler.End();
            }
            DeepProfiler.Start("Rebind defs (early).");
            try
            {
                DefOfHelper.RebindAllDefOfs(earlyTryMode: true);
            }
            finally
            {
                DeepProfiler.End();
            }
            DeepProfiler.Start("TKeySystem.BuildMappings()");
            try
            {
                TKeySystem.BuildMappings();
            }
            finally
            {
                DeepProfiler.End();
            }
            DeepProfiler.Start("Inject selected language data into game data (early pass).");
            try
            {
                LanguageDatabase.activeLanguage.InjectIntoData_BeforeImpliedDefs();
            }
            finally
            {
                DeepProfiler.End();
            }
            DeepProfiler.Start("Generate implied Defs (pre-resolve).");
            try
            {
                DefGenerator.GenerateImpliedDefs_PreResolve();
            }
            finally
            {
                DeepProfiler.End();
            }
            DeepProfiler.Start("Resolve cross-references between Defs made by the implied defs.");
            try
            {
                DirectXmlCrossRefLoader.ResolveAllWantedCrossReferences(FailMode.LogErrors);
            }
            finally
            {
                DirectXmlCrossRefLoader.Clear();
                DeepProfiler.End();
            }
            DeepProfiler.Start("Rebind DefOfs (final).");
            try
            {
                DefOfHelper.RebindAllDefOfs(earlyTryMode: false);
            }
            finally
            {
                DeepProfiler.End();
            }
            DeepProfiler.Start("Other def binding, resetting and global operations (pre-resolve).");
            try
            {
                PlayerKnowledgeDatabase.ReloadAndRebind();
                LessonAutoActivator.Reset();
                CostListCalculator.Reset();
                Pawn.ResetStaticData();
                PawnApparelGenerator.Reset();
                RestUtility.Reset();
                ThoughtUtility.Reset();
                ThinkTreeKeyAssigner.Reset();
                ThingCategoryNodeDatabase.FinalizeInit();
                TrainableUtility.Reset();
                HaulAIUtility.Reset();
                GenConstruct.Reset();
                MedicalCareUtility.Reset();
                InspectPaneUtility.Reset();
                GraphicDatabaseHeadRecords.Reset();
                DateReadout.Reset();
                ResearchProjectDef.GenerateNonOverlappingCoordinates();
                BaseGen.Reset();
                ResourceCounter.ResetDefs();
                ApparelProperties.ResetStaticData();
                WildPlantSpawner.ResetStaticData();
                PawnGenerator.Reset();
                TunnelHiveSpawner.ResetStaticData();
                Hive.ResetStaticData();
                ExpectationsUtility.Reset();
                WealthWatcher.ResetStaticData();
                SkillUI.Reset();
                QuestNode_GetThingPlayerCanProduce.ResetStaticData();
                Pawn_PsychicEntropyTracker.ResetStaticData();
                ColoredText.ResetStaticData();
                QuestNode_GetRandomNegativeGameCondition.ResetStaticData();
                RoyalTitleUtility.ResetStaticData();
                RewardsGenerator.ResetStaticData();
                WorkGiver_FillFermentingBarrel.ResetStaticData();
                WorkGiver_DoBill.ResetStaticData();
                WorkGiver_InteractAnimal.ResetStaticData();
                WorkGiver_Warden_DoExecution.ResetStaticData();
                WorkGiver_GrowerSow.ResetStaticData();
                WorkGiver_Miner.ResetStaticData();
                WorkGiver_FixBrokenDownBuilding.ResetStaticData();
                WorkGiver_ConstructDeliverResources.ResetStaticData();
            }
            finally
            {
                DeepProfiler.End();
            }
            DeepProfiler.Start("Resolve references.");
            try
            {
                DeepProfiler.Start("ThingCategoryDef resolver");
                try
                {
                    DefDatabase <ThingCategoryDef> .ResolveAllReferences();
                }
                finally
                {
                    DeepProfiler.End();
                }
                DeepProfiler.Start("RecipeDef resolver");
                try
                {
                    DeepProfiler.enabled = false;
                    DefDatabase <RecipeDef> .ResolveAllReferences(onlyExactlyMyType : true, parallel : true);

                    DeepProfiler.enabled = true;
                }
                finally
                {
                    DeepProfiler.End();
                }
                DeepProfiler.Start("Static resolver calls");
                try
                {
                    foreach (Type item2 in typeof(Def).AllSubclasses())
                    {
                        if (!(item2 == typeof(ThingDef)) && !(item2 == typeof(ThingCategoryDef)) && !(item2 == typeof(RecipeDef)))
                        {
                            GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item2, "ResolveAllReferences", true, false);
                        }
                    }
                }
                finally
                {
                    DeepProfiler.End();
                }
                DeepProfiler.Start("ThingDef resolver");
                try
                {
                    DefDatabase <ThingDef> .ResolveAllReferences();
                }
                finally
                {
                    DeepProfiler.End();
                }
            }
            finally
            {
                DeepProfiler.End();
            }
            DeepProfiler.Start("Generate implied Defs (post-resolve).");
            try
            {
                DefGenerator.GenerateImpliedDefs_PostResolve();
            }
            finally
            {
                DeepProfiler.End();
            }
            DeepProfiler.Start("Other def binding, resetting and global operations (post-resolve).");
            try
            {
                PawnWeaponGenerator.Reset();
                BuildingProperties.FinalizeInit();
                ThingSetMakerUtility.Reset();
            }
            finally
            {
                DeepProfiler.End();
            }
            if (Prefs.DevMode)
            {
                DeepProfiler.Start("Error check all defs.");
                try
                {
                    foreach (Type item3 in typeof(Def).AllSubclasses())
                    {
                        GenGeneric.InvokeStaticMethodOnGenericType(typeof(DefDatabase <>), item3, "ErrorCheckAllDefs");
                    }
                }
                finally
                {
                    DeepProfiler.End();
                }
            }
            LongEventHandler.SetCurrentEventText("Initializing".Translate());
            DeepProfiler.Start("Load keyboard preferences.");
            try
            {
                KeyPrefs.Init();
            }
            finally
            {
                DeepProfiler.End();
            }
            DeepProfiler.Start("Short hash giving.");
            try
            {
                ShortHashGiver.GiveAllShortHashes();
            }
            finally
            {
                DeepProfiler.End();
            }
            LongEventHandler.ExecuteWhenFinished(delegate
            {
                DeepProfiler.Start("Load backstories.");
                try
                {
                    BackstoryDatabase.ReloadAllBackstories();
                }
                finally
                {
                    DeepProfiler.End();
                }
            });
            LongEventHandler.ExecuteWhenFinished(delegate
            {
                DeepProfiler.Start("Inject selected language data into game data.");
                try
                {
                    LanguageDatabase.activeLanguage.InjectIntoData_AfterImpliedDefs();
                    GenLabel.ClearCache();
                }
                finally
                {
                    DeepProfiler.End();
                }
            });
            LongEventHandler.ExecuteWhenFinished(delegate
            {
                DeepProfiler.Start("Static constructor calls");
                try
                {
                    StaticConstructorOnStartupUtility.CallAll();
                    if (Prefs.DevMode)
                    {
                        StaticConstructorOnStartupUtility.ReportProbablyMissingAttributes();
                    }
                }
                finally
                {
                    DeepProfiler.End();
                }
                DeepProfiler.Start("Garbage Collection");
                try
                {
                    AbstractFilesystem.ClearAllCache();
                    GC.Collect(int.MaxValue, GCCollectionMode.Forced);
                }
                finally
                {
                    DeepProfiler.End();
                }
            });
        }
コード例 #16
0
        public override bool Inject()
        {
            // Loop through all detour attributes and try to hook them up
            foreach (Type targetType in Assembly.GetTypes())
            {
                foreach (BindingFlags bindingFlags in bindingFlagCombos)
                {
                    foreach (MethodInfo targetMethod in targetType.GetMethods(bindingFlags))
                    {
                        foreach (DetourAttribute detour in targetMethod.GetCustomAttributes(
                                     typeof(DetourAttribute),
                                     true))
                        {
                            BindingFlags flags = detour.bindingFlags != default(BindingFlags)
                                                     ? detour.bindingFlags
                                                     : bindingFlags;
                            MethodInfo sourceMethod = detour.source.GetMethod(targetMethod.Name, flags);
                            if (sourceMethod == null)
                            {
                                Log.Error(
                                    string.Format(
                                        "Outfitter :: Detours :: Can't find source method '{0} with bindingflags {1}",
                                        targetMethod.Name,
                                        flags));
                                return(false);
                            }

                            if (!Detours.TryDetourFromTo(sourceMethod, targetMethod))
                            {
                                return(false);
                            }
                        }
                    }
                }
            }

            /*
             * MethodInfo coreMethod = typeof(JobGiver_OptimizeApparel).GetMethod("TryGiveJob", BindingFlags.Instance | BindingFlags.NonPublic);
             * MethodInfo autoEquipMethod = typeof(Outfitter_JobGiver_OptimizeApparel).GetMethod("TryGiveJob", BindingFlags.Instance | BindingFlags.NonPublic);
             *
             * if (!Detours.TryDetourFromTo(coreMethod, autoEquipMethod))
             *  Log.Error("Could not Detour AutoEquip.");
             */

            // inject ITab into all humanlikes
            if (useApparelSense)
            {
                // get a list of all apparel in the game
                List <ThingDef> allApparel = DefDatabase <ThingDef> .AllDefsListForReading.Where(t => t.IsApparel)
                                             .ToList();

                // detach all existing categories under apparel
                foreach (ThingCategoryDef cat in apparelRoot.childCategories)
                {
                    cat.parent = null;
                }

                apparelRoot.childCategories = new List <ThingCategoryDef>();

                // loop over all apparel, adding categories where appropriate.
                foreach (ThingDef thing in allApparel)
                {
                    // create list of categories on thing if necessary (shouldn't ever be, but what the heck)
                    if (thing.thingCategories.NullOrEmpty())
                    {
                        thing.thingCategories = new List <ThingCategoryDef>();
                    }

                    // remove existing categories on thing
                    foreach (ThingCategoryDef cat in thing.thingCategories)
                    {
                        cat.childThingDefs.Remove(thing);
                    }

                    // add in new categories
                    ApparelProperties apparel = thing.apparel;

                    // categories based on bodyparts
                    foreach (BodyPartGroupDef bodyPart in apparel.bodyPartGroups)
                    {
                        // get or create category
                        ThingCategoryDef cat =
                            DefDatabase <ThingCategoryDef> .GetNamedSilentFail(GetCatName(bodyPart.label, "BP"));

                        if (cat == null)
                        {
                            cat = CreateCategory(bodyPart.label, "BP");
                        }

                        foreach (ApparelLayer layer in apparel.layers)
                        {
                            // get or create category
                            ThingCategoryDef childCat =
                                DefDatabase <ThingCategoryDef> .GetNamedSilentFail(
                                    GetChildCatName(bodyPart.label, layer.ToString(), "CC"));

                            if (childCat == null)
                            {
                                childCat = CreateChildCategory(cat, bodyPart.label, layer.ToString(), "CC");
                            }

                            // add category to thing, and thing to category. (Tynan, pls.)
                            thing.thingCategories.Add(childCat);
                            childCat.childThingDefs.Add(thing);
                        }
                    }

                    // categories based on tag (too messy)

                    //// categories based on tag (too messy)
                    // foreach ( string tag in apparel.tags )
                    // {
                    // // get or create category
                    // ThingCategoryDef cat = DefDatabase<ThingCategoryDef>.GetNamedSilentFail( GetCatName( tag, "BP" ) );
                    // if( cat == null )
                    // {
                    // cat = CreateCategory( tag, "BP" );
                    // }

                    // // add category to thing, and thing to category. (Tynan, pls.)
                    // thing.thingCategories.Add( cat );
                    // cat.childThingDefs.Add( thing );
                    // }
                }

                // set nest levels on new categories
                SetNestLevelRecursive(apparelRoot.treeNode, apparelRoot.treeNode.nestDepth);
            }

            return(true);
        }