// 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(); } }
public int destroyAll() { int result = 0; clsObject obj = new clsObject(_db); result += obj.destroyAll(); clsAttribute attribute = new clsAttribute(_db); result += attribute.destroyAll(); return result; }
public List<clsAttribute> fromJSON(JArray JSONArray) { List<clsAttribute> results = new List<clsAttribute>(); // loop thorugh all the JSON obects in the JSON array foreach (JObject JSONObject in JSONArray) { clsAttribute attribute = new clsAttribute(_db); // create new blank template attribute.fromJSON(JSONObject); // load template based on JSON Object results.Add(attribute); // add new template to results } return results; }
public new bool fromJSON(JObject JSONObj) { bool result = base.fromJSON(JSONObj); this.save(); // check for templateAtributes if (JSONObj["attributes"] != null) { JArray JSONArray = (JArray)JSONObj["attributes"]; // convert to attribute objects clsAttribute attribute = new clsAttribute(_db); attribute.objectId = this.id; List<clsAttribute> attributes = attribute.fromJSON(JSONArray); foreach (clsAttribute a in attributes) { a.objectId = this.id; // we will not know our template id until was save our template a.save(); } } return result; }
// destroys all objects in a particular area and container. (0 is not in a container) public int destroyArea(int x1, int y1, int x2, int y2, int containerId = 0) { util.sort(ref x1, ref x2); util.sort(ref y1, ref y2); int result = 0; // destroy objects result += this.execute("DELETE FROM " + this.tableName + "s WHERE x>=" + x1 + " AND y>=" + y1 + " AND x<=" + x2 + " AND y<=" + y2 + " AND containerId = " + containerId); // destroy disconnected objects result += this.destroyDisconnected(); // destroy disconnected attributes clsAttribute attribute = new clsAttribute(_db); result += attribute.destroyDisconnected(); return result; }
public int destroyContents(bool internalUseOnly = true) { int result = 0; // execute this same function for the imeadiate contents of each of this objects imeadiate contents List<clsObject> objects = this.getList("SELECT * FROM " + this.tableName + "s WHERE containerId = " + this.id + ";"); foreach (clsObject obj in objects) { result += obj.destroyContents(false); } // delete this objects imeadiate contents in one call result += this.execute("DELETE FROM " + this.tableName + "s WHERE containerId = " + this.id + ";"); // once all objects and their contents are destroyed then destroy all disconnected attributes in one call if (internalUseOnly == true) { clsAttribute attribute = new clsAttribute(_db); attribute.destroyDisconnected(); } return result; }