// TODO: Generally we should create static spawner behaviors that exist in the world, which in turn spawn mobs, // since we probably shouldn't try to persist mob instances in the world. (It would get barren quickly.) /// <summary>Gets a list of mobiles that should exist for the specified room.</summary> /// <param name="roomId">The ID of the room.</param> /// <returns>A list of mobile data structures for mobiles that start in this room.</returns> public static ICollection <MobRecord> GetMobsForRoom(this RelationalRepository <MobRecord> repository, long roomId) { using (IDbCommand session = Helpers.OpenRelationalSession()) { return(session.Connection.Select <MobRecord>("CurrentRoomID = {0}", roomId)); } }
/// <summary>Gets the rooms for area.</summary> /// <param name="repository">The Area repository.</param> /// <param name="areaId">The id for the area that will be worked upon.</param> /// <returns>Returns an collection of RoomRecord objects.</returns> public static ICollection <RoomRecord> GetRoomsForArea(this RelationalRepository <AreaRecord> repository, long areaId) { using (IDbCommand session = Helpers.OpenRelationalSession()) { return(session.Connection.Select <RoomRecord>("AreaID = {0}", areaId)); } }
/// <summary>Loads the exits for a room.</summary> /// <param name="roomId">The room id used to load the exits.</param> /// <returns>Returns a collection of ExitRecord objects.</returns> public static ICollection <ExitRecord> LoadExitsForRoom(this RelationalRepository <RoomRecord> repository, long roomId) { using (IDbCommand session = Helpers.OpenRelationalSession()) { // Return just "standard" exits, where this room is the primary owner. return(session.Connection.Select <ExitRecord>("ExitRoomAID = {0}", roomId)); } }
/// <summary>Loads the alias entries for a given help topic.</summary> /// <param name="helpTopicId">The ID of the parent help topic</param> /// <returns>List of Help Topic Alias records</returns> public static List <HelpTopicAliasRecord> LoadAliasForTopic(this RelationalRepository <HelpTopicRecord> repository, long helpTopicId) { string sql = @"SELECT * FROM HelpTopicAliases WHERE HelpTopicID = {0}"; using IDbCommand session = Helpers.OpenRelationalSession(); return(session.Connection.Select <HelpTopicAliasRecord>(sql, helpTopicId)); }
/// <summary>Deletes a list of roles from a player.</summary> /// <param name="playerId">The id of the player that will have roles removed.</param> public static void DeleteAllRolesForPlayer(this RelationalRepository <PlayerRoleRecord> repository, long playerId) { ICollection <PlayerRoleRecord> playerRoleRecords = repository.FetchAllPlayerRoleRecordsForPlayer(playerId); foreach (var playerRoleRecord in playerRoleRecords) { repository.Remove(playerRoleRecord); } }
/// <summary>Adds a list of roles to a player.</summary> /// <param name="roles">The roles that will be added to a player.</param> public static void AddRolesToPlayer(this RelationalRepository <PlayerRoleRecord> repository, List <PlayerRoleRecord> roles) { foreach (var role in roles) { if (role.ID == 0) { repository.Add(role); } else { repository.Update(role); } } }
/// <summary>Gets a list of RoleRecords for a specific player</summary> /// <param name="playerId">The player Id for which we want roles loaded.</param> /// <returns>Returns a list of RoleRecords, if any, for the specified player Id.</returns> public static List <RoleRecord> GetPlayerRoles(this RelationalRepository <PlayerRecord> repository, long playerId) { const string sql = @"SELECT DISTINCT pr.RoleID As ID, r.Name, r.SecurityRoleMask FROM PlayerRoles pr INNER JOIN Roles r ON pr.RoleID = r.ID WHERE pr.PlayerID = {0}"; using (IDbCommand session = Helpers.OpenRelationalSession()) { return(session.Connection.Select <RoleRecord>(sql, playerId)); } }
/// <summary>Gets a role record that is associated with the role name.</summary> /// <param name="roleName">The user name to look up a role.</param> /// <returns>Returns a role record loaded with the role's data.</returns> public static RoleRecord GetRoleByName(this RelationalRepository <RoleRecord> repository, string roleName) { RoleRecord roleRecord; using (IDbCommand session = Helpers.OpenRelationalSession()) { if ("sqlite".Equals(AppConfigInfo.Instance.RelationalDataProviderName, StringComparison.OrdinalIgnoreCase)) { var sql = new StringBuilder(); sql.Append("SELECT * FROM Roles "); sql.Append("WHERE Name = {0} "); sql.Append(" COLLATE NOCASE "); roleRecord = session.Connection.Select <RoleRecord>(sql.ToString(), roleName).First(); } else { roleRecord = session.Connection.Select <RoleRecord>("Name = {0}", roleName).First(); } } return(roleRecord); }
/// <summary>Fetches all player role records for player.</summary> /// <param name="playerId">The player id that will be used to retrieve the roles.</param> /// <returns>A list of PlayerRoleRecord objects.</returns> public static ICollection <PlayerRoleRecord> FetchAllPlayerRoleRecordsForPlayer(this RelationalRepository <PlayerRoleRecord> repository, long playerId) { long id = playerId; using (IDbCommand session = Helpers.OpenRelationalSession()) { return(session.Connection.Select <PlayerRoleRecord>("PlayerID = {0}", id)); } }