public static void BindCharacterToGame( AsyncRPGDataContext context, int character_id, int new_game_id) { // Get the most recent event that occurred in the new game int last_game_event_id = GameEventQueries.GetLastGameEvent(context, new_game_id); // Tell the character which game they are bound to // and set an initial location var dbCharacter = (from c in context.Characters where c.CharacterID == character_id select c).Single(); dbCharacter.GameID = new_game_id; dbCharacter.RoomX = 0; dbCharacter.RoomY = 0; dbCharacter.RoomZ = 0; dbCharacter.X = 0; dbCharacter.Y = 0; dbCharacter.Z = 0; dbCharacter.Angle = 0; dbCharacter.LastSentEventID = last_game_event_id; dbCharacter.NewEventsPosted = false; context.SubmitChanges(); }
public static void DeleteCharacter( AsyncRPGDataContext context, int character_id) { context.Characters.DeleteOnSubmit(context.Characters.Single(c => c.CharacterID == character_id)); context.SubmitChanges(); }
// Database Config Interface //-------------------------- public static void InitializeConfig( AsyncRPGDataContext context, int version, string appUrl, string appDebugUrl, string clientUrl, string emailAddress, string emailHost, int emailPort, string emailUsername, string emailPassword, string ircServer, int ircPort) { Config config = new Config { Version = version, AppURL = appUrl, AppDebugURL = appDebugUrl, ClientURL = clientUrl, EmailAddress = emailAddress, EmailHost = emailHost, EmailPort = emailPort, EmailUserName = emailUsername, EmailPassword = emailPassword, IrcServer = ircServer, IrcPort = ircPort }; context.Configs.InsertOnSubmit(config); context.SubmitChanges(); }
public static void CreateCharacter( AsyncRPGDataContext context, int account_id, string name, GameConstants.eGender gender, GameConstants.eArchetype archetype, int picture_id) { Characters newCharacter = new Characters { AccountID= account_id, GameID= -1, RoomX = 0, RoomY = 0, RoomZ = 0, LastPingTime = DateTime.Now, LastSentEventID = -1, NewEventsPosted = false, X= 0.0f, Y= 0.0f, Z= 0.0f, Angle= 0.0f, Name= name, Gender = (gender == GameConstants.eGender.Male), Archetype = (int)archetype, PictureID = picture_id, PowerLevel= 1, Energy= 0 }; context.Characters.InsertOnSubmit(newCharacter); context.SubmitChanges(); }
public RequestCache( ICacheAdapter sessionCache, AsyncRPGDataContext dbContext) { m_sessionCache = sessionCache; m_dbContext = dbContext; m_requestRoomCache = null; }
public static string GetRoomStaticData( AsyncRPGDataContext context, RoomKey roomKey) { return (from r in context.Rooms where r.GameID == roomKey.game_id && r.X == roomKey.x && r.Y == roomKey.y && r.Z == roomKey.z select r.StaticData).Single(); }
public static int GetRoomRandomSeed( AsyncRPGDataContext context, RoomKey roomKey) { return (from r in context.Rooms where r.GameID == roomKey.game_id && r.X == roomKey.x && r.Y == roomKey.y && r.Z == roomKey.z select r.RandomSeed).Single(); }
public static bool DoesRoomExist( AsyncRPGDataContext context, RoomKey roomKey) { return (from r in context.Rooms where r.GameID == roomKey.game_id && r.X == roomKey.x && r.Y == roomKey.y && r.Z == roomKey.z select r).Count() > 0; }
public static EnergyTank GetEnergyTank( AsyncRPGDataContext db_context, int energyTankID) { return EnergyTank.CreateEnergyTank( (from e in db_context.EnergyTanks where e.EnergyTankID == energyTankID select e).Single()); }
public static Portal GetPortal( AsyncRPGDataContext context, int portal_id) { var dbPortal= (from p in context.Portals where p.PortalID == portal_id select p).Single(); return Portal.CreatePortal(dbPortal); }
public static void UpdateEnergyTankEnergy( AsyncRPGDataContext db_context, int energyTankID, int newEnergy) { var energyTankQuery = (from e in db_context.EnergyTanks where e.EnergyTankID == energyTankID select e).SingleOrDefault(); db_context.SubmitChanges(); }
public static void ClearCharacterNewEventFlag( AsyncRPGDataContext context, int character_id) { var query = (from c in context.Characters where c.CharacterID == character_id select c).Single(); query.NewEventsPosted = false; context.SubmitChanges(); }
public static WorldTemplate GetWorldGenerationParameters( AsyncRPGDataContext context, int game_id) { WorldTemplate worldTemplate = new WorldTemplate(); Games[] game = (from g in context.Games where g.GameID == game_id select g).ToArray<Games>(); worldTemplate.dungeon_size = (GameConstants.eDungeonSize)(game[0].DungeonSize); worldTemplate.dungeon_difficulty = (GameConstants.eDungeonDifficulty)(game[0].DungeonDifficulty); return worldTemplate; }
public static void UpdateEnergyTankOwnership( AsyncRPGDataContext db_context, int energyTankID, GameConstants.eFaction newOwnership) { var energyTankQuery = (from e in db_context.EnergyTanks where e.EnergyTankID == energyTankID select e).SingleOrDefault(); energyTankQuery.Ownership = (int)newOwnership; db_context.SubmitChanges(); }
public static int CreateGame( AsyncRPGDataContext context, int account_id, string game_name, GameConstants.eDungeonSize dungeonSize, GameConstants.eDungeonDifficulty dungeonDifficulty, bool irc_enabled, string irc_server, int irc_port, bool irc_encryption_enabled) { int new_game_id = -1; // Create a random 256-bit (32 byte) encryption key for encrypting chat string irc_encryption_key = RNGUtilities.CreateNonDeterministicRandomBase64String(256); Debug.Assert(irc_encryption_key.Length == 44); if (irc_server.Length == 0) { irc_server = IrcConstants.DEFAULT_IRC_SERVER; } if (irc_port < IrcConstants.LOWEST_VALID_IRC_PORT || irc_port > IrcConstants.HIGHEST_VALID_IRC_PORT) { irc_port = IrcConstants.DEFAULT_IRC_PORT; } { Games newGame = new Games { OwnerAccountID = account_id, Name = game_name, DungeonSize = (int)dungeonSize, DungeonDifficulty = (int)dungeonDifficulty, IrcEnabed = irc_enabled, IrcServer = irc_server, IrcPort = irc_port, IrcEncryptionKey = irc_encryption_key, IrcEncryptionEnabed = irc_encryption_enabled }; context.Games.InsertOnSubmit(newGame); context.SubmitChanges(); new_game_id = newGame.GameID; } return new_game_id; }
public static WorldBuilder GetWorldBuilder( AsyncRPGDataContext db_context, ICacheAdapter cache) { WorldBuilder worldBuilder = (WorldBuilder)cache["world_builder"]; if (worldBuilder == null) { worldBuilder = new WorldBuilder(); worldBuilder.Initialize(db_context); cache["world_builder"] = worldBuilder; } return worldBuilder; }
public bool BuildWorld( AsyncRPGDataContext db_context, int game_id, out World world, out string result) { bool success = true; WorldTemplate worldTemplate = null; DungeonLayout layout = null; world = null; result = SuccessMessages.GENERAL_SUCCESS; // Get the world generation parameters from the DB worldTemplate = WorldQueries.GetWorldGenerationParameters( db_context, game_id); // Create the initial set of rooms for the world if (success) { layout = new DungeonLayout(game_id, worldTemplate, m_roomTemplateSet, m_mobSpawnTableSet); if (!layout.BuildRoomLayout(out result)) { success = false; } } // Copy the rooms and portals from the layout into the world if (success) { world = new World(this, layout.LayoutWorldTemplate, game_id); world.ApplyLayout(layout); } // TODO: WorldBuilder: Generate the environment objects, etc // Save the cached world into the database if (success) { WorldQueries.InsertWorld(db_context, world); } return success; }
public static World GetWorld( AsyncRPGDataContext db_context, ICacheAdapter cache, int game_id) { string world_identifier = GetWorldCacheIdentifier(game_id); World world = (World)cache[world_identifier]; if (world == null) { world = WorldBuilderCache.GetWorldBuilder(db_context, cache).LazyLoadWorld(db_context, game_id); cache[world_identifier] = world; } return world; }
public static int GetDatabaseVersion( string connection_string) { int version = -1; try { AsyncRPGDataContext context = new AsyncRPGDataContext(connection_string); version = context.Configs.Take(1).Select(c => c.Version).SingleOrDefault(); } catch (System.Exception) { version = -1; } return version; }
public static List<Portal> GetRoomPortals( AsyncRPGDataContext context, RoomKey roomKey) { List<Portal> portals = new List<Portal>(); var query = from p in context.Portals where p.GameID == roomKey.game_id && p.RoomX == roomKey.x && p.RoomY == roomKey.y && p.RoomZ == roomKey.z select p; foreach (var dbPortal in query) { Portal portal = Portal.CreatePortal(dbPortal); portals.Add(portal); } return portals; }
public static bool BuildWorld( AsyncRPGDataContext db_context, ICacheAdapter cache, int game_id, out string result) { World world = null; bool success = WorldBuilderCache.GetWorldBuilder(db_context, cache).BuildWorld(db_context, game_id, out world, out result); if (success) { string world_identifier = GetWorldCacheIdentifier(game_id); cache[world_identifier] = world; } return success; }
public static List<EnergyTank> GetEnergyTanks( AsyncRPGDataContext db_context, RoomKey roomKey) { List<EnergyTank> energyTanks = new List<EnergyTank>(); var roomEnergyTankQuery = from e in db_context.EnergyTanks where e.GameID == roomKey.game_id && e.RoomX == roomKey.x && e.RoomY == roomKey.y && e.RoomZ == roomKey.z select e; foreach (EnergyTanks dbEnergyTank in roomEnergyTankQuery) { EnergyTank energyTank = EnergyTank.CreateEnergyTank(dbEnergyTank); energyTanks.Add(energyTank); } return energyTanks; }
public static void UpdateEnergyTank( AsyncRPGDataContext db_context, EnergyTank energyTank) { var dbEnergyTank = (from e in db_context.EnergyTanks where e.EnergyTankID == energyTank.ID select e).SingleOrDefault(); dbEnergyTank.GameID = energyTank.RoomKey.game_id; dbEnergyTank.RoomX = energyTank.RoomKey.x; dbEnergyTank.RoomY = energyTank.RoomKey.y; dbEnergyTank.RoomZ = energyTank.RoomKey.z; dbEnergyTank.X = energyTank.Position.x; dbEnergyTank.Y = energyTank.Position.y; dbEnergyTank.Z = energyTank.Position.z; dbEnergyTank.Ownership = (int)energyTank.Faction; dbEnergyTank.Energy = energyTank.Energy; db_context.SubmitChanges(); }
//TODO: LoadRoom - Convert this over to a request processor public static bool LoadRoom( AsyncRPGDataContext context, World world, RoomKey room_key, out Room room, out string result) { bool success; string json_static_data = WorldQueries.GetRoomStaticData(context, room_key); room = null; success = false; // Load static room data for this room if (json_static_data.Length > 0) { StaticRoomData static_room_data = null; try { if (json_static_data.Length == 0) { throw new ArgumentException(); } static_room_data = JsonMapper.ToObject<StaticRoomData>(json_static_data); } catch (System.Exception) { static_room_data = null; } if (static_room_data != null) { room = new Room(room_key); room.static_room_data = static_room_data; success = true; result = SuccessMessages.GENERAL_SUCCESS; } else { result = ErrorMessages.DB_ERROR + "(Failed to parse room static data)"; } } else { result = ErrorMessages.DB_ERROR + "(Failed to get room static data)"; } // If the static room data parsed, load everything else if (success) { RoomTemplate roomTemplate = world.RoomTemplates.GetTemplateByName(room.static_room_data.room_template_name); // Load the random seed for the room room.random_seed = WorldQueries.GetRoomRandomSeed(context, room_key); // Setup the runtime nav mesh room.runtime_nav_mesh = new NavMesh(room.room_key, roomTemplate.NavMeshTemplate); // Load all of the portals for this room room.portals = WorldQueries.GetRoomPortals(context, room_key); // Flag all of the room sides that have portals foreach (Portal p in room.portals) { room.portalRoomSideBitmask.Set(p.room_side, true); } // Load mob spawners for this room room.mobSpawners = MobQueries.GetMobSpawners(context, world.MobSpawnTables, room_key); } return success; }
public void Initialize(AsyncRPGDataContext db_context) { m_roomTemplates = WorldQueries.LoadRoomTemplates(db_context); }
public static void DeleteGame( AsyncRPGDataContext context, int gameid) { // Detach all of the Characters from the game { var query = from character in context.Characters where character.GameID == gameid select character; foreach (Characters character in query) { character.GameID = -1; character.RoomX = 0; character.RoomY = 0; character.RoomZ = 0; character.X = 0; character.Y = 0; character.Z = 0; character.Angle = 0; } context.SubmitChanges(); } // Free all of the portals { var query = from portal in context.Portals where portal.GameID == gameid select portal; foreach (Portals portal in query) { context.Portals.DeleteOnSubmit(portal); } context.SubmitChanges(); } // Free all of the mobs { var query = from mob in context.Mobs where mob.GameID == gameid select mob; foreach (Mobs mob in query) { context.Mobs.DeleteOnSubmit(mob); } context.SubmitChanges(); } // Free all of the mob spawners { var query = from mobSpawner in context.MobSpawners where mobSpawner.GameID == gameid select mobSpawner; foreach (MobSpawners mobSpawner in query) { context.MobSpawners.DeleteOnSubmit(mobSpawner); } context.SubmitChanges(); } // TODO DeleteGame: Delete loot // Free all of the rooms { var query = from room in context.Rooms where room.GameID == gameid select room; foreach (Rooms room in query) { context.Rooms.DeleteOnSubmit(room); } context.SubmitChanges(); } // Free all of the game_events associated from the game GameEventQueries.DeleteAllEventsForGame(context, gameid); // Finally, Free the game itself { var query = from game in context.Games where game.GameID == gameid select game; foreach (Games game in query) { context.Games.DeleteOnSubmit(game); } context.SubmitChanges(); } }
public static bool VerifyGameExists( AsyncRPGDataContext context, int gameid) { return (from g in context.Games where g.GameID == gameid select g).Count() > 0; }
public static bool VerifyAccountOwnsGame( AsyncRPGDataContext context, int account_id, int gameid) { return (from game in context.Games where game.GameID == gameid && game.OwnerAccountID == account_id select game).Count() > 0; }
public static void UnBindCharacterFromGame( AsyncRPGDataContext context, int character_id) { var dbCharacter = (from c in context.Characters where c.CharacterID == character_id select c).Single(); dbCharacter.GameID = -1; dbCharacter.RoomX = 0; dbCharacter.RoomY = 0; dbCharacter.RoomZ = 0; dbCharacter.X = 0; dbCharacter.Y = 0; dbCharacter.Z = 0; dbCharacter.Angle = 0; context.SubmitChanges(); }
public static string GetGameName( AsyncRPGDataContext context, int gameid) { return (from g in context.Games where g.GameID == gameid select g.Name).Single(); }