public static RoomInfo New <T>(float chance, Func <bool> callback, params string[] biomes) where T : RoomDef { return(new RoomInfo { Chance = chance, CanAppear = callback, Type = RoomDef.DecideType(null, typeof(T)), Room = typeof(T), Biomes = biomes }); }
public bool ConnectWithRoom(RoomDef roomDef) { if ((Neighbours.Contains(roomDef) || ConnectTo(roomDef)) && !Connected.ContainsKey(roomDef) && CanConnect(roomDef)) { Connected[roomDef] = null; roomDef.Connected[this] = null; return(true); } return(false); }
public virtual bool CanConnect(RoomDef r) { var I = Intersect(r); var FoundPoint = false; foreach (var P in I.GetPoints()) { if (CanConnect(r, P) && r.CanConnect(r, P)) { FoundPoint = true; break; } } if (!FoundPoint) { return(false); } if (I.GetWidth() == 0 && I.Left == Left) { return(CanConnect(Connection.Left) && r.CanConnect(Connection.Left)); } if (I.GetHeight() == 0 && I.Top == Top) { return(CanConnect(Connection.Top) && r.CanConnect(Connection.Top)); } if (I.GetWidth() == 0 && I.Right == Right) { return(CanConnect(Connection.Right) && r.CanConnect(Connection.Right)); } if (I.GetHeight() == 0 && I.Bottom == Bottom) { return(CanConnect(Connection.Bottom) && r.CanConnect(Connection.Bottom)); } return(false); }
public bool ConnectTo(RoomDef Other) { if (Neighbours.Contains(Other)) { return(true); } var I = Intersect(Other); var W = I.GetWidth(); var H = I.GetHeight(); if ((W == 0 && H >= 2) || (H == 0 && W >= 2)) { Neighbours.Add(Other); Other.Neighbours.Add(this); return(true); } return(false); }
public static RoomType DecideType(RoomDef r, Type room) { if (typeof(TrapRoom).IsAssignableFrom(room)) { return(RoomType.Trap); } if (typeof(SubShopRoom).IsAssignableFrom(room)) { return(RoomType.SubShop); } if (typeof(DarkMarketRoom).IsAssignableFrom(room)) { return(RoomType.DarkMarket); } if (typeof(PayedRoom).IsAssignableFrom(room)) { return(RoomType.Payed); } if (typeof(ScourgedRoom).IsAssignableFrom(room)) { return(RoomType.Scourged); } if (typeof(ChallengeRoom).IsAssignableFrom(room)) { return(RoomType.Challenge); } if (typeof(SpikedRoom).IsAssignableFrom(room)) { return(RoomType.Spiked); } if (typeof(BossRoom).IsAssignableFrom(room)) { return(RoomType.Boss); } if (typeof(GrannyRoom).IsAssignableFrom(room)) { return(RoomType.Granny); } if (typeof(OldManRoom).IsAssignableFrom(room)) { return(RoomType.OldMan); } if (typeof(EntranceRoom).IsAssignableFrom(room)) { return(RoomType.Entrance); } if (typeof(ExitRoom).IsAssignableFrom(room)) { return(RoomType.Exit); } if (typeof(SecretRoom).IsAssignableFrom(room)) { return(RoomType.Secret); } if (typeof(TreasureRoom).IsAssignableFrom(room)) { return(RoomType.Treasure); } if (typeof(ShopRoom).IsAssignableFrom(room)) { return(RoomType.Shop); } if (typeof(SpecialRoom).IsAssignableFrom(room)) { return(RoomType.Special); } if (typeof(ConnectionRoom).IsAssignableFrom(room)) { return(RoomType.Connection); } return(RoomType.Regular); }
public void PaintTunnel(Level Level, Tile Floor, Rect space = null, bool Bold = false, bool shift = true, bool randomRect = true, RoomDef defTo = null, DoorPlaceholder to = null) { if (Connected.Count == 0) { Log.Error("Invalid connection room"); return; } var C = space ?? GetConnectionSpace(); var minLeft = C.Left; var maxRight = C.Right; var minTop = C.Top; var maxBottom = C.Bottom; var doors = to == null ? Connected : new Dictionary <RoomDef, DoorPlaceholder>() { { defTo, to } }; foreach (var pair in doors) { if (pair.Key is GrannyRoom || pair.Key is OldManRoom) { continue; } var Door = pair.Value; var Start = new Dot(Door.X, Door.Y); Dot Mid; Dot End; if (shift) { if ((int)Start.X == Left) { Start.X++; } else if ((int)Start.Y == Top) { Start.Y++; } else if ((int)Start.X == Right) { Start.X--; } else if ((int)Start.Y == Bottom) { Start.Y--; } } int RightShift; int DownShift; if (Start.X < C.Left) { RightShift = (int)(C.Left - Start.X); } else if (Start.X > C.Right) { RightShift = (int)(C.Right - Start.X); } else { RightShift = 0; } if (Start.Y < C.Top) { DownShift = (int)(C.Top - Start.Y); } else if (Start.Y > C.Bottom) { DownShift = (int)(C.Bottom - Start.Y); } else { DownShift = 0; } if (Door.X == Left || Door.X == Right) { Mid = new Dot(MathUtils.Clamp(Left + 1, Right - 1, Start.X + RightShift), MathUtils.Clamp(Top + 1, Bottom - 1, Start.Y)); End = new Dot(MathUtils.Clamp(Left + 1, Right - 1, Mid.X), MathUtils.Clamp(Top + 1, Bottom - 1, Mid.Y + DownShift)); } else { Mid = new Dot(MathUtils.Clamp(Left + 1, Right - 1, Start.X), MathUtils.Clamp(Top + 1, Bottom - 1, Start.Y + DownShift)); End = new Dot(MathUtils.Clamp(Left + 1, Right - 1, Mid.X + RightShift), MathUtils.Clamp(Top + 1, Bottom - 1, Mid.Y)); } Painter.DrawLine(Level, Start, Mid, Floor, Bold); Painter.DrawLine(Level, Mid, End, Floor, Bold); if (Rnd.Chance(10)) { Painter.Set(Level, End, Tiles.RandomFloor()); } minLeft = Math.Min(minLeft, End.X); minTop = Math.Min(minTop, End.Y); maxRight = Math.Max(maxRight, End.X); maxBottom = Math.Max(maxBottom, End.Y); } if (randomRect && Rnd.Chance(20)) { if (Rnd.Chance()) { minLeft--; } if (Rnd.Chance()) { minTop--; } if (Rnd.Chance()) { maxRight++; } if (Rnd.Chance()) { maxBottom++; } } minLeft = MathUtils.Clamp(Left + 1, Right - 1, minLeft); minTop = MathUtils.Clamp(Top + 1, Bottom - 1, minTop); maxRight = MathUtils.Clamp(Left + 1, Right - 1, maxRight); maxBottom = MathUtils.Clamp(Top + 1, Bottom - 1, maxBottom); if (Rnd.Chance()) { Painter.Fill(Level, minLeft, minTop, maxRight - minLeft + 1, maxBottom - minTop + 1, Rnd.Chance() ? Floor : Tiles.RandomFloorOrSpike()); } else { Painter.Rect(Level, minLeft, minTop, maxRight - minLeft + 1, maxBottom - minTop + 1, Rnd.Chance() ? Floor : Tiles.RandomFloorOrSpike()); } }
public virtual bool CanConnect(RoomDef r, Dot p) { return(((int)p.X == Left || (int)p.X == Right) != ((int)p.Y == Top || (int)p.Y == Bottom)); }