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
4 changes: 4 additions & 0 deletions documentation/manual-test-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ should give the same NPCs.
player stays
- [ ] The champion area tower does not answer a player without a champion level; the volunteers'
guard asks for champion level 60 and 25 000 gold
- [ ] Once a capture of the trip has been parsed: the Land of Life entrance (dialog 552) takes a
champion of level 30 to the Land of Life, 60 to the Advanced and 80 to the Expert one, for
free; a champion below the level is told "You must be champion level 30 (60, 80) or above to enter
this region." with that menu's own level, and stays
- [ ] A teleportation stone that leads across its own map (vnum 856) shows a five-second bar when
talked to, and the bar running out carries you and your pet to its destination cell

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// __ _ __ __ ___ __ ___ ___
// | \| |/__\ /' _/ / _//__\| _ \ __|
// | | ' | \/ |`._`.| \_| \/ | v / _|
// |_|\__|\__/ |___/ \__/\__/|_|_\___|
//

using System.Collections.Generic;
using JetBrains.Annotations;
using NosCore.Data.StaticEntities;
using NosCore.GameObject.Services.MapChangeService;
using NosCore.Packets.Enumerations;

namespace NosCore.GameObject.Messaging.Handlers.Nrun
{
[UsedImplicitly]
public sealed class AdvancedLandOfLifeEntryHandler(IMapChangeService mapChangeService, List<TeleporterDto> teleporters)
: NpcTeleportHandler(mapChangeService, teleporters)
{
public override NrunRunnerType Runner => NrunRunnerType.EnterAdvancedLandOfLife;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// __ _ __ __ ___ __ ___ ___
// | \| |/__\ /' _/ / _//__\| _ \ __|
// | | ' | \/ |`._`.| \_| \/ | v / _|
// |_|\__|\__/ |___/ \__/\__/|_|_\___|
//

using System.Collections.Generic;
using JetBrains.Annotations;
using NosCore.Data.StaticEntities;
using NosCore.GameObject.Services.MapChangeService;
using NosCore.Packets.Enumerations;

namespace NosCore.GameObject.Messaging.Handlers.Nrun
{
[UsedImplicitly]
public sealed class ExpertLandOfLifeEntryHandler(IMapChangeService mapChangeService, List<TeleporterDto> teleporters)
: NpcTeleportHandler(mapChangeService, teleporters)
{
public override NrunRunnerType Runner => NrunRunnerType.EnterExpertLandOfLife;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
// __ _ __ __ ___ __ ___ ___
// | \| |/__\ /' _/ / _//__\| _ \ __|
// | | ' | \/ |`._`.| \_| \/ | v / _|
// |_|\__|\__/ |___/ \__/\__/|_|_\___|
//

using System.Collections.Generic;
using JetBrains.Annotations;
using NosCore.Data.StaticEntities;
using NosCore.GameObject.Services.MapChangeService;
using NosCore.Packets.Enumerations;

namespace NosCore.GameObject.Messaging.Handlers.Nrun
{
[UsedImplicitly]
public sealed class LandOfLifeEntryHandler(IMapChangeService mapChangeService, List<TeleporterDto> teleporters)
: NpcTeleportHandler(mapChangeService, teleporters)
{
public override NrunRunnerType Runner => NrunRunnerType.EnterLandOfLife;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ public async Task HandleAsync(ClientSession session, IAliveEntity? target, NrunP
await session.SendPacketAsync(new MsgiPacket
{
Type = MessageType.Default,
Message = Game18NConstString.ChampionLevelRequirement,
Message = Game18NConstString.YouMustBeChampionLevelOr,
ArgumentType = 4,
Game18NArguments = { destination.MinimumHeroLevel },
});
}

Expand Down
6 changes: 6 additions & 0 deletions src/NosCore.Parser/Parsers/TeleporterFares.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,18 @@ public static class TeleporterFares
public const short RunePieceVNum = 5919;

public const byte VolunteerChampionLevel = 60;
public const byte LandOfLifeChampionLevel = 30;
public const byte AdvancedLandOfLifeChampionLevel = 60;
public const byte ExpertLandOfLifeChampionLevel = 80;

// The champion area menus answer champions only, and the volunteers' guard asks for more.
public static byte MinimumHeroLevel(NrunRunnerType? runner, short? npcDialog) => runner switch
{
NrunRunnerType.MoveToMap when npcDialog is VolunteerDialog => VolunteerChampionLevel,
NrunRunnerType.MoveToMap => 1,
NrunRunnerType.EnterLandOfLife => LandOfLifeChampionLevel,
NrunRunnerType.EnterAdvancedLandOfLife => AdvancedLandOfLifeChampionLevel,
NrunRunnerType.EnterExpertLandOfLife => ExpertLandOfLifeChampionLevel,
_ => 0,
};

Expand Down
3 changes: 3 additions & 0 deletions src/NosCore.Parser/Parsers/TeleporterParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public class TeleporterParser(IDao<TeleporterDto, short> teleporterDao, IDao<Map
NrunRunnerType.TravelToMap,
NrunRunnerType.MoveToMap,
NrunRunnerType.GoToNextDimension,
NrunRunnerType.EnterLandOfLife,
NrunRunnerType.EnterAdvancedLandOfLife,
NrunRunnerType.EnterExpertLandOfLife,
};

// Menus whose option is the destination map id: a landing elsewhere answered another request.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using NosCore.Data.StaticEntities;
using NosCore.GameObject.Messaging.Handlers.Nrun;
using NosCore.GameObject.Networking.ClientSession;
using NosCore.GameObject.Services.BattleService;
using NosCore.GameObject.Services.InventoryService;
using NosCore.GameObject.Services.ItemGenerationService;
using NosCore.GameObject.Services.ItemGenerationService.Item;
Expand Down Expand Up @@ -43,6 +44,11 @@ public class ChampionAreaTravelHandlerTests
private const short CelestialLairDialog = 540;
private const short VolunteerDialog = 554;
private const short RunePiece = 5919;
private const int LandOfLifeNpcId = 104;
private const short LandOfLifeDialog = 552;
private const short LandOfLife = 2750;
private const short AdvancedLandOfLife = 2751;
private const short ExpertLandOfLife = 2758;

private TestWorld World;
private ClientSession _session;
Expand All @@ -59,7 +65,7 @@ public async Task SetupAsync()
World.Inject(new List<ItemDto> { new Item { VNum = RunePiece, Type = NoscorePocketType.Main } });
World.Inject<IItemCatalog>(World.Create<ItemCatalog>());
_itemProvider = World.GenerateItemProvider();
_mapChangeService = new Mock<IMapChangeService>();
_mapChangeService = World.Freeze<Mock<IMapChangeService>>();
_teleporters = new List<TeleporterDto>
{
new() { MapNpcId = TowerNpcId, Runner = NrunRunnerType.MoveToMap, Index = Dragonveil, MapId = Dragonveil, MapX = 80, MapY = 60, MinimumHeroLevel = 1 },
Expand All @@ -68,27 +74,37 @@ public async Task SetupAsync()
new() { MapNpcId = TowerNpcId, Runner = NrunRunnerType.TravelToMap, Index = 279, MapId = 279, MapX = 10, MapY = 20 },
new() { MapNpcId = TowerNpcId, Runner = NrunRunnerType.GoToNextDimension, Index = 296, MapId = 296, MapX = 15, MapY = 25 },
new() { MapNpcId = SerizadNpcId, Runner = NrunRunnerType.GoToGrenigasTemple, Index = 0, MapId = GrenigasTemple, MapX = 50, MapY = 70, FareItemVNum = RunePiece },
new() { MapNpcId = LandOfLifeNpcId, Runner = NrunRunnerType.EnterLandOfLife, Index = 0, MapId = LandOfLife, MapX = 35, MapY = 45, MinimumHeroLevel = 30 },
new() { MapNpcId = LandOfLifeNpcId, Runner = NrunRunnerType.EnterAdvancedLandOfLife, Index = 0, MapId = AdvancedLandOfLife, MapX = 36, MapY = 46, MinimumHeroLevel = 60 },
new() { MapNpcId = LandOfLifeNpcId, Runner = NrunRunnerType.EnterExpertLandOfLife, Index = 0, MapId = ExpertLandOfLife, MapX = 37, MapY = 47, MinimumHeroLevel = 80 },
};
World.Inject(_teleporters);
World.Inject(new List<NpcMonsterDto> { new() { NpcMonsterVNum = 1 } });
World.UseReal<INpcMonsterCatalog, NpcMonsterCatalog>();
_session.Character.MapInstance.LoadNpcs(
new List<MapNpcDto>
{
Npc(TowerNpcId, TowerDialog),
Npc(CelestialLairNpcId, CelestialLairDialog),
Npc(GuardNpcId, VolunteerDialog),
Npc(SerizadNpcId, SerizadDialog),
Npc(LandOfLifeNpcId, LandOfLifeDialog),
},
new NosCore.GameObject.Services.BattleService.NpcMonsterCatalog(new List<NpcMonsterDto> { new() { NpcMonsterVNum = 1 } }));
_handler = new MoveToMapHandler(_mapChangeService.Object, _teleporters);
World.Create<INpcMonsterCatalog>());
_handler = World.Create<MoveToMapHandler>();
}

[TestMethod]
public async Task RunnersMatchTheirMenus()
{
await new Spec("Each travel menu answers its own n_run")
.Then(HandlerOf_ShouldAnswer_, typeof(MoveToMapHandler), NrunRunnerType.MoveToMap)
.And(HandlerOf_ShouldAnswer_, typeof(TravelToMapHandler), NrunRunnerType.TravelToMap)
.And(HandlerOf_ShouldAnswer_, typeof(NextDimensionHandler), NrunRunnerType.GoToNextDimension)
.And(HandlerOf_ShouldAnswer_, typeof(GrenigasTempleTeleporterHandler), NrunRunnerType.GoToGrenigasTemple)
.Then(HandlerOf_ShouldAnswer_<MoveToMapHandler>, NrunRunnerType.MoveToMap)
.And(HandlerOf_ShouldAnswer_<TravelToMapHandler>, NrunRunnerType.TravelToMap)
.And(HandlerOf_ShouldAnswer_<NextDimensionHandler>, NrunRunnerType.GoToNextDimension)
.And(HandlerOf_ShouldAnswer_<GrenigasTempleTeleporterHandler>, NrunRunnerType.GoToGrenigasTemple)
.And(HandlerOf_ShouldAnswer_<LandOfLifeEntryHandler>, NrunRunnerType.EnterLandOfLife)
.And(HandlerOf_ShouldAnswer_<AdvancedLandOfLifeEntryHandler>, NrunRunnerType.EnterAdvancedLandOfLife)
.And(HandlerOf_ShouldAnswer_<ExpertLandOfLifeEntryHandler>, NrunRunnerType.EnterExpertLandOfLife)
.ExecuteAsync();
}

Expand Down Expand Up @@ -151,7 +167,7 @@ public async Task VolunteersNeedChampionLevelSixty()
.WhenAsync(Option_IsPickedAtNpc_, InvadedWesternMinePlains, GuardNpcId)
.Then(NoMapChangeShouldHaveBeenInvoked)
.And(CharacterGoldShouldBe_, 30_000L)
.And(PlayerShouldBeTold_, Game18NConstString.ChampionLevelRequirement)
.And(PlayerShouldBeToldTheChampionLevel_, 60)
.ExecuteAsync();
}

Expand Down Expand Up @@ -184,7 +200,7 @@ public async Task TravelToMapIsFree()
{
await new Spec("The railway trip to the Undercity under Biaron's rule is free")
.Given(CharacterGoldIs_, 0L)
.And(TheMenuIs_, typeof(TravelToMapHandler))
.And(TheMenuIs_<TravelToMapHandler>)
.WhenAsync(Option_IsPickedAtNpc_, (short)279, TowerNpcId)
.Then(PlayerShouldBeSentTo_At_, (short)279, (short)10, (short)20)
.ExecuteAsync();
Expand All @@ -195,7 +211,7 @@ public async Task TheNextDimensionIsFree()
{
await new Spec("Doctor Dimensio sends the player on to the next dimension for free")
.Given(CharacterGoldIs_, 0L)
.And(TheMenuIs_, typeof(NextDimensionHandler))
.And(TheMenuIs_<NextDimensionHandler>)
.WhenAsync(Option_IsPickedAtNpc_, (short)296, TowerNpcId)
.Then(PlayerShouldBeSentTo_At_, (short)296, (short)15, (short)25)
.ExecuteAsync();
Expand All @@ -206,7 +222,7 @@ public async Task ARunePieceTakesThePlayerToGrenigasTemple()
{
await new Spec("Serizad uses one Rune Piece and the client says the player arrived at the temple entrance")
.Given(TheCharacterHas_RunePieces, (short)2)
.And(TheMenuIs_, typeof(GrenigasTempleTeleporterHandler))
.And(TheMenuIs_<GrenigasTempleTeleporterHandler>)
.WhenAsync(Option_IsPickedAtNpc_, (short)0, SerizadNpcId)
.Then(TheCharacterShouldHave_RunePieces, 1)
.And(PlayerShouldBeSentTo_At_, GrenigasTemple, (short)50, (short)70)
Expand All @@ -218,21 +234,90 @@ public async Task ARunePieceTakesThePlayerToGrenigasTemple()
public async Task WithoutARunePieceSerizadSendsNobody()
{
await new Spec("Without a Rune Piece the player stays")
.Given(TheMenuIs_, typeof(GrenigasTempleTeleporterHandler))
.Given(TheMenuIs_<GrenigasTempleTeleporterHandler>)
.WhenAsync(Option_IsPickedAtNpc_, (short)0, SerizadNpcId)
.Then(NoMapChangeShouldHaveBeenInvoked)
.ExecuteAsync();
}

[TestMethod]
public async Task AChampionOfLevelThirtyEntersTheLandOfLife()
{
await new Spec("At champion level 30 the player is sent to the Land of Life for free")
.Given(ChampionLevelIs_, (byte)30)
.And(CharacterGoldIs_, 0L)
.And(TheMenuIs_<LandOfLifeEntryHandler>)
.WhenAsync(Option_IsPickedAtNpc_, (short)0, LandOfLifeNpcId)
.Then(PlayerShouldBeSentTo_At_, LandOfLife, (short)35, (short)45)
.And(CharacterGoldShouldBe_, 0L)
.ExecuteAsync();
}

[TestMethod]
public async Task TheLandOfLifeRefusesAChampionBelowLevelThirty()
{
await new Spec("Below champion level 30 the player is told the requirement and stays")
.Given(ChampionLevelIs_, (byte)29)
.And(TheMenuIs_<LandOfLifeEntryHandler>)
.WhenAsync(Option_IsPickedAtNpc_, (short)0, LandOfLifeNpcId)
.Then(NoMapChangeShouldHaveBeenInvoked)
.And(PlayerShouldBeToldTheChampionLevel_, 30)
.ExecuteAsync();
}

[TestMethod]
public async Task AChampionOfLevelSixtyEntersTheAdvancedLandOfLife()
{
await new Spec("At champion level 60 the player is sent to the Advanced Land of Life")
.Given(ChampionLevelIs_, (byte)60)
.And(TheMenuIs_<AdvancedLandOfLifeEntryHandler>)
.WhenAsync(Option_IsPickedAtNpc_, (short)0, LandOfLifeNpcId)
.Then(PlayerShouldBeSentTo_At_, AdvancedLandOfLife, (short)36, (short)46)
.ExecuteAsync();
}

[TestMethod]
public async Task TheAdvancedLandOfLifeRefusesAChampionBelowLevelSixty()
{
await new Spec("Below champion level 60 the Advanced Land of Life tells the requirement")
.Given(ChampionLevelIs_, (byte)59)
.And(TheMenuIs_<AdvancedLandOfLifeEntryHandler>)
.WhenAsync(Option_IsPickedAtNpc_, (short)0, LandOfLifeNpcId)
.Then(NoMapChangeShouldHaveBeenInvoked)
.And(PlayerShouldBeToldTheChampionLevel_, 60)
.ExecuteAsync();
}

[TestMethod]
public async Task AChampionOfLevelEightyEntersTheExpertLandOfLife()
{
await new Spec("At champion level 80 the player is sent to the Expert Land of Life")
.Given(ChampionLevelIs_, (byte)80)
.And(TheMenuIs_<ExpertLandOfLifeEntryHandler>)
.WhenAsync(Option_IsPickedAtNpc_, (short)0, LandOfLifeNpcId)
.Then(PlayerShouldBeSentTo_At_, ExpertLandOfLife, (short)37, (short)47)
.ExecuteAsync();
}

[TestMethod]
public async Task TheExpertLandOfLifeRefusesAChampionBelowLevelEighty()
{
await new Spec("Below champion level 80 the Expert Land of Life tells the requirement")
.Given(ChampionLevelIs_, (byte)79)
.And(TheMenuIs_<ExpertLandOfLifeEntryHandler>)
.WhenAsync(Option_IsPickedAtNpc_, (short)0, LandOfLifeNpcId)
.Then(NoMapChangeShouldHaveBeenInvoked)
.And(PlayerShouldBeToldTheChampionLevel_, 80)
.ExecuteAsync();
}

private MapNpcDto Npc(int id, short dialog) =>
new() { MapNpcId = id, MapId = _session.Character.MapInstance.Map.MapId, VNum = 1, Dialog = dialog };

private INrunEventHandler Create(System.Type type) =>
((INrunEventHandler)System.Activator.CreateInstance(type, _mapChangeService.Object, _teleporters).NotNull()).NotNull();

private void HandlerOf_ShouldAnswer_(System.Type type, NrunRunnerType runner) => Assert.AreEqual(runner, Create(type).Runner);
private void HandlerOf_ShouldAnswer_<T>(NrunRunnerType runner) where T : INrunEventHandler =>
Assert.AreEqual(runner, World.Create<T>().Runner);

private void TheMenuIs_(System.Type type) => _handler = Create(type);
private void TheMenuIs_<T>() where T : INrunEventHandler => _handler = World.Create<T>();

private void ChampionLevelIs_(byte level) => _session.Character.HeroLevel = level;

Expand Down Expand Up @@ -268,5 +353,14 @@ private void PlayerShouldBeToldNotEnoughGold() =>

private void PlayerShouldBeTold_(Game18NConstString message) =>
Assert.IsTrue(_session.LastPackets.OfType<MsgiPacket>().Any(p => p.Message == message));

private void PlayerShouldBeToldTheChampionLevel_(int level) =>
PacketAssert.AreEqual(new MsgiPacket
{
Type = MessageType.Default,
Message = Game18NConstString.YouMustBeChampionLevelOr,
ArgumentType = 4,
Game18NArguments = { level },
}, _session.LastPackets.OfType<MsgiPacket>().Single());
}
}
20 changes: 20 additions & 0 deletions test/NosCore.Parser.Tests/TeleporterParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,26 @@ public void ChampionMenusAskForAChampionLevel()
Assert.AreEqual((byte)0, TeleporterFares.MinimumHeroLevel(NrunRunnerType.TravelToMap, null));
}

[TestMethod]
public void EachLandOfLifeAsksForTheChampionLevelItsButtonNames()
{
Assert.AreEqual((byte)30, TeleporterFares.MinimumHeroLevel(NrunRunnerType.EnterLandOfLife, null));
Assert.AreEqual((byte)60, TeleporterFares.MinimumHeroLevel(NrunRunnerType.EnterAdvancedLandOfLife, null));
Assert.AreEqual((byte)80, TeleporterFares.MinimumHeroLevel(NrunRunnerType.EnterExpertLandOfLife, null));
}

[TestMethod]
public async Task ALandOfLifeEntryIsRecordedWithItsChampionLevel()
{
await _parser.InsertTeleportersAsync([Captured.Talk(NrunRunnerType.EnterAdvancedLandOfLife, 0, 1899), Captured.Arrival(2751, 40, 50)]);

var teleporter = _saved.Single(s => s.MapNpcId == 1899);
Assert.AreEqual(NrunRunnerType.EnterAdvancedLandOfLife, teleporter.Runner);
Assert.AreEqual((short)2751, teleporter.MapId);
Assert.AreEqual((byte)60, teleporter.MinimumHeroLevel);
Assert.AreEqual(0L, teleporter.Fare);
}

[TestMethod]
public async Task AStoredDestinationTheCaptureDoesNotShowForItsNpcIsRemoved()
{
Expand Down