public ZoneGroundSpawns(MySqlConnection connection, string zone, Database.QueryConfig config)
            : base(config)
        {
            SubscribeToChanges();

            _connection = connection;
            _zone = zone;

            if (_connection == null)
            {
                throw new NullReferenceException();
            }

            var sql = String.Format(SelectString, SelectArgValues);
            var results = Database.QueryHelper.RunQuery(_connection, sql);

            var v = _queries.SelectQueryFields.FirstOrDefault(x => x.Property == "ZoneId");
            string zoneIdField = null;
            if (v != null)
            {
                zoneIdField = v.Column;
            }

            foreach (var row in results)
            {
                var gspawn = new GroundSpawn(_queryConfig);
                if (zoneIdField != null && row.ContainsKey(zoneIdField))
                {
                    _zoneId = Int32.Parse(row[zoneIdField].ToString());
                }
                gspawn.SetProperties(Queries, row);
                gspawn.Created();
                this.GroundSpawns.Add(gspawn);
            }
        }
 public void ShowSpawn(GroundSpawn spawn, DisplayFlags flags=DisplayFlags.None)
 {
     if (spawn == null) return;
     CreateSpawn(spawn,flags);
 }
        private void HideSpawn(GroundSpawn spawn)
        {
            Model3DGroup group = Model as Model3DGroup;
            Model3DCollection collection = new Model3DCollection();

            if (_mapping.ContainsKey(spawn))
            {
                foreach (Model3D model in _mapping[spawn])
                {
                    group.Children.Remove(model);
                }
            }
        }
        private void CreateSpawn(GroundSpawn spawn,DisplayFlags flags)
        {
            Model3DGroup group = Model as Model3DGroup;
            Model3DCollection collection = new Model3DCollection();

            if (_mapping.ContainsKey(spawn))
            {
                foreach (Model3D model in _mapping[spawn])
                {
                    group.Children.Remove(model);
                }
            }

            Point3D p = new Point3D(
                (spawn.MaxX + spawn.MinX) / 2,
                (spawn.MaxY + spawn.MinY) / 2,
                spawn.MaxZ);

            if (!Clipping.DrawPoint(p)) return;

            var xlen = spawn.MaxX - spawn.MinX;
            var ylen = spawn.MaxY - spawn.MinY;

            xlen = xlen <= 0 ? 4 : xlen;
            ylen = ylen <= 0 ? 4 : ylen;

            MeshBuilder builder = new MeshBuilder();
            builder.AddBox(p, ylen, xlen, 2);

            GeometryModel3D box = new GeometryModel3D(builder.ToMesh(), Materials.Gold);

            collection.Add(box);

            if ( flags != DisplayFlags.None )
            {
                var scale = 1.25;
                builder = new MeshBuilder();

                if (flags.HasFlag(DisplayFlags.DarkGrayAura))
                {
                    builder.AddBox(p, ylen * scale, xlen * scale, 1);
                    box = new GeometryModel3D(builder.ToMesh(), Materials.DarkGray);
                    collection.Add(box);
                }
                else if (flags.HasFlag(DisplayFlags.GreenAura))
                {
                    builder.AddBox(p, ylen * scale, xlen * scale, 1);
                    box = new GeometryModel3D(builder.ToMesh(), Materials.Green);
                    collection.Add(box);
                }
            }

            _mapping[spawn] = collection;

            foreach (Model3D model in collection)
            {
                group.Children.Add(model);
            }
        }