Exemplo n.º 1
0
        public long AddJetty(JettyObject jetty)
        {
            try
            {
                if (jetty == null)
                {
                    return(-2);
                }



                using (var db = new ImportPermitEntities())
                {
                    var jettyEntity = new Jetty
                    {
                        Name   = jetty.Name,
                        PortId = jetty.PortId
                    };
                    var returnStatus = db.Jetties.Add(jettyEntity);
                    db.SaveChanges();
                    return(returnStatus.Id);
                }
            }
            catch (Exception ex)
            {
                ErrorLogger.LoggError(ex.StackTrace, ex.Source, ex.Message);
                return(0);
            }
        }
Exemplo n.º 2
0
        private static bool TryMakeJetty(Map map, TileLayer terrainLayer, TileLayer waterLayer, Point start, Point direction)
        {
            Vector2 jettyPos = Helper.PtoV(start) * map.TileWidth;
            foreach (Jetty otherJ in map.Jetties) if ((otherJ.Position - jettyPos).Length() < 5000) return false;

            Rectangle bounds = new Rectangle();
            Vector2 boatPos = Vector2.Zero;
            float boatRot = 0f;
            if (direction.Y == -1)
            {
                bounds = new Rectangle(start.X - 1, start.Y - 10, 2, 10);
                boatPos = (new Vector2(bounds.Left, bounds.Top) * map.TileWidth) + new Vector2(100, -100);
            }
            if (direction.Y == 1)
            {
                bounds = new Rectangle(start.X - 1, start.Y, 2, 10);
                boatPos = (new Vector2(bounds.Left, bounds.Bottom) * map.TileWidth) + new Vector2(100, 100);

            }
            if (direction.X == -1)
            {
                bounds = new Rectangle(start.X - 10, start.Y - 1, 10, 2);
                boatPos = (new Vector2(bounds.Left, bounds.Top) * map.TileWidth) + new Vector2(-100, 100);
                boatRot = MathHelper.PiOver2;

            }
            if (direction.X == 1)
            {
                bounds = new Rectangle(start.X, start.Y - 1, 10, 2);
                boatPos = (new Vector2(bounds.Right, bounds.Top) * map.TileWidth) + new Vector2(100, 100);
                boatRot = MathHelper.PiOver2;

            }

            for (int xx = bounds.Left; xx < bounds.Right; xx++)
            {
                for (int yy = bounds.Top; yy < bounds.Bottom; yy++)
                {
                    terrainLayer.Tiles[xx, yy] = (direction.Y!=0?map.Tiles[JETTY_H]:map.Tiles[JETTY_V]);
                    waterLayer.Tiles[xx, yy] = null;
                }
            }

            Jetty newJ = new Jetty();
            newJ.Position = jettyPos;
            newJ.Bounds = bounds;
            newJ.BoatPosition = boatPos;
            newJ.BoatRotation = boatRot;
            map.Jetties.Add(newJ);

            return true;
        }