Esempio n. 1
0
        public void Update()
        {
            var currentWorldId = ZetaDia.Globals.WorldId;

            if (currentWorldId <= 0)
            {
                return;
            }

            if (_currentWorld != currentWorldId)
            {
                if (!ZetaDia.IsInGame)
                {
                    s_logger.Debug($"[{nameof(Update)}] Left Game...");
                    Reset();
                    return;
                }
                if (ZetaDia.Globals.IsLoadingWorld)
                {
                    s_logger.Debug($"[{nameof(Update)}] World loading...");
                    return;
                }

                s_logger.Information($"[{nameof(Update)}] World has changed from {_currentWorld} to {currentWorldId}.");
                _currentWorld = currentWorldId;
                Reset();
            }

            var          addedScenes = new List <WorldScene>();
            List <Scene> newScenes;

            try
            {
                newScenes = ZetaDia.Scenes
                            .Where(s => s.IsAlmostValid() && !CurrentWorldSceneIds.Contains(s.GetSceneNameString())).ToList();
            }
            catch (NullReferenceException)
            {
                return;
            }
            catch (PartialReadWriteException)
            {
                return;
            }

            SNOWorld worldId = 0;

            foreach (var scene in newScenes)
            {
                try
                {
                    if (!scene.IsAlmostValid())
                    {
                        continue;
                    }

                    var sceneHashName = scene.GetSceneNameString();
                    worldId = scene.Mesh.WorldId;

                    var subScene = scene.Mesh.SubScene;
                    if (scene.IsAlmostValid() && scene.Mesh.ParentSceneId <= 0 && worldId == currentWorldId)
                    {
                        if (scene.Mesh.Zone.GridSquares.Length <= 1 && (subScene != null && !subScene.HasGridSquares()))
                        {
                            continue;
                        }

                        var adventurerScene = new WorldScene(scene, ExplorationData.ExplorationNodeBoxSize,
                                                             ExplorationData.ExplorationNodeBoxTolerance);
                        if (adventurerScene.Cells.Count > 0)
                        {
                            CurrentWorldScenes.Add(adventurerScene);
                            addedScenes.Add(adventurerScene);
                        }
                    }
                    CurrentWorldSceneIds.Add(sceneHashName);
                }
                catch (NullReferenceException)
                {
                }
            }

            if (addedScenes.Count <= 0)
            {
                return;
            }

            s_logger.Information($"[{nameof(Update)}] Found {addedScenes.Count} new scenes.");
            var sceneData = CreateSceneData(addedScenes, worldId);

            foreach (var grid in GridStore.GetCurrentGrids())
            {
                grid.Update(sceneData);
            }

            if (CurrentScene != null)
            {
                foreach (var scene in CurrentWorldScenes.Where(s => !s.HasPlayerConnection))
                {
                    if (scene == CurrentScene || CurrentScene.IsConnected(scene))
                    {
                        scene.HasPlayerConnection = true;
                    }
                }
            }

            ScenesAdded?.Invoke(addedScenes);
            s_logger.Information($"[{nameof(Update)}] Updates Finished.");
        }
Esempio n. 2
0
        public void Update()
        {
            var currentWorldId = ZetaDia.Globals.WorldId;

            if (currentWorldId <= 0)
            {
                return;
            }

            if (_currentWorld != currentWorldId)
            {
                //if (GameData.MenuWorldSnoIds.Contains(ZetaDia.Globals.WorldSnoId))
                //{
                //    Core.Logger.Debug("[SceneStorage] Left Game....");
                //    Reset();
                //    return;
                //}
                //if (ZetaDia.Globals.IsLoadingWorld)
                //{
                //    Core.Logger.Debug("[SceneStorage] World loading....");
                //    return;
                //}

                Core.Logger.Debug("[SceneStorage] World has changed from {0} to {1}", _currentWorld, currentWorldId);
                _currentWorld = currentWorldId;
                Reset();
            }

            var          addedScenes = new List <WorldScene>();
            List <Scene> newScenes;

            try
            {
                newScenes = ZetaDia.Scenes.Where(s => s.IsAlmostValid() && !CurrentWorldSceneIds.Contains(s.GetSceneNameString())).ToList();
            }
            catch (NullReferenceException)
            {
                return;
            }
            catch (Exception ex)
            {
                if (ex.Message.Contains("ReadProcessMemory"))
                {
                    return;
                }
                throw;
            }

            var worldId = 0;

            foreach (var scene in newScenes)
            {
                try
                {
                    if (!scene.IsAlmostValid())
                    {
                        continue;
                    }

                    var sceneHashName = scene.GetSceneNameString();
                    worldId = scene.Mesh.WorldId;

                    Scene subScene = scene.Mesh.SubScene;
                    if (scene.IsAlmostValid() && scene.Mesh.ParentSceneId <= 0 && worldId == currentWorldId)
                    {
                        if (scene.Mesh.Zone.GridSquares.Length <= 1 && (subScene != null && !subScene.HasGridSquares()))
                        {
                            continue;
                        }

                        var adventurerScene = new WorldScene(scene, ExplorationData.ExplorationNodeBoxSize,
                                                             ExplorationData.ExplorationNodeBoxTolerance);
                        if (adventurerScene.Cells.Count > 0)
                        {
                            CurrentWorldScenes.Add(adventurerScene);
                            addedScenes.Add(adventurerScene);
                        }
                    }
                    CurrentWorldSceneIds.Add(sceneHashName);
                }
                catch (NullReferenceException)
                {
                }
            }

            if (addedScenes.Count > 0)
            {
                Core.Logger.Debug("[ScenesStorage] Found {0} new scenes", addedScenes.Count);
                var sceneData = CreateSceneData(addedScenes, worldId);
                foreach (var grid in GridStore.GetCurrentGrids())
                {
                    grid.Update(sceneData);
                }
                ScenesAdded?.Invoke(addedScenes);
                Core.Logger.Debug("[ScenesStorage] Updates Finished", addedScenes.Count);
            }
        }