/// <summary> /// Converts a <c>Verse.Thing</c> into a <c>Trading.Thing</c>. /// Used for preparing a <c>Verse.Thing</c> for transport. /// </summary> /// <param name="verseThing">Thing to convert</param> /// <returns>Converted thing</returns> public static Trading.ProtoThing ConvertThingFromVerse(Verse.Thing verseThing) { // Try get the quality of the thing, failure defaulting to none Quality quality = verseThing.TryGetQuality(out QualityCategory gottenQuality) ? (Quality)gottenQuality : Quality.None; // Create a Trading.Thing with attributes from verseThing Trading.ProtoThing protoThing = new Trading.ProtoThing { DefName = verseThing.def.defName, StackCount = verseThing.stackCount, HitPoints = verseThing.HitPoints, Quality = quality }; // Check if verseThing has stuff if (verseThing.Stuff?.defName != null) { // Set protoThing's stuff def protoThing.StuffDefName = verseThing.Stuff.defName; } // Check if verseThing is minified if (verseThing is MinifiedThing minifiedVerseThing) { // Set protoThing's inner thing protoThing.InnerProtoThing = ConvertThingFromVerse(minifiedVerseThing.InnerThing); } // Return constructed protoThing return(protoThing); }
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); }
/// <summary> /// Converts a <c>Trading.Thing</c> into a <c>Verse.Thing</c>. /// Used for unloading a <c>Trading.Thing</c> after transport. /// </summary> /// <param name="protoThing">Thing to convert</param> /// <returns>Converted thing</returns> /// <exception cref="InvalidOperationException">Could not find a single def that matches Trading.Thing def name</exception> /// <exception cref="InvalidOperationException">Could not find a single def that matches Trading.Thing stuff def name</exception> public static Verse.Thing ConvertThingFromProto(Trading.ProtoThing protoThing) { // Try to get the ThingDef for protoThing ThingDef thingDef; try { thingDef = DefDatabase <ThingDef> .AllDefs.Single(def => def.defName == protoThing.DefName); } catch (InvalidOperationException e) { throw new InvalidOperationException(string.Format("Could not find a single def that matches def name '{0}'", protoThing.DefName), e); } // Try to get the ThingDef for stuff inside protoThing ThingDef stuffDef = null; try { // Check if we actually have stuff inside the thing if (!string.IsNullOrEmpty(protoThing.StuffDefName)) { stuffDef = DefDatabase <ThingDef> .AllDefs.Single(def => def.defName == protoThing.StuffDefName); } } catch (InvalidOperationException e) { throw new InvalidOperationException(string.Format("Could not find a single def that matches stuff def name '{0}'", protoThing.StuffDefName), e); } // Make our base verseThing and give it protoThing's stack count and hit points Verse.Thing verseThing = ThingMaker.MakeThing(thingDef, stuffDef); verseThing.stackCount = protoThing.StackCount; verseThing.HitPoints = protoThing.HitPoints; // Check if verseThing should have its quality set if (protoThing.Quality != Quality.None) { // Set verseThing's quality if it is capable of having a quality // Art generation should be that of an outsider given that this is a traded item verseThing.TryGetComp <CompQuality>()?.SetQuality((QualityCategory)protoThing.Quality, ArtGenerationContext.Outsider); } // Check if verseThing is minified if (verseThing is MinifiedThing minifiedVerseThing) { // Set verseThing's inner thing to protoThing's inner thing minifiedVerseThing.InnerThing = protoThing.InnerProtoThing != null?ConvertThingFromProto(protoThing.InnerProtoThing) : null; } // Return the constructed Verse.Thing return(verseThing); }
static bool Prefix(ref bool __result, Verse.Thing bedThing, Pawn sleeper, Pawn traveler, bool sleeperWillBePrisoner, bool checkSocialProperness, bool allowMedBedEvenIfSetToNoCare = false, bool ignoreOtherReservations = false) { //如果目标床是束缚床则本次查找失败 if (bedThing is Building_BondageBed) { __result = false; return(false); } else { return(true); } }
public TargetInfo(Thing thing) { this.thingInt = thing; this.cellInt = IntVec3.Invalid; this.mapInt = null; }
public LocalTargetInfo(IntVec3 cell) { this.thingInt = null; this.cellInt = cell; }
public static bool TryFindRandomAdjacentCell8WayWithRoomGroup(Thing t, out IntVec3 result) { return(GenAdj.TryFindRandomAdjacentCell8WayWithRoomGroup(t.Position, t.Rotation, t.def.size, t.Map, out result)); }
public static void DrawThingLabel(Thing thing, string text, Color textColor) { DrawThingLabel(LabelDrawPosFor(thing, -0.4f), text, textColor); }
public LocalTargetInfo(Thing thing) { this.thingInt = thing; this.cellInt = IntVec3.Invalid; }
public static void Look <T>(ref T target, bool saveDestroyedThings, string label, params object[] ctorArgs) { if (Scribe.mode == LoadSaveMode.Saving) { Thing thing = target as Thing; if (thing != null && thing.Destroyed) { if (!saveDestroyedThings) { Log.Warning(string.Concat(new object[] { "Deep-saving destroyed thing ", thing, " with saveDestroyedThings==false. label=", label })); } else if (thing.Discarded) { Log.Warning(string.Concat(new object[] { "Deep-saving discarded thing ", thing, ". This mode means that the thing is no longer managed by anything in the code and should not be deep-saved anywhere. (even with saveDestroyedThings==true) , label=", label })); } } IExposable exposable = target as IExposable; if (target != null && exposable == null) { Log.Error(string.Concat(new object[] { "Cannot use LookDeep to save non-IExposable non-null ", label, " of type ", typeof(T) })); return; } if (target == null) { if (Scribe.EnterNode(label)) { try { Scribe.saver.WriteAttribute("IsNull", "True"); } finally { Scribe.ExitNode(); } } } else if (Scribe.EnterNode(label)) { try { if (target.GetType() != typeof(T) || typeof(T).IsGenericTypeDefinition) { Scribe.saver.WriteAttribute("Class", GenTypes.GetTypeNameWithoutIgnoredNamespaces(target.GetType())); } exposable.ExposeData(); } catch (Exception ex) { Log.Error(string.Concat(new object[] { "Exception while saving ", exposable.ToStringSafe <IExposable>(), ": ", ex })); } finally { Scribe.ExitNode(); } } Scribe.saver.loadIDsErrorsChecker.RegisterDeepSaved(target, label); } else if (Scribe.mode == LoadSaveMode.LoadingVars) { try { target = ScribeExtractor.SaveableFromNode <T>(Scribe.loader.curXmlParent[label], ctorArgs); } catch (Exception ex2) { Log.Error(string.Concat(new object[] { "Exception while loading ", Scribe.loader.curXmlParent[label].ToStringSafe <XmlElement>(), ": ", ex2 })); target = default(T); } } }
public static void DrawThingLabel(Thing thing, string text) { DrawThingLabel(thing, text, DefaultThingLabelColor); }
public static bool IsAdjacentToCardinalOrInside(this Thing t1, Thing t2) { return(GenAdj.IsAdjacentToCardinalOrInside(t1.OccupiedRect(), t2.OccupiedRect())); }
public static IEnumerable <IntVec3> CellsAdjacentCardinal(Thing t) { return(GenAdj.CellsAdjacentCardinal(t.Position, t.Rotation, t.def.size)); }
public override void Regenerate() { Building[] innerArray = base.Map.edificeGrid.InnerArray; float y = AltitudeLayer.Shadows.AltitudeFor(); CellRect cellRect = new CellRect(section.botLeft.x, section.botLeft.z, 17, 17); cellRect.ClipInsideMap(base.Map); LayerSubMesh sm = GetSubMesh(MatBases.EdgeShadow); sm.Clear(MeshParts.All); sm.verts.Capacity = cellRect.Area * 4; sm.colors.Capacity = cellRect.Area * 4; sm.tris.Capacity = cellRect.Area * 8; bool[] array = new bool[4]; bool[] array2 = new bool[4]; bool[] array3 = new bool[4]; float num = 0f; float num2 = 0f; CellIndices cellIndices = base.Map.cellIndices; for (int i = cellRect.minX; i <= cellRect.maxX; i++) { for (int j = cellRect.minZ; j <= cellRect.maxZ; j++) { Thing thing = innerArray[cellIndices.CellToIndex(i, j)]; if (thing != null && thing.def.castEdgeShadows) { sm.verts.Add(new Vector3((float)i, y, (float)j)); sm.verts.Add(new Vector3((float)i, y, (float)(j + 1))); sm.verts.Add(new Vector3((float)(i + 1), y, (float)(j + 1))); sm.verts.Add(new Vector3((float)(i + 1), y, (float)j)); sm.colors.Add(Shadowed); sm.colors.Add(Shadowed); sm.colors.Add(Shadowed); sm.colors.Add(Shadowed); int count = sm.verts.Count; sm.tris.Add(count - 4); sm.tris.Add(count - 3); sm.tris.Add(count - 2); sm.tris.Add(count - 4); sm.tris.Add(count - 2); sm.tris.Add(count - 1); } else { array[0] = false; array[1] = false; array[2] = false; array[3] = false; array2[0] = false; array2[1] = false; array2[2] = false; array2[3] = false; array3[0] = false; array3[1] = false; array3[2] = false; array3[3] = false; IntVec3 a = new IntVec3(i, 0, j); IntVec3[] cardinalDirectionsAround = GenAdj.CardinalDirectionsAround; for (int k = 0; k < 4; k++) { IntVec3 c = a + cardinalDirectionsAround[k]; if (c.InBounds(base.Map)) { thing = innerArray[cellIndices.CellToIndex(c)]; if (thing != null && thing.def.castEdgeShadows) { array2[k] = true; array[(k + 3) % 4] = true; array[k] = true; } } } IntVec3[] diagonalDirectionsAround = GenAdj.DiagonalDirectionsAround; for (int l = 0; l < 4; l++) { if (!array[l]) { IntVec3 c = a + diagonalDirectionsAround[l]; if (c.InBounds(base.Map)) { thing = innerArray[cellIndices.CellToIndex(c)]; if (thing != null && thing.def.castEdgeShadows) { array[l] = true; array3[l] = true; } } } } Action <int> action = delegate(int idx) { sm.tris.Add(sm.verts.Count - 2); sm.tris.Add(idx); sm.tris.Add(sm.verts.Count - 1); sm.tris.Add(sm.verts.Count - 1); sm.tris.Add(idx); sm.tris.Add(idx + 1); }; Action action2 = delegate { sm.colors.Add(Shadowed); sm.colors.Add(Lit); sm.colors.Add(Lit); sm.tris.Add(sm.verts.Count - 3); sm.tris.Add(sm.verts.Count - 2); sm.tris.Add(sm.verts.Count - 1); }; int count2 = sm.verts.Count; if (array[0]) { if (array2[0] || array2[1]) { num = (num2 = 0f); if (array2[0]) { num2 = 0.45f; } if (array2[1]) { num = 0.45f; } sm.verts.Add(new Vector3((float)i, y, (float)j)); sm.colors.Add(Shadowed); sm.verts.Add(new Vector3((float)i + num, y, (float)j + num2)); sm.colors.Add(Lit); if (array[1] && !array3[1]) { action(sm.verts.Count); } } else { sm.verts.Add(new Vector3((float)i, y, (float)j)); sm.verts.Add(new Vector3((float)i, y, (float)j + 0.45f)); sm.verts.Add(new Vector3((float)i + 0.45f, y, (float)j)); action2(); } } if (array[1]) { if (array2[1] || array2[2]) { num = (num2 = 0f); if (array2[1]) { num = 0.45f; } if (array2[2]) { num2 = -0.45f; } sm.verts.Add(new Vector3((float)i, y, (float)(j + 1))); sm.colors.Add(Shadowed); sm.verts.Add(new Vector3((float)i + num, y, (float)(j + 1) + num2)); sm.colors.Add(Lit); if (array[2] && !array3[2]) { action(sm.verts.Count); } } else { sm.verts.Add(new Vector3((float)i, y, (float)(j + 1))); sm.verts.Add(new Vector3((float)i + 0.45f, y, (float)(j + 1))); sm.verts.Add(new Vector3((float)i, y, (float)(j + 1) - 0.45f)); action2(); } } if (array[2]) { if (array2[2] || array2[3]) { num = (num2 = 0f); if (array2[2]) { num2 = -0.45f; } if (array2[3]) { num = -0.45f; } sm.verts.Add(new Vector3((float)(i + 1), y, (float)(j + 1))); sm.colors.Add(Shadowed); sm.verts.Add(new Vector3((float)(i + 1) + num, y, (float)(j + 1) + num2)); sm.colors.Add(Lit); if (array[3] && !array3[3]) { action(sm.verts.Count); } } else { sm.verts.Add(new Vector3((float)(i + 1), y, (float)(j + 1))); sm.verts.Add(new Vector3((float)(i + 1), y, (float)(j + 1) - 0.45f)); sm.verts.Add(new Vector3((float)(i + 1) - 0.45f, y, (float)(j + 1))); action2(); } } if (array[3]) { if (array2[3] || array2[0]) { num = (num2 = 0f); if (array2[3]) { num = -0.45f; } if (array2[0]) { num2 = 0.45f; } sm.verts.Add(new Vector3((float)(i + 1), y, (float)j)); sm.colors.Add(Shadowed); sm.verts.Add(new Vector3((float)(i + 1) + num, y, (float)j + num2)); sm.colors.Add(Lit); if (array[0] && !array3[0]) { action(count2); } } else { sm.verts.Add(new Vector3((float)(i + 1), y, (float)j)); sm.verts.Add(new Vector3((float)(i + 1) - 0.45f, y, (float)j)); sm.verts.Add(new Vector3((float)(i + 1), y, (float)j + 0.45f)); action2(); } } } } } if (sm.verts.Count > 0) { sm.FinalizeMesh(MeshParts.Verts | MeshParts.Tris | MeshParts.Colors); } }
public static CellRect OccupiedRect(this Thing t) { return(GenAdj.OccupiedRect(t.Position, t.Rotation, t.def.size)); }
public static bool IsInside(this IntVec3 root, Thing t) { return(GenAdj.IsInside(root, t.Position, t.Rotation, t.def.size)); }
public static bool AdjacentTo8WayOrInside(this Thing a, Thing b) { return(GenAdj.AdjacentTo8WayOrInside(a.OccupiedRect(), b.OccupiedRect())); }
public static bool AdjacentTo8WayOrInside(this IntVec3 root, Thing t) { return(root.AdjacentTo8WayOrInside(t.Position, t.Rotation, t.def.size)); }
public virtual bool IsUsableOn(Thing target) { return(true); }
public static GlobalTargetInfo GetAdjustedTarget(GlobalTargetInfo target) { if (target.HasThing) { Thing thing = target.Thing; if (thing.Spawned) { return(thing); } GlobalTargetInfo result = GlobalTargetInfo.Invalid; for (IThingHolder parentHolder = thing.ParentHolder; parentHolder != null; parentHolder = parentHolder.ParentHolder) { Thing thing2 = parentHolder as Thing; if (thing2 != null && thing2.Spawned) { result = thing2; break; } ThingComp thingComp = parentHolder as ThingComp; if (thingComp != null && thingComp.parent.Spawned) { result = thingComp.parent; break; } WorldObject worldObject = parentHolder as WorldObject; if (worldObject != null && worldObject.Spawned) { result = worldObject; break; } } if (result.IsValid) { return(result); } if (target.Thing.TryGetComp <CompCauseGameCondition>() != null) { List <Site> sites = Find.WorldObjects.Sites; for (int i = 0; i < sites.Count; i++) { for (int j = 0; j < sites[i].parts.Count; j++) { if (sites[i].parts[j].conditionCauser == target.Thing) { return(sites[i]); } } } } if (thing.Tile >= 0) { return(new GlobalTargetInfo(thing.Tile)); } } else if (target.Cell.IsValid && target.Tile >= 0 && target.Map != null && !Find.Maps.Contains(target.Map)) { MapParent parent = target.Map.Parent; if (parent != null && parent.Spawned) { return(parent); } return(GlobalTargetInfo.Invalid); } return(target); }