Beispiel #1
0
        /// <summary>
        /// Deletes a <see cref="DataReader" /> that belongs to the <see cref="Subscriber" />.
        /// </summary>
        /// <remarks>
        /// <para>If the <see cref="DataReader" /> does not belong to the <see cref="Subscriber" />, the operation returns the error <see cref="ReturnCode.PreconditionNotMet" />.</para>
        /// <para>The deletion of a <see cref="DataReader" /> is not allowed if there are any existing <see cref="ReadCondition" /> or <see cref="QueryCondition" /> objects that are
        /// attached to the <see cref="DataReader" />. If the DeleteDataReader operation is called on a <see cref="DataReader" /> with any of these existing objects
        /// attached to it, it will return <see cref="ReturnCode.PreconditionNotMet" />.</para>
        /// <para>The DeleteDataReader operation must be called on the same <see cref="Subscriber" /> object used to create the <see cref="DataReader" />. If
        /// DeleteDataReader is called on a different <see cref="Subscriber" />, the operation will have no effect and it will return
        /// <see cref="ReturnCode.PreconditionNotMet" />.</para>
        /// </remarks>
        /// <param name="dataReader">The <see cref="DataReader" /> to be deleted.</param>
        /// <returns>The <see cref="ReturnCode" /> that indicates the operation result.</returns>
        public ReturnCode DeleteDataReader(DataReader dataReader)
        {
            if (dataReader == null)
            {
                return(ReturnCode.Ok);
            }

            ReturnCode ret = UnsafeNativeMethods.DeleteDataReader(_native, dataReader.ToNative());

            if (ret == ReturnCode.Ok)
            {
                EntityManager.Instance.Remove((dataReader as Entity).ToNative());
                ContainedEntities.Remove(dataReader);
            }

            return(ret);
        }
        public override void HandleComponentState(dynamic state)
        {
            var theState     = state as InventoryComponentState;
            var stateChanged = false;

            if (MaxSlots != theState.MaxSlots)
            {
                MaxSlots     = theState.MaxSlots;
                stateChanged = true;
            }

            var newEntities = new List <int>(theState.ContainedEntities);
            var toRemove    = new List <IEntity>();

            foreach (var e in ContainedEntities)
            {
                if (newEntities.Contains(e.Uid))
                {
                    newEntities.Remove(e.Uid);
                }
                else
                {
                    toRemove.Add(e);
                }
            }
            stateChanged = stateChanged || toRemove.Any() || newEntities.Any();
            foreach (var e in toRemove)
            {
                ContainedEntities.Remove(e);
            }

            foreach (var uid in newEntities)
            {
                ContainedEntities.Add(Owner.EntityManager.GetEntity(uid));
            }

            if (stateChanged && Changed != null)
            {
                Changed(this, MaxSlots, ContainedEntities);
            }
        }