public PortalRequestProcessor( int character_id, Point3d portal_position, float portal_angle, int portal_id) { m_character_id = character_id; m_portal_position = new Point3d(portal_position); m_portal_angle = portal_angle; m_portal_id = portal_id; m_world = null; m_room = null; m_opposing_room = null; m_portal = null; m_opposing_portal = null; m_opposing_portal_position = new Point3d(); m_current_room_key = null; m_opposing_room_key = null; m_current_character_position = new Point3d(); m_current_character_angle = 0.0f; m_game_id = -1; m_move_to_target = false; m_result_event_list = null; }
public FullGameStateRequestProcessor( int character_id) { m_character_id = character_id; m_world = null; m_game_id = -1; }
public SpawnMobsRequestProcessor( World world, Room room) { m_world = world; m_room = room; m_chosenMobSpawners = new List<MobSpawner>(); m_newMobs = new List<Mob>(); }
public AIMoveRequestProcessor( RoomKey roomKey) { m_roomKey = new RoomKey(roomKey); m_world = null; m_room = null; m_mobContexts = new List<MobUpdateContext>(); m_relevantGameEvents = new List<GameEventParameters>(); m_playerPaths = new List<EntityPath>(); }
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 HackEnergyTankRequestProcessor( int character_id, int energy_tank_id) { m_character_id = character_id; m_energy_tank_id = energy_tank_id; m_world = null; m_room = null; m_energy_tank = null; m_current_room_key = null; m_current_character_position = new Point3d(); m_current_character_angle = 0.0f; m_game_id = -1; m_move_to_target = false; m_ai_relevant_events = new List<GameEventParameters>(); m_result_event_list = null; }
public MoveRequestProcessor( int character_id, Point3d target_position, float target_angle) { m_character_id = character_id; m_target_position = new Point3d(target_position); m_target_angle = target_angle; m_world = null; m_room = null; m_current_room_key = null; m_current_character_position = new Point3d(); m_current_character_angle = 0.0f; m_game_id = -1; m_ai_relevant_events = new List<GameEventParameters>(); m_result_event_list = null; }
//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 World LazyLoadWorld( AsyncRPGDataContext db_context, int game_id) { World world = new World( this, WorldQueries.GetWorldGenerationParameters(db_context, game_id), game_id); return world; }
public RoomRequestProcessor( RoomKey roomKey) { m_room_key = new RoomKey(roomKey); m_world = null; }
public static void InsertWorld( AsyncRPGDataContext db_context, World world) { Dictionary<int, Portal> portalIdMap = new Dictionary<int, Portal>(); Dictionary<int, int> portalIdRemapping = new Dictionary<int, int>(); Dictionary<int, int> reversePortalIdRemapping = new Dictionary<int, int>(); // Insert all the rooms and portals with their initial IDs { foreach (Room room in world.Rooms) { // Save each room into the database { Rooms dbRoom = new Rooms { X = room.room_key.x, Y = room.room_key.y, Z = room.room_key.z, GameID = world.GameID, RandomSeed = room.random_seed, StaticData = JsonMapper.ToJson(room.static_room_data) }; db_context.Rooms.InsertOnSubmit(dbRoom); db_context.SubmitChanges(); } // Save each portal into the database foreach (Portal portal in room.portals) { Portals dbPortal = new Portals { PortalType = (int)portal.portal_type, TargetPortalID = -1, GameID = world.GameID, RoomX = portal.room_x, RoomY = portal.room_y, RoomZ = portal.room_z, RoomSide = (int)portal.room_side, BboxX0 = portal.bounding_box.Min.x, BboxY0 = portal.bounding_box.Min.y, BboxX1 = portal.bounding_box.Max.x, BboxY1 = portal.bounding_box.Max.y }; db_context.Portals.InsertOnSubmit(dbPortal); db_context.SubmitChanges(); portalIdMap.Add(portal.portal_id, portal); portalIdRemapping.Add(portal.portal_id, dbPortal.PortalID); reversePortalIdRemapping.Add(dbPortal.PortalID, portal.portal_id); // Portal ID assignment has to happen after all the portals are inserted } // Save each mob spawner to the database foreach (MobSpawner spawner in room.mobSpawners) { MobSpawners dbMobSpawner = new MobSpawners { GameID = world.GameID, RoomX = room.room_key.x, RoomY = room.room_key.y, RoomZ = room.room_key.z, X = spawner.Position.x, Y = spawner.Position.y, Z = spawner.Position.z, MobSpawnerTableID = spawner.SpawnTable.ID, RemainingSpawnCount = spawner.RemainingSpawnCount, RandomSeed = spawner.RandomSeed }; db_context.MobSpawners.InsertOnSubmit(dbMobSpawner); db_context.SubmitChanges(); // Assign an id once the spawner has been inserted into the DB spawner.ID = dbMobSpawner.MobSpawnerID; } // Save each energy tank to the database if (room is RoomLayout) { RoomLayout roomLayout = (RoomLayout)room; foreach (EnergyTank energyTank in roomLayout.energyTanks) { EnergyTanks dbEnergyTank = new EnergyTanks { GameID = world.GameID, RoomX = room.room_key.x, RoomY = room.room_key.y, RoomZ = room.room_key.z, X = energyTank.Position.x, Y = energyTank.Position.y, Z = energyTank.Position.z, Ownership = (int)energyTank.Faction, Energy = energyTank.Energy }; db_context.EnergyTanks.InsertOnSubmit(dbEnergyTank); db_context.SubmitChanges(); // Assign an id once the energy tank has been inserted into the DB energyTank.ID = dbEnergyTank.EnergyTankID; } // Drop the energy tanks now that we've saved them roomLayout.energyTanks = null; } } } // Fix up portal IDs { // Fixed the cached portal ids to match the ids in the database var query = from dbPortal in db_context.Portals where dbPortal.GameID == world.GameID select dbPortal; foreach (Portals dbPortal in query) { // Find the cache portal id from the db portal id using the reverse mapping int cachePortalId = reversePortalIdRemapping[dbPortal.PortalID]; // Get the cached portal using the cached portal Portal cachePortal = portalIdMap[cachePortalId]; // Remap the cached portal's target id to be a db portal id int dbTargetPortalId = portalIdRemapping[cachePortal.target_portal_id]; // Set the target portal id in the database dbPortal.TargetPortalID = dbTargetPortalId; // Fix-up the portal ids on the cached portal cachePortal.portal_id = dbPortal.PortalID; cachePortal.target_portal_id = dbTargetPortalId; } db_context.SubmitChanges(); } }
protected static bool LookupWorld( RequestCache requestCache, int game_id, out World world, out string result_code) { bool success; // Get the room data for the room that the player is currently in world = requestCache.GetWorld(game_id); if (world != null) { result_code = SuccessMessages.GENERAL_SUCCESS; success = true; } else { result_code = ErrorMessages.INVALID_WORLD; success = false; } return success; }