Exemplo n.º 1
0
        public void PlacedObjectInCell()
        {
            var mod   = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimSE);
            var block = new CellBlock()
            {
                BlockNumber = 2,
                GroupType   = GroupTypeEnum.InteriorCellBlock,
            };
            var subBlock = new CellSubBlock()
            {
                BlockNumber = 4,
                GroupType   = GroupTypeEnum.InteriorCellSubBlock,
            };

            block.SubBlocks.Add(subBlock);
            mod.Cells.Records.Add(block);
            var cell1 = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);
            var cell2 = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            subBlock.Cells.Add(cell1);
            subBlock.Cells.Add(cell2);
            var block2 = new CellBlock()
            {
                BlockNumber = 5,
                GroupType   = GroupTypeEnum.InteriorCellBlock,
            };
            var subBlock2 = new CellSubBlock()
            {
                BlockNumber = 8,
                GroupType   = GroupTypeEnum.InteriorCellSubBlock,
            };

            block2.SubBlocks.Add(subBlock2);
            mod.Cells.Records.Add(block2);
            var cell3 = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            subBlock2.Cells.Add(cell3);

            var placedNpc = new PlacedNpc(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            cell2.Persistent.Add(placedNpc);
            var placedObj = new PlacedObject(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            cell2.Persistent.Add(placedObj);

            var cache    = mod.ToImmutableLinkCache();
            var contexts = mod.EnumerateMajorRecordContexts <IPlacedObject, IPlacedObjectGetter>(linkCache: cache).ToArray();

            contexts.Should().HaveCount(1);

            var mod2 = new SkyrimMod(TestConstants.PluginModKey2, SkyrimRelease.SkyrimSE);
            var placedObjOverride = contexts[0].GetOrAddAsOverride(mod2);

            Assert.Equal(placedObj.FormKey, placedObjOverride.FormKey);
            mod2.Cells.Records.Should().HaveCount(1);
            mod2.Cells.Records.First().SubBlocks.Should().HaveCount(1);
            mod2.Cells.Records.First().SubBlocks.First().Cells.Should().HaveCount(1);
            mod2.Cells.Records.First().SubBlocks.First().Cells.First().Persistent.Should().HaveCount(1);
            Assert.Same(placedObjOverride, mod2.Cells.Records.First().SubBlocks.First().Cells.First().Persistent.First());
        }
        public void FormLink_Direct_Resolve_MarkerInterface_DeepRecord_Linked(LinkCacheTestTypes cacheType)
        {
            var mod        = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimLE);
            var worldspace = mod.Worldspaces.AddNew();
            var subBlock   = new WorldspaceSubBlock();
            var cell       = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimLE);

            subBlock.Items.Add(cell);
            var placedNpc = new PlacedNpc(mod.GetNextFormKey(), SkyrimRelease.SkyrimLE);

            cell.Temporary.Add(placedNpc);
            var block = new WorldspaceBlock();

            block.Items.Add(subBlock);
            worldspace.SubCells.Add(block);
            var(style, package) = GetLinkCache(mod, cacheType);
            var placedFormLink = new FormLink <IPlacedGetter>(placedNpc.FormKey);

            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.Same(placedNpc, placedFormLink.TryResolve(package));
            });
            var cellFormLink = new FormLink <ICellGetter>(cell.FormKey);

            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.Same(cell, cellFormLink.TryResolve(package));
            });
            var worldspaceFormLink = new FormLink <IWorldspaceGetter>(worldspace.FormKey);

            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.Same(worldspace, worldspaceFormLink.TryResolve(package));
            });
        }
Exemplo n.º 3
0
        public void ParentRefs()
        {
            WarmupSkyrim.Init();
            var mod        = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimSE);
            var worldspace = mod.Worldspaces.AddNew();
            var block      = new WorldspaceBlock()
            {
                BlockNumberX = 2,
                BlockNumberY = 3,
                GroupType    = GroupTypeEnum.ExteriorCellBlock,
            };
            var subBlock = new WorldspaceSubBlock()
            {
                BlockNumberX = 4,
                BlockNumberY = 5,
                GroupType    = GroupTypeEnum.ExteriorCellSubBlock,
            };

            block.Items.Add(subBlock);
            worldspace.SubCells.Add(block);
            var cell = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            subBlock.Items.Add(cell);

            var placedNpc = new PlacedNpc(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            cell.Persistent.Add(placedNpc);
            var placedObj = new PlacedObject(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            cell.Persistent.Add(placedObj);

            var cache    = mod.ToImmutableLinkCache();
            var contexts = mod.EnumerateMajorRecordContexts <IPlacedObject, IPlacedObjectGetter>(linkCache: cache).ToArray();

            contexts.Should().HaveCount(1);
            var baseContext = contexts[0];
            var cellContext = baseContext.Parent;

            cellContext.Should().BeOfType(typeof(ModContext <ISkyrimMod, ISkyrimModGetter, ICell, ICellGetter>));
            cellContext !.Record.Should().Be(cell);
            var subBlockContext = cellContext.Parent;

            subBlockContext !.Record.Should().Be(subBlock);
            var blockContext = subBlockContext.Parent;

            blockContext !.Record.Should().Be(block);
            var worldspaceContext = blockContext.Parent;

            worldspaceContext !.Record.Should().Be(worldspace);
            baseContext.IsUnderneath <IWorldspaceGetter>().Should().BeTrue();
            baseContext.TryGetParent <IWorldspaceGetter>(out var worldParent).Should().BeTrue();
            worldParent.Should().Be(worldspace);
            baseContext.TryGetParentContext <IWorldspace, IWorldspaceGetter>(out var worldParentContext).Should().BeTrue();
            worldParentContext !.Record.Should().Be(worldspace);
        }
Exemplo n.º 4
0
        public void Cell()
        {
            var mod   = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimSE);
            var block = new CellBlock()
            {
                BlockNumber = 2,
                GroupType   = GroupTypeEnum.InteriorCellBlock,
            };
            var subBlock = new CellSubBlock()
            {
                BlockNumber = 4,
                GroupType   = GroupTypeEnum.InteriorCellSubBlock,
            };

            block.SubBlocks.Add(subBlock);
            mod.Cells.Records.Add(block);
            var cell1 = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);
            var cell2 = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            subBlock.Cells.Add(cell1);
            subBlock.Cells.Add(cell2);
            var block2 = new CellBlock()
            {
                BlockNumber = 5,
                GroupType   = GroupTypeEnum.InteriorCellBlock,
            };
            var subBlock2 = new CellSubBlock()
            {
                BlockNumber = 8,
                GroupType   = GroupTypeEnum.InteriorCellSubBlock,
            };

            block2.SubBlocks.Add(subBlock2);
            mod.Cells.Records.Add(block2);
            var cell3 = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            subBlock2.Cells.Add(cell3);

            var mod2     = new SkyrimMod(TestConstants.PluginModKey2, SkyrimRelease.SkyrimSE);
            var contexts = mod.EnumerateMajorRecordContexts <ICell, ICellGetter>(linkCache: null !).ToArray();

            contexts.Should().HaveCount(3);
            Assert.Same(contexts[0].Record, cell1);
            Assert.Same(contexts[1].Record, cell2);
            Assert.Same(contexts[2].Record, cell3);
            var cell2Override = contexts[1].GetOrAddAsOverride(mod2);

            Assert.Equal(cell2.FormKey, cell2Override.FormKey);
            mod2.Cells.Records.Should().HaveCount(1);
            mod2.Cells.Records.First().SubBlocks.Should().HaveCount(1);
            mod2.Cells.Records.First().SubBlocks.First().Cells.Should().HaveCount(1);
        }
Exemplo n.º 5
0
        public void FormLink_LoadOrder_TryResolve_DeepRecord_Linked(LinkCacheTestTypes cacheType)
        {
            var mod        = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimLE);
            var worldspace = mod.Worldspaces.AddNew();
            var subBlock   = new WorldspaceSubBlock();
            var cell       = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimLE);

            subBlock.Items.Add(cell);
            var placedNpc = new PlacedNpc(mod.GetNextFormKey(), SkyrimRelease.SkyrimLE);

            cell.Temporary.Add(placedNpc);
            var block = new WorldspaceBlock();

            block.Items.Add(subBlock);
            worldspace.SubCells.Add(block);
            var loadOrder = new LoadOrder <ISkyrimModGetter>()
            {
                mod,
                new SkyrimMod(TestConstants.PluginModKey2, SkyrimRelease.SkyrimLE),
            };

            var(style, package) = GetLinkCache(loadOrder, cacheType);
            FormLink <IPlacedNpc> placedFormLink = new FormLink <IPlacedNpc>(placedNpc.FormKey);

            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(placedFormLink.TryResolve(package, out var linkedPlacedNpc));
                Assert.Same(placedNpc, linkedPlacedNpc);
            });
            FormLink <ICell> cellFormLink = new FormLink <ICell>(cell.FormKey);

            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(cellFormLink.TryResolve(package, out var linkedCell));
                Assert.Same(cell, linkedCell);
            });
            FormLink <IWorldspace> worldspaceFormLink = new FormLink <IWorldspace>(worldspace.FormKey);

            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(worldspaceFormLink.TryResolve(package, out var linkedWorldspace));
                Assert.Same(worldspace, linkedWorldspace);
            });
        }
Exemplo n.º 6
0
        public void Worldspace_WinningContextOverride_IPlaced()
        {
            WarmupSkyrim.Init();
            var mod        = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimSE);
            var worldspace = mod.Worldspaces.AddNew();
            var block      = worldspace.SubCells.AddReturn(new WorldspaceBlock());
            var subBlock   = block.Items.AddReturn(new WorldspaceSubBlock());
            var cell       = subBlock.Items.AddReturn(new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE));
            var placedObj  = cell.Persistent.AddReturn(new PlacedObject(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE));

            worldspace.TopCell = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);
            var placedObj2 = worldspace.TopCell.Persistent.AddReturn(new PlacedObject(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE));
            var placedObjs = mod.EnumerateMajorRecordContexts <IPlacedObject, IPlacedObjectGetter>(linkCache: null !).ToList();

            placedObjs.Should().HaveCount(2);
            var placed = mod.EnumerateMajorRecordContexts <IPlaced, IPlacedGetter>(linkCache: null !).ToList();

            placed.Should().HaveCount(2);
        }
Exemplo n.º 7
0
        public static void CleanFormLinkListAPI()
        {
            SkyrimMod sourceMod = new SkyrimMod(Utility.PluginModKey, SkyrimRelease.SkyrimSE);
            FormKey   key       = sourceMod.GetNextFormKey();
            Keyword   keyword   = sourceMod.Keywords.AddNew();
            Armor     armor     = sourceMod.Armors.AddNew();

            armor.Keywords = new ExtendedList <IFormLinkGetter <IKeywordGetter> >();
            var test = armor.Keywords;

            test.Add(key);
            test.Add(keyword);
        }
Exemplo n.º 8
0
        public void Worldspace_GetOrAddAsOverride_Clean()
        {
            WarmupSkyrim.Init();
            var mod        = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimSE);
            var worldspace = mod.Worldspaces.AddNew();
            var block      = worldspace.SubCells.AddReturn(new WorldspaceBlock());
            var subBlock   = block.Items.AddReturn(new WorldspaceSubBlock());
            var cell       = subBlock.Items.AddReturn(new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE));

            var mod2 = new SkyrimMod(TestConstants.PluginModKey2, SkyrimRelease.SkyrimSE);
            var worldspaceOverride = mod2.Worldspaces.GetOrAddAsOverride(worldspace);

            Assert.Empty(worldspaceOverride.SubCells);
        }
Exemplo n.º 9
0
        public void SetModKeys()
        {
            WarmupSkyrim.Init();
            var mod        = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimSE);
            var worldspace = mod.Worldspaces.AddNew();
            var block      = new WorldspaceBlock()
            {
                BlockNumberX = 2,
                BlockNumberY = 3,
                GroupType    = GroupTypeEnum.ExteriorCellBlock,
            };
            var subBlock = new WorldspaceSubBlock()
            {
                BlockNumberX = 4,
                BlockNumberY = 5,
                GroupType    = GroupTypeEnum.ExteriorCellSubBlock,
            };

            block.Items.Add(subBlock);
            worldspace.SubCells.Add(block);
            var cell = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            subBlock.Items.Add(cell);

            var placedNpc = new PlacedNpc(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            cell.Persistent.Add(placedNpc);
            var placedObj = new PlacedObject(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            cell.Persistent.Add(placedObj);

            var cache    = mod.ToImmutableLinkCache();
            var contexts = mod.EnumerateMajorRecordContexts <IPlacedObject, IPlacedObjectGetter>(linkCache: cache).ToArray();

            contexts.Should().HaveCount(1);
            contexts[0].ModKey.Should().Be(TestConstants.PluginModKey);
        }
Exemplo n.º 10
0
        public void FormLink_Direct_TryResolveContext_DeepRecord_Linked(LinkCacheTestTypes cacheType, AContextRetriever contextRetriever)
        {
            var mod        = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimLE);
            var worldspace = mod.Worldspaces.AddNew();
            var subBlock   = new WorldspaceSubBlock();
            var cell       = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimLE);

            subBlock.Items.Add(cell);
            var placedNpc = new PlacedNpc(mod.GetNextFormKey(), SkyrimRelease.SkyrimLE);

            cell.Temporary.Add(placedNpc);
            var block = new WorldspaceBlock();

            block.Items.Add(subBlock);
            worldspace.SubCells.Add(block);
            var(style, package) = GetLinkCache(mod, cacheType);
            var placedFormLink = new FormLink <IPlacedNpcGetter>(placedNpc.FormKey);

            WrapPotentialThrow(cacheType, style, () =>
            {
                Assert.True(contextRetriever.TryResolveContext <IPlacedNpc, IPlacedNpcGetter>(placedFormLink, package, out var linkedPlacedNpc));
                linkedPlacedNpc.Record.Should().BeSameAs(placedNpc);
                linkedPlacedNpc.ModKey.Should().Be(TestConstants.PluginModKey);
                linkedPlacedNpc.Parent.Record.Should().Be(cell);
                var cellFormLink = new FormLink <ICellGetter>(cell.FormKey);
                Assert.True(contextRetriever.TryResolveContext <ICell, ICellGetter>(cellFormLink, package, out var linkedCell));
                linkedCell.Record.Should().BeSameAs(cell);
                linkedCell.ModKey.Should().Be(TestConstants.PluginModKey);
                linkedCell.Parent.Record.Should().Be(subBlock);
                var worldspaceFormLink = new FormLink <IWorldspaceGetter>(worldspace.FormKey);
                Assert.True(contextRetriever.TryResolveContext <IWorldspace, IWorldspaceGetter>(worldspaceFormLink, package, out var linkedWorldspace));
                linkedWorldspace.Record.Should().BeSameAs(worldspace);
                linkedWorldspace.ModKey.Should().Be(TestConstants.PluginModKey);
                linkedWorldspace.Parent.Should().BeNull();
            });
        }
Exemplo n.º 11
0
        public void DisableAPI()
        {
            // Some calls assuring the Disable() API is accessible and working.
            SkyrimMod    sourceMod    = new SkyrimMod(Utility.PluginModKey, SkyrimRelease.SkyrimSE);
            FormKey      key          = sourceMod.GetNextFormKey();
            PlacedObject placedObject = new PlacedObject(key, SkyrimRelease.SkyrimSE);

            // Simplistic Disable access and verification.
            PlacedObject disabledObj = placedObject;

            disabledObj.Disable();
            //_testOutputHelper.WriteLine($"{disabledPlacedObject.MajorRecordFlagsRaw}");
            Assert.True(EnumExt.HasFlag(disabledObj.MajorRecordFlagsRaw, Constants.InitiallyDisabled));
            MajorRecord majorRecord = placedObject;

            majorRecord.Disable();
            Assert.True(EnumExt.HasFlag(majorRecord.MajorRecordFlagsRaw, Constants.InitiallyDisabled));
            IMajorRecordCommon interfaceRecord = placedObject;

            interfaceRecord.Disable();
            Assert.True(EnumExt.HasFlag(interfaceRecord.MajorRecordFlagsRaw, Constants.InitiallyDisabled));
            IPlaced interfacePlaced = placedObject;

            interfacePlaced.Disable();
            Assert.True(EnumExt.HasFlag(interfacePlaced.MajorRecordFlagsRaw, Constants.InitiallyDisabled));

            // Sanity test both API are invokable under Placed context.
            PlacedTrap placedTrap = new PlacedTrap(key, SkyrimRelease.SkyrimSE);

            placedTrap.Disable(IPlaced.DisableType.DisableWithoutZOffset);
            interfacePlaced = placedTrap;
            interfacePlaced.Disable(IPlaced.DisableType.JustInitiallyDisabled);
            IPlaced abstractPlaced = placedTrap;

            abstractPlaced.Disable();
            abstractPlaced.Disable(IPlaced.DisableType.SafeDisable);

            //Try any other object other than Placed (invoke MajorRecord.Disable() and see if it works)
            var armor = new Armor(key, SkyrimRelease.SkyrimSE);

            armor.Disable();
            Assert.True(EnumExt.HasFlag(armor.MajorRecordFlagsRaw, Constants.InitiallyDisabled));
        }
Exemplo n.º 12
0
        public void ComplexOverrides()
        {
            WarmupSkyrim.Init();

            // Construct base mod
            const string Mod1Name   = "Mod1";
            var          mod        = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimSE);
            var          worldspace = mod.Worldspaces.AddNew();

            worldspace.EditorID = Mod1Name;
            var block = new WorldspaceBlock()
            {
                BlockNumberX = 2,
                BlockNumberY = 3,
                GroupType    = GroupTypeEnum.ExteriorCellBlock,
            };
            var subBlock = new WorldspaceSubBlock()
            {
                BlockNumberX = 4,
                BlockNumberY = 5,
                GroupType    = GroupTypeEnum.ExteriorCellSubBlock,
            };

            block.Items.Add(subBlock);
            worldspace.SubCells.Add(block);
            var cell = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            cell.EditorID = Mod1Name;
            subBlock.Items.Add(cell);

            var placedObj = new PlacedObject(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            placedObj.EditorID = Mod1Name;
            cell.Persistent.Add(placedObj);

            // Override cell in 2nd mod
            const string Mod2Name    = "Mod2";
            var          mod2        = new SkyrimMod(TestConstants.PluginModKey2, SkyrimRelease.SkyrimSE);
            var          worldspace2 = new Worldspace(worldspace.FormKey, SkyrimRelease.SkyrimSE);

            worldspace2.EditorID = Mod2Name;
            mod2.Worldspaces.Add(worldspace2);
            var block2 = new WorldspaceBlock()
            {
                BlockNumberX = 2,
                BlockNumberY = 3,
                GroupType    = GroupTypeEnum.ExteriorCellBlock,
            };
            var subBlock2 = new WorldspaceSubBlock()
            {
                BlockNumberX = 4,
                BlockNumberY = 5,
                GroupType    = GroupTypeEnum.ExteriorCellSubBlock,
            };

            block2.Items.Add(subBlock2);
            worldspace2.SubCells.Add(block2);
            var cell2 = new Cell(cell.FormKey, SkyrimRelease.SkyrimSE);

            cell2.EditorID = Mod2Name;
            subBlock2.Items.Add(cell2);

            // Override worldspace in 3rd mod
            const string Mod3Name    = "Mod3";
            var          mod3        = new SkyrimMod(TestConstants.PluginModKey3, SkyrimRelease.SkyrimSE);
            var          worldspace3 = new Worldspace(worldspace.FormKey, SkyrimRelease.SkyrimSE);

            worldspace3.EditorID = Mod3Name;
            mod3.Worldspaces.Add(worldspace3);

            // Override in 4th, and check sources
            var loadOrder = new LoadOrder <ISkyrimModGetter>(mod.AsEnumerable().And(mod2).And(mod3));
            var cache     = loadOrder.ToImmutableLinkCache();

            var contexts = mod.EnumerateMajorRecordContexts <IPlaced, IPlacedGetter>(linkCache: cache).ToArray();

            contexts.Should().HaveCount(1);

            var mod4 = new SkyrimMod(TestConstants.PluginModKey4, SkyrimRelease.SkyrimSE);
            var placedObjOverride = contexts[0].GetOrAddAsOverride(mod4);

            placedObjOverride.EditorID.Should().Be(Mod1Name);
            var cellOverride = mod4.Worldspaces.First().SubCells.First().Items.First().Items.First();

            cellOverride.EditorID.Should().Be(Mod2Name);
            var worldspaceOverride = mod4.Worldspaces.First();

            worldspaceOverride.EditorID.Should().Be(Mod3Name);
        }
Exemplo n.º 13
0
        public void IPlacedInWorldspace()
        {
            WarmupSkyrim.Init();
            var mod        = new SkyrimMod(TestConstants.PluginModKey, SkyrimRelease.SkyrimSE);
            var worldspace = mod.Worldspaces.AddNew();
            var block      = new WorldspaceBlock()
            {
                BlockNumberX = 2,
                BlockNumberY = 3,
                GroupType    = GroupTypeEnum.ExteriorCellBlock,
            };
            var subBlock = new WorldspaceSubBlock()
            {
                BlockNumberX = 4,
                BlockNumberY = 5,
                GroupType    = GroupTypeEnum.ExteriorCellSubBlock,
            };

            block.Items.Add(subBlock);
            worldspace.SubCells.Add(block);
            var cell1 = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);
            var cell2 = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            subBlock.Items.Add(cell1);
            subBlock.Items.Add(cell2);
            var block2 = new WorldspaceBlock()
            {
                BlockNumberX = 5,
                BlockNumberY = 6,
                GroupType    = GroupTypeEnum.ExteriorCellBlock,
            };
            var subBlock2 = new WorldspaceSubBlock()
            {
                BlockNumberX = 8,
                BlockNumberY = 9,
                GroupType    = GroupTypeEnum.ExteriorCellSubBlock,
            };

            block2.Items.Add(subBlock2);
            worldspace.SubCells.Add(block2);
            var cell3 = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            subBlock2.Items.Add(cell3);

            var placedNpc = new PlacedNpc(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            cell2.Persistent.Add(placedNpc);
            var placedObj = new PlacedObject(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            cell2.Persistent.Add(placedObj);

            var cache    = mod.ToImmutableLinkCache();
            var contexts = mod.EnumerateMajorRecordContexts <IPlaced, IPlacedGetter>(linkCache: cache).ToArray();

            Assert.Equal(2, contexts.Length);

            var mod2 = new SkyrimMod(TestConstants.PluginModKey2, SkyrimRelease.SkyrimSE);
            var placedNpcOverride = contexts[0].GetOrAddAsOverride(mod2);
            var placedObjOverride = contexts[1].GetOrAddAsOverride(mod2);

            Assert.Equal(placedNpc.FormKey, placedNpcOverride.FormKey);
            Assert.Equal(placedObj.FormKey, placedObjOverride.FormKey);
            mod2.Worldspaces.Should().HaveCount(1);
            mod2.Worldspaces.First().SubCells.Should().HaveCount(1);
            mod2.Worldspaces.First().SubCells.First().Items.Should().HaveCount(1);
            mod2.Worldspaces.First().SubCells.First().Items.First().Items.Should().HaveCount(1);
            mod2.Worldspaces.First().SubCells.First().Items.First().Items.First().Persistent.Should().HaveCount(2);
            Assert.Same(placedNpcOverride, mod2.Worldspaces.First().SubCells.First().Items.First().Items.First().Persistent.First());
        }
Exemplo n.º 14
0
        public void CellInWorldspace()
        {
            WarmupSkyrim.Init();
            var mod        = new SkyrimMod(Utility.PluginModKey, SkyrimRelease.SkyrimSE);
            var worldspace = mod.Worldspaces.AddNew();
            var block      = new WorldspaceBlock()
            {
                BlockNumberX = 2,
                BlockNumberY = 3,
                GroupType    = GroupTypeEnum.ExteriorCellBlock,
            };
            var subBlock = new WorldspaceSubBlock()
            {
                BlockNumberX = 4,
                BlockNumberY = 5,
                GroupType    = GroupTypeEnum.ExteriorCellSubBlock,
            };

            block.Items.Add(subBlock);
            worldspace.SubCells.Add(block);
            var cell1 = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);
            var cell2 = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            subBlock.Items.Add(cell1);
            subBlock.Items.Add(cell2);
            var block2 = new WorldspaceBlock()
            {
                BlockNumberX = 5,
                BlockNumberY = 6,
                GroupType    = GroupTypeEnum.ExteriorCellBlock,
            };
            var subBlock2 = new WorldspaceSubBlock()
            {
                BlockNumberX = 8,
                BlockNumberY = 9,
                GroupType    = GroupTypeEnum.ExteriorCellSubBlock,
            };

            block2.Items.Add(subBlock2);
            worldspace.SubCells.Add(block2);
            var cell3 = new Cell(mod.GetNextFormKey(), SkyrimRelease.SkyrimSE);

            subBlock2.Items.Add(cell3);

            var cache    = mod.ToImmutableLinkCache();
            var contexts = mod.EnumerateMajorRecordContexts <ICell, ICellGetter>(linkCache: cache).ToArray();

            Assert.Equal(3, contexts.Length);
            Assert.Same(contexts[0].Record, cell1);
            Assert.Same(contexts[1].Record, cell2);
            Assert.Same(contexts[2].Record, cell3);

            var mod2          = new SkyrimMod(Utility.PluginModKey2, SkyrimRelease.SkyrimSE);
            var cell2Override = contexts[1].GetOrAddAsOverride(mod2);

            Assert.Equal(cell2.FormKey, cell2Override.FormKey);
            mod2.Worldspaces.Should().HaveCount(1);
            mod2.Worldspaces.First().SubCells.Should().HaveCount(1);
            mod2.Worldspaces.First().SubCells.First().Items.Should().HaveCount(1);
            mod2.Worldspaces.First().SubCells.First().Items.First().Items.Should().HaveCount(1);
            Assert.Same(cell2Override, mod2.Worldspaces.First().SubCells.First().Items.First().Items.First());
        }