Example #1
0
        /// <summary>
        /// Used to transfer an entity between managers.
        /// </summary>
        /// <exception cref="InvalidOperationException">Thrown when trying to transfer the static InvalidEntity.</exception>
        /// <exception cref="ArgumentNullException">Thrown when the provided manager is null.</exception>
        public void Transfer([NotNull] EntityManager newManager)
        {
            if (!IsValid)
            {
                throw new InvalidOperationException("Cannot transfer an invalid entity.");
            }
            if (newManager == null)
            {
                throw new ArgumentNullException(nameof(newManager));
            }
            // Store dataBlobs.
            List <BaseDataBlob> dataBlobs = Manager.GetAllDataBlobsForEntity(ID);

            // Remove myself from the old manager.
            Manager.RemoveEntity(this);

            // Add myself the the new manager.
            Manager = newManager;
            newManager.SetupEntity(this, dataBlobs);

            /*
             * _protectedDataBlobMask_ = Manager.EntityMasks[ID];
             *
             * foreach (BaseDataBlob dataBlob in dataBlobs)
             * {
             *  SetDataBlob(dataBlob);
             * }*/
        }
Example #2
0
        internal Entity(Guid id, [NotNull] EntityManager manager, Guid factionOwner, IEnumerable <BaseDataBlob> dataBlobs = null)
        {
            Manager      = manager;
            Guid         = id;
            FactionOwner = factionOwner;
            //This is problematic, currently, if a datablob references it's own entity (ie namedb in faction entity) the entity will get a new guid.
            //and (presumably) the db will point to an empty entity.
            //TODO: should we throw an exception instead of just replacing the guid with a new one? I'm leaning towards yes.
            while (Guid == Guid.Empty || manager.EntityExistsGlobaly(Guid)) //using a while here removes the infintisimal chance of creating a guid that already exsists.
            {
                Guid = Guid.NewGuid();
            }

            Manager.SetupEntity(this, dataBlobs);

            /* Moved this to Manager.SetupEntity
             * _protectedDataBlobMask_ = Manager.EntityMasks[ID];
             *
             *
             * if (dataBlobs == null)
             * {
             *  return;
             * }
             *
             * foreach (BaseDataBlob dataBlob in dataBlobs)
             * {
             *  if (dataBlob != null)
             *  {
             *      SetDataBlob(dataBlob);
             *  }
             * }
             */
        }
Example #3
0
        internal Entity([NotNull] EntityManager manager, Guid id, IEnumerable <BaseDataBlob> dataBlobs = null)
        {
            Manager = manager;
            Guid    = id;

            Entity checkEntity;

            while (Guid == Guid.Empty || manager.FindEntityByGuid(Guid, out checkEntity))
            {
                Guid = Guid.NewGuid();
            }

            ID = Manager.SetupEntity(this);
            _protectedDataBlobMask_ = Manager.EntityMasks[ID];

            if (dataBlobs == null)
            {
                return;
            }

            foreach (BaseDataBlob dataBlob in dataBlobs)
            {
                if (dataBlob != null)
                {
                    SetDataBlob(dataBlob);
                }
            }
        }