static bool Prefix(ref bool __result, Verse.Thing item) { if (item != null) { if (item.GetType() == typeof(Pawn)) { Pawn p = (Pawn)item; //搬运的是人形 bool hasBondageBed = false; //没有被束缚床束缚 for (int i = 0; i < p.health.hediffSet.hediffs.Count; i++) { if (p.health.hediffSet.hediffs[i].def == SR.DA.Hediff.HediffDefOf.SR_Hediff_BondageBed) { hasBondageBed = true; break; } } //如果已经被束缚 if (hasBondageBed) { Building_Bed bbb = (Building_BondageBed)p.CurrentBed();//获取当前躺着的束缚床 if (bbb != null) { CompRemoveEffectBondageBed crebb = bbb.GetComp <CompRemoveEffectBondageBed>(); if (crebb != null) { crebb.DoEffect(p);//解除束缚 } } } } } return(true); }
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); }
public static void Swap(Building_Bed bed) { Building_Bed newBed; if (bed is Building_GuestBed) { newBed = (Building_Bed)MakeBed(bed, bed.def.defName.Split(new[] { "Guest" }, StringSplitOptions.RemoveEmptyEntries)[0]); } else { newBed = (Building_GuestBed)MakeBed(bed, bed.def.defName + "Guest"); } 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 compQuality = spawnedBed.TryGetComp <CompQuality>(); if (compQuality != null) { compQuality.SetQuality(bed.GetComp <CompQuality>().Quality, ArtGenerationContext.Outsider); } //var compArt = bed.TryGetComp<CompArt>(); //if (compArt != null) //{ // var art = spawnedBed.GetComp<CompArt>(); // Traverse.Create(art).Field("authorNameInt").SetValue(Traverse.Create(compArt).Field("authorNameInt").GetValue()); // Traverse.Create(art).Field("titleInt").SetValue(Traverse.Create(compArt).Field("titleInt").GetValue()); // Traverse.Create(art).Field("taleRef").SetValue(Traverse.Create(compArt).Field("taleRef").GetValue()); // // // TODO: Make this work, art is now destroyed //} Find.Selector.Select(spawnedBed, false); }
private static IEnumerable <Gizmo> Process(Building_Bed __instance, IEnumerable <Gizmo> __result) { var isPrisonCell = __instance.GetRoom()?.isPrisonCell == true; if (!__instance.ForPrisoners && !__instance.Medical && __instance.def.building.bed_humanlike && !isPrisonCell) { yield return (new Command_Toggle { defaultLabel = "CommandBedSetAsGuestLabel".Translate(), defaultDesc = "CommandBedSetAsGuestDesc".Translate(), icon = ContentFinder <Texture2D> .Get("UI/Commands/AsGuest"), isActive = __instance.IsGuestBed, toggleAction = () => Building_GuestBed.Swap(__instance), hotKey = KeyBindingDefOf.Misc4, disabled = __instance.GetComp <CompAssignableToPawn_Bed>() == null, disabledReason = "This bed type is not assignable to pawns." }); } foreach (var gizmo in __result) { yield return(gizmo); } }