예제 #1
0
        /// <summary>
        /// Gets the center of a given Navigation Zone
        /// </summary>
        /// <param name="zone"></param>
        /// <returns></returns>
        private Vector3 GetNavZoneCenter(NavZone zone)
        {
            var X = zone.ZoneMin.X + ((zone.ZoneMax.X - zone.ZoneMin.X) / 2);
            var Y = zone.ZoneMin.Y + ((zone.ZoneMax.Y - zone.ZoneMin.Y) / 2);

            return(new Vector3(X, Y, 0));
        }
예제 #2
0
        /// <summary>
        /// Gets the center of a given Navigation Zone
        /// </summary>
        /// <param name="zone"></param>
        /// <returns></returns>
        internal static Vector3 GetNavZoneCenter(NavZone zone)
        {
            float x = zone.ZoneMin.X + ((zone.ZoneMax.X - zone.ZoneMin.X) / 2);
            float y = zone.ZoneMin.Y + ((zone.ZoneMax.Y - zone.ZoneMin.Y) / 2);

            return(new Vector3(x, y, 0));
        }
예제 #3
0
        /// <summary>
        /// Gets the center of a given box with min/max, adjusted for the Navigation Zone
        /// </summary>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <param name="zone"></param>
        /// <returns></returns>
        private Vector3 GetNavCellCenter(Vector3 min, Vector3 max, NavZone zone)
        {
            var X = zone.ZoneMin.X + min.X + ((max.X - min.X) / 2);
            var Y = zone.ZoneMin.Y + min.Y + ((max.Y - min.Y) / 2);
            var Z = min.Z + ((max.Z - min.Z) / 2);

            return(new Vector3(X, Y, Z));
        }
예제 #4
0
        /// <summary>
        /// Gets the center of a given box with min/max, adjusted for the Navigation Zone
        /// </summary>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <param name="zone"></param>
        /// <returns></returns>
        internal static Vector3 GetNavCellCenter(Vector3 min, Vector3 max, NavZone zone)
        {
            float x = zone.ZoneMin.X + min.X + ((max.X - min.X) / 2);
            float y = zone.ZoneMin.Y + min.Y + ((max.Y - min.Y) / 2);
            float z = min.Z + ((max.Z - min.Z) / 2);

            return(new Vector3(x, y, z));
        }
예제 #5
0
        public static SceneDefinition Create(Scene.NavMesh mesh, NavZone zone, NavZoneDef navZoneDef)
        {
            var filePath = string.Format("{0}{1}.json", SCENES_PATH, mesh.SceneSnoId);

            if (USE_DISK_CACHE)
            {
                if (File.Exists(filePath))
                {
                    var fileContent = File.ReadAllText(filePath);
                    if (!string.IsNullOrWhiteSpace(fileContent))
                    {
                        var savedScene = JsonSerializer.Deserialize <SceneDefinition>(fileContent);
                        if (savedScene != null)
                        {
                            return(savedScene);
                        }
                    }
                }
            }
            var sceneDefinition = new SceneDefinition {
                SceneSNO = mesh.SceneSnoId
            };

            #region NavCells
            var cachedNavCells = new List <NavCellDefinition>();
            var sceneNavCells  = navZoneDef.NavCells.ToList();

            if (sceneNavCells.Count > 0)
            {
                cachedNavCells.AddRange(sceneNavCells.Select(NavCellDefinition.Create));
            }
            sceneDefinition.NavCellDefinitions = cachedNavCells;
            #endregion


            if (USE_DISK_CACHE)
            {
                var serializedScene = JsonSerializer.Serialize(sceneDefinition);
                File.WriteAllText(filePath, serializedScene);
            }
            Logger.Warn("[GridProvider] Added SceneDefinition {0} (Dimensions: {1}, NavCells: {2})", sceneDefinition.SceneSNO, zone.ZoneMax - zone.ZoneMin, sceneDefinition.NavCellDefinitions.Count);
            return(sceneDefinition);
        }
예제 #6
0
        public static SceneDefinition Create(Scene.NavMesh mesh, NavZone zone, NavZoneDef navZoneDef)
        {
            var filePath = string.Format("{0}{1}.json", SCENES_PATH, mesh.SceneSnoId);
            if (USE_DISK_CACHE)
            {
                if (File.Exists(filePath))
                {
                    var fileContent = File.ReadAllText(filePath);
                    if (!string.IsNullOrWhiteSpace(fileContent))
                    {
                        var savedScene = JsonSerializer.Deserialize<SceneDefinition>(fileContent);
                        if (savedScene != null)
                        {
                            return savedScene;
                        }
                    }
                }
            }
            var sceneDefinition = new SceneDefinition { SceneSNO = mesh.SceneSnoId };

            #region NavCells
            var cachedNavCells = new List<NavCellDefinition>();
            var sceneNavCells = navZoneDef.NavCells.ToList();

            if (sceneNavCells.Count > 0)
            {
                cachedNavCells.AddRange(sceneNavCells.Select(NavCellDefinition.Create));
            }
            sceneDefinition.NavCellDefinitions = cachedNavCells;
            #endregion


            if (USE_DISK_CACHE)
            {

                var serializedScene = JsonSerializer.Serialize(sceneDefinition);
                File.WriteAllText(filePath, serializedScene);
            }
            Logger.Warn("[GridProvider] Added SceneDefinition {0} (Dimensions: {1}, NavCells: {2})", sceneDefinition.SceneSNO, zone.ZoneMax - zone.ZoneMin, sceneDefinition.NavCellDefinitions.Count);
            return sceneDefinition;
        }
예제 #7
0
        public static GridScene Create(Scene scene, Scene.NavMesh mesh, NavZone zone)
        {
            var gridScene = new GridScene();

            gridScene.SceneSNO        = mesh.SceneSnoId;
            gridScene.WorldId         = mesh.WorldId;
            gridScene.LevelAreaSNO    = mesh.LevelAreaSnoId;
            gridScene.Name            = scene.Name;
            gridScene.NameHash        = GridProvider.GetSceneNameHash(mesh, zone);
            gridScene.Min             = zone.ZoneMin;
            gridScene.Max             = zone.ZoneMax;
            gridScene.Center          = (gridScene.Max + gridScene.Min) / 2;
            gridScene.SceneDefinition = GridProvider.SceneDefinitions[mesh.SceneSnoId];
            gridScene.BaseHeight      = mesh.BaseHeight;

            //#region GridNodes

            var         gridNodes       = new List <GridNode>();
            var         sceneDimensions = zone.ZoneMax - zone.ZoneMin;
            const float searchBeginning = GridProvider.GridNodeBoxSize / 2;

            for (var x = searchBeginning; x <= sceneDimensions.X; x = x + GridProvider.GridNodeBoxSize)
            {
                for (var y = searchBeginning; y <= sceneDimensions.Y; y = y + GridProvider.GridNodeBoxSize)
                {
                    var cell = gridScene.SceneDefinition.NavCellDefinitions.FirstOrDefault(c => c.IsInCell(x, y));
                    if (cell != null)
                    {
                        var gridNode = GridNode.Create(new Vector2(x, y), gridScene, cell);
                        gridNodes.Add(gridNode);
                    }
                }
            }
            gridScene.GridNodes = gridNodes;
            //#endregion

            return(gridScene);
        }
예제 #8
0
        public static GridScene Create(Scene scene, Scene.NavMesh mesh, NavZone zone)
        {
            var gridScene = new GridScene();
            gridScene.SceneSNO = mesh.SceneSnoId;
            gridScene.WorldId = mesh.WorldId;
            gridScene.LevelAreaSNO = mesh.LevelAreaSnoId;
            gridScene.Name = scene.Name;
            gridScene.NameHash = GridProvider.GetSceneNameHash(mesh, zone);
            gridScene.Min = zone.ZoneMin;
            gridScene.Max = zone.ZoneMax;
            gridScene.Center = (gridScene.Max + gridScene.Min) / 2;
            gridScene.SceneDefinition = GridProvider.SceneDefinitions[mesh.SceneSnoId];
            gridScene.BaseHeight = mesh.BaseHeight;

            //#region GridNodes

            var gridNodes = new List<GridNode>();
            var sceneDimensions = zone.ZoneMax - zone.ZoneMin;
            const float searchBeginning = GridProvider.GridNodeBoxSize / 2;
            for (var x = searchBeginning; x <= sceneDimensions.X; x = x + GridProvider.GridNodeBoxSize)
            {
                for (var y = searchBeginning; y <= sceneDimensions.Y; y = y + GridProvider.GridNodeBoxSize)
                {
                    var cell = gridScene.SceneDefinition.NavCellDefinitions.FirstOrDefault(c => c.IsInCell(x, y));
                    if (cell != null)
                    {
                        var gridNode = GridNode.Create(new Vector2(x, y), gridScene, cell);
                        gridNodes.Add(gridNode);
                    }
                }
            }
            gridScene.GridNodes = gridNodes;
            //#endregion

            return gridScene;
        }
예제 #9
0
 /// <summary>
 /// Gets the center of a given Navigation Cell
 /// </summary>
 /// <param name="cell"></param>
 /// <param name="zone"></param>
 /// <returns></returns>
 private Vector3 GetNavCellCenter(NavCell cell, NavZone zone)
 {
     return(GetNavCellCenter(cell.Min, cell.Max, zone));
 }
예제 #10
0
        /// <summary>
        /// Gets the center of a given box with min/max, adjusted for the Navigation Zone
        /// </summary>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <param name="zone"></param>
        /// <returns></returns>
        private Vector3 GetNavCellCenter(Vector3 min, Vector3 max, NavZone zone)
        {
            float x = zone.ZoneMin.X + min.X + ((max.X - min.X) / 2);
            float y = zone.ZoneMin.Y + min.Y + ((max.Y - min.Y) / 2);
            float z = min.Z + ((max.Z - min.Z) / 2);

            return new Vector3(x, y, z);
        }
예제 #11
0
 public static string GetSceneNameHash(Scene.NavMesh mesh, NavZone navZone)
 {
     return string.Format("{0}-{1}-{2}-{3}-{4}", mesh.SceneSnoId, mesh.WorldId, mesh.LevelAreaSnoId, navZone.ZoneMin, navZone.ZoneMax);
 }
예제 #12
0
 /// <summary>
 /// Gets the center of a given Navigation Cell
 /// </summary>
 /// <param name="cell"></param>
 /// <param name="zone"></param>
 /// <returns></returns>
 internal static Vector3 GetNavCellCenter(NavCell cell, NavZone zone)
 {
     return GetNavCellCenter(cell.Min, cell.Max, zone);
 }
예제 #13
0
        /// <summary>
        /// Gets the center of a given Navigation Zone
        /// </summary>
        /// <param name="zone"></param>
        /// <returns></returns>
        private Vector3 GetNavZoneCenter(NavZone zone)
        {
            var X=zone.ZoneMin.X+((zone.ZoneMax.X-zone.ZoneMin.X)/2);
                var Y=zone.ZoneMin.Y+((zone.ZoneMax.Y-zone.ZoneMin.Y)/2);

                return new Vector3(X, Y, 0);
        }
예제 #14
0
        /// <summary>
        /// Finds a navigable point in a priority scene
        /// </summary>
        private void FindPrioritySceneTarget()
        {
            if (SceneId == 0 && SceneName == String.Empty)
            {
                return;
            }

            gp.Update();

            if (PrioritySceneTarget != Vector3.Zero)
            {
                return;
            }

            bool foundPriorityScene = false;

            // find any matching priority scenes in scene manager - match by name or SNOId

            List <Scene> PScenes = ZetaDia.Scenes.GetScenes()
                                   .Where(s => s.SceneInfo.SNOId == SceneId).ToList();

            PScenes.AddRange(ZetaDia.Scenes.GetScenes()
                             .Where(s => SceneName.Trim() != String.Empty && s.Name.ToLower().Contains(SceneName.ToLower())).ToList());

            List <Scene> foundPriorityScenes = new List <Scene>();
            Dictionary <int, Vector3> foundPrioritySceneIndex = new Dictionary <int, Vector3>();

            foreach (Scene scene in PScenes)
            {
                if (PriorityScenesInvestigated.Contains(scene.SceneInfo.SNOId))
                {
                    continue;
                }

                foundPriorityScene = true;

                NavZone    navZone = scene.Mesh.Zone;
                NavZoneDef zoneDef = navZone.NavZoneDef;

                Vector2 zoneMin = navZone.ZoneMin;
                Vector2 zoneMax = navZone.ZoneMax;

                Vector3 zoneCenter = GetNavZoneCenter(navZone);

                List <NavCell> NavCells = zoneDef.NavCells.Where(c => c.Flags.HasFlag(NavCellFlags.AllowWalk)).ToList();

                if (!NavCells.Any())
                {
                    continue;
                }

                NavCell bestCell = NavCells.OrderBy(c => GetNavCellCenter(c.Min, c.Max, navZone).Distance2D(zoneCenter)).FirstOrDefault();

                if (bestCell != null)
                {
                    foundPrioritySceneIndex.Add(scene.SceneInfo.SNOId, GetNavCellCenter(bestCell, navZone));
                    foundPriorityScenes.Add(scene);
                }
                else
                {
                    DbHelper.Log(TrinityLogLevel.Normal, LogCategory.ProfileTag, "Found Priority Scene but could not find a navigable point!", true);
                }
            }

            if (foundPrioritySceneIndex.Any())
            {
                KeyValuePair <int, Vector3> nearestPriorityScene = foundPrioritySceneIndex.OrderBy(s => s.Value.Distance2D(myPos)).FirstOrDefault();

                PrioritySceneSNOId   = nearestPriorityScene.Key;
                PrioritySceneTarget  = nearestPriorityScene.Value;
                CurrentPriorityScene = foundPriorityScenes.FirstOrDefault(s => s.SceneInfo.SNOId == PrioritySceneSNOId);

                DbHelper.Log(TrinityLogLevel.Normal, LogCategory.ProfileTag, "Found Priority Scene {0} - {1} Center {2} Distance {3:0}",
                             CurrentPriorityScene.Name, CurrentPriorityScene.SceneInfo.SNOId, PrioritySceneTarget, PrioritySceneTarget.Distance2D(myPos));
            }

            if (!foundPriorityScene)
            {
                PrioritySceneTarget = Vector3.Zero;
            }
        }
예제 #15
0
 public static string GetSceneNameHash(Scene.NavMesh mesh, NavZone navZone)
 {
     return(string.Format("{0}-{1}-{2}-{3}-{4}", mesh.SceneSnoId, mesh.WorldId, mesh.LevelAreaSnoId, navZone.ZoneMin, navZone.ZoneMax));
 }
예제 #16
0
 public static int GetSceneHash(NavZone zone)
 {
     return (int)((zone.ZoneMin.X + zone.ZoneMin.Y * 17) + (zone.ZoneMax.X + zone.ZoneMax.Y * 21)) ^ zone.SceneSNO;
 }
예제 #17
0
 public static int GetSceneHash(NavZone zone)
 {
     return((int)((zone.ZoneMin.X + zone.ZoneMin.Y * 17) + (zone.ZoneMax.X + zone.ZoneMax.Y * 21)) ^ zone.SceneSNO);
 }
예제 #18
0
        /// <summary>
        /// Gets the center of a given box with min/max, adjusted for the Navigation Zone
        /// </summary>
        /// <param name="min"></param>
        /// <param name="max"></param>
        /// <param name="zone"></param>
        /// <returns></returns>
        private Vector3 GetNavCellCenter(Vector3 min, Vector3 max, NavZone zone)
        {
            float X=zone.ZoneMin.X+min.X+((max.X-min.X)/2);
            float Y=zone.ZoneMin.Y+min.Y+((max.Y-min.Y)/2);
            float Z=min.Z+((max.Z-min.Z)/2);

            return new Vector3(X, Y, Z);
        }
예제 #19
0
 /// <summary>
 /// Gets the center of a given Navigation Cell
 /// </summary>
 /// <param name="cell"></param>
 /// <param name="zone"></param>
 /// <returns></returns>
 internal static Vector3 GetNavCellCenter(NavCell cell, NavZone zone)
 {
     return(GetNavCellCenter(cell.Min, cell.Max, zone));
 }
예제 #20
0
        /// <summary>
        /// Gets the center of a given Navigation Zone
        /// </summary>
        /// <param name="zone"></param>
        /// <returns></returns>
        private Vector3 GetNavZoneCenter(NavZone zone)
        {
            float x = zone.ZoneMin.X + ((zone.ZoneMax.X - zone.ZoneMin.X) / 2);
            float y = zone.ZoneMin.Y + ((zone.ZoneMax.Y - zone.ZoneMin.Y) / 2);

            return new Vector3(x, y, 0);
        }
예제 #21
0
 /// <summary>
 /// Gets the center of a given Navigation Cell
 /// </summary>
 /// <param name="cell"></param>
 /// <param name="zone"></param>
 /// <returns></returns>
 private Vector3 GetNavCellCenter(NavCell cell, NavZone zone)
 {
     return GetNavCellCenter(cell.Min, cell.Max, zone);
 }
예제 #22
0
        /// <summary>
        /// Finds a navigable point in a priority scene
        /// </summary>
        private void FindPrioritySceneTarget()
        {
            if (SceneId == 0 && string.IsNullOrWhiteSpace(SceneName))
            {
                return;
            }

            if (_prioritySceneTarget != Vector3.Zero)
            {
                return;
            }

            bool foundPriorityScene = false;

            // find any matching priority scenes in scene manager - match by name or SNOId

            List <Scene> pScenes;
            var          allScenes = ZetaDia.Scenes.ToList();

            if (allScenes.Any())
            {
                pScenes = GetPScenesBySceneId(allScenes);

                pScenes.AddRange(GetPScenesByName(allScenes));
            }
            else
            {
                return;
            }

            List <Scene> foundPriorityScenes = new List <Scene>();
            Dictionary <int, Vector3> foundPrioritySceneIndex = new Dictionary <int, Vector3>();

            foreach (Scene scene in pScenes)
            {
                try
                {
                    if (_priorityScenesInvestigated.Contains(scene.SceneInfo.SNOId))
                    {
                        continue;
                    }

                    foundPriorityScene = true;

                    NavZone    navZone = scene.Mesh.Zone;
                    NavZoneDef zoneDef = navZone.NavZoneDef;

                    Vector3 zoneCenter = GetNavZoneCenter(navZone);

                    List <NavCell> navCells = zoneDef.NavCells.Where(c => c.Flags.HasFlag(NavCellFlags.AllowWalk)).ToList();

                    if (!navCells.Any())
                    {
                        continue;
                    }

                    NavCell bestCell = navCells.OrderBy(c => GetNavCellCenter(c.Min, c.Max, navZone).Distance2D(zoneCenter)).FirstOrDefault();

                    if (bestCell != null)
                    {
                        foundPrioritySceneIndex.Add(scene.SceneInfo.SNOId, GetNavCellCenter(bestCell, navZone));
                        foundPriorityScenes.Add(scene);
                    }
                    else
                    {
                        Logger.Log("Found Scene but could not find a navigable point!", true);
                    }
                }
                catch (Exception ex)
                {
                    Logger.Log(ex.ToString());
                }
            }

            if (foundPrioritySceneIndex.Any())
            {
                KeyValuePair <int, Vector3> nearestPriorityScene = foundPrioritySceneIndex.OrderBy(s => s.Value.Distance2D(myPos)).FirstOrDefault();

                _prioritySceneSNOId   = nearestPriorityScene.Key;
                _prioritySceneTarget  = nearestPriorityScene.Value;
                _currentPriorityScene = foundPriorityScenes.FirstOrDefault(s => s.SceneInfo.SNOId == _prioritySceneSNOId);

                if (_currentPriorityScene != null)
                {
                    Logger.Log("Found Scene {0} - {1} Center {2} Distance {3:0}",
                               _currentPriorityScene.Name, _currentPriorityScene.SceneInfo.SNOId, _prioritySceneTarget, _prioritySceneTarget.Distance2D(myPos));
                }
            }

            if (!foundPriorityScene)
            {
                _prioritySceneTarget = Vector3.Zero;
            }
        }