コード例 #1
0
        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);
        }
コード例 #2
0
        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)));
        }
コード例 #3
0
        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)));
        }
コード例 #4
0
        private Area GetArea()
        {
            var area = AreaFactory.Create(this.GetPin("Area").GetValue());

            if (!(area is RectArea rectArea))
            {
                return(null);
            }

            return(rectArea.GetTileArea());
        }
コード例 #5
0
ファイル: AreaInput.cs プロジェクト: NateMcCloud/WireMod
        public override void Draw(SpriteBatch spriteBatch)
        {
            if (!this.GetPin("Distance").IsConnected())
            {
                return;
            }

            var area = AreaFactory.Create(this.Output());

            area.Draw(spriteBatch, Color.LightGreen);
        }
コード例 #6
0
ファイル: TilePaster.cs プロジェクト: NateMcCloud/WireMod
        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);
                    }
                }
            }
        }
コード例 #7
0
        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());
        }
コード例 #8
0
ファイル: TileCopier.cs プロジェクト: NateMcCloud/WireMod
        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()));
        }
コード例 #9
0
ファイル: TileCopier.cs プロジェクト: NateMcCloud/WireMod
        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);
        }