Exemplo n.º 1
0
        /// <summary>
        /// Tries to get the first available entity ID.
        /// </summary>

        /// <returns>a non-zero ID if one was available; 0 otheriwse</returns>
        /// <remarks>If an available ID is found, it will be removed from the database.</remarks>
        public static uint GetLowEntityId(ObjectTypeId type)
        {
            // Lock so someone else doesn't grab the same row
            s_idLock.Enter();

            try
            {
                EntityIdStorage eid = GetFirstRecycledId(type);

                if (eid == null)
                {
                    return(0);
                }
                else
                {
                    RemoveRecycledId(eid);

                    return((uint)eid.EntityId);
                }
            }
            finally
            {
                s_idLock.Exit();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Recycles an entity ID of the given type.
        /// </summary>
        /// <param name="lowerEntityId">the lower entity id</param>

        public static bool RecycleLowerEntityId(uint lowerEntityId, ObjectTypeId idType)
        {
            if (DoesIdExist(lowerEntityId, idType))
            {
                // TODO: What should we do if it already exists? This is are a serious bug.
                s_log.Debug(Resources.AlreadyRecycledEntityId, lowerEntityId.ToString(), idType.ToString());

                return(false);
            }

            EntityIdStorage eid = new EntityIdStorage();

            eid.EntityId   = lowerEntityId;
            eid.EntityType = idType;

            AddRecycledId(eid);

            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Tries to get the first available player entity ID.
        /// </summary>

        /// <returns>a non-zero ID if one was available; 0 otheriwse</returns>
        /// <remarks>If an available ID is found, it will be removed from the database.</remarks>
        public static uint GetPlayerEntityId()
        {
            // Lock so someone else doesn't grab the same row
            s_idLock.Enter();

            try
            {
                EntityIdStorage eid = GetFirstRecycledId(ObjectTypeId.Player);

                if (eid == null)
                {
                    if (CharacterRecord.Exists())
                    {
                        if (s_highestPlayerId == 0)
                        {
                            CharacterRecord highestChr =
                                CharacterRecord.FindFirst(new Order("_entityLowId", false));

                            s_highestPlayerId = highestChr.EntityLowId;
                        }
                    }

                    return(++s_highestPlayerId);
                }
                else
                {
                    RemoveRecycledId(eid);

                    return((uint)eid.EntityId);
                }
            }
            catch (Exception ex)
            {
                s_log.ErrorException("couldn't get an entity id", ex);
            }
            finally
            {
                s_idLock.Exit();
            }

            return(0);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Tries to get the first available player entity ID.
        /// </summary>

        /// <returns>a non-zero ID if one was available; 0 otheriwse</returns>
        /// <remarks>If an available ID is found, it will be removed from the database.</remarks>
        public static uint GetItemEntityId()
        {
            // Lock so someone else doesn't grab the same row
            s_idLock.Enter();

            try
            {
                EntityIdStorage eid = GetFirstRecycledId(ObjectTypeId.Item);

                if (eid == null)
                {
                    //if (ItemRecord.Exists())
                    if (s_highestItemId == 0)
                    {
                        //ItemRecord highestItem =
                        //	ItemRecord.FindFirst(new Order("_entityId", false));

                        //s_highestItemId = highestItem.EntityId;
                        s_highestItemId = 1;
                    }

                    return(++s_highestItemId);
                }
                else
                {
                    RemoveRecycledId(eid);

                    return((uint)eid.EntityId);
                }
            }
            catch (Exception ex)
            {
                s_log.ErrorException("Could not fetch EntityId", ex);
            }
            finally
            {
                s_idLock.Exit();
            }

            return(0);
        }
Exemplo n.º 5
0
		/// <summary>
		/// Removes a recycled ID from the database.
		/// </summary>
		/// <param name="id">the ID to remove</param>
		public static void RemoveRecycledId(EntityIdStorage id)
		{
			id.DeleteAndFlush();
		}
Exemplo n.º 6
0
		/// <summary>
		/// Adds a new recycled ID to the database.
		/// </summary>
		/// <param name="id">the ID to add</param>
		public static void AddRecycledId(EntityIdStorage id)
		{
			id.SaveCopyAndFlush();
		}
Exemplo n.º 7
0
		/// <summary>
		/// Recycles an entity ID of the given type.
		/// </summary>
		/// <param name="lowerEntityId">the lower entity id</param>
		
		public static bool RecycleLowerEntityId(uint lowerEntityId, ObjectTypeId idType)
		{
			if (DoesIdExist(lowerEntityId, idType))
			{
				// TODO: What should we do if it already exists? This is are a serious bug.
				s_log.Debug(Resources.AlreadyRecycledEntityId, lowerEntityId.ToString(), idType.ToString());

				return false;
			}

			EntityIdStorage eid = new EntityIdStorage();
			eid.EntityId = lowerEntityId;
			eid.EntityType = idType;

			AddRecycledId(eid);

			return true;
		}
Exemplo n.º 8
0
 /// <summary>
 /// Removes a recycled ID from the database.
 /// </summary>
 /// <param name="id">the ID to remove</param>
 public static void RemoveRecycledId(EntityIdStorage id)
 {
     id.DeleteAndFlush();
 }
Exemplo n.º 9
0
 /// <summary>
 /// Adds a new recycled ID to the database.
 /// </summary>
 /// <param name="id">the ID to add</param>
 public static void AddRecycledId(EntityIdStorage id)
 {
     id.SaveCopyAndFlush();
 }