Ejemplo n.º 1
0
        public static T ItemFromXmlString <T>(string xml, bool resolveCrossRefs = true) where T : new()
        {
            if (resolveCrossRefs && DirectXmlCrossRefLoader.LoadingInProgress)
            {
                Log.Error("Cannot call ItemFromXmlFile with resolveCrossRefs=true while loading is already in progress.", false);
            }
            if (xml.NullOrEmpty())
            {
                return(Activator.CreateInstance <T>());
            }
            T result;

            try
            {
                XmlDocument xmlDocument = new XmlDocument();
                // Trim should theoretically also get rid of BOMs
                xmlDocument.LoadXml(xml.Trim());
                T t = DirectXmlToObject.ObjectFromXml <T>(xmlDocument.DocumentElement, false);
                if (resolveCrossRefs)
                {
                    DirectXmlCrossRefLoader.ResolveAllWantedCrossReferences(FailMode.LogErrors);
                }
                result = t;
            }
            catch (Exception ex)
            {
                Log.Error($"Exception loading item from string. Loading defaults instead. \nXML: {xml}\n\nException: {ex}");
                result = Activator.CreateInstance <T>();
            }
            return(result);
        }
Ejemplo n.º 2
0
        public static void GenerateImpliedDefs_PreResolve()
        {
            IEnumerable <ThingDef> enumerable = ThingDefGenerator_Buildings.ImpliedBlueprintAndFrameDefs().Concat(ThingDefGenerator_Meat.ImpliedMeatDefs()).Concat(ThingDefGenerator_Corpses.ImpliedCorpseDefs())
                                                .Concat(ThingDefGenerator_Leather.ImpliedLeatherDefs());

            foreach (ThingDef item in enumerable)
            {
                item.PostLoad();
                DefDatabase <ThingDef> .Add(item);
            }
            DirectXmlCrossRefLoader.ResolveAllWantedCrossReferences(FailMode.Silent);
            foreach (TerrainDef item2 in TerrainDefGenerator_Stone.ImpliedTerrainDefs())
            {
                item2.PostLoad();
                DefDatabase <TerrainDef> .Add(item2);
            }
            foreach (RecipeDef item3 in RecipeDefGenerator.ImpliedRecipeDefs())
            {
                item3.PostLoad();
                DefDatabase <RecipeDef> .Add(item3);
            }
            foreach (PawnColumnDef item4 in PawnColumnDefgenerator.ImpliedPawnColumnDefs())
            {
                item4.PostLoad();
                DefDatabase <PawnColumnDef> .Add(item4);
            }
        }
Ejemplo n.º 3
0
 public static void GenerateImpliedDefs_PreResolve()
 {
     foreach (ThingDef item in ThingDefGenerator_Buildings.ImpliedBlueprintAndFrameDefs().Concat(ThingDefGenerator_Meat.ImpliedMeatDefs()).Concat(ThingDefGenerator_Techprints.ImpliedTechprintDefs())
              .Concat(ThingDefGenerator_Corpses.ImpliedCorpseDefs()))
     {
         AddImpliedDef(item);
     }
     DirectXmlCrossRefLoader.ResolveAllWantedCrossReferences(FailMode.Silent);
     foreach (TerrainDef item2 in TerrainDefGenerator_Stone.ImpliedTerrainDefs())
     {
         AddImpliedDef(item2);
     }
     foreach (RecipeDef item3 in RecipeDefGenerator.ImpliedRecipeDefs())
     {
         AddImpliedDef(item3);
     }
     foreach (PawnColumnDef item4 in PawnColumnDefgenerator.ImpliedPawnColumnDefs())
     {
         AddImpliedDef(item4);
     }
     foreach (ThingDef item5 in NeurotrainerDefGenerator.ImpliedThingDefs())
     {
         AddImpliedDef(item5);
     }
 }
Ejemplo n.º 4
0
 private static void GenerateImpliedDefs_PreResolve_Postfix()
 {
     foreach (ThingDef def in ThingDefGenerator_Blood.ImpliedBloodDefs())
     {
         DefGenerator.AddImpliedDef(def);
     }
     DirectXmlCrossRefLoader.ResolveAllWantedCrossReferences(FailMode.Silent);
     foreach (RecipeDef op in RecipeDefGenerator_BloodSurgeries.ImpliedOperationDefs())
     {
         DefGenerator.AddImpliedDef(op);
     }
 }
Ejemplo n.º 5
0
        public static void GenerateImpliedDefs_PreResolve()
        {
            IEnumerable <ThingDef> enumerable = ThingDefGenerator_Buildings.ImpliedBlueprintAndFrameDefs().Concat(ThingDefGenerator_Meat.ImpliedMeatDefs()).Concat(ThingDefGenerator_Corpses.ImpliedCorpseDefs());

            foreach (ThingDef current in enumerable)
            {
                DefGenerator.AddImpliedDef <ThingDef>(current);
            }
            DirectXmlCrossRefLoader.ResolveAllWantedCrossReferences(FailMode.Silent);
            foreach (TerrainDef current2 in TerrainDefGenerator_Stone.ImpliedTerrainDefs())
            {
                DefGenerator.AddImpliedDef <TerrainDef>(current2);
            }
            foreach (RecipeDef current3 in RecipeDefGenerator.ImpliedRecipeDefs())
            {
                DefGenerator.AddImpliedDef <RecipeDef>(current3);
            }
            foreach (PawnColumnDef current4 in PawnColumnDefgenerator.ImpliedPawnColumnDefs())
            {
                DefGenerator.AddImpliedDef <PawnColumnDef>(current4);
            }
        }
Ejemplo n.º 6
0
        public static void AddSaltedMeats()
        {
            HashSet <ThingDef> defsToAdd = new HashSet <ThingDef>();

            foreach (ThingDef td in DefDatabase <ThingDef> .AllDefs.Where(t => t.IsMeat))
            {
                ThingDef d = new ThingDef
                {
                    resourceReadoutPriority = td.resourceReadoutPriority, //ResourceCountPriority.Middle;
                    category    = td.category,                            // ThingCategory.Item;
                    thingClass  = td.thingClass,                          // typeof(ThingWithComps);
                    graphicData = new GraphicData()
                };
                d.graphicData.graphicClass = td.graphicData.graphicClass; // typeof(Graphic_Single);
                d.useHitPoints             = td.useHitPoints;             // true;
                d.selectable = td.selectable;                             // true;
                //d.SetStatBaseValue(StatDefOf.MaxHitPoints, 115f);
                d.SetStatBaseValue(StatDefOf.MaxHitPoints, td.GetStatValueAbstract(StatDefOf.MaxHitPoints) * 1.15f);
                d.altitudeLayer = td.altitudeLayer; // AltitudeLayer.Item;
                d.stackLimit    = td.stackLimit;    // 75;
                d.comps.Add(new CompProperties_Forbiddable());
                CompProperties_Rottable rotProps = new CompProperties_Rottable
                {
                    daysToRotStart = td.GetCompProperties <CompProperties_Rottable>().daysToRotStart, // 2f;
                    rotDestroys    = td.GetCompProperties <CompProperties_Rottable>().rotDestroys     // true;
                };
                d.comps.Add(rotProps);
                d.tickerType = td.tickerType;                                                                                 // TickerType.Rare;
                d.SetStatBaseValue(StatDefOf.Beauty, td.GetStatValueAbstract(StatDefOf.Beauty));                              // -20f
                d.alwaysHaulable          = td.alwaysHaulable;                                                                // true;
                d.rotatable               = td.rotatable;                                                                     // false;
                d.pathCost                = td.pathCost;                                                                      // 15;
                d.drawGUIOverlay          = td.drawGUIOverlay;                                                                // true;
                d.socialPropernessMatters = td.socialPropernessMatters;                                                       // true;

                d.modContentPack = td.modContentPack;                                                                         // +

                d.category     = td.category;                                                                                 // ThingCategory.Item;
                d.description  = td.description;
                d.useHitPoints = td.useHitPoints;                                                                             // true;
                d.SetStatBaseValue(StatDefOf.MaxHitPoints, td.GetStatValueAbstract(StatDefOf.MaxHitPoints) * 1.15f);          // 65f
                d.SetStatBaseValue(StatDefOf.DeteriorationRate, td.GetStatValueAbstract(StatDefOf.DeteriorationRate) * 0.5f); // 3f
                d.SetStatBaseValue(StatDefOf.Mass, td.GetStatValueAbstract(StatDefOf.Mass));                                  // 0.025f
                d.SetStatBaseValue(StatDefOf.Flammability, td.GetStatValueAbstract(StatDefOf.Flammability));                  // 0.5f
                d.SetStatBaseValue(StatDefOf.Nutrition, td.GetStatValueAbstract(StatDefOf.Nutrition) * 1.6f);
                //d.ingestible.nutrition = td.ingestible.nutrition + 0.03f;
                d.SetStatBaseValue(StatDefOf.FoodPoisonChanceFixedHuman, 0.02f);
                //d.comps.Add(new CompProperties_FoodPoisonable());
                d.BaseMarketValue = td.BaseMarketValue;
                if (d.thingCategories == null)
                {
                    d.thingCategories = new List <ThingCategoryDef>();
                }
                DirectXmlCrossRefLoader.RegisterListWantsCrossRef <ThingCategoryDef>(d.thingCategories, "LotR_MeatRawSalted", d);
                d.ingestible = new IngestibleProperties {
                    parent = d
                };
                d.ingestible.foodType      = td.ingestible.foodType;      // FoodTypeFlags.Meat;
                d.ingestible.preferability = td.ingestible.preferability; // FoodPreferability.RawBad;
                DirectXmlCrossRefLoader.RegisterObjectWantsCrossRef(d.ingestible, "tasteThought", ThoughtDefOf.AteRawFood.defName);
                d.ingestible.ingestEffect               = td.ingestible.ingestEffect;
                d.ingestible.ingestSound                = td.ingestible.ingestSound;
                d.ingestible.specialThoughtDirect       = td.ingestible.specialThoughtDirect;
                d.ingestible.specialThoughtAsIngredient = td.ingestible.specialThoughtAsIngredient;

                d.graphicData.texPath = td.graphicData.texPath;
                d.graphicData.color   = td.graphicData.color;
                //d.thingCategories.Add(TTADefOf.LotR_MeatRawSalted);
                d.defName = td.defName + "Salted";
                d.label   = "TTA_SaltedLabel".Translate(td.label);
                d.ingestible.sourceDef = td.ingestible.sourceDef;
                defsToAdd.Add(d);
            }
            TTADefOf.LotR_MeatRawSalted.parent = ThingCategoryDefOf.MeatRaw;
            while (defsToAdd?.Count > 0)
            {
                var thingDef = defsToAdd.FirstOrDefault();
                if (thingDef != null)
                {
                    if (!DefDatabase <ThingDef> .AllDefs.Contains(thingDef))
                    {
                        thingDef.PostLoad();
                        DefDatabase <ThingDef> .Add(thingDef);

                        if (!TTADefOf.LotR_MeatRawSalted.childThingDefs.Contains(thingDef))
                        {
                            TTADefOf.LotR_MeatRawSalted.childThingDefs.Add(thingDef);
                        }
                    }
                    defsToAdd.Remove(thingDef);
                }
                else
                {
                    break;
                }
            }

            DirectXmlCrossRefLoader.ResolveAllWantedCrossReferences(FailMode.Silent);
        }