Пример #1
0
        public static void Postfix(PawnRenderer __instance, Pawn ___pawn, Vector3 drawLoc)
        {
            Building_Bed    softWarmBed = ___pawn.CurrentBed();
            CompMakeableBed bedComp     = softWarmBed.TryGetComp <CompMakeableBed>();

            if (___pawn.RaceProps.Humanlike && bedComp != null)//___pawn.CurrentBed() is Building_SoftWarmBed)
            {
                if (!bedComp.Loaded)
                {
                    // Thanks to @Zamu & @Mehni!
                    var        rotDrawMode  = (RotDrawMode)AccessTools.Property(typeof(PawnRenderer), "CurRotDrawMode").GetGetMethod(true).Invoke(__instance, new object[0]);
                    MethodInfo layingFacing = AccessTools.Method(type: typeof(PawnRenderer), name: "LayingFacing");
                    Rot4       rot          = (Rot4)layingFacing.Invoke(__instance, new object[0]);
                    float      angle;
                    Vector3    rootLoc;
                    Rot4       rotation = softWarmBed.Rotation;
                    rotation.AsInt += 2;
                    angle           = rotation.AsAngle;
                    AltitudeLayer altLayer = (AltitudeLayer)Mathf.Max((int)softWarmBed.def.altitudeLayer, 15);
                    Vector3       vector2  = ___pawn.Position.ToVector3ShiftedWithAltitude(altLayer);
                    Vector3       vector3  = vector2;
                    vector3.y += 0.02734375f;
                    float   d = -__instance.BaseHeadOffsetAt(Rot4.South).z;
                    Vector3 a = rotation.FacingCell.ToVector3();
                    rootLoc    = vector2 + a * d;
                    rootLoc.y += 0.0078125f;
                    MethodInfo renderPawnInternal = AccessTools.Method(type: typeof(PawnRenderer), name: "RenderPawnInternal", parameters: new[] { typeof(Vector3), typeof(float), typeof(bool), typeof(Rot4), typeof(Rot4), typeof(RotDrawMode), typeof(bool), typeof(bool), typeof(bool) });
                    renderPawnInternal.Invoke(__instance, new object[] { rootLoc, angle, true, rot, rot, rotDrawMode, false, false, false });
                }
            }
        }
Пример #2
0
 private float SelectValue(StatRequest req, StatDef stat)
 {
     if (stat != null)
     {
         CompMakeableBed bedComp = req.Thing.TryGetComp <CompMakeableBed>();
         ThingDef        stuff   = null;
         if (bedComp != null)
         {
             if (bedComp.Loaded)
             {
                 stuff = bedComp.blanketStuff; // comp = stuff from bedding
             }
             else
             {
                 if (stat == additiveStat)
                 {
                     //Log.Message(stat + " is +zero for no bedding at " + req.Thing);
                     return(0f); // unmade bed = additive zero
                 }
             }
         }
         else
         {
             if (req.StuffDef != null)
             {
                 stuff = req.StuffDef; // no comp (Bedroll)
             }
             else
             {
                 if (stat == additiveStat)
                 {
                     //Log.Message(stat + " is +zero for no comp at " + req.Thing);
                     return(0f); // no comp, no stuff (SleepingSpot)
                 }
             }
         }
         bool both = additiveStat != null && multiplierStat != null;
         if (both)
         {
             if (stat == additiveStat)
             {
                 //Log.Message(stat + " is " + stuff.GetStatValueAbstract(stat, null) + " on " + stuff + " (case 1)");
                 return(stuff.GetStatValueAbstract(stat, null)); // if additive = get it from bed/bedding stuff
             }
             //Log.Message(stat + " is " + req.Def.GetStatValueAbstract(stat, null) + " on " + req.Def + " (case 2)");
             //return req.Def.GetStatValueAbstract(stat, null); // Changed on 1.1: method transfered to a Def child:
             return(req.BuildableDef.GetStatValueAbstract(stat, null)); // if multiplier = get it from bed
         }
         if (stat == additiveStat)
         {
             //Log.Message(stat + " is " + stuff.GetStatValueAbstract(stat, null) + " on " + stuff + " (case 3)");
             return(stuff.GetStatValueAbstract(stat, null)); // just additive = get it from bed/bedding stuff
         }
         //Log.Message(stat + " is " + req.Def.GetStatValueAbstract(stat, null) + " on " + req.Def + " (case 4)");
         //return req.Def.GetStatValueAbstract(stat, null); // Changed on 1.1: method transfered to a Def child:
         return(req.BuildableDef.GetStatValueAbstract(stat, null)); // just multiplier (just in case) = get from bed
     }
     //Log.Message(stat + " tried selecting without target");
     return(0f);
 }
        public static bool CanMakeBed(Pawn pawn, Building_Bed t, bool forced = false)
        {
            CompMakeableBed CompMakeableBed = t.TryGetComp <CompMakeableBed>();

            if (CompMakeableBed == null || CompMakeableBed.Loaded)
            {
                return(false);
            }
            if (!t.IsForbidden(pawn))
            {
                LocalTargetInfo target = t;
                if (pawn.CanReserve(target, 1, -1, null, forced))
                {
                    if (t.Faction != pawn.Faction)
                    {
                        return(false);
                    }
                    if (FindBestBedding(pawn, t) == null)
                    {
                        ThingFilter beddingFilter = new ThingFilter();
                        beddingFilter.SetAllow(t.TryGetComp <CompMakeableBed>().allowedBedding, true);
                        JobFailReason.Is("NoSuitableBedding".Translate(beddingFilter.Summary), null);
                        return(false);
                    }
                    return(true);
                }
            }
            return(false);
        }
Пример #4
0
 public static void Postfix(object __instance)
 {
     if (__instance is Building_Bed bed)
     {
         CompMakeableBed bedComp = bed.TryGetComp <CompMakeableBed>();
         if (bedComp != null && bedComp.loaded && bedComp.blanketDef != null)
         {
             bedComp.bedding.Notify_ColorChanged();
         }
     }
 }
Пример #5
0
 public static void Prefix(object __instance)
 {
     if (__instance is Building_Bed bed)
     {
         CompMakeableBed bedComp = bed.TryGetComp <CompMakeableBed>();
         if (bedComp != null && bedComp.loaded && bedComp.NotTheBlanket)
         {
             bedComp.Unmake();
         }
     }
 }
Пример #6
0
 public static void Postfix(object __instance)
 {
     if (__instance is Building_Bed bed)
     {
         CompMakeableBed bedComp = bed.TryGetComp <CompMakeableBed>();
         if (bedComp != null && bedComp.loaded)
         {
             bedComp.DrawBed();
         }
     }
 }
Пример #7
0
        public static void Postfix(Pawn ___pawn, ref bool showBody)
        {
            if (showBody)
            {
                return;
            }
            Building_Bed    softWarmBed = ___pawn.CurrentBed();
            CompMakeableBed bedComp     = softWarmBed.TryGetComp <CompMakeableBed>();

            showBody = ___pawn.RaceProps.Humanlike && bedComp != null && !bedComp.Loaded;
        }
Пример #8
0
        public static bool SwapPatch(object __instance, Building_Bed bed)
        {
            CompMakeableBed bedComp = bed.TryGetComp <CompMakeableBed>();

            if (bedComp != null)
            {
                bedComp.NotTheBlanket = false;
                Swap(__instance, bed, bedComp.settings, bedComp);
                return(false);
            }
            return(true);
        }
Пример #9
0
 public static bool Prefix(object __instance)
 {
     if (__instance is ThingComp compInstance)
     {
         if (compInstance.parent is Building_Bed bed)
         {
             CompMakeableBed bedComp = bed.TryGetComp <CompMakeableBed>();
             if (bedComp != null)
             {
                 return(!bedComp.loaded);
             }
         }
     }
     return(true);
 }
Пример #10
0
        public override string ExplanationPart(StatRequest req)
        {
            Building_Bed bed = req.Thing as Building_Bed;

            if (req.HasThing && bed != null)
            {
                StringBuilder   stringBuilder = new StringBuilder();
                CompMakeableBed bedComp       = req.Thing.TryGetComp <CompMakeableBed>();
                string          material      = null;
                if (bedComp != null)
                {
                    if (bedComp.Loaded)
                    {
                        ThingDef BedStuff = bedComp.blanketStuff;
                        material = BedStuff.label;
                    }
                    else
                    {
                        material = "NoBeddings".Translate();
                    }
                }
                else if (req.StuffDef != null)
                {
                    material = req.StuffDef.label;
                }
                if (material != null)
                {
                    string number = Addend.ToStringByStyle(parentStat.ToStringStyleUnfinalized, ToStringNumberSense.Absolute);
                    if (additiveStat != null)
                    {
                        stringBuilder.AppendLine("StatsReport_Material".Translate() + " (" + material + "): +" + number);
                    }
                    if (multiplierStat != null)
                    {
                        stringBuilder.AppendLine("StatsReport_StuffEffectMultiplier".Translate() + ": x" + Factor.ToStringPercent("F0"));
                    }
                    return(stringBuilder.ToString().TrimEndNewlines());
                }
            }
            return(null);
        }
Пример #11
0
 public static void Postfix(object __instance, ref string __result)
 {
     if (__instance is Building_Bed bed)
     {
         CompMakeableBed bedComp = bed.TryGetComp <CompMakeableBed>();
         if (bedComp != null)
         {
             StringBuilder stringBuilder = new StringBuilder();
             stringBuilder.AppendLine();
             if (bedComp.Loaded)
             {
                 stringBuilder.AppendLine("BedMade".Translate(bedComp.blanketStuff.LabelCap, bedComp.blanketStuff));
             }
             else
             {
                 stringBuilder.AppendLine("BedNotMade".Translate());
             }
             __result += stringBuilder.ToString().TrimEndNewlines();
         }
     }
 }
Пример #12
0
 public static void Postfix(object __instance, ref Color __result)
 {
     if (__instance is Building_Bed bed)
     {
         CompMakeableBed bedComp = bed.TryGetComp <CompMakeableBed>();
         if (bedComp != null || bed.def.MadeFromStuff) // unmakeable non-stuffed beds aren't affected
         {
             bool forPrisoners         = bed.ForPrisoners;
             bool medical              = bed.Medical;
             bool invertedColorDisplay = (SoftWarmBedsSettings.colorDisplayOption == ColorDisplayOption.Blanket);
             if (!forPrisoners && !medical && !invertedColorDisplay)
             {
                 if (bedComp != null && bedComp.loaded && bedComp.blanketDef == null) // bedding color for beds that are made
                 {
                     __result = bedComp.blanketStuff.stuffProps.color;
                 }
                 else if (bed.def.MadeFromStuff) // stuff color for umade beds & bedrolls
                 {
                     __result = bed.DrawColor;
                 }
             }
         }
     }
 }
Пример #13
0
        public static void Swap(object __instance, Building_Bed bed, StorageSettings settings, CompMakeableBed compMakeable)
        {
            ThingDef bedLoadedBedding = null;
            Thing    bedBedding       = null;

            if (compMakeable != null)
            {
                if (compMakeable.Loaded)
                {
                    bedLoadedBedding = compMakeable.loadedBedding;
                    bedBedding       = compMakeable.bedding;
                }
            }
            //reflection info
            Type       guestBed    = AccessTools.TypeByName("Hospitality.Building_GuestBed");
            MethodInfo makeBedinfo = AccessTools.Method(guestBed, "MakeBed", new[] { typeof(Building_Bed), typeof(string) });
            //
            Building_Bed newBed;
            string       newName;

            if (bed.GetType() == guestBed)
            {
                newName = bed.def.defName.Split(new string[] { "Guest" }, StringSplitOptions.RemoveEmptyEntries)[0];
            }
            else
            {
                newName = bed.def.defName + "Guest";
            }
            // Thanks again to @Zamu for figuring out it was actually very simple!
            newBed = (Building_Bed)makeBedinfo.Invoke(__instance, new object[] { bed, newName });
            newBed.SetFactionDirect(bed.Faction);
            var spawnedBed = (Building_Bed)GenSpawn.Spawn(newBed, bed.Position, bed.Map, bed.Rotation);

            spawnedBed.HitPoints    = bed.HitPoints;
            spawnedBed.ForPrisoners = bed.ForPrisoners;
            var SpawnedCompQuality = spawnedBed.TryGetComp <CompQuality>();

            if (SpawnedCompQuality != null)
            {
                SpawnedCompQuality.SetQuality(bed.GetComp <CompQuality>().Quality, ArtGenerationContext.Outsider);
            }
            var SpawnedCompMakeable = spawnedBed.TryGetComp <CompMakeableBed>();

            if (SpawnedCompMakeable != null)
            {
                SpawnedCompMakeable.settings = settings;
                if (bedLoadedBedding != null)
                {
                    SpawnedCompMakeable.LoadBedding(bedLoadedBedding, bedBedding);
                }
            }
            Find.Selector.Select(spawnedBed, false, true);
        }
Пример #14
0
        public static void Swap(object __instance, Building_Bed bed, StorageSettings settings, CompMakeableBed compMakeable)
        {
            //reflection info
            Type       guestBed    = AccessTools.TypeByName("Hospitality.Building_GuestBed");
            MethodInfo makeBedinfo = AccessTools.Method(guestBed, "MakeBed", new[] { typeof(Building_Bed), typeof(string) });
            //
            Building_Bed newBed;
            string       newName;

            if (bed.GetType() == guestBed)
            {
                newName = bed.def.defName.Split(new string[] { "Guest" }, StringSplitOptions.RemoveEmptyEntries)[0];
            }
            else
            {
                newName = bed.def.defName + "Guest";
            }
            // Thanks again to @Zamu for figuring out it was actually very simple!
            newBed = (Building_Bed)makeBedinfo.Invoke(__instance, new object[] { bed, newName });
            newBed.SetFactionDirect(bed.Faction);
            var spawnedBed = (Building_Bed)GenSpawn.Spawn(newBed, bed.Position, bed.Map, bed.Rotation);

            spawnedBed.HitPoints    = bed.HitPoints;
            spawnedBed.ForPrisoners = bed.ForPrisoners;
            // This should be on Hospitality, Orion!
            spawnedBed.AllComps.Clear();
            spawnedBed.AllComps.AddRange(bed.AllComps);
            foreach (ThingComp comp in spawnedBed.AllComps)
            {
                comp.parent = spawnedBed;
            }
            compMakeable.parent.Notify_ColorChanged();
            Find.Selector.Select(spawnedBed, false, true);
        }