示例#1
0
        private void ExecuteLoadUnloadRequest(List <RegionNames> regionsToLoad, List <RegionNames> regionsToUnload)
        {
            if (regionsToLoad.Count == 0 && regionsToUnload.Count == 0)
            {
                return;
            }

            var crossRegionNpcsToLoad        = NpcMapper.GetCrossRegionNpcsForRegions(regionsToLoad);
            var currentCrossRegionNpcsUnload = NpcMapper.GetCrossRegionNpcsForRegions(_currentLoadedRegions);

            var crossRegionSoundsToLoad        = SoundMapper.GetCrossRegionSoundEffects(regionsToLoad);
            var currentCrossRegionSoundsUnload = SoundMapper.GetCrossRegionSoundEffects(_currentLoadedRegions);

            foreach (var npc in crossRegionNpcsToLoad)
            {
                foreach (var region in NpcMapper.GetRegionsForCrossRegionNpc(npc))
                {
                    if (_currentLoadedRegions.Contains(region))
                    {
                        crossRegionNpcsToLoad.Remove(npc);
                        break;
                    }
                }
            }

            foreach (var sound in crossRegionSoundsToLoad)
            {
                foreach (var region in SoundMapper.GetRegionsForSound(sound))
                {
                    if (_currentLoadedRegions.Contains(region))
                    {
                        crossRegionSoundsToLoad.Remove(sound);
                        break;
                    }
                }
            }

            foreach (var region in regionsToLoad)
            {
                _currentLoadedRegions.Add(region);
            }

            foreach (var region in regionsToUnload)
            {
                _currentLoadedRegions.Remove(region);
            }

            foreach (var npc in currentCrossRegionNpcsUnload)
            {
                foreach (var region in NpcMapper.GetRegionsForCrossRegionNpc(npc))
                {
                    if (_currentLoadedRegions.Contains(region))
                    {
                        currentCrossRegionNpcsUnload.Remove(npc);
                        break;
                    }
                }
            }

            foreach (var sound in currentCrossRegionSoundsUnload)
            {
                foreach (var region in SoundMapper.GetRegionsForSound(sound))
                {
                    if (_currentLoadedRegions.Contains(region))
                    {
                        currentCrossRegionSoundsUnload.Remove(sound);
                        break;
                    }
                }
            }

            var saveData           = DataHelper.GetCopySaveDataForCurrentFile(); // we need to use this to create the regions
            var regionContent      = RegionContentLoader.LoadContentForRegions(_serviceProvider, _rootDirectory, regionsToLoad);
            var regions            = RegionFactory.CreateRegions(regionsToLoad, saveData);
            var crossRegionNpcs    = NpcMapper.CreateCrossRegionNpcs(crossRegionNpcsToLoad, saveData);
            var crossRegionContent = NpcContentLoader.LoadCrossRegionNpcContent(_serviceProvider, _rootDirectory, crossRegionNpcsToLoad);

            crossRegionContent.AddRange(SoundMapper.CreateCrossRegionSoundContent(_serviceProvider, _rootDirectory, crossRegionSoundsToLoad));

            var loadedArgs = new AssetsLoadedEventArgs();

            loadedArgs.RegionContent      = regionContent;
            loadedArgs.Regions            = regions;
            loadedArgs.CrossRegionContent = crossRegionContent;
            loadedArgs.CrossRegionNpcs    = crossRegionNpcs;

            var unloadedArgs = new AssetsUnloadedEventArgs();

            unloadedArgs.RegionsUnloaded          = regionsToUnload;
            unloadedArgs.CrossRegionSoundUnloaded = currentCrossRegionSoundsUnload;
            unloadedArgs.CrossRegionNpcsUnloaded  = currentCrossRegionNpcsUnload;

            AssetsLoaded(loadedArgs);
            AssetsUnloaded(unloadedArgs);
        }