public Point3d world_position; // World space coordinates of the lower-left hand corner (min corner) #endregion Fields #region Constructors public Room(RoomKey rk) { room_key = rk; random_seed = rk.GetHashCode(); world_position.Set( (float)room_key.x * WorldConstants.ROOM_X_SIZE, (float)room_key.y * WorldConstants.ROOM_Y_SIZE, (float)room_key.z * WorldConstants.ROOM_Z_SIZE); portalRoomSideBitmask = new TypedFlags<MathConstants.eSignedDirection>(); connectivity_id= -1; portals = new List<Portal>(); mobSpawners = new List<MobSpawner>(); static_room_data = new StaticRoomData(); static_room_data.room_template_name = ""; static_room_data.objects = null; runtime_nav_mesh = new NavMesh(); }
//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 bool GetRoom( AsyncRPGDataContext context, RoomKey roomKey, out Point3d world_position, out PortalEntry[] portals, out StaticRoomData staticRoomData, out string result) { Room cached_room = null; bool success = GetRoom( context, roomKey, out cached_room, out result); if (success && cached_room != null) { world_position= new Point3d(cached_room.world_position); portals = new PortalEntry[cached_room.portals.Count]; for (int portal_index = 0; portal_index < cached_room.portals.Count; ++portal_index) { portals[portal_index] = new PortalEntry(); portals[portal_index].id = cached_room.portals[portal_index].portal_id; portals[portal_index].target_portal_id = cached_room.portals[portal_index].target_portal_id; portals[portal_index].x0 = cached_room.portals[portal_index].bounding_box.Min.x; portals[portal_index].y0 = cached_room.portals[portal_index].bounding_box.Min.y; portals[portal_index].x1 = cached_room.portals[portal_index].bounding_box.Max.x; portals[portal_index].y1 = cached_room.portals[portal_index].bounding_box.Max.y; } staticRoomData = cached_room.static_room_data; } else { world_position = new Point3d(); portals = null; staticRoomData = null; } return success; }