예제 #1
0
        void newLayerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (FormNewLayer frmNewLayer = new FormNewLayer(levelData.MapWidth, levelData.MapHeight))
            {
                frmNewLayer.ShowDialog();

                if (frmNewLayer.OKPressed)
                {
                    MapLayerData data = frmNewLayer.MapLayerData;
                    if (clbLayers.Items.Contains(data.MapLayerName))
                    {
                        MessageBox.Show("Layer with name " + data.MapLayerName + " exists.", "Existing layer");
                        return;
                    }

                    MapLayer layer = MapLayer.FromMapLayerData(data);

                    clbLayers.Items.Add(data.MapLayerName, true);
                    clbLayers.SelectedIndex = clbLayers.Items.Count - 1;
                    layers.Add(layer);

                    if (map == null)
                    {
                        map = new TileMap(tileSets, layers);
                    }

                    charactersToolStripMenuItem.Enabled = true;
                    chestsToolStripMenuItem.Enabled     = true;
                    keysToolStripMenuItem.Enabled       = true;
                }
            }
        }
예제 #2
0
        /* This function is called when the OK button on the form is clicked.
         * It checks if the entered data is valid to create a MapLayerData, and then makes the MapLayerData if it can. */
        void btnOK_Click(object sender, EventArgs e)
        {
            /* The function checks if there's any text in the Layer Name text box, by using string.IsNullOrEmpty().
             * If the user not entered a Layer Name, a MessageBox is shown telling the user they need to enter a name, and the function returns. */
            if (string.IsNullOrEmpty(tbLayerName.Text))
            {
                MessageBox.Show("The layer must have a name.");
                return;
            }

            /* Once we know the layer will have a valid name, it needs to be constructed using the name, map width, and map height.
             * There's an optional check box (cbFill) that allows the user to choose a certain tile that they can fill the layer with.
             * If the check box is checked, the MapLayerData constructor will be passed the values of the tileset and tile NumericalUpDownSelectors.
             * Otherwise, the other overload of the constructor is used, which initializes each tile as empty. */
            if (cbFill.Checked)
            {
                mapLayerData = new MapLayerData(tbLayerName.Text, mapWidth, mapHeight, (int)nudTile.Value, (int)nudTileset.Value);
            }
            else
            {
                mapLayerData = new MapLayerData(tbLayerName.Text, mapWidth, mapHeight);
            }

            /* The formFinished field is set to true to let the main form know that everything has been done.
             * The form is then closed. */
            formFinished = true;
            Close();
        }
예제 #3
0
        void btnOK_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(tbLayerName.Text))
            {
                MessageBox.Show("You must enter a name for the layer.", "Missing Layer Name");
                return;
            }

            if (cbFill.Checked)
            {
                mapLayerData = new MapLayerData(
                    tbLayerName.Text,
                    LayerWidth,
                    LayerHeight,
                    (int)nudTileset.Value,
                    (int)nudTileset.Value);
            }
            else
            {
                mapLayerData = new MapLayerData(
                    tbLayerName.Text,
                    LayerWidth,
                    LayerHeight);
            }

            okPressed = true;
            this.Close();
        }
예제 #4
0
        public async Task <MapLayerData> AddUserLayer(MapLayerData layerData)
        {
            var response = await _elasticClient.IndexAsync(layerData, r => r.Index(CUSTOM_USER_LAYERS));

            layerData.Id = response.Id;
            return(layerData);
        }
예제 #5
0
 public void PreviousLayer()
 {
     if (CurrentMapLayerData.LayerId > 0 && DicLayerDatas.ContainsKey(CurrentMapLayerData.LayerId - 1))
     {
         CurrentMapLayerData = DicLayerDatas[CurrentMapLayerData.LayerId - 1];
         //切换层表现
     }
 }
예제 #6
0
    public void MakeMapByLayerData(PBMapLayerData layerData)
    {
        MapCardBase playerDoorCard = null;

        if (currentMapLayerData != null)
        {
            if (lastMapLayerData != null)
            {
                for (int i = 0; i < lastMapLayerData.Width; i++)
                {
                    for (int j = 0; j < lastMapLayerData.Height; j++)
                    {
                        if (lastMapLayerData[i, j] != null && lastMapLayerData[i, j] != currentMapLayerData[i, j])
                        {
                            lastMapLayerData[i, j].Destory();
                        }
                    }
                }
            }
            lastMapLayerData = currentMapLayerData;
            for (int i = 0; i < lastMapLayerData.Width; i++)
            {
                for (int j = 0; j < lastMapLayerData.Height; j++)
                {
                    //共用传送门
                    if (i == m_MyMapPlayer.CurPos.X && j == m_MyMapPlayer.CurPos.Y)
                    {
                        playerDoorCard = lastMapLayerData[i, j];
                    }
                    else if (lastMapLayerData[i, j] != null)
                    {
                        lastMapLayerData[i, j].ExitMap();
                    }
                }
            }
        }
        MapLayerData mapLayerData = new MapLayerData(layerData.Index, layerData.Width, layerData.Height);

        for (int i = 0; i < layerData.Width; i++)
        {
            for (int j = 0; j < layerData.Height; j++)
            {
                if (playerDoorCard != null && i == m_MyMapPlayer.CurPos.X && j == m_MyMapPlayer.CurPos.Y)
                {
                    mapLayerData[i, j] = playerDoorCard;
                    continue;
                }
                int index = i * layerData.Width + j;
                mapLayerData[i, j] = MapCardBase.CreateMapCard((MapCardType)layerData.PointTypes[index],
                                                               layerData.PointIds[index],
                                                               new MapCardPos(i, j));
            }
        }
        currentMapLayerData = mapLayerData;
        Messenger.BroadcastSync(MessageId.MAP_GET_MAP_LAYER_DATA);
    }
예제 #7
0
        public void PutUserLayer_InvalidId_ShouldReturnBadRequest()
        {
            var id    = "id";
            var layer = new MapLayerData {
                Key = "key", Address = "address", Id = id
            };

            var results = _controller.PutUserLayer("42", layer).Result as BadRequestObjectResult;

            Assert.IsNotNull(results);
        }
예제 #8
0
 private string IsValidMapLayer(MapLayerData mapLayer)
 {
     if (string.IsNullOrWhiteSpace(mapLayer.Key))
     {
         return("key cannot be empty");
     }
     if (string.IsNullOrWhiteSpace(mapLayer.Address))
     {
         return("address cannot be empty");
     }
     return(string.Empty);
 }
예제 #9
0
        public async Task <IActionResult> PutUserLayer(string id, [FromBody] MapLayerData mapLayer)
        {
            var validationResults = await ValidateInput(id, mapLayer);

            if (validationResults != null)
            {
                return(validationResults);
            }
            await _repository.UpdateUserLayer(mapLayer);

            return(Ok(mapLayer));
        }
예제 #10
0
        void newLayerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (FormNewLayer frmNewLayer = new FormNewLayer(levelData.MapWidth,
                                                               levelData.MapHeight))
            {
                frmNewLayer.ShowDialog();

                if (frmNewLayer.OKPressed)
                {
                    MapLayerData data = frmNewLayer.MapLayerData;

                    if (clbLayers.Items.Contains(data.MapLayerName))
                    {
                        MessageBox.Show("Layer with name " + data.MapLayerName + " exists.",
                                        "Existing layer");
                        return;
                    }

                    MapLayer layer = MapLayer.FromMapLayerData(data);

                    clbLayers.Items.Add(data.MapLayerName, true);
                    clbLayers.SelectedIndex = clbLayers.Items.Count - 1;

                    layers.Add(layer);

                    if (map == null)
                    {
                        map = new TileMap(tileSets[0], animatedSet, (MapLayer)layers[0]);

                        for (int i = 1; i < tileSets.Count; i++)
                        {
                            map.AddTileset(tileSets[1]);
                        }

                        for (int i = 1; i < layers.Count; i++)
                        {
                            map.AddLayer(layers[1]);
                        }
                    }

                    charactersToolStripMenuItem.Enabled = true;
                    chestsToolStripMenuItem.Enabled     = true;
                    keysToolStripMenuItem.Enabled       = true;

                    if (animatedSet != null)
                    {
                        chkPaintAnimated.Enabled = true;
                    }

                    chkPaintCollision.Enabled = true;
                }
            }
        }
예제 #11
0
        public async Task <IActionResult> PostUserLayer([FromBody] MapLayerData mapLayer)
        {
            var validation = IsValidMapLayer(mapLayer);

            if (validation != string.Empty)
            {
                return(BadRequest(validation));
            }
            mapLayer.OsmUserId = User.Identity.Name;
            var response = await _repository.AddUserLayer(mapLayer);

            return(Ok(response));
        }
예제 #12
0
        public void PutUserLayer_InvalidUser_ShouldReturnBadRequest()
        {
            var id = "id";

            _controller.SetupIdentity();
            var layer = new MapLayerData {
                Key = "key", Address = "address", Id = id, OsmUserId = "123"
            };

            var results = _controller.PutUserLayer(id, layer).Result as BadRequestObjectResult;

            Assert.IsNotNull(results);
        }
예제 #13
0
        public static MapLayer FromMapLayerData(MapLayerData data)
        {
            MapLayer layer = new MapLayer(data.Width, data.Height);

            for (int y = 0; y < data.Height; y++)
            {
                for (int x = 0; x < data.Width; x++)
                {
                    layer.SetTile(x, y, data.GetTile(x, y).TileIndex, data.GetTile(x, y).TileSetIndex);
                }
            }

            return(layer);
        }
예제 #14
0
        void openLayerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofDialog = new OpenFileDialog();

            ofDialog.Filter          = "Map Layer Data (*.mldt)|*.mldt";
            ofDialog.CheckPathExists = true;
            ofDialog.CheckFileExists = true;

            DialogResult result = ofDialog.ShowDialog();

            if (result != DialogResult.OK)
            {
                return;
            }

            MapLayerData data = null;

            try
            {
                data = XnaSerializer.Deserialize <MapLayerData>(ofDialog.FileName);
            }
            catch (Exception exc)
            {
                MessageBox.Show(exc.Message, "Error reading map layer");
                return;
            }

            for (int i = 0; i < clbLayers.Items.Count; i++)
            {
                if (clbLayers.Items[i].ToString() == data.MapLayerName)
                {
                    MessageBox.Show("Layer by that name already exists.", "Existing layer");
                    return;
                }
            }

            clbLayers.Items.Add(data.MapLayerName, true);

            layers.Add(MapLayer.FromMapLayerData(data));

            if (map == null)
            {
                map = new TileMap(tileSets[0], (MapLayer)layers[0]);

                for (int i = 0; i < tileSets.Count; i++)
                {
                    map.AddTileset(tileSets[i]);
                }
            }
        }
예제 #15
0
        public void PutUserLayer_InvalidLayer_ShouldReturnBadRequest()
        {
            var id        = "id";
            var osmUserId = "osmUserId";

            _controller.SetupIdentity(null, osmUserId);
            var layer = new MapLayerData {
                Id = id, OsmUserId = osmUserId
            };

            var results = _controller.PutUserLayer(id, layer).Result as BadRequestObjectResult;

            Assert.IsNotNull(results);
        }
예제 #16
0
        void saveLayerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (layers.Count == 0)
            {
                return;
            }

            if (layers[clbLayers.SelectedIndex] is MapLayer)
            {
                SaveFileDialog sfDialog = new SaveFileDialog();
                sfDialog.Filter          = "Map Layer Data (*.mldt)|*.mldt";
                sfDialog.CheckPathExists = true;
                sfDialog.OverwritePrompt = true;
                sfDialog.ValidateNames   = true;

                DialogResult result = sfDialog.ShowDialog();

                if (result != DialogResult.OK)
                {
                    return;
                }

                MapLayerData data = new MapLayerData(
                    clbLayers.SelectedItem.ToString(),
                    ((MapLayer)layers[clbLayers.SelectedIndex]).Width,
                    ((MapLayer)layers[clbLayers.SelectedIndex]).Height);

                for (int y = 0; y < ((MapLayer)layers[clbLayers.SelectedIndex]).Height; y++)
                {
                    for (int x = 0; x < ((MapLayer)layers[clbLayers.SelectedIndex]).Width; x++)
                    {
                        data.SetTile(
                            x,
                            y,
                            ((MapLayer)layers[clbLayers.SelectedIndex]).GetTile(x, y).TileIndex,
                            ((MapLayer)layers[clbLayers.SelectedIndex]).GetTile(x, y).Tileset);
                    }
                }

                try
                {
                    XnaSerializer.Serialize <MapLayerData>(sfDialog.FileName, data);
                }
                catch (Exception exc)
                {
                    MessageBox.Show(exc.Message, "Error saving map layer data");
                }
            }
        }
예제 #17
0
        public void PutUserLayer_LayerDoesNotBelongToUser_ShouldReturnBadRequest()
        {
            var id        = "id";
            var osmUserId = "osmUserId";

            _controller.SetupIdentity(null, osmUserId);
            _repository.GetUserLayers(osmUserId).Returns(new List <MapLayerData>());
            var layer = new MapLayerData {
                Key = "key", Address = "address", Id = id, OsmUserId = osmUserId
            };

            var results = _controller.PutUserLayer(id, layer).Result as BadRequestObjectResult;

            Assert.IsNotNull(results);
        }
예제 #18
0
        void saveMapToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (map == null)
            {
                return;
            }

            List <MapLayerData> mapLayerData = new List <MapLayerData>();

            for (int i = 0; i < clbLayers.Items.Count; i++)
            {
                if (layers[i] is MapLayer)
                {
                    MapLayerData data = new MapLayerData(
                        clbLayers.Items[i].ToString(),
                        ((MapLayer)layers[i]).Width,
                        ((MapLayer)layers[i]).Height,
                        ((MapLayer)layers[i]).LayerLevel);
                    for (int y = 0; y < ((MapLayer)layers[i]).Height; y++)
                    {
                        for (int x = 0; x < ((MapLayer)layers[i]).Width; x++)
                        {
                            data.SetTile(
                                x,
                                y,
                                ((MapLayer)layers[i]).GetTile(x, y).TileIndex,
                                ((MapLayer)layers[i]).GetTile(x, y).Tileset);
                        }
                    }

                    mapLayerData.Add(data);
                }
            }

            mData.setAdditionalData(tileSetData, mapLayerData);

            FolderBrowserDialog fbDialog = new FolderBrowserDialog();

            fbDialog.Description  = "Select Folder";
            fbDialog.SelectedPath = Application.StartupPath;

            DialogResult result = fbDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                XnaSerializer.Serialize <MapData>(fbDialog.SelectedPath + "\\" + mData.MapName + ".xml", mData);
            }
        }
예제 #19
0
        public void PostUserLayer_AuthorizedUser_ShouldUpdateUserLayers()
        {
            var id        = "id";
            var osmUserId = "osmUserId";
            var layer     = new MapLayerData {
                Key = "key", Address = "address"
            };

            _controller.SetupIdentity(null, osmUserId);
            _repository.AddUserLayer(layer).Returns(layer).AndDoes(l => (l[0] as MapLayerData).Id = id);

            var results = _controller.PostUserLayer(layer).Result as OkObjectResult;

            Assert.IsNotNull(results);
            Assert.AreEqual(id, (results.Value as MapLayerData).Id);
        }
예제 #20
0
        private void AddLayer(string name, int lowerZoom, int upperZoom, int zoomLevel)
        {
            // The larger map sizes (>map50) are 80MB, so I'm not including them in the GitHub repository.
            // Therefore, just silently skip any missing maps without raising an error
            if (File.Exists(GetMapFileName(name)))
            {
                MapLayerData data;

                data           = new MapLayerData();
                data.Name      = name;
                data.UpperZoom = upperZoom;
                data.LowerZoom = lowerZoom;
                data.ZoomLevel = zoomLevel;

                LayerData.Add(data);
            }
        }
예제 #21
0
        public void DeleteUserLayer_InvalidRequest_ShouldReturnBadRequest()
        {
            var id        = "id";
            var osmUserId = "osmUserId";
            var layer     = new MapLayerData {
                Id = id, OsmUserId = osmUserId
            };

            _controller.SetupIdentity(null, osmUserId);
            _repository.GetUserLayerById(id).Returns(layer);
            _repository.GetUserLayers(osmUserId).Returns(new List <MapLayerData> {
                layer
            });

            var results = _controller.DeleteUserLayer(id).Result as BadRequestObjectResult;

            Assert.IsNotNull(results);
        }
예제 #22
0
        public void DeleteUserLayer_ValidRequest_ShouldDeleteFromRepository()
        {
            var id        = "id";
            var osmUserId = "osmUserId";
            var layer     = new MapLayerData {
                Key = "key", Address = "address", Id = id, OsmUserId = osmUserId
            };

            _controller.SetupIdentity(null, osmUserId);
            _repository.GetUserLayerById(id).Returns(layer);
            _repository.GetUserLayers(osmUserId).Returns(new List <MapLayerData> {
                layer
            });

            var results = _controller.DeleteUserLayer(id).Result as OkObjectResult;

            Assert.IsNotNull(results);
            _repository.Received(1).DeleteUserLayer(layer);
        }
예제 #23
0
        /* This function converts a MapLayerData object (created in the Level Editor) into a MapLayer. */
        public static MapLayer FromMapLayerData(MapLayerData data)
        {
            /* First, a new MapLayer is created using the width and height of the MapLayerData.
             * Then, for each Tile in the MapLayerData, the tile is copied from the MapLayerData to the MapLayer.
             * The TileIndex, TilesetIndex, Solid, and Spawn properties are copied separately using the relevant methods. */
            MapLayer layer = new MapLayer(data.Width, data.Height);

            for (int y = 0; y < data.Height; y++)
            {
                for (int x = 0; x < data.Width; x++)
                {
                    layer.SetTile(x, y, data.GetTile(x, y).TileIndex, data.GetTile(x, y).TilesetIndex);
                    layer.SetSolid(x, y, data.GetTile(x, y).Solid);
                    layer.SetSpawn(x, y, data.GetTile(x, y).Spawn);
                }
            }

            /* Finally, the newly created layer is returned. */
            return(layer);
        }
예제 #24
0
        private void LoudDefaultLayers()
        {
            MapLayerData mapLayerData1 = new MapLayerData("Water", mData.MapWidth, mData.MapHeight, 0, 0, 6);

            MapLayer layer = MapLayer.FromMapLayerData(mapLayerData1);

            clbLayers.Items.Add(mapLayerData1.MapLayerName, true);
            clbLayers.SelectedIndex = clbLayers.Items.Count - 1;

            layers.Add(layer);

            MapLayerData mapLayerData2 = new MapLayerData("Level 1", mData.MapWidth, mData.MapHeight, 1, -1, -1);

            layer = MapLayer.FromMapLayerData(mapLayerData2);
            clbLayers.Items.Add(mapLayerData2.MapLayerName, true);
            clbLayers.SelectedIndex = clbLayers.Items.Count - 1;

            layers.Add(layer);

            MapLayerData mapLayerData3 = new MapLayerData("Level 2", mData.MapWidth, mData.MapHeight, 2, -1, -1);

            layer = MapLayer.FromMapLayerData(mapLayerData3);
            clbLayers.Items.Add(mapLayerData3.MapLayerName, true);
            clbLayers.SelectedIndex = clbLayers.Items.Count - 1;

            layers.Add(layer);
            if (map == null)
            {
                map = new TileMapIso(tileSets[0], (MapLayer)layers[0]);

                for (int i = 1; i < tileSets.Count; i++)
                {
                    map.AddTileset(tileSets[1]);
                }

                for (int i = 1; i < layers.Count; i++)
                {
                    map.AddLayer(layers[1]);
                }
            }
        }
예제 #25
0
        void newLayerToolStripMenuItem_Click(object sender, EventArgs e)
        {
            using (FormNewLayer frmNewLayer = new FormNewLayer(mData.MapWidth, mData.MapHeight))
            {
                frmNewLayer.ShowDialog();

                if (frmNewLayer.OKPressed)
                {
                    MapLayerData data = frmNewLayer.MapLayerData;

                    if (clbLayers.Items.Contains(data.MapLayerName))
                    {
                        MessageBox.Show("Layer with name " + data.MapLayerName + " exists.", "Existing layer");
                        return;
                    }

                    MapLayer layer = MapLayer.FromMapLayerData(data);
                    clbLayers.Items.Add(data.MapLayerName, true);
                    clbLayers.SelectedIndex = clbLayers.Items.Count - 1;

                    layers.Add(layer);

                    if (map == null)
                    {
                        map = new TileMapIso(tileSets[0], (MapLayer)layers[0]);

                        for (int i = 1; i < tileSets.Count; i++)
                        {
                            map.AddTileset(tileSets[1]);
                        }

                        for (int i = 1; i < layers.Count; i++)
                        {
                            map.AddLayer(layers[1]);
                        }
                    }
                }
            }
        }
예제 #26
0
        private async Task <IActionResult> ValidateInput(string id, MapLayerData mapLayer)
        {
            if (id != mapLayer.Id)
            {
                return(BadRequest("id must match mapLayer's id"));
            }
            if (mapLayer.OsmUserId != User.Identity.Name)
            {
                return(BadRequest("You can't manipulate a layer that is not yours..."));
            }
            var validation = IsValidMapLayer(mapLayer);

            if (validation != string.Empty)
            {
                return(BadRequest(validation));
            }
            var userLayers = await _repository.GetUserLayers(User.Identity.Name);

            if (userLayers.All(l => l.Id != mapLayer.Id))
            {
                return(BadRequest("You can't manipulate a layer that is not yours..."));
            }
            return(null);
        }
예제 #27
0
 void MakeMap(MapLayerData mapLayerData)
 {
 }
예제 #28
0
        void saveLevelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (map == null)
            {
                return;
            }

            List <MapLayerData> mapLayerData = new List <MapLayerData>();

            for (int i = 0; i < clbLayers.Items.Count; i++)
            {
                if (layers[i] is MapLayer)
                {
                    MapLayerData data = new MapLayerData(
                        clbLayers.Items[i].ToString(),
                        ((MapLayer)layers[i]).Width,
                        ((MapLayer)layers[i]).Height);

                    for (int y = 0; y < ((MapLayer)layers[i]).Height; y++)
                    {
                        for (int x = 0; x < ((MapLayer)layers[i]).Width; x++)
                        {
                            data.SetTile(x, y, ((MapLayer)layers[i]).GetTile(x, y).TileIndex, ((MapLayer)layers[i]).GetTile(x, y).Tileset);
                        }
                    }

                    mapLayerData.Add(data);
                }
            }

            MapData mapData = new MapData(levelData.MapName, tileSetData, mapLayerData);

            FolderBrowserDialog fbDialog = new FolderBrowserDialog();

            fbDialog.Description  = "Select Game Folder";
            fbDialog.SelectedPath = Application.StartupPath;

            DialogResult result = fbDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                if (!File.Exists(fbDialog.SelectedPath + @"\Game.xml"))
                {
                    MessageBox.Show("Game not found", "Error");
                    return;
                }

                string LevelPath = Path.Combine(fbDialog.SelectedPath, @"Levels\");
                string MapPath   = Path.Combine(LevelPath, @"Maps\");

                if (!Directory.Exists(LevelPath))
                {
                    Directory.CreateDirectory(LevelPath);
                }

                if (!Directory.Exists(MapPath))
                {
                    Directory.CreateDirectory(MapPath);
                }

                XnaSerializer.Serialize <LevelData>(LevelPath + levelData.LevelName + ".xml", levelData);
                XnaSerializer.Serialize <MapData>(MapPath + mapData.MapName + ".xml", mapData);
            }
        }
예제 #29
0
    void MakeMap(int layerId)
    {
        MapCardBase playerDoorCard = null;

        if (currentMapLayerData != null)
        {
            if (lastMapLayerData != null)
            {
                for (int i = 0; i < ConstValue.MAP_WIDTH; i++)
                {
                    for (int j = 0; j < ConstValue.MAP_HEIGHT; j++)
                    {
                        if (lastMapLayerData[i, j] != null && lastMapLayerData[i, j] != currentMapLayerData[i, j])
                        {
                            lastMapLayerData[i, j].Destory();
                        }
                    }
                }
            }
            lastMapLayerData = currentMapLayerData;
            for (int i = 0; i < ConstValue.MAP_WIDTH; i++)
            {
                for (int j = 0; j < ConstValue.MAP_HEIGHT; j++)
                {
                    //共用传送门
                    if (i == m_MyMapPlayer.CurPos.X && j == m_MyMapPlayer.CurPos.Y)
                    {
                        playerDoorCard = lastMapLayerData[i, j];
                    }
                    else if (lastMapLayerData[i, j] != null)
                    {
                        lastMapLayerData[i, j].ExitMap();
                    }
                }
            }
        }
        MapLayerData layerData = new MapLayerData(layerId, 5, 5);

        currentMapLayerData = layerData;
        List <MapCardBase> mapCards = new List <MapCardBase>();
        int cardCount = Random.Range(10, 15);

        //先确定出生点
        {
            if (playerDoorCard == null)
            {
                playerDoorCard = MapCardBase.CreateMapCard <MapCardDoor>(m_MyMapPlayer.CurPos, MapCardBase.CardState.Front);
            }
            mapCards.Add(playerDoorCard);
            layerData[playerDoorCard.X, playerDoorCard.Y] = playerDoorCard;
            playerDoorCard.SetUsed(true);
            playerDoorCard.SetActive(true);
            playerDoorCard.SetParent(MapCardRoot.transform);
        }
        for (int i = 1; i < cardCount; i++)
        {
            MapCardPos pos = mapCards[Random.Range(0, i)].Position;

            List <MapCardPos> poss = layerData.GetNearEmptyPoss(pos.X, pos.Y);

            if (poss.Count == 0)
            {
                i--;
                continue;
            }
            int count = Random.Range(0, poss.Count - 1);
            pos = poss[count];
            mapCards.Add(MapCardBase.GetRandomMapCard(pos, MapCardBase.CardState.Behind));
            layerData[mapCards[i].X, mapCards[i].Y] = mapCards[i];
            mapCards[i].SetActive(true);
            mapCards[i].SetParent(MapCardRoot.transform);
        }
        //创建出口
        {
            MapCardPos pos = mapCards[Random.Range(0, cardCount)].Position;

            List <MapCardPos> poss = layerData.GetNearEmptyPoss(pos.X, pos.Y);

            while (poss.Count == 0)
            {
                pos  = mapCards[Random.Range(0, cardCount)].Position;
                poss = layerData.GetNearEmptyPoss(pos.X, pos.Y);
            }
            int count = Random.Range(0, poss.Count - 1);
            pos = poss[count];
            MapCardBase door = MapCardBase.CreateMapCard <MapCardDoor>(pos, MapCardBase.CardState.Behind);
            mapCards.Add(door);
            layerData[door.X, door.Y] = door;
            door.SetActive(true);
            door.SetParent(MapCardRoot.transform);
        }
    }
    private void AddLayer(string name, int lowerZoom, int upperZoom)
    {
      // The larger map sizes (>map50) are 80MB, so I'm not including them in the GitHub repository.
      // Therefore, just silently skip any missing maps without raising an error

      if (File.Exists(this.GetMapFileName(name)))
      {
        MapLayerData data;

        data = new MapLayerData();
        data.Name = name;
        data.UpperZoom = upperZoom;
        data.LowerZoom = lowerZoom;

        this.LayerData.Add(data);
      }
    }
예제 #31
0
        void saveLevelToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (map == null)
            {
                return;
            }

            List <MapLayerData> mapLayerData = new List <MapLayerData>();

            for (int i = 0; i < clbLayers.Items.Count; i++)
            {
                if (layers[i] is MapLayer)
                {
                    MapLayerData data = new MapLayerData(
                        clbLayers.Items[i].ToString(),
                        ((MapLayer)layers[i]).Width,
                        ((MapLayer)layers[i]).Height);

                    for (int y = 0; y < ((MapLayer)layers[i]).Height; y++)
                    {
                        for (int x = 0; x < ((MapLayer)layers[i]).Width; x++)
                        {
                            data.SetTile(
                                x,
                                y,
                                ((MapLayer)layers[i]).GetTile(x, y).TileIndex,
                                ((MapLayer)layers[i]).GetTile(x, y).Tileset);
                        }
                    }

                    mapLayerData.Add(data);
                }
            }

            MapData mapData = new MapData(levelData.MapName, tileSetData, animatedSetData,
                                          mapLayerData, collisionLayer, animatedLayer);

            CharacterLayerData charData = new CharacterLayerData();

            foreach (var c in FormMain.characters.Characters)
            {
                CharacterData character;

                if (c.Value is NonPlayerCharacter)
                {
                    character = new NonPlayerCharacterData();
                    ((NonPlayerCharacterData)character).Quests = ((NonPlayerCharacter)c.Value).Quests;
                    ((NonPlayerCharacterData)character).CurrentConversation = ((NonPlayerCharacter)c.Value).CurrentConversation;
                    ((NonPlayerCharacterData)character).CurrentQuest        = ((NonPlayerCharacter)c.Value).CurrentQuest;
                }
                else
                {
                    character = new CharacterData();
                }

                character.Name        = c.Value.Entity.EntityName;
                character.Gender      = c.Value.Entity.Gender;
                character.TextureName = c.Value.Sprite.Texture.Name;
                character.Head        = new GameItemData();
                character.Torso       = new GameItemData();
                character.Feet        = new GameItemData();
                character.Hands       = new GameItemData();
                character.MainHand    = new GameItemData();
                character.OffHand     = new GameItemData();
                character.EntityData  = new EntityData(
                    c.Value.Entity.EntityName,
                    c.Value.Entity.Level,
                    c.Value.Entity.Strength,
                    c.Value.Entity.Dexterity,
                    c.Value.Entity.Cunning,
                    c.Value.Entity.Willpower,
                    c.Value.Entity.Magic,
                    c.Value.Entity.Constitution,
                    c.Value.Entity.Health.MaximumValue,
                    c.Value.Entity.Stamina.MaximumValue,
                    c.Value.Entity.Mana.MaximumValue);

                charData.Characters.Add(c.Key, character);
            }

            FolderBrowserDialog fbDialog = new FolderBrowserDialog
            {
                Description  = "Select Game Folder",
                SelectedPath = Application.StartupPath
            };

            DialogResult result = fbDialog.ShowDialog();

            if (result == DialogResult.OK)
            {
                if (!File.Exists(fbDialog.SelectedPath + @"\Game.xml"))
                {
                    MessageBox.Show("Game not found", "Error");
                    return;
                }

                string LevelPath = Path.Combine(fbDialog.SelectedPath, @"Levels\");
                string MapPath   = Path.Combine(LevelPath, @"Maps\");
                string CharPath  = Path.Combine(LevelPath, @"Chars\");

                if (!Directory.Exists(LevelPath))
                {
                    Directory.CreateDirectory(LevelPath);
                }

                if (!Directory.Exists(MapPath))
                {
                    Directory.CreateDirectory(MapPath);
                }

                if (!Directory.Exists(CharPath))
                {
                    Directory.CreateDirectory(CharPath);
                }

                XnaSerializer.Serialize <LevelData>(
                    LevelPath + levelData.LevelName + ".xml",
                    levelData);

                XnaSerializer.Serialize <MapData>(
                    MapPath + mapData.MapName + ".xml",
                    mapData);

                XnaSerializer.Serialize <CharacterLayerData>(
                    CharPath + levelData.LevelName + ".xml",
                    charData);
            }
        }