Пример #1
0
        public static Thing MakeThing(ThingDef def, ThingDef stuff = null)
        {
            if (stuff != null && !stuff.IsStuff)
            {
                Log.Error(string.Concat(new object[]
                {
                    "MakeThing error: Tried to make ",
                    def,
                    " from ",
                    stuff,
                    " which is not a stuff. Assigning default."
                }), false);
                stuff = GenStuff.DefaultStuffFor(def);
            }
            if (def.MadeFromStuff && stuff == null)
            {
                Log.Error("MakeThing error: " + def + " is madeFromStuff but stuff=null. Assigning default.", false);
                stuff = GenStuff.DefaultStuffFor(def);
            }
            if (!def.MadeFromStuff && stuff != null)
            {
                Log.Error(string.Concat(new object[]
                {
                    "MakeThing error: ",
                    def,
                    " is not madeFromStuff but stuff=",
                    stuff,
                    ". Setting to null."
                }), false);
                stuff = null;
            }
            Thing thing = (Thing)Activator.CreateInstance(def.thingClass);

            thing.def = def;
            thing.SetStuffDirect(stuff);
            thing.PostMake();
            return(thing);
        }
Пример #2
0
        public static Thing MakeThing(ThingDef def, ThingDef stuff = null)
        {
            if (stuff != null && !stuff.IsStuff)
            {
                Log.Error("MakeThing error: Tried to make " + def + " from " + stuff + " which is not a stuff. Assigning default.");
                stuff = GenStuff.DefaultStuffFor(def);
            }
            if (def.MadeFromStuff && stuff == null)
            {
                Log.Error("MakeThing error: " + def + " is madeFromStuff but stuff=null. Assigning default.");
                stuff = GenStuff.DefaultStuffFor(def);
            }
            if (!def.MadeFromStuff && stuff != null)
            {
                Log.Error("MakeThing error: " + def + " is not madeFromStuff but stuff=" + stuff + ". Setting to null.");
                stuff = null;
            }
            Thing obj = (Thing)Activator.CreateInstance(def.thingClass);

            obj.def = def;
            obj.SetStuffDirect(stuff);
            obj.PostMake();
            return(obj);
        }
        public override void PostExposeData(object obj)
        {
            if (Scribe.mode == LoadSaveMode.LoadingVars)
            {
                Game game = obj as Game;
                if (game != null && game.questManager == null)
                {
                    game.questManager = new QuestManager();
                }
                Zone zone = obj as Zone;
                if (zone != null && zone.ID == -1)
                {
                    zone.ID = Find.UniqueIDsManager.GetNextZoneID();
                }
            }
            if (Scribe.mode != LoadSaveMode.PostLoadInit)
            {
                return;
            }
            Pawn pawn = obj as Pawn;

            if (pawn != null && pawn.royalty == null)
            {
                pawn.royalty = new Pawn_RoyaltyTracker(pawn);
            }
            Pawn_NativeVerbs pawn_NativeVerbs = obj as Pawn_NativeVerbs;

            if (pawn_NativeVerbs != null && pawn_NativeVerbs.verbTracker == null)
            {
                pawn_NativeVerbs.verbTracker = new VerbTracker(pawn_NativeVerbs);
            }
            Thing thing = obj as Thing;

            if (thing != null)
            {
                if (thing.def.defName == "Sandbags" && thing.Stuff == null)
                {
                    thing.SetStuffDirect(ThingDefOf.Cloth);
                }
                if (thing.def == ThingDefOf.MechCapsule)
                {
                    foreach (XmlNode oldCrashedShipPart in oldCrashedShipParts)
                    {
                        XmlElement xmlElement  = oldCrashedShipPart["def"];
                        XmlElement xmlElement2 = oldCrashedShipPart["id"];
                        if (xmlElement != null && xmlElement2 != null && Thing.IDNumberFromThingID(xmlElement2.InnerText) == thing.thingIDNumber)
                        {
                            upgradedCrashedShipParts.Add(new UpgradedCrashedShipPart
                            {
                                originalDefName = xmlElement.InnerText,
                                thing           = thing
                            });
                        }
                    }
                }
            }
            StoryWatcher storyWatcher = obj as StoryWatcher;

            if (storyWatcher != null)
            {
                if (storyWatcher.watcherAdaptation == null)
                {
                    storyWatcher.watcherAdaptation = new StoryWatcher_Adaptation();
                }
                if (storyWatcher.watcherPopAdaptation == null)
                {
                    storyWatcher.watcherPopAdaptation = new StoryWatcher_PopAdaptation();
                }
            }
            FoodRestrictionDatabase foodRestrictionDatabase = obj as FoodRestrictionDatabase;

            if (foodRestrictionDatabase != null && VersionControl.BuildFromVersionString(ScribeMetaHeaderUtility.loadedGameVersion) < 2057)
            {
                List <FoodRestriction> allFoodRestrictions = foodRestrictionDatabase.AllFoodRestrictions;
                for (int i = 0; i < allFoodRestrictions.Count; i++)
                {
                    allFoodRestrictions[i].filter.SetAllow(ThingCategoryDefOf.CorpsesHumanlike, allow: true);
                    allFoodRestrictions[i].filter.SetAllow(ThingCategoryDefOf.CorpsesAnimal, allow: true);
                }
            }
            SitePart sitePart = obj as SitePart;

            if (sitePart != null)
            {
                sitePart.hidden = sitePart.def.defaultHidden;
            }
        }