public WorldScene(Scene scene, float boxSize, float boxTolerance) { using (new PerformanceLogger("[WorldScene] ctor", false)) { // Core.Logger.Debug("[WorldScene] Scene GridSquare Size: {0} X:{1} Y:{2}", scene.Mesh.Zone.NavZoneDef.GridSquareSize,scene.Mesh.Zone.NavZoneDef.NavGridSquareCountX, scene.Mesh.Zone.NavZoneDef.NavGridSquareCountY); _boxSize = boxSize; _boxTolerance = boxTolerance; //Scene = scene; var mesh = scene.Mesh; Name = scene.Name; HashName = scene.GetSceneNameString(); SnoId = scene.SceneInfo.SNOId; LevelAreaId = mesh.LevelAreaSnoId; Min = mesh.Zone.ZoneMin; Max = mesh.Zone.ZoneMax; Size = Max - Min; Center = (Max + Min) / 2; //Rect = new Rect(new Point(Center.X, Center.Y), new Size(_boxSize, _boxSize)); HasChild = mesh.SubSceneId > 0; HasParent = mesh.ParentSceneId > 0; IsIgnored = ExplorationData.IgnoreScenes.Contains(Name); DynamicWorldId = mesh.WorldId; NorthWest = Min; NorthEast = new Vector2(Min.X, Max.Y); SouthEast = Max; SouthWest = new Vector2(Max.X, Min.Y); if (ExplorationHelpers.BlacklistedPositionsBySceneSnoId.ContainsKey(SnoId)) { BlacklistedPositions = ExplorationHelpers.BlacklistedPositionsBySceneSnoId[SnoId]; } SceneId = scene.Mesh.SceneId; if (HasChild) { SubScene = new WorldScene(mesh.SubScene, boxSize, boxTolerance); } Core.Logger.Verbose("[WorldScene] Created a new world scene. Name: {0} LevelArea: {1} ({2})", Name, (SNOLevelArea)LevelAreaId, LevelAreaId); if (LevelAreaId != AdvDia.CurrentLevelAreaId && !ExplorationData.OpenWorldIds.Contains(AdvDia.CurrentWorldId)) { Core.Logger.Verbose("[WorldScene] The scene LevelAreaID is different than the CurrentLevelAreaID"); Core.Logger.Verbose("[WorldScene] Scene Name: {0}", Name); Core.Logger.Verbose("[WorldScene] Scene: {0} ({1})", (SNOLevelArea)LevelAreaId, LevelAreaId); Core.Logger.Verbose("[WorldScene] Current: {0} ({1})", (SNOLevelArea)AdvDia.CurrentLevelAreaId, AdvDia.CurrentLevelAreaId); } CreateGrid(mesh); if (!ExitPositions.Any()) { ScanExitDirection(SceneExitDirections.North); ScanExitDirection(SceneExitDirections.South); ScanExitDirection(SceneExitDirections.East); ScanExitDirection(SceneExitDirections.West); } } }
public IEnumerable <ConnectedSceneResult> GetConnectedScenes(WorldScene to) { var results = TryConnectScenes(this, to); if (results == null || !results.Any()) { return(Enumerable.Empty <ConnectedSceneResult>()); } return(results); }
public bool IsConnected(WorldScene to) { var results = TryConnectScenes(this, to); if (results == null || !results.Any()) { return(false); } results.ForEach(r => Core.Logger.Verbose(LogCategory.Movement, $"> {r.Scene.Name} {r.Direction} {(ExitPositions.ContainsKey(r.Direction) ? ExitPositions[r.Direction].ToString() : "")}")); return(true); }
public static void UpdateIgnoreRegions() { var currentScene = Core.Scenes.CurrentScene; if (currentScene != null && currentScene != _currentScene) { MarkIgnoreRegionsAsVisited(currentScene); foreach (var connectedScene in currentScene.ConnectedScenes()) { MarkIgnoreRegionsAsVisited(connectedScene.Scene); } _currentScene = currentScene; } }
private static List <ConnectedSceneResult> TryConnectScenes(WorldScene from, WorldScene to, WorldScene parent = null, HashSet <string> sceneHashes = null) { if (from == null || to == null) { return(null); } var checkedScenes = sceneHashes ?? new HashSet <string>(); if (!checkedScenes.Contains(from.HashName)) { checkedScenes.Add(from.HashName); } foreach (var connection in from.ConnectedScenes().Where(s => s.Scene != parent).OrderBy(s => s.ExitPosition.Distance(to.Center.ToVector3()))) { if (connection.Scene == to) { return new List <ConnectedSceneResult> { connection } } ; if (connection.Scene == null) { continue; } if (checkedScenes.Contains(connection.Scene.HashName)) { continue; } checkedScenes.Add(connection.Scene.HashName); var childResults = TryConnectScenes(connection.Scene, to, from, checkedScenes); if (childResults == null || !childResults.Any()) { continue; } childResults.Insert(0, connection); return(childResults); } return(null); }
public ExplorationNode(Vector2 center, float boxSize, float boxTolerance, WorldScene scene) { _boxSize = boxSize; _boxTolerance = boxTolerance; _scene = scene; var halfSize = (float)boxSize / 2; //_maxCellsCount = _boxSize / 2.5 / 2; Center = center; TopLeft = Center + new Vector2(-(halfSize), -(halfSize)); BottomLeft = Center + new Vector2(-(halfSize), halfSize); TopRight = Center + new Vector2(halfSize, -(halfSize)); BottomRight = Center + new Vector2(halfSize, halfSize); NavigableCenterNode = null; IsBlacklisted = Scene.BlacklistedPositions.Any(IsInNode); Calculate(this); }
public static bool MarkIgnoreRegionsAsVisited(WorldScene scene) { if (scene?.Nodes == null) { return(false); } int modifiedNodes = 0; foreach (var node in scene.Nodes) { if (node == null) { continue; } if (scene.IgnoreRegions.Contains(node.NavigableCenter)) { modifiedNodes++; node.IsVisited = true; } } Core.Logger.Debug($"Marked {modifiedNodes} exploration nodes for ignore regions in {scene.Name} ({scene.SnoId}) as visited"); return(modifiedNodes > 0); }
public NavigationNode(Vector3 center, float boxSize, ExplorationNode node, WorldSceneCell cell) { if (node != null) { _explorationNode = node; _scene = node.Scene; } if (cell != null) { NodeFlags = (NodeFlags)cell.NavCellFlags; } var halfSize = (float)boxSize / 2; Center = center.ToVector2(); TopLeft = Center + new Vector2(-(halfSize), -(halfSize)); BottomLeft = Center + new Vector2(-(halfSize), halfSize); TopRight = Center + new Vector2(halfSize, -(halfSize)); BottomRight = Center + new Vector2(halfSize, halfSize); NavigableCenter = center; NavigableCenter2D = Center; }
public WorldScene(Scene scene, float boxSize, float boxTolerance) { using (new PerformanceLogger("[WorldScene] ctor", false)) { _boxSize = boxSize; _boxTolerance = boxTolerance; //Scene = scene; var mesh = scene.Mesh; Name = scene.Name; HashName = scene.GetSceneNameString(); SnoId = scene.SceneInfo.SNOId; LevelAreaId = mesh.LevelAreaSnoId; Min = mesh.Zone.ZoneMin; Max = mesh.Zone.ZoneMax; Size = Max - Min; Center = (Max + Min) / 2; //Rect = new Rect(new Point(Center.X, Center.Y), new Size(_boxSize, _boxSize)); HasChild = mesh.SubSceneId > 0; HasParent = mesh.ParentSceneId > 0; IsIgnored = ExplorationData.IgnoreScenes.Contains(Name); DynamicWorldId = mesh.WorldId; NorthWest = Min; NorthEast = new Vector2(Min.X, Max.Y); SouthEast = Max; SouthWest = new Vector2(Max.X, Min.Y); CornerPositions = new HashSet <Vector2> { NorthWest, NorthEast, SouthEast, SouthWest }; if (ExplorationHelpers.BlacklistedPositionsBySceneSnoId.ContainsKey(SnoId)) { BlacklistedPositions = ExplorationHelpers.BlacklistedPositionsBySceneSnoId[SnoId]; } SceneId = scene.Mesh.SceneId; if (HasChild) { SubScene = new WorldScene(mesh.SubScene, boxSize, boxTolerance); } s_logger.Debug($"[{nameof(WorldScene)}] Created a new world scene. Name: {Name} LevelArea: {LevelAreaId}"); if (LevelAreaId != AdvDia.CurrentLevelAreaId && !ExplorationData.OpenWorldIds.Contains(AdvDia.CurrentWorldId)) { s_logger.Debug($"[{nameof(WorldScene)}] The scene LevelAreaID is different than the CurrentLevelAreaID"); s_logger.Debug($"[{nameof(WorldScene)}] Scene Name: {Name}"); s_logger.Debug($"[{nameof(WorldScene)}] Scene: {LevelAreaId}"); s_logger.Debug($"[{nameof(WorldScene)}] Current: {AdvDia.CurrentLevelAreaId}"); } CreateGrid(mesh); if (!ExitPositions.Any()) { ScanExitDirection(SceneExitDirections.North); ScanExitDirection(SceneExitDirections.South); ScanExitDirection(SceneExitDirections.East); ScanExitDirection(SceneExitDirections.West); } } }