public static Command_SetStoneType SetStoneToMineCommand(CompRockSpawner passingbuilding)
        {
            return(new Command_SetStoneType()
            {
                hotKey = KeyBindingDefOf.Misc1,

                building = passingbuilding
            });
        }
Beispiel #2
0
        public bool TryDoSpawn()
        {
            if (!this.parent.Spawned)
            {
                return(false);
            }

            IntVec3 center;

            IEnumerable <ThingDef> rocksInThisBiome  = Find.World.NaturalRockTypesIn(this.parent.Map.Tile);
            List <ThingDef>        chunksInThisBiome = new List <ThingDef>();

            foreach (ThingDef rock in rocksInThisBiome)
            {
                chunksInThisBiome.Add(rock.building.mineableThing);
            }
            ThingDef rockToSpawnNow = Find.World.NaturalRockTypesIn(this.parent.Map.Tile).RandomElementWithFallback().building.mineableThing;


            for (int i = 0; i < this.AdjCellsCardinalInBounds.Count; i++)
            {
                IntVec3 c = this.AdjCellsCardinalInBounds[i];
                if (c.InBounds(this.parent.Map))
                {
                    List <Thing> thingList = c.GetThingList(this.parent.Map);
                    for (int j = 0; j < thingList.Count; j++)
                    {
                        if (chunksInThisBiome.Contains(thingList[j].def))
                        {
                            return(false);
                        }
                    }
                }
            }

            if (RockTypeToMine != null)
            {
                rockToSpawnNow = RockTypeToMine;
            }


            if (CompRockSpawner.TryFindSpawnCell(this.parent, rockToSpawnNow, this.PropsSpawner.spawnCount, out center))
            {
                Thing thing = ThingMaker.MakeThing(rockToSpawnNow, null);
                thing.stackCount = this.PropsSpawner.spawnCount;
                if (thing == null)
                {
                    Log.Error("Could not spawn anything for " + this.parent);
                }
                if (this.PropsSpawner.inheritFaction && thing.Faction != this.parent.Faction)
                {
                    thing.SetFaction(this.parent.Faction, null);
                }
                Thing t;
                GenPlace.TryPlaceThing(thing, this.parent.InteractionCell, this.parent.Map, ThingPlaceMode.Direct, out t, null, null, default(Rot4));
                if (this.PropsSpawner.spawnForbidden)
                {
                    t.SetForbidden(true, true);
                }
                if (this.PropsSpawner.showMessageIfOwned && this.parent.Faction == Faction.OfPlayer)
                {
                    Messages.Message("MessageCompSpawnerSpawnedItem".Translate(rockToSpawnNow.LabelCap), thing, MessageTypeDefOf.PositiveEvent, true);
                }
                return(true);
            }
            return(false);
        }