/// <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); }