Пример #1
0
        // create an object from a template
        public clsObject(clsDatabase db, int x,int y, int z, clsTemplate template): base(db)
        {
            this.x = x;
            this.y = y;
            this.z = z;

            this.type = template.type;
            this.name = template.name; // this should be the attribute name not the template name
            this.image = template.image;
            this.weight = template.weight;
            this.stackable = template.stackable;
            this.blocking = template.blocking;
            this.save();

            // loop through template attibutes and use them to create object
            foreach (clsTemplateAttribute ta in template.templateAttributes)
            {
                // copy paste right now but could have random numbers, names etc....
                clsAttribute a = new clsAttribute(_db);
                a.objectId = this.id;
                a.name = ta.name;
                a.value = ta.value;
                a.save();
            }
        }
Пример #2
0
        public int destroyAll()
        {
            int result = 0;

            // destroy templates
            clsTemplate template = new clsTemplate(db);
            result += template.destroyAll();

            // destroy template attributes
            clsTemplateAttribute templateAttribute = new clsTemplateAttribute(db);
            result += templateAttribute.destroyAll();

            this.map.destroyAll(); // destroy objects and attributes

            return result;
        }
Пример #3
0
        public List<clsTemplate> fromJSON(JArray JSONArray)
        {
            List<clsTemplate> results = new List<clsTemplate>();

            // loop thorugh all the JSON obects in the JSON array
            foreach (JObject JSONObject in JSONArray)
            {
                clsTemplate template = new clsTemplate(_db); // create new blank template
                template.fromJSON(JSONObject); // load based on JSON Object
                results.Add(template); // add new to results
            }
            return results;
        }
Пример #4
0
 public List<clsTemplate> getAllTemplates()
 {
     clsTemplate template = new clsTemplate(this.db);
     return template.getAllTemplates();
 }
Пример #5
0
 // only the worl object has access to template this may get promoted
 public clsObject createObject(int x, int y, int z, clsTemplate template)
 {
     return new clsObject(_db, x, y, z, template);
 }
Пример #6
0
        public string SaveMap(clsPoint worldLocation)
        {
            int size = heights.GetLength(0);

            // clear block
            clsPoint worldLocationBotRight = new clsPoint(worldLocation.x + heights.Length - 1, worldLocation.y + heights.Length - 1);
            this.destroyArea(worldLocation, worldLocationBotRight);

            // load templates
            clsTemplate template = new clsTemplate(_db);
            List<clsTemplate> templates = template.getAllTemplates();

            int waterLevel = 0;

            // save results to database
            clsObject obj = new clsObject(_db);
            List<clsObject> results = new List<clsObject>();
            for (int y = 0; y < size; y++)
            {
                for (int x = 0; x < size; x++)
                {
                    obj = this.createObject((int)worldLocation.x + x, (int)worldLocation.y + y, heights[x, y] * 32, templates.Find(i => i.name.Contains("MC Grass")));

                    if (heights[x, y] < waterLevel)
                    {
                        for (int z = heights[x, y] + 1; z <= waterLevel; z++)
                        {
                            obj = this.createObject((int)worldLocation.x + x, (int)worldLocation.y + y, z * 32, templates.Find(i => i.name.Contains("MC Water")));
                        }
                    }

                }
            }

            // height map to JSON
            string JSON;
            JSON = "{";
            JSON = "\"objectsCreated\":" + results.Count + "";
            JSON += "}";
            return JSON;

        }