/// <summary>
        /// Добавить новый объект на карту
        /// </summary>
        /// <param name="ActiveObject">Активный объект</param>
        /// <param name="Position">Координаты левой верхней точки</param>
        /// <param name="Id">Идентификатор (для десериализации)</param>
        /// <returns>Идентификатор</returns>
        public Guid AddActiveObject(MapActiveObject ActiveObject, MapPoint Position)
        {
            if (ActiveObject == null)
            {
                throw new ArgumentNullException("ActiveObject", "ActiveObject cannot be null");
            }

            if (Position.Level >= this.LevelsCount)
            {
                throw new ArgumentOutOfRangeException("Position.Level", "Level cannot be out of map");
            }

            if ((Position.X + ActiveObject.Tile.Size.Width > this.Size.Width) ||
                (Position.Y + ActiveObject.Tile.Size.Height > this.Size.Height))
            {
                throw new ArgumentOutOfRangeException("Position", "Position cannot be out of map");
            }

            if (!CheckPlaceForActiveObject(ActiveObject, Position))
            {
                throw new ArgumentException("ActiveObject", "ActiveObject cannot be located to this Position");
            }

            Guid Id = Guid.NewGuid();

            MapActiveObjectState state = new MapActiveObjectState(ActiveObject, Position);

            state.Destroying += (sender, args) => { OnActiveObjectDestroying(args.ActiveObject); };
            state.Destroyed  += (sender, args) => { OnActiveObjectDestroyed(args.ActiveObject); };
            this.ActiveObjects.Add(Id, state);

            AttachActiveObject(state, Position);

            return(Id);
        }
        /// <summary>
        /// Проверить возможность размещения объекта на карт
        /// </summary>
        /// <param name="ActiveObject">Активный объект</param>
        /// <param name="Position">Координаты левой верхней точки</param>
        public bool CheckPlaceForActiveObject(MapActiveObject ActiveObject, MapPoint Position)
        {
            if (ActiveObject == null)
            {
                throw new ArgumentNullException("ActiveObject", "ActiveObject cannot be null");
            }

            if (Position.Level >= this.LevelsCount)
            {
                throw new ArgumentOutOfRangeException("Position.Level", "Position.Level cannot be out of map");
            }

            if ((Position.X + ActiveObject.Tile.Size.Width > this.Size.Width) ||
                (Position.Y + ActiveObject.Tile.Size.Height > this.Size.Height))
            {
                throw new ArgumentOutOfRangeException("Position", "Position cannot be out of map");
            }

            for (UInt16 x = Position.X; x < Position.X + ActiveObject.Tile.Size.Width; x++)
            {
                for (UInt16 y = Position.Y; y < Position.Y + ActiveObject.Tile.Size.Height; y++)
                {
                    bool North = (y == Position.Y);
                    bool South = (y == (Position.Y + ActiveObject.Tile.Size.Height - 1));
                    bool West  = (x == Position.X);
                    bool East  = (x == (Position.Y + ActiveObject.Tile.Size.Width - 1));
                    if (!CheckCell(ActiveObject, Position, North, South, West, East))
                    {
                        return(false);
                    }
                }
            }

            return(true);
        }
        /// <summary>
        /// Проверка возможности размещения в данной клетке объекта
        /// </summary>
        /// <param name="ActiveObject">Объект</param>
        /// <param name="Position">Координаты</param>
        /// <param name="IgnoreNorth">Игнорируется ли северная стена</param>
        /// <param name="IgnoreSouth">Мгнорируется ли южная стена</param>
        /// <param name="IgnoreWest">Игнорируется ли западная стена</param>
        /// <param name="IgnoreEast">Игнорируется ли восточная стена</param>
        /// <returns>Возможно ли разместить объект в данной клетке</returns>
        private bool CheckCell(MapActiveObject ActiveObject, MapPoint Position, bool IgnoreNorth, bool IgnoreSouth, bool IgnoreWest, bool IgnoreEast)
        {
            MapCellState cell = Levels[Position.Level].Cells[Position];

            if ((cell.Place != null) && (cell.Place.Passability < ActiveObject.Passability))
            {
                return(false);
            }
            if (!IgnoreNorth && (cell.GetPassbilityByDirection(MapDirection.North) < ActiveObject.Passability))
            {
                return(false);
            }
            if (!IgnoreSouth && (cell.GetPassbilityByDirection(MapDirection.South) < ActiveObject.Passability))
            {
                return(false);
            }
            if (!IgnoreWest && (cell.GetPassbilityByDirection(MapDirection.West) < ActiveObject.Passability))
            {
                return(false);
            }
            if (!IgnoreEast && (cell.GetPassbilityByDirection(MapDirection.East) < ActiveObject.Passability))
            {
                return(false);
            }
            return(true);
        }
 /// <summary>
 /// Состояние активного объекта карты
 /// </summary>
 /// <param name="ActiveObject">Активный объект</param>        
 /// <param name="Position">Координаты левой верхней точки</param>
 public MapActiveObjectState(MapActiveObject ActiveObject, MapPoint Position)
     : base(ActiveObject)
 {
     this.Position = Position;
     this.ArmorType = ActiveObject.ArmorType;
     this._Health = ActiveObject.Health;
     this._Direction = Direction;
     this.ActualSize = this.Size;
 }
示例#5
0
 /// <summary>
 /// Состояние активного объекта карты
 /// </summary>
 /// <param name="ActiveObject">Активный объект</param>
 /// <param name="Position">Координаты левой верхней точки</param>
 public MapActiveObjectState(MapActiveObject ActiveObject, MapPoint Position)
     : base(ActiveObject)
 {
     this.Position   = Position;
     this.ArmorType  = ActiveObject.ArmorType;
     this._Health    = ActiveObject.Health;
     this._Direction = Direction;
     this.ActualSize = this.Size;
 }
        /// <summary>
        /// Активный объект карты
        /// </summary>        
        /// <param name="Image">Картинка</param>
        /// <param name="DestroyedActiveObject">Разрушенный активный объект (если нет - null)</param>
        /// <param name="Size">Размер (в клетках карты)</param>
        /// <param name="Direction">Направление</param>
        /// <param name="ArmorType">Тип брони</param>
        /// <param name="Health">Здоровье (0...)</param>
        /// <param name="Passability">Проходимость (0..1)</param>
        public MapActiveObject(MapImage Image, MapActiveObject DestroyedActiveObject, MapSize Size, MapDirection Direction, MapArmorType ArmorType, UInt16 Health, MapPassability Passability)
            : base(new MapTile(Image, Size))
        {
            if ((Passability < 0) || (Passability > 1)) throw new ArgumentOutOfRangeException("Passability", "Passability of Place must be in range 0..1");

            this.DestroyedActiveObject = DestroyedActiveObject;
            this.BaseDirection = Direction;
            this.Health = Health;
            this.Passability = Passability;
            this.ArmorType = ArmorType;
        }
示例#7
0
        /// <summary>
        /// Активный объект карты
        /// </summary>
        /// <param name="Image">Картинка</param>
        /// <param name="DestroyedActiveObject">Разрушенный активный объект (если нет - null)</param>
        /// <param name="Size">Размер (в клетках карты)</param>
        /// <param name="Direction">Направление</param>
        /// <param name="ArmorType">Тип брони</param>
        /// <param name="Health">Здоровье (0...)</param>
        /// <param name="Passability">Проходимость (0..1)</param>
        public MapActiveObject(MapImage Image, MapActiveObject DestroyedActiveObject, MapSize Size, MapDirection Direction, MapArmorType ArmorType, UInt16 Health, MapPassability Passability)
            : base(new MapTile(Image, Size))
        {
            if ((Passability < 0) || (Passability > 1))
            {
                throw new ArgumentOutOfRangeException("Passability", "Passability of Place must be in range 0..1");
            }

            this.DestroyedActiveObject = DestroyedActiveObject;
            this.BaseDirection         = Direction;
            this.Health      = Health;
            this.Passability = Passability;
            this.ArmorType   = ArmorType;
        }
示例#8
0
        /// <summary>
        /// Удалить активный объект
        /// </summary>
        /// <param name="ActiveObject">Активный объект</param>
        public void RemoveActiveObject(MapActiveObject ActiveObject)
        {
            if (ActiveObject == null)
            {
                return;
            }
            if (ActiveObjects == null)
            {
                return;
            }
            if (!ActiveObjects.Contains(ActiveObject))
            {
                return;
            }
            List <MapActiveObject> objects = new List <MapActiveObject>(ActiveObjects);

            objects.Remove(ActiveObject);
            ActiveObjects = objects.ToArray();
        }
示例#9
0
        /// <summary>
        /// Добавить активный объект
        /// </summary>
        /// <param name="ActiveObject">Активный объект</param>
        public void AddActiveObject(MapActiveObject ActiveObject)
        {
            if (ActiveObject == null)
            {
                return;
            }
            List <MapActiveObject> objects;

            if (ActiveObjects == null)
            {
                objects = new List <MapActiveObject>();
                objects.Add(ActiveObject);
            }
            else
            {
                if (ActiveObjects.Contains(ActiveObject))
                {
                    return;
                }
                objects = new List <MapActiveObject>(ActiveObjects);
                objects.Add(ActiveObject);
            }
            ActiveObjects = objects.ToArray();
        }
示例#10
0
 /// <summary>
 /// Проверка возможности размещения в данной клетке объекта
 /// </summary>
 /// <param name="ActiveObject">Объект</param>
 /// <param name="Position">Координаты</param>
 /// <param name="IgnoreNorth">Игнорируется ли северная стена</param>
 /// <param name="IgnoreSouth">Мгнорируется ли южная стена</param>
 /// <param name="IgnoreWest">Игнорируется ли западная стена</param>
 /// <param name="IgnoreEast">Игнорируется ли восточная стена</param>
 /// <returns>Возможно ли разместить объект в данной клетке</returns>
 private bool CheckCell(MapActiveObject ActiveObject, MapPoint Position, bool IgnoreNorth, bool IgnoreSouth, bool IgnoreWest, bool IgnoreEast)
 {
     MapCellState cell = Levels[Position.Level].Cells[Position];
     if ((cell.Place != null) && (cell.Place.Passability < ActiveObject.Passability)) return false;
     if (!IgnoreNorth && (cell.GetPassbilityByDirection(MapDirection.North) < ActiveObject.Passability)) return false;
     if (!IgnoreSouth && (cell.GetPassbilityByDirection(MapDirection.South) < ActiveObject.Passability)) return false;
     if (!IgnoreWest && (cell.GetPassbilityByDirection(MapDirection.West) < ActiveObject.Passability)) return false;
     if (!IgnoreEast && (cell.GetPassbilityByDirection(MapDirection.East) < ActiveObject.Passability)) return false;
     return true;
 }
示例#11
0
        /// <summary>
        /// Проверить возможность размещения объекта на карт
        /// </summary>
        /// <param name="ActiveObject">Активный объект</param>        
        /// <param name="Position">Координаты левой верхней точки</param>
        public bool CheckPlaceForActiveObject(MapActiveObject ActiveObject, MapPoint Position)
        {
            if (ActiveObject == null) throw new ArgumentNullException("ActiveObject", "ActiveObject cannot be null");

            if (Position.Level >= this.LevelsCount)
                throw new ArgumentOutOfRangeException("Position.Level", "Position.Level cannot be out of map");

            if ((Position.X + ActiveObject.Tile.Size.Width > this.Size.Width)
                || (Position.Y + ActiveObject.Tile.Size.Height > this.Size.Height))
                throw new ArgumentOutOfRangeException("Position", "Position cannot be out of map");

            for (UInt16 x = Position.X; x < Position.X + ActiveObject.Tile.Size.Width; x++)
                for (UInt16 y = Position.Y; y < Position.Y + ActiveObject.Tile.Size.Height; y++)
                {
                    bool North = (y == Position.Y);
                    bool South = (y == (Position.Y + ActiveObject.Tile.Size.Height - 1));
                    bool West = (x == Position.X);
                    bool East = (x == (Position.Y + ActiveObject.Tile.Size.Width - 1));
                    if (!CheckCell(ActiveObject, Position, North, South, West, East)) return false;
                }

            return true;
        }
示例#12
0
        /// <summary>
        /// Добавить новый объект на карту
        /// </summary>
        /// <param name="ActiveObject">Активный объект</param>
        /// <param name="Position">Координаты левой верхней точки</param>
        /// <param name="Id">Идентификатор (для десериализации)</param>
        /// <returns>Идентификатор</returns>
        public Guid AddActiveObject(MapActiveObject ActiveObject, MapPoint Position)
        {
            if (ActiveObject == null) throw new ArgumentNullException("ActiveObject", "ActiveObject cannot be null");

            if (Position.Level >= this.LevelsCount)
                throw new ArgumentOutOfRangeException("Position.Level", "Level cannot be out of map");

            if ((Position.X + ActiveObject.Tile.Size.Width > this.Size.Width)
                || (Position.Y + ActiveObject.Tile.Size.Height > this.Size.Height))
                throw new ArgumentOutOfRangeException("Position", "Position cannot be out of map");

            if (!CheckPlaceForActiveObject(ActiveObject, Position))
                throw new ArgumentException("ActiveObject", "ActiveObject cannot be located to this Position");

            Guid Id = Guid.NewGuid();

            MapActiveObjectState state = new MapActiveObjectState(ActiveObject, Position);
            state.Destroying += (sender, args) => { OnActiveObjectDestroying(args.ActiveObject); };
            state.Destroyed += (sender, args) => { OnActiveObjectDestroyed(args.ActiveObject); };
            this.ActiveObjects.Add(Id, state);

            AttachActiveObject(state, Position);

            return Id;
        }
示例#13
0
 /// <summary>
 /// Удалить активный объект
 /// </summary>
 /// <param name="ActiveObject">Активный объект</param>
 public void RemoveActiveObject(MapActiveObject ActiveObject)
 {
     if (ActiveObject == null) return;
     if (ActiveObjects == null) return;
     if (!ActiveObjects.Contains(ActiveObject)) return;
     List<MapActiveObject> objects = new List<MapActiveObject>(ActiveObjects);
     objects.Remove(ActiveObject);
     ActiveObjects = objects.ToArray();
 }
示例#14
0
 /// <summary>
 /// Добавить активный объект
 /// </summary>
 /// <param name="ActiveObject">Активный объект</param>
 public void AddActiveObject(MapActiveObject ActiveObject)
 {
     if (ActiveObject == null) return;
     List<MapActiveObject> objects;
     if (ActiveObjects == null)
     {
         objects = new List<MapActiveObject>();
         objects.Add(ActiveObject);
     }
     else
     {
         if (ActiveObjects.Contains(ActiveObject)) return;
         objects = new List<MapActiveObject>(ActiveObjects);
         objects.Add(ActiveObject);
     }
     ActiveObjects = objects.ToArray();
 }
示例#15
0
 public Npc(NpcType Type, MapActiveObject MapActiveObject)
 {
     this.MapActiveObject = MapActiveObject;
     this.Type = Type;
 }
示例#16
0
        //[TestMethod]
        public void TestSaveMap()
        {
            MapImage image = new MapImage(MapImageType.Bmp, null);
            MapSize mapSize = new MapSize(1000, 1000);
            Map map = new Map(1, mapSize);
            map.Version = new Version(1, 2, 3, 4);
            MapPlace place1 = new MapPlace(image, 1);
            MapPlace place2 = new MapPlace(image, 0.8f);
            MapWall wall = new MapWall(image, MapDirection.North, 200);

            MapActiveObject testObj1 = new MapActiveObject(image, null, new MapSize(2, 3), MapDirection.West, MapArmorType.Heavy, 120, 1);
            MapActiveObject testObj2 = new MapActiveObject(image, null, new MapSize(20, 30), MapDirection.West, MapArmorType.Machine, 121, 1);
            MapActiveObject testObj3 = new MapActiveObject(image, null, new MapSize(200, 300), MapDirection.West, MapArmorType.None, 122, 1);
            MapActiveObject testObj4 = new MapActiveObject(image, null, new MapSize(259, 355), MapDirection.West, MapArmorType.Undead, 123, 1);

            MapArea area1 = new MapArea(new MapPoint(0, 20, 30), new MapSize(50, 50));
            MapArea area2 = new MapArea(new MapPoint(0, 200, 300), new MapSize(100, 100));
            MapArea area3 = new MapArea(new MapPoint(0, 100, 100), new MapSize(10, 10));

            MapAreaTransitionPoint transPoint1 = new MapAreaTransitionPoint(area1, area2, new MapPoint(0, 25, 35), new MapSize(5, 5));
            MapAreaTransitionPoint transPoint2 = new MapAreaTransitionPoint(area2, area3, new MapPoint(0, 225, 325), new MapSize(5, 5));
            MapAreaTransitionPoint transPoint3 = new MapAreaTransitionPoint(area3, area1, new MapPoint(0, 105, 105), new MapSize(2, 2));

            area1.TransitionPoints.Add(transPoint1);
            area2.TransitionPoints.Add(transPoint2);
            area3.TransitionPoints.Add(transPoint3);

            map.TileSet.Add(place1);
            map.TileSet.Add(place2);
            map.TileSet.Add(wall);
            map.TileSet.Add(testObj1);
            map.TileSet.Add(testObj2);
            map.TileSet.Add(testObj3);
            map.TileSet.Add(testObj4);
            map.Areas.Areas.Add(area1);
            map.Areas.Areas.Add(area2);
            map.Areas.Areas.Add(area3);

            for (int x = 0; x < mapSize.Width / 2; x++)
                for (int y = 0; y < mapSize.Height; y++)
                    map.Levels[0].Cells[x, y] = new MapCell(place1, new Dictionary<MapDirection, MapWall>());

            for (int x = mapSize.Width / 2; x < mapSize.Width; x++)
                for (int y = 0; y < mapSize.Height; y++)
                    map.Levels[0].Cells[x, y] = new MapCell(place2, new Dictionary<MapDirection, MapWall>());

            map.Levels[0].Cells[5, 6].SetWall(MapDirection.South, wall);

            Exception exception = null;

            MapState mapState = new MapState(map);

            mapState.AddActiveObject(testObj1, new MapPoint(0, 1, 1));
            mapState.AddActiveObject(testObj2, new MapPoint(0, 100, 100));
            mapState.AddActiveObject(testObj3, new MapPoint(0, 200, 200));
            mapState.AddActiveObject(testObj4, new MapPoint(0, 500, 500));
            Map map2 = null;
            MapState mapState2 = null;

            try
            {
                DateTime start = DateTime.Now;
                byte[] data = MapSerializer.Instance.SerializeMapState(mapState);
                DateTime finish = DateTime.Now;
                mapState2 = MapSerializer.Instance.DeserializeMapState(data);
                map2 = mapState2.Map;

            }
            catch (Exception ex)
            {
                exception = ex;
            }

            Assert.IsNull(exception);

            Assert.IsNotNull(map2);
            Assert.AreEqual(map2[0, 0, 0].Place.Id, place1.Id);
            Assert.AreEqual(map2[0, 0, 0].Place.Passability, place1.Passability);
            Assert.AreEqual(map2[0, mapSize.Width - 1, 0].Place.Id, place2.Id);
            Assert.AreEqual(map2[0, mapSize.Width - 1, 0].Place.Passability, place2.Passability);
            Assert.AreEqual(map2[0, 5, 6].Walls[MapDirection.South].Id, wall.Id);
            Assert.AreEqual(map2[0, 5, 6].Walls[MapDirection.South].Health, wall.Health);
            Assert.AreEqual(map2.Areas.Areas[1].Position, map.Areas.Areas[1].Position);
            Assert.AreEqual(map2.Areas.Areas[2].TransitionPoints[0].From.Name, map.Areas.Areas[2].TransitionPoints[0].From.Name);
            Assert.AreEqual(map2.Areas.Areas[2].TransitionPoints[0].To.Name, map.Areas.Areas[2].TransitionPoints[0].To.Name);
            Assert.AreEqual(map2.Areas.Areas[2].TransitionPoints[0].Position, map.Areas.Areas[2].TransitionPoints[0].Position);
            Assert.AreEqual(mapState2.ActiveObjects.Count, mapState.ActiveObjects.Count);
        }
 public ActiveObjectViewModel(MapActiveObject activeObject)
     : base(activeObject)
 {
     Source = activeObject;
 }