Example #1
0
        public void Validate()
        {
            for (int x = 0; x < TilesWide; x++)
            {
                OnProgressChanged(this,
                                  new ProgressChangedEventArgs((int)(x / (float)TilesWide * 100.0), "验证世界文件..."));

                for (int y = 0; y < TilesHigh; y++)
                {
                    Tile curTile = Tiles[x, y];

                    if (curTile.Type == (int)TileType.IceByRod)
                    {
                        curTile.IsActive = false;
                    }

                    ValSpecial(x, y);
                }
            }

            foreach (Chest chest in Chests.ToArray())
            {
                bool removed = false;
                for (int x = chest.X; x < chest.X + 1; x++)
                {
                    for (int y = chest.Y; y < chest.Y + 1; y++)
                    {
                        if (!Tiles[x, y].IsActive || !Tile.IsChest(Tiles[x, y].Type))
                        {
                            Chests.Remove(chest);
                            removed = true;
                            break;
                        }
                    }
                    if (removed)
                    {
                        break;
                    }
                }
            }

            foreach (Sign sign in Signs.ToArray())
            {
                if (sign.Text == null)
                {
                    Signs.Remove(sign);
                    continue;
                }

                bool removed = false;
                for (int x = sign.X; x < sign.X + 1; x++)
                {
                    for (int y = sign.Y; y < sign.Y + 1; y++)
                    {
                        if (!Tiles[x, y].IsActive || !Tile.IsSign(Tiles[x, y].Type))
                        {
                            Signs.Remove(sign);
                            removed = true;
                            break;
                        }
                    }
                    if (removed)
                    {
                        break;
                    }
                }
            }

            foreach (TileEntity tileEntity in TileEntities.ToArray())
            {
                int x = tileEntity.PosX;
                int y = tileEntity.PosY;
                if (!Tiles[x, y].IsActive || !Tile.IsTileEntity(Tiles[x, y].Type))
                {
                    TileEntities.Remove(tileEntity);
                }
            }

            OnProgressChanged(this,
                              new ProgressChangedEventArgs(0, "验证完整性..."));
            if (Chests.Count > 1000)
            {
                throw new ArgumentOutOfRangeException(string.Format("宝箱数量为 {0} 且大于1000.", Chests.Count));
            }
            if (Signs.Count > 1000)
            {
                throw new ArgumentOutOfRangeException(string.Format("标牌数量为 {0} 且大于1000.", Signs.Count));
            }
        }
Example #2
0
        public void Validate()
        {
            for (int x = 0; x < TilesWide; x++)
            {
                OnProgressChanged(this,
                                  new ProgressChangedEventArgs((int)(x / (float)TilesWide * 100.0), "Validating World..."));

                for (int y = 0; y < TilesHigh; y++)
                {
                    Tile curTile = Tiles[x, y];

                    if (curTile.Type == 127)
                    {
                        curTile.IsActive = false;
                    }

                    // TODO: Let Validate handle these
                    //validate chest entry exists
                    if (curTile.Type == 21 || curTile.Type == 88)
                    {
                        if (GetChestAtTile(x, y) == null)
                        {
                            Chests.Add(new Chest(x, y));
                        }
                    }
                    //validate sign entry exists
                    else if (curTile.Type == 55 || curTile.Type == 85)
                    {
                        if (GetSignAtTile(x, y) == null)
                        {
                            Signs.Add(new Sign(x, y, string.Empty));
                        }
                    }
                }
            }

            foreach (Chest chest in Chests.ToArray())
            {
                bool removed = false;
                for (int x = chest.X; x < chest.X + 1; x++)
                {
                    for (int y = chest.Y; y < chest.Y + 1; y++)
                    {
                        if (!Tiles[x, y].IsActive || (Tiles[x, y].Type != 21 && Tiles[x, y].Type != 88))
                        {
                            Chests.Remove(chest);
                            removed = true;
                            break;
                        }
                    }
                    if (removed)
                    {
                        break;
                    }
                }
            }

            foreach (Sign sign in Signs.ToArray())
            {
                if (sign.Text == null)
                {
                    Signs.Remove(sign);
                    continue;
                }

                bool removed = false;
                for (int x = sign.X; x < sign.X + 1; x++)
                {
                    for (int y = sign.Y; y < sign.Y + 1; y++)
                    {
                        if (!Tiles[x, y].IsActive || (Tiles[x, y].Type != 55 && Tiles[x, y].Type != 85))
                        {
                            Signs.Remove(sign);
                            removed = true;
                            break;
                        }
                    }
                    if (removed)
                    {
                        break;
                    }
                }
            }
        }
Example #3
0
        public void Validate()
        {
            var t = TaskFactoryHelper.UiTaskFactory.StartNew(() =>
            {
                for (int x = 0; x < TilesWide; x++)
                {
                    OnProgressChanged(this,
                                      new ProgressChangedEventArgs((int)(x / (float)TilesWide * 100.0), "Validating World..."));

                    for (int y = 0; y < TilesHigh; y++)
                    {
                        Tile curTile = Tiles[x, y];

                        if (curTile.Type == (int)TileType.IceByRod)
                        {
                            curTile.IsActive = false;
                        }

                        ValSpecial(x, y);
                    }
                }
            });

            foreach (Chest chest in Chests.ToArray())
            {
                bool removed = false;
                for (int x = chest.X; x < chest.X + 1; x++)
                {
                    for (int y = chest.Y; y < chest.Y + 1; y++)
                    {
                        if (!Tiles[x, y].IsActive || !Tile.IsChest(Tiles[x, y].Type))
                        {
                            Chests.Remove(chest);
                            removed = true;
                            break;
                        }
                    }
                    if (removed)
                    {
                        break;
                    }
                }
            }

            foreach (Sign sign in Signs.ToArray())
            {
                if (sign.Text == null)
                {
                    Signs.Remove(sign);
                    continue;
                }

                bool removed = false;
                for (int x = sign.X; x < sign.X + 1; x++)
                {
                    for (int y = sign.Y; y < sign.Y + 1; y++)
                    {
                        if (!Tiles[x, y].IsActive || !Tile.IsSign(Tiles[x, y].Type))
                        {
                            Signs.Remove(sign);
                            removed = true;
                            break;
                        }
                    }
                    if (removed)
                    {
                        break;
                    }
                }
            }


            foreach (TileEntity tileEntity in TileEntities.ToArray())
            {
                int x      = tileEntity.PosX;
                int y      = tileEntity.PosY;
                var anchor = GetAnchor(x, y);
                if (!Tiles[anchor.X, anchor.Y].IsActive || !Tile.IsTileEntity(Tiles[anchor.X, anchor.Y].Type))
                {
                    TaskFactoryHelper.ExecuteUiTask(() => TileEntities.Remove(tileEntity));
                }
            }

            OnProgressChanged(this,
                              new ProgressChangedEventArgs(0, "Validating Complete..."));
            if (Chests.Count > World.MaxChests)
            {
                throw new ArgumentOutOfRangeException($"Chest Count is {Chests.Count} which is greater than 1000");
            }
            if (Signs.Count > World.MaxSigns)
            {
                throw new ArgumentOutOfRangeException($"Sign Count is {Signs.Count} which is greater than 1000");
            }
        }