Ejemplo n.º 1
0
        public override void NetReceive(BinaryReader reader, bool lightReceive)
        {
            //PathOfModifiers.Instance.Logger.Info($"NetReceive: {Main.netMode}");
            var newTimeLeft = reader.ReadInt32();

            bool isBoundsNull = reader.ReadBoolean();
            var  newBounds    = isBoundsNull ? null : (Rectangle?)reader.ReadRectangle();

            mapItem = ItemIO.Receive(reader, true);

            if (timeLeft == 0 && newTimeLeft != 0)
            {
                MapBorder.AddActiveBounds(newBounds.Value);
            }
            else if (timeLeft != 0 && newTimeLeft == 0)
            {
                MapBorder.RemoveActiveBounds(bounds.Value);
            }

            timeLeft = newTimeLeft;
            bounds   = newBounds;

            if (Main.netMode == NetmodeID.MultiplayerClient)
            {
                if (MapDevice.activeMD?.Position == Position)
                {
                    MapDeviceUI.ShowUI(this);
                }
            }
        }
Ejemplo n.º 2
0
        public override void Load(TagCompound tag)
        {
            //PathOfModifiers.Log($"Load{Main.netMode}");

            timeLeft = tag.GetInt("timeLeft");
            bool isBoundsNull = tag.GetBool("isBoundsNull");

            bounds = isBoundsNull ? null : (Rectangle?)tag.Get <Rectangle>("bounds");
            if (timeLeft > 0 && bounds.HasValue)
            {
                MapBorder.AddActiveBounds(bounds.Value);
            }

            mapItem = ItemIO.Load(tag.GetCompound("map"));

            if (Main.netMode != 2)
            {
                MapDeviceUI.Instance.UpdateText();
            }
        }
Ejemplo n.º 3
0
        //Should never run on a client.
        public void CloseMap()
        {
            //PathOfModifiers.Instance.Logger.Info($"CloseMap: {Main.netMode}");
            if (!CanClose())
            {
                return;
            }

            timeLeft = 0;

            Items.Map mapModItem = ((Items.Map)mapItem.modItem);
            Rectangle dimensions = new Rectangle(bounds.Value.X + 1, bounds.Value.Y + 1, bounds.Value.Width - 2, bounds.Value.Height - 2);

            var map = mapModItem.map;

            map.Close();

            MapBorder.RemoveActiveBounds(bounds.Value);

            SendToClients();
        }
Ejemplo n.º 4
0
        //Should never run on a client.
        public void OpenMap()
        {
            //PathOfModifiers.Instance.Logger.Info($"OpenMap: {Main.netMode}");
            if (!CanOpen())
            {
                return;
            }

            //TODO: Set timeLeft somewhere else(map settings/config)
            timeLeft = 10 * 60 * 60;

            Items.Map mapModItem = ((Items.Map)mapItem.modItem);
            Rectangle dimensions = new Rectangle(bounds.Value.X + 1, bounds.Value.Y + 1, bounds.Value.Width - 2, bounds.Value.Height - 2);

            var map = mapModItem.map;

            map.Open(dimensions);

            MapBorder.AddActiveBounds(bounds.Value);

            SendToClients();
        }
Ejemplo n.º 5
0
        bool DetectBounds()
        {
            List <Rectangle> boundss = new List <Rectangle>();
            List <Tuple <Point, bool, bool> > adjacentTiles = new List <Tuple <Point, bool, bool> >();
            Point size           = new Point(4, 4);
            int   length         = size.X * 2 + size.Y * 2 + 4;
            int   x              = 0;
            int   y              = 0;
            bool  lastTileOfType = false;

            for (int i = 0; i < length; i++)
            {
                bool scanHoriz = true;
                bool scanVert  = true;
                if (i == 0)
                {
                }
                else if (i > 0 && i < size.X + 2)
                {
                    x++;
                    scanHoriz = !lastTileOfType;
                }
                else if (i < size.X + 2 + size.Y + 1)
                {
                    y++;
                    scanVert = !lastTileOfType;
                }
                else if (i < size.X + 2 + size.Y + 1 + size.X + 1)
                {
                    x--;
                    scanHoriz = !lastTileOfType;
                }
                else
                {
                    y--;
                    scanVert = !lastTileOfType;
                }

                Point tilePos  = new Point(Position.X - 1 + x, Position.Y - 1 + y);
                Tile  tile     = Main.tile[tilePos.X, tilePos.Y];
                int?  tileType = PoMUtil.GetTileType(tile);
                if (tileType.HasValue && tileType == ModContent.TileType <MapBorder>())
                {
                    adjacentTiles.Add(new Tuple <Point, bool, bool>(tilePos, scanHoriz, scanVert));
                    lastTileOfType = true;
                }
                else
                {
                    lastTileOfType = false;
                }
            }

            foreach (var tilePos in adjacentTiles)
            {
                PoMUtil.FindAdjacentBounds(tilePos.Item1, boundss, tilePos.Item2, tilePos.Item3);
            }

            Rectangle tileBounds         = new Rectangle(Position.X, Position.Y, size.X - 1, size.Y - 1);
            Rectangle tileBoundsInflated = tileBounds;

            tileBoundsInflated.Inflate(2, 2);
            for (int i = boundss.Count - 1; i >= 0; i--)
            {
                Rectangle bound      = boundss[i];
                bool      intersecnt = tileBoundsInflated.X < bound.X + bound.Width && bound.X < tileBoundsInflated.X + tileBoundsInflated.Width && tileBoundsInflated.Y < bound.Y + bound.Height && bound.Y < tileBoundsInflated.Y + tileBoundsInflated.Height;
                if (!bound.Intersects(tileBoundsInflated) || bound.Contains(tileBounds) || MapBorder.InteresectsOrContainsActiveBounds(bound))
                {
                    boundss.RemoveAt(i);
                }
            }

            if (boundss.Count > 0)
            {
                bounds = boundss.Aggregate((b1, b2) => b1.Width * b1.Height > b2.Width * b2.Height ? b1 : b2);

                return(true);
            }
            else
            {
                bounds = null;
                return(false);
            }
        }