public World LazyLoadWorld( AsyncRPGDataContext db_context, int game_id) { World world = new World( this, WorldQueries.GetWorldGenerationParameters(db_context, game_id), game_id); return(world); }
private void UpdateRoomRandomSeed( RequestCache requestCache) { Random random = new Random(m_room.random_seed); m_room.random_seed = random.Next(); // Save the random seed back to the room since we just burned a seed // REVIEW: UpdateRoomRandomSeed - Not sure if this will be determinism issues if another user enters the room // around the same time since this isn't updated as a transaction WorldQueries.UpdateRoomRandomSeed( requestCache.DatabaseContext, m_room.room_key, m_room.random_seed); }
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 bool GetRoom( AsyncRPGDataContext context, RoomKey room_key, out Room room, out string result) { bool success = true; room = null; result = SuccessMessages.GENERAL_SUCCESS; if (m_rooms.ContainsKey(room_key)) { room = m_rooms[room_key]; } else { if (!WorldQueries.DoesRoomExist(context, room_key)) { room = null; success = false; result = ErrorMessages.INVALID_ROOM; } if (success && !Room.LoadRoom(context, this, room_key, out room, out result)) { result = ErrorMessages.DB_ERROR; success = false; } // If we got a room, update the cache if (success) { m_rooms[room_key] = room; } } return(success); }
private bool LookupOpposingPortal( RequestCache requestCache, out string result_code) { bool success; // If the opposing portal doesn't exist yet, // create a new room adjacent to the current room with an opposing portal if (m_portal.target_portal_id != -1) { //If an opposing portal exists, retrieve it from the DB m_opposing_portal = WorldQueries.GetPortal( requestCache.DatabaseContext, m_portal.target_portal_id); m_opposing_room_key = new RoomKey( m_game_id, m_opposing_portal.room_x, m_opposing_portal.room_y, m_opposing_portal.room_z); // Compute our target position in the new room // Clamp the players position into the bounding box of the portal in the new room m_opposing_portal_position = m_opposing_portal.bounding_box.ClipPoint(m_portal_position); result_code = SuccessMessages.GENERAL_SUCCESS; success = true; } else { result_code = ErrorMessages.CACHE_ERROR; success = false; } return(success); }
//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 bool Initialize(string connectionString, out string result) { return(WorldQueries.LoadRoomTemplates(connectionString, out m_roomTemplates, out result)); }