Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions documentation/manual-test-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -2364,6 +2364,8 @@ dropping their `MaxHp` makes the run quick.
- [ ] Three hostile monsters appear in the first room and are drawn as soon as the room is, and a padlocked portal stands at its
east edge; walking onto the padlock does nothing
- [ ] No time-space stone is drawn inside the rooms
- [ ] No portal of Chicken Farm Path is drawn inside the rooms: the ring south of the start
spot is gone, and walking onto its cell leaves you in the room with the clock still running
- [ ] Killing the third monster opens the padlock; walking onto it moves you to the second
room, where a single Weak Devil Vampire waits
- [ ] Killing it shows Mission Clear with the monsters killed, the rooms explored and
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace NosCore.GameObject.Services.MapInstanceGenerationService
{
public interface IMapInstanceGeneratorService
{
Task AddMapInstanceAsync(MapInstance mapInstance);
Task AddMapInstanceAsync(MapInstance mapInstance, bool withMapPortals = true);
Task InitializeAsync();
Task RemoveMapAsync(Guid guid);
MapInstance CreateMapInstance(Map.Map map, Guid guid, bool shopAllowed, MapInstanceType normalInstance);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,14 @@ public class MapInstanceGeneratorService(List<MapDto> maps, List<NpcMonsterDto>
List<MapTypeMapDto> mapTypeMaps)
: IMapInstanceGeneratorService
{
public Task AddMapInstanceAsync(MapInstance mapInstance)
public Task AddMapInstanceAsync(MapInstance mapInstance, bool withMapPortals = true)
{
mapInstanceRegistry.Register(mapInstance.MapInstanceId, mapInstance);
if (!withMapPortals)
{
return Task.CompletedTask;
}

return LoadPortalsAsync(mapInstance, portalDao.Where(s => s.SourceMapId == mapInstance.Map.MapId)?.ToList() ?? new List<PortalDto>());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,9 @@ public IReadOnlyList<ScriptedInstance> GetByMap(short mapId)
LoadMapNpcs(mapInstance, room);
}

await _mapInstanceGeneratorService.Value.AddMapInstanceAsync(mapInstance);
// A room only has the portals its script spawns; its map's world exits would let a
// player walk out without going through the run's own exit.
await _mapInstanceGeneratorService.Value.AddMapInstanceAsync(mapInstance, withMapPortals: false);
await mapInstance.StartLifeAsync();
built[room.Key] = mapInstance;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using NosCore.GameObject.Services.BattleService;
using NosCore.GameObject.Services.BattleService.Model;
using NosCore.GameObject.Services.MapInstanceGenerationService;
using NosCore.Packets.Enumerations;
using NosCore.Tests.Shared;
using NosCore.Data.Enumerations.I18N;
using NosCore.Shared.I18N;
Expand Down Expand Up @@ -108,6 +109,37 @@ public async Task ADeadMonsterComesBackWholeAtItsSpawnOnceItsTimeHasCome()
await map.DisposeAsync();
}

[TestMethod]
public async Task AnAddedMapTakesItsMapsWorldPortals()
{
await World.PortalDao.TryInsertOrUpdateAsync(new PortalDto
{
PortalId = 9100, SourceMapId = 0, SourceX = 1, SourceY = 1, DestinationMapId = 1, DestinationX = 2,
DestinationY = 2, Type = PortalType.MapPortal,
});
var map = NewMap();

await World.MapInstanceGeneratorService.AddMapInstanceAsync(map);

Assert.AreEqual(9100, map.Portals.Single().PortalId);
}

[TestMethod]
public async Task AMapAddedWithoutMapPortalsHasNone()
{
await World.PortalDao.TryInsertOrUpdateAsync(new PortalDto
{
PortalId = 9100, SourceMapId = 0, SourceX = 1, SourceY = 1, DestinationMapId = 1, DestinationX = 2,
DestinationY = 2, Type = PortalType.MapPortal,
});
var map = NewMap();

await World.MapInstanceGeneratorService.AddMapInstanceAsync(map, withMapPortals: false);

Assert.AreEqual(0, map.Portals.Count);
Assert.AreSame(map, World.GetMap(map.MapInstanceId));
}

[TestMethod]
public async Task RemovingAMapStopsItsLifeAndReleasesItsWorld()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ private ScriptedInstanceDto Scripted(short id, short mapId, short x, short y, st
It.IsAny<NosCore.Data.Enumerations.Map.MapInstanceType>()))
.Returns((GameObject.Map.Map map, Guid id, bool shop, NosCore.Data.Enumerations.Map.MapInstanceType type)
=> World.MapInstanceGeneratorService.CreateMapInstance(map, id, shop, type));
generator.Setup(s => s.AddMapInstanceAsync(It.IsAny<GameObject.Services.MapInstanceGenerationService.MapInstance>()))
generator.Setup(s => s.AddMapInstanceAsync(It.IsAny<GameObject.Services.MapInstanceGenerationService.MapInstance>(), It.IsAny<bool>()))
.Returns(Task.CompletedTask);
generator.Setup(s => s.RemoveMapAsync(It.IsAny<Guid>()))
.Callback<Guid>(removed.Add).Returns(Task.CompletedTask);
Expand Down Expand Up @@ -217,8 +217,8 @@ public async Task AMapRoomComesWithItsMapsMonstersAsync()
var (service, generator, _) = BuildWithMaps(Scripted(1, 1, 5, 6, MapRooms),
[new NpcMonsterDto { NpcMonsterVNum = 58, MaxHp = 10 }], 2004);
var built = new List<GameObject.Services.MapInstanceGenerationService.MapInstance>();
generator.Setup(s => s.AddMapInstanceAsync(It.IsAny<GameObject.Services.MapInstanceGenerationService.MapInstance>()))
.Callback<GameObject.Services.MapInstanceGenerationService.MapInstance>(built.Add).Returns(Task.CompletedTask);
generator.Setup(s => s.AddMapInstanceAsync(It.IsAny<GameObject.Services.MapInstanceGenerationService.MapInstance>(), It.IsAny<bool>()))
.Callback<GameObject.Services.MapInstanceGenerationService.MapInstance, bool>((map, _) => built.Add(map)).Returns(Task.CompletedTask);

var run = (await service.InstantiateAsync(service.GetAt(1, 5, 6).NotNull())).NotNull();

Expand Down Expand Up @@ -253,6 +253,19 @@ public async Task EachRoomOfTheDefinitionBecomesItsOwnMapInstanceAsync()
Assert.AreNotEqual(rooms[1], rooms[2]);
}

[TestMethod]
public async Task RoomsDoNotTakeTheirMapsWorldPortalsAsync()
{
var (service, generator, _) = BuildWithMaps(Scripted(1, 1, 5, 6, TwoRooms), 2004, 2005);

await service.InstantiateAsync(service.GetAt(1, 5, 6).NotNull());

generator.Verify(s => s.AddMapInstanceAsync(It.IsAny<GameObject.Services.MapInstanceGenerationService.MapInstance>(), false),
Times.Exactly(2));
generator.Verify(s => s.AddMapInstanceAsync(It.IsAny<GameObject.Services.MapInstanceGenerationService.MapInstance>(), true),
Times.Never);
}

[TestMethod]
public async Task TwoPartiesEnteringTheSameDoorDoNotMeetAsync()
{
Expand All @@ -271,7 +284,7 @@ public async Task ADoorWithNoScriptBuildsNothingAsync()
var (service, generator, _) = BuildWithMaps(Scripted(1, 1, 5, 6, null));

Assert.IsNull(await service.InstantiateAsync(service.GetAt(1, 5, 6).NotNull()));
generator.Verify(s => s.AddMapInstanceAsync(It.IsAny<GameObject.Services.MapInstanceGenerationService.MapInstance>()),
generator.Verify(s => s.AddMapInstanceAsync(It.IsAny<GameObject.Services.MapInstanceGenerationService.MapInstance>(), It.IsAny<bool>()),
Times.Never);
}

Expand All @@ -281,7 +294,7 @@ public async Task AScriptThatDoesNotCompileBuildsNothingAsync()
var (service, generator, _) = BuildWithMaps(Scripted(1, 1, 5, 6, Broken), 2004, 2005);

Assert.IsNull(await service.InstantiateAsync((service.GetAt(1, 5, 6) ?? throw new AssertFailedException("no entrance"))));
generator.Verify(s => s.AddMapInstanceAsync(It.IsAny<GameObject.Services.MapInstanceGenerationService.MapInstance>()),
generator.Verify(s => s.AddMapInstanceAsync(It.IsAny<GameObject.Services.MapInstanceGenerationService.MapInstance>(), It.IsAny<bool>()),
Times.Never);
}

Expand All @@ -293,7 +306,7 @@ public async Task AMissingScriptLeavesTheTimeSpaceOutAsync()

Assert.IsFalse(await service.LoadAsync(entrance));
Assert.IsNull(await service.InstantiateAsync(entrance));
generator.Verify(s => s.AddMapInstanceAsync(It.IsAny<GameObject.Services.MapInstanceGenerationService.MapInstance>()),
generator.Verify(s => s.AddMapInstanceAsync(It.IsAny<GameObject.Services.MapInstanceGenerationService.MapInstance>(), It.IsAny<bool>()),
Times.Never);
}

Expand Down
Loading