public override EntityAbstract Clone()
 {
     string oldEntity = this.ToEString();
     oldEntity = oldEntity.Substring(3);
     EntityTemplate newEntityTemplate = new EntityTemplate(oldEntity);
     return newEntityTemplate;
 }
 public Entity(EntityTemplate tmpTemplate, int lvl)
     : base(tmpTemplate.id,tmpTemplate.name)
 {
     this.maxHP = tmpTemplate.getBaseHP() * lvl;
     this.level = lvl;
     this.speed = tmpTemplate.getSpeed();
     this.currentDamage = 0;
     this.equipWeapon(tmpTemplate.getEquipedWeapon());
     Thread.Sleep(1);
 }
 private void btnAddEdit_Click(object sender, EventArgs e)
 {
     if (selectedEntityID == -1)
     {
         int tmpID = this._entityWrapper.getNextID();
         Weapon selectedWep = (Weapon) this._weaponWrapper.getItem(this.selectedWeaponID);
         EntityTemplate tmpNewEntityTemplate = new EntityTemplate(tmpID, this.txtName.Text, (int)this.nLevel.Value, selectedWep,(int) nBaseHP.Value,(int)this.nSpeed.Value);
         this._entityWrapper.AddEntity(tmpNewEntityTemplate);
         this.populateDataGrid();
     }
     else
     {
         int tmpID = selectedEntityID;
         Weapon selectedWep = (Weapon)this._weaponWrapper.getItem(this.selectedWeaponID);
         EntityTemplate tmpNewEntityTemplate = new EntityTemplate(tmpID, this.txtName.Text, (int)this.nLevel.Value, selectedWep, (int)nBaseHP.Value, (int)this.nSpeed.Value);
         this._entityWrapper.AddEntity(tmpNewEntityTemplate);
         this.populateDataGrid();
     }
     changesSaved = false;
     clearInfo();
 }
        /// <summary>
        /// Creates the wrapper for the specified type. Current valid types are:
        /// 
        /// "Entity"
        /// "Player Entity"
        /// "Generated Entity"
        /// "Entity Template"
        /// 
        /// </summary>
        /// <param name="tmpType"></param>
        public EntityTemplateWrapper(string tmpType)
        {
            this._EntityEncrypter = new EncrypterDecrypter();
            this._EntityEncrypter.setKey(this._key);
            if (tmpType == "Entity Template")
            {

                this.bLogger = new BasicLogger(this._ETLog);
                this._ActivePath = this._ETPath;
                string encryptedEntities = this._EntityEncrypter.decryptFile(this._ETPath);
                if (encryptedEntities.Length > 0)
                {
                    int TotalEntries = ParseItems.parseIntFrom(encryptedEntities, 4);
                    encryptedEntities = encryptedEntities.Substring(4);
                    int i = 0;
                    while (i < TotalEntries)
                    {
                        int lengthOfEntity = ParseItems.parseIntFrom(encryptedEntities, 3);
                        encryptedEntities = encryptedEntities.Substring(3);
                        this.bLogger.Log("Attempting to decrypt: " + encryptedEntities.Substring(0, lengthOfEntity), debug);
                        EntityTemplate newEntity = new EntityTemplate(encryptedEntities.Substring(0, lengthOfEntity));
                        encryptedEntities = encryptedEntities.Substring(lengthOfEntity);
                        this._listOfEntities.Add(newEntity);
                        this._usedIDs.Add(newEntity.id);
                        i++;
                    }
                }

            }
            else
            {
                this.bLogger = new BasicLogger(this._ActivePath);
                bLogger.Log("ItemWrapper:ItemWrapper(Type): - Critical Error - Invalid ItemType");
                MessageBox.Show("Critical Error, please see crit.err");
                Environment.FailFast("Invalid Type");
            }
        }
 public EntityTemplate Clone()
 {
     string oldEntity = this.ToEString();
     oldEntity = oldEntity.Substring(3);
     EntityTemplate newEntityTemplate = new EntityTemplate(oldEntity);
     return newEntityTemplate;
 }
        public bool AddEntity(EntityTemplate tmpNewEntity)
        {
            bool added = false;

            //Loops through all pre-exsisting Entities and adds if a matchis found
            for (int i = 0; i < this._listOfEntities.Count; i++)
            {
                if (this._listOfEntities[i].id == tmpNewEntity.id)
                {
                    this._listOfEntities[i] = tmpNewEntity;
                    added = true;
                }
            }

            //If no match is found then add new entry
            if (!added)
            {
                this._listOfEntities.Add(tmpNewEntity);
                if (!this._usedIDs.Contains(tmpNewEntity.id))
                {
                    this._usedIDs.Add(tmpNewEntity.id);
                }
                added = true;
            }

            return added;
        }
        public bool removeEntity(EntityTemplate tmpRemoveEntity)
        {
            bool removed = false;

            for (int i = 0; i < this._listOfEntities.Count; i++)
            {
                if (this._listOfEntities[i].id == tmpRemoveEntity.id)
                {
                    this._usedIDs.Remove(tmpRemoveEntity.id);
                    this._listOfEntities.RemoveAt(i);
                    removed = true;
                }
            }

            return removed;
        }