private IEnumerable <Tile> GetTiles() { var tiles = new List <Tile>(); if (!this.GetPin("TileID").IsConnected() || !int.TryParse(this.GetPin("TileID").GetValue(), out var id)) { id = -1; } var area = AreaFactory.Create(this.GetPin("Area").GetValue()); if (!(area is RectArea rectArea)) { return(tiles); } var areaRect = rectArea.GetTileArea().GetRect(); for (var y = 0; y < areaRect.Height; y++) { for (var x = 0; x < areaRect.Width; x++) { var tile = Main.tile[areaRect.X + x, areaRect.Y + y]; if (!tile.active() || (id > -1 && tile.type != id)) { continue; } tiles.Add(tile); } } return(tiles); }
private IEnumerable <Player> GetPlayers() { if (!this.GetPin("Area").IsConnected()) { return(new List <Player>()); } var area = AreaFactory.Create(this.GetPin("Area").GetValue()); if (area == null) { return(new List <Player>()); } var players = Main.player.Select(p => p); if (this.GetPin("TeamColorFilter").IsConnected()) { var team = TeamColor.White; if (int.TryParse(this.GetPin("TeamColorFilter").GetValue(), out var tc)) { team = (TeamColor)tc; } players = players.Where(p => p.team == (int)team); } return(players.Where(p => area.Contains(p.position))); }
private IEnumerable <NPC> GetNPCs() { if (!this.GetPin("Area").IsConnected()) { return(new List <NPC>()); } var area = AreaFactory.Create(this.GetPin("Area").GetValue()); if (area == null) { return(new List <NPC>()); } var npc = Main.npc.Select(n => n).Where(n => !n.dontCountMe); if (this.GetPin("IsHostile").IsConnected() && int.TryParse(this.GetPin("IsHostile").GetValue(), out var hostile)) { npc = npc.Where(n => n.friendly == (hostile == 0)); } if (this.GetPin("IsTownNPC").IsConnected() && int.TryParse(this.GetPin("IsTownNPC").GetValue(), out var townNPC)) { npc = npc.Where(n => n.townNPC == (townNPC == 1)); } return(npc.Where(p => area.Contains(p.position))); }
private Area GetArea() { var area = AreaFactory.Create(this.GetPin("Area").GetValue()); if (!(area is RectArea rectArea)) { return(null); } return(rectArea.GetTileArea()); }
public override void Draw(SpriteBatch spriteBatch) { if (!this.GetPin("Distance").IsConnected()) { return; } var area = AreaFactory.Create(this.Output()); area.Draw(spriteBatch, Color.LightGreen); }
public void Trigger(Pin pin = null) { if (!this.GetPin("Data").IsConnected() || !this.GetPin("Area").IsConnected()) { return; } var area = AreaFactory.Create(this.GetPin("Area").GetValue()); if (!(area is RectArea rectArea)) { return; } var data = this.GetPin("Data").GetValue().Split(';'); var srcTiles = data.Select(d => new TileInfo(d)).ToList(); var srcRect = new Rectangle(srcTiles.Min(t => t.X), srcTiles.Min(t => t.Y), (srcTiles.Max(t => t.X) - srcTiles.Min(t => t.X)) + 1, (srcTiles.Max(t => t.Y) - srcTiles.Min(t => t.Y)) + 1); var destRect = rectArea.GetTileArea().GetRect(); for (var y = 0; y < Math.Min(srcRect.Height, destRect.Height); y++) { for (var x = 0; x < Math.Min(srcRect.Width, destRect.Width); x++) { var srcTile = Main.tile[srcRect.X + x, srcRect.Y + y]; var destTile = Main.tile[destRect.X + x, destRect.Y + y]; if (Constants.CopyTileBlacklist.Contains(srcTile.type)) { continue; } var(wire, wire2, wire3, wire4) = (destTile.wire(), destTile.wire2(), destTile.wire3(), destTile.wire4()); destTile.CopyFrom(srcTile); // Preserve tile wires destTile.wire(wire); destTile.wire2(wire2); destTile.wire3(wire3); destTile.wire4(wire4); WorldGen.SquareTileFrame(destRect.X + x, destRect.Y + y); if (Main.netMode == NetmodeID.Server) { NetMessage.SendTileSquare(-1, destRect.X + x, destRect.Y + y, 1); } } } }
private int GetOutput() { if (!this.GetPin("Area").IsConnected()) { return(-1); } var area = AreaFactory.Create(this.GetPin("Area").GetValue()); if (!(area is RectArea)) { return(-2); } if (this.GetPin("TileID").IsConnected() && !int.TryParse(this.GetPin("TileID").GetValue(), out var _)) { return(-2); } return(this.GetTiles().Count()); }
public override void Update(GameTime gameTime) { if (!this.GetPin("Copy").IsConnected() || this.GetPin("Copy").GetValue() != "1") { return; } if (!this.GetPin("Area").IsConnected()) { this.Settings["Value"] = ""; return; } var area = AreaFactory.Create(this.GetPin("Area").GetValue()); if (!(area is RectArea)) { return; } this.Settings["Value"] = string.Join(";", this.GetTiles().Select(t => t.ToString())); }
private IEnumerable <TileInfo> GetTiles() { var tiles = new List <TileInfo>(); var area = AreaFactory.Create(this.GetPin("Area").GetValue()); if (!(area is RectArea rectArea)) { return(tiles); } var areaRect = rectArea.GetTileArea().GetRect(); for (var y = areaRect.Y; y < areaRect.Y + areaRect.Height; y++) { for (var x = areaRect.X; x < areaRect.X + areaRect.Width; x++) { tiles.Add(new TileInfo(x, y)); } } return(tiles); }