Ejemplo n.º 1
0
 //RoomRequirement_ThingAnyOf
 public static void Vamp_RoyalCoffinsCountAsBeds(RoomRequirement_ThingAnyOf __instance, Room r, ref bool __result)
 {
     foreach (ThingDef thing in __instance.things)
     {
         if (thing == ThingDefOf.RoyalBed)
         {
             if (r.ContainsThing(ThingDef.Named("ROMV_RoyalCoffin")))
             {
                 __result = true;
                 return;
             }
             if (r.ContainsThing(ThingDef.Named("ROMV_RoyalCoffinDouble")))
             {
                 __result = true;
                 return;
             }
         }
     }
 }
Ejemplo n.º 2
0
        public void Inject()
        {
            Type bed = typeof(Building_Bed);
            Dictionary <string, ThingDef> bedDefs = DefDatabase <ThingDef> .AllDefsListForReading
                                                    .Where(d => !d.defName.StartsWith("Ogre_NanoTech") && bed.IsAssignableFrom(d.thingClass))
                                                    .ToDictionary(x => x.defName, y => y);

            HashSet <string> modSupport = new HashSet <string>(StringComparer.OrdinalIgnoreCase);

            List <ThingDef> linkableBuildings         = ThingDef.Named("Ogre_NanoTech_Bed").GetCompProperties <CompProperties_AffectedByFacilities>().linkableFacilities;
            List <CompProperties_Facility> facilities = linkableBuildings
                                                        .Select(x => x.GetCompProperties <CompProperties_Facility>())
                                                        .Where(x => x != null)
                                                        .ToList();

            List <ThingDef> linkableHospitalOnly = ThingDef.Named("Ogre_NanoTech_HospitalBed").GetCompProperties <CompProperties_AffectedByFacilities>().linkableFacilities;
            List <CompProperties_Facility> hospitalOnlyFacilities = linkableHospitalOnly
                                                                    .Select(x => x.GetCompProperties <CompProperties_Facility>())
                                                                    .Where(x => x != null)
                                                                    .ToList();

            ThingCategoryDef buildingCategory = DefDatabase <ThingCategoryDef> .AllDefsListForReading.Find(x => x.defName == "BuildingsFurniture");

            List <MemeDef> memesRef = new List <MemeDef>();

            Dictionary <string, List <MemeDef> > designatorViaMeme = new Dictionary <string, List <MemeDef> >();
            Dictionary <string, List <RoomRequirement_ThingAnyOf> > reqViaTitle = new Dictionary <string, List <RoomRequirement_ThingAnyOf> >();

            if (ModsConfig.IdeologyActive)
            {
                // build a lookup of all memes
                // that have unlockable buildables
                // ex pain in virtue ( slab beds )
                List <MemeDef> memes = new List <MemeDef>(DefDatabase <MemeDef> .AllDefsListForReading);
                foreach (MemeDef m in memes)
                {
                    if (m.addDesignators != null)
                    {
                        foreach (BuildableDef d in m.addDesignators)
                        {
                            if (d != null && !string.IsNullOrWhiteSpace(d.defName))
                            {
                                List <MemeDef> o;
                                if (!designatorViaMeme.TryGetValue(d.defName, out o))
                                {
                                    o = new List <MemeDef>();
                                    designatorViaMeme.Add(d.defName, o);
                                }
                                o.Add(m);
                            }
                        }
                    }
                }
            }

            if (ModsConfig.RoyaltyActive)
            {
                List <RoyalTitleDef> titles = DefDatabase <RoyalTitleDef> .AllDefsListForReading;
                if (titles != null)
                {
                    foreach (RoyalTitleDef title in titles)
                    {
                        List <RoomRequirement> requirements = title.bedroomRequirements;
                        if (requirements != null)
                        {
                            foreach (RoomRequirement req in requirements)
                            {
                                RoomRequirement_ThingAnyOf anyReq = (req as RoomRequirement_ThingAnyOf);
                                if (anyReq != null)
                                {
                                    List <ThingDef> things = anyReq.things;
                                    if (things != null && things.Count > 0)
                                    {
                                        List <RoomRequirement_ThingAnyOf> o;
                                        foreach (ThingDef d in things)
                                        {
                                            if (!reqViaTitle.TryGetValue(d.defName, out o))
                                            {
                                                o = new List <RoomRequirement_ThingAnyOf>();
                                                reqViaTitle.Add(d.defName, o);
                                            }
                                            o.Add(anyReq);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                modSupport.Add("Royalty");

                Dictionary <string, ThingDef> defaultSupport = new Dictionary <string, ThingDef>()
                {
                    { "DoubleBed", DefDatabase <ThingDef> .AllDefsListForReading.Where(x => x.defName == "Ogre_NanoTech_DoubleBed").First() },
                    { "RoyalBed", DefDatabase <ThingDef> .AllDefsListForReading.Where(x => x.defName == "Ogre_NanoTech_RoyalBed").First() }
                };

                foreach (string key in reqViaTitle.Keys)
                {
                    if (defaultSupport.ContainsKey(key))
                    {
                        foreach (RoomRequirement_ThingAnyOf a in reqViaTitle[key])
                        {
                            a.things.Add(defaultSupport[key]);
                        }
                    }
                }
            }

            foreach (SupportedBed b in _BEDS_TO_SUPPORT)
            {
                if (bedDefs.ContainsKey(b.DefName))
                {
                    ThingDef nanoBed = NanoUtil.CreateNanoBedDefFromSupportedBed(
                        bed: bedDefs[b.DefName],
                        fnAdditionalProcessing: b.FnPostProcess,
                        linkableBuildings: b.UseHospitalLinkablesOnly ? linkableHospitalOnly : linkableBuildings,
                        facilities: b.UseHospitalLinkablesOnly ? hospitalOnlyFacilities : facilities
                        );

                    DefDatabase <ThingDef> .Add(nanoBed);

                    buildingCategory.childThingDefs.Add(nanoBed);                     // so beds are in stockpile filters
                    modSupport.Add(b.ModName);

                    if (ModsConfig.IdeologyActive)
                    {
                        // check if this bed is listed as an
                        // unlockable building via a memedef
                        if (!nanoBed.canGenerateDefaultDesignator)
                        {
                            if (designatorViaMeme.ContainsKey(b.DefName))
                            {
                                foreach (MemeDef m in designatorViaMeme[b.DefName])
                                {
                                    m.addDesignators.Add(nanoBed);
                                }
                            }
                        }
                    }

                    if (ModsConfig.RoyaltyActive)
                    {
                        if (reqViaTitle.ContainsKey(b.DefName))
                        {
                            foreach (RoomRequirement_ThingAnyOf a in reqViaTitle[b.DefName])
                            {
                                a.things.Add(nanoBed);
                            }
                        }
                    }
                }
            }

            Verse.Log.Message("Nano Repair Tech Added Support: [ " + string.Join(", ", modSupport.OrderBy(x => x).ToArray()) + " ]");

            // defs show up where they are
            // supposed to in the game menus?
            DefDatabase <DesignationCategoryDef> .AllDefsListForReading.Find(x => x.defName == "Ogre_NanoRepairTech_DesignationCategory").ResolveReferences();

            // pawns will not auto seek out
            // the beds unless the
            // RestUtilty is reset
            RestUtility.Reset();
        }