示例#1
0
        public void Place(Point16 mouse, Player player)
        {
            if (Main.LocalPlayer.inventory.Any(x => x.modItem is Items.Wires.HeatPipe))
            {
                int  type = player.inventory.First(x => x.modItem is Items.Wires.HeatPipe).type;
                Item item = player.inventory.First(x => x.type == type);
                item.stack--;
                if (item.stack <= 0)
                {
                    item.TurnToAir();
                }

                HeatPipe heatPipe = new HeatPipe();
                heatPipe.SetDefaults(type);
                heatPipe.position = mouse;
                elements.Add(mouse, heatPipe);

                HeatPipeGrid grid = new HeatPipeGrid();
                grid.tiles.Add(heatPipe);
                heatPipe.grid = grid;

                heatPipe.Merge();
                heatPipe.Frame();

                foreach (Point16 add in TheOneLibrary.Utility.Utility.CheckNeighbours())
                {
                    if (elements.ContainsKey(mouse.X + add.X, mouse.Y + add.Y))
                    {
                        HeatPipe merge = elements[mouse + add];
                        if (merge.type == type)
                        {
                            merge.Frame();
                        }
                    }
                }
            }
        }
示例#2
0
        public void Modify(Point16 mouse)
        {
            HeatPipe heatPipe = elements[mouse];

            int x = (int)Main.MouseWorld.X - mouse.X * 16;
            int y = (int)Main.MouseWorld.Y - mouse.Y * 16;

            Rectangle io = new Rectangle(4, 4, 8, 8);

            if (!io.Contains(x, y))
            {
                if (TheOneLibrary.Utility.Utility.PointInTriangle(new Point(x, y), new Point(0, 0), new Point(8, 8), new Point(0, 16)))
                {
                    heatPipe.connections[TheOneLibrary.Utility.Utility.Facing.Left] = !heatPipe.connections[TheOneLibrary.Utility.Utility.Facing.Left];
                    heatPipe.Frame();

                    Main.NewText(heatPipe.grid.tiles.Count.ToString());
                    if (!heatPipe.connections[TheOneLibrary.Utility.Utility.Facing.Left])
                    {
                        heatPipe.grid.ReformGrid();
                    }

                    if (elements.ContainsKey(mouse.X - 1, mouse.Y))
                    {
                        HeatPipe other = elements[mouse.X - 1, mouse.Y];
                        other.connections[TheOneLibrary.Utility.Utility.Facing.Right] = !other.connections[TheOneLibrary.Utility.Utility.Facing.Right];
                        if (heatPipe.connections[TheOneLibrary.Utility.Utility.Facing.Left])
                        {
                            heatPipe.grid.MergeGrids(other.grid);
                        }
                        other.Frame();
                    }
                }
                else if (TheOneLibrary.Utility.Utility.PointInTriangle(new Point(x, y), new Point(16, 0), new Point(16, 16), new Point(8, 8)))
                {
                    heatPipe.connections[TheOneLibrary.Utility.Utility.Facing.Right] = !heatPipe.connections[TheOneLibrary.Utility.Utility.Facing.Right];
                    heatPipe.Frame();

                    if (!heatPipe.connections[TheOneLibrary.Utility.Utility.Facing.Right])
                    {
                        heatPipe.grid.ReformGrid();
                    }

                    if (elements.ContainsKey(mouse.X + 1, mouse.Y))
                    {
                        HeatPipe other = elements[mouse.X + 1, mouse.Y];
                        other.connections[TheOneLibrary.Utility.Utility.Facing.Left] = !elements[mouse.X + 1, mouse.Y].connections[TheOneLibrary.Utility.Utility.Facing.Left];
                        if (heatPipe.connections[TheOneLibrary.Utility.Utility.Facing.Right])
                        {
                            heatPipe.grid.MergeGrids(elements[mouse.X + 1, mouse.Y].grid);
                        }
                        elements[mouse.X + 1, mouse.Y].Frame();
                    }
                }
                else if (TheOneLibrary.Utility.Utility.PointInTriangle(new Point(x, y), new Point(0, 0), new Point(16, 0), new Point(8, 8)))
                {
                    heatPipe.connections[TheOneLibrary.Utility.Utility.Facing.Up] = !heatPipe.connections[TheOneLibrary.Utility.Utility.Facing.Up];
                    heatPipe.Frame();

                    if (!heatPipe.connections[TheOneLibrary.Utility.Utility.Facing.Up])
                    {
                        heatPipe.grid.ReformGrid();
                    }

                    if (elements.ContainsKey(mouse.X, mouse.Y - 1))
                    {
                        HeatPipe other = elements[mouse.X, mouse.Y - 1];
                        other.connections[TheOneLibrary.Utility.Utility.Facing.Down] = !other.connections[TheOneLibrary.Utility.Utility.Facing.Down];
                        if (heatPipe.connections[TheOneLibrary.Utility.Utility.Facing.Up])
                        {
                            heatPipe.grid.MergeGrids(other.grid);
                        }
                        other.Frame();
                    }
                }
                else if (TheOneLibrary.Utility.Utility.PointInTriangle(new Point(x, y), new Point(0, 16), new Point(8, 8), new Point(16, 16)))
                {
                    heatPipe.connections[TheOneLibrary.Utility.Utility.Facing.Down] = !heatPipe.connections[TheOneLibrary.Utility.Utility.Facing.Down];
                    heatPipe.Frame();

                    if (!heatPipe.connections[TheOneLibrary.Utility.Utility.Facing.Down])
                    {
                        heatPipe.grid.ReformGrid();
                    }

                    if (elements.ContainsKey(mouse.X, mouse.Y + 1))
                    {
                        HeatPipe other = elements[mouse.X, mouse.Y + 1];
                        other.connections[TheOneLibrary.Utility.Utility.Facing.Up] = !other.connections[TheOneLibrary.Utility.Utility.Facing.Up];
                        if (heatPipe.connections[TheOneLibrary.Utility.Utility.Facing.Down])
                        {
                            heatPipe.grid.MergeGrids(other.grid);
                        }
                        other.Frame();
                    }
                }
            }
        }