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
6 changes: 6 additions & 0 deletions documentation/manual-test-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,12 @@ should give the same NPCs.
- [ ] Port Alveus Market (map 146): Sarakael, Leika Passage, Isalin, Lilith and the other stall
keepers all stand on the map, and the minimap shows them
- [ ] The shops, skill shops and teleporters of the NPCs above still open and work
- [ ] Rerun the parser on a filled database: the town teleporter in NosVille takes 1 000 gold for
its second destination and 2 000 for its third, as before
- [ ] Priestess Serizad's trip to Grenigas Temple uses one Rune Piece and says so; without one the
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
- [ ] 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
9 changes: 9 additions & 0 deletions src/NosCore.Database/Entities/Teleporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ public class Teleporter : IStaticEntity
// The n_run runner of the NPC menu offering this destination.
public NrunRunnerType? Runner { get; set; }

// Gold taken for the trip.
public long Fare { get; set; }

// An item the trip uses up, one per trip.
public short? FareItemVNum { get; set; }

// Champion level the trip asks for; 0 lets anyone travel.
public byte MinimumHeroLevel { get; set; }

[Key]
public short TeleporterId { get; set; }
}
Expand Down
5,352 changes: 5,352 additions & 0 deletions src/NosCore.Database/Migrations/20261129121213_AddTeleporterFares.Designer.cs

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace NosCore.Database.Migrations;

/// <inheritdoc />
public partial class _20261129121213_AddTeleporterFares : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<long>(
name: "Fare",
table: "Teleporter",
type: "bigint",
nullable: false,
defaultValue: 0L);

migrationBuilder.AddColumn<short>(
name: "FareItemVNum",
table: "Teleporter",
type: "smallint",
nullable: true);

migrationBuilder.AddColumn<byte>(
name: "MinimumHeroLevel",
table: "Teleporter",
type: "smallint",
nullable: false,
defaultValue: (byte)0);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "Fare",
table: "Teleporter");

migrationBuilder.DropColumn(
name: "FareItemVNum",
table: "Teleporter");

migrationBuilder.DropColumn(
name: "MinimumHeroLevel",
table: "Teleporter");
}
}
11 changes: 10 additions & 1 deletion src/NosCore.Database/Migrations/NosCoreContextModelSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ partial class NosCoreContextModelSnapshot : ModelSnapshot
// If you encounter a merge conflict in the line below, it means you need to
// discard one of the migration branches and recreate its migrations on top of
// the other branch. See https://aka.ms/efcore-docs-migrations-conflicts for more info.
public override string LastMigrationId => "20261129091909_AddNpcExchangeDialogGoldAndBuff";
public override string LastMigrationId => "20261129121213_AddTeleporterFares";

protected override void BuildModel(ModelBuilder modelBuilder)
{
Expand Down Expand Up @@ -3710,6 +3710,12 @@ protected override void BuildModel(ModelBuilder modelBuilder)

NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(teleporterId);

b.Property<long>("Fare")
.HasColumnType("bigint");

b.Property<short?>("FareItemVNum")
.HasColumnType("smallint");

b.Property<short>("Index")
.HasColumnType("smallint");

Expand All @@ -3725,6 +3731,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<short>("MapY")
.HasColumnType("smallint");

b.Property<byte>("MinimumHeroLevel")
.HasColumnType("smallint");

b.Property<short?>("Runner")
.HasColumnType("smallint");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Collections.Generic;
using JetBrains.Annotations;
using NosCore.Data.StaticEntities;
using NosCore.GameObject.Ecs;
using NosCore.GameObject.Services.MapChangeService;
using NosCore.Packets.Enumerations;

Expand All @@ -18,7 +17,5 @@ public sealed class ActVTeleporterHandler(IMapChangeService mapChangeService, Li
: NpcTeleportHandler(mapChangeService, teleporters)
{
public override NrunRunnerType Runner => NrunRunnerType.TeleportActV;

protected override long Cost(NpcComponentBundle npc, short index) => 5000L * index;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Collections.Generic;
using JetBrains.Annotations;
using NosCore.Data.StaticEntities;
using NosCore.GameObject.Ecs;
using NosCore.GameObject.Services.MapChangeService;
using NosCore.Packets.Enumerations;

Expand All @@ -18,7 +17,5 @@ public sealed class ForgottenArchipelagoTeleporterHandler(IMapChangeService mapC
: NpcTeleportHandler(mapChangeService, teleporters)
{
public override NrunRunnerType Runner => NrunRunnerType.GoToForgottenArchipelago;

protected override long Cost(NpcComponentBundle npc, short index) => 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Collections.Generic;
using JetBrains.Annotations;
using NosCore.Data.StaticEntities;
using NosCore.GameObject.Ecs;
using NosCore.GameObject.Services.MapChangeService;
using NosCore.Packets.Enumerations;

Expand All @@ -18,7 +17,5 @@ public sealed class GlacerusCaveTeleporterHandler(IMapChangeService mapChangeSer
: NpcTeleportHandler(mapChangeService, teleporters)
{
public override NrunRunnerType Runner => NrunRunnerType.GoToGlacerusCave;

protected override long Cost(NpcComponentBundle npc, short index) => 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@
using System.Threading.Tasks;
using JetBrains.Annotations;
using NosCore.Data.StaticEntities;
using NosCore.GameObject.Ecs;
using NosCore.GameObject.Networking.ClientSession;
using NosCore.GameObject.Services.InventoryService;
using NosCore.GameObject.Services.MapChangeService;
using NosCore.Packets.Enumerations;
using NosCore.Packets.ServerPackets.UI;
Expand All @@ -22,18 +20,10 @@ namespace NosCore.GameObject.Messaging.Handlers.Nrun
public sealed class GrenigasTempleTeleporterHandler(IMapChangeService mapChangeService, List<TeleporterDto> teleporters)
: NpcTeleportHandler(mapChangeService, teleporters)
{
public const short RunePieceVNum = 5919;

public override NrunRunnerType Runner => NrunRunnerType.GoToGrenigasTemple;

protected override long Cost(NpcComponentBundle npc, short index) => 0;

protected override Task<bool> MayTravelAsync(ClientSession session, NpcComponentBundle npc) =>
Task.FromResult(session.Character.InventoryService.CountItem(RunePieceVNum) > 0);

protected override async Task TravelAsync(ClientSession session, TeleporterDto destination)
{
await session.SendPacketsAsync(session.Character.InventoryService.RemoveItemAmountByVNum(RunePieceVNum, 1));
await base.TravelAsync(session, destination);
await session.SendPacketAsync(new MsgiPacket
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Collections.Generic;
using JetBrains.Annotations;
using NosCore.Data.StaticEntities;
using NosCore.GameObject.Ecs;
using NosCore.GameObject.Services.MapChangeService;
using NosCore.Packets.Enumerations;

Expand All @@ -18,7 +17,5 @@ public sealed class MortazDesertReturnHandler(IMapChangeService mapChangeService
: NpcTeleportHandler(mapChangeService, teleporters)
{
public override NrunRunnerType Runner => NrunRunnerType.ReturnFromMortazDesert;

protected override long Cost(NpcComponentBundle npc, short index) => 0;
}
}
33 changes: 0 additions & 33 deletions src/NosCore.GameObject/Messaging/Handlers/Nrun/MoveToMapHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,10 @@
//

using System.Collections.Generic;
using System.Threading.Tasks;
using JetBrains.Annotations;
using NosCore.Data.StaticEntities;
using NosCore.GameObject.Ecs;
using NosCore.GameObject.Networking.ClientSession;
using NosCore.GameObject.Services.MapChangeService;
using NosCore.Packets.Enumerations;
using NosCore.Packets.ServerPackets.UI;

namespace NosCore.GameObject.Messaging.Handlers.Nrun
{
Expand All @@ -21,35 +17,6 @@ namespace NosCore.GameObject.Messaging.Handlers.Nrun
public sealed class MoveToMapHandler(IMapChangeService mapChangeService, List<TeleporterDto> teleporters)
: NpcTeleportHandler(mapChangeService, teleporters)
{
public const short CelestialLairJourneyDialog = 540;
public const short VolunteerDialog = 554;
public const long Fare = 25_000;
public const byte VolunteerChampionLevel = 60;

public override NrunRunnerType Runner => NrunRunnerType.MoveToMap;

protected override long Cost(NpcComponentBundle npc, short index) =>
npc.Dialog is CelestialLairJourneyDialog or VolunteerDialog ? Fare : 0;

protected override async Task<bool> MayTravelAsync(ClientSession session, NpcComponentBundle npc)
{
var character = session.Character;
if (character.HeroLevel == 0)
{
return false;
}

if (npc.Dialog == VolunteerDialog && character.HeroLevel < VolunteerChampionLevel)
{
await session.SendPacketAsync(new MsgiPacket
{
Type = MessageType.Default,
Message = Game18NConstString.ChampionLevelRequirement,
});
return false;
}

return true;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Collections.Generic;
using JetBrains.Annotations;
using NosCore.Data.StaticEntities;
using NosCore.GameObject.Ecs;
using NosCore.GameObject.Services.MapChangeService;
using NosCore.Packets.Enumerations;

Expand All @@ -18,7 +17,5 @@ public sealed class NextDimensionHandler(IMapChangeService mapChangeService, Lis
: NpcTeleportHandler(mapChangeService, teleporters)
{
public override NrunRunnerType Runner => NrunRunnerType.GoToNextDimension;

protected override long Cost(NpcComponentBundle npc, short index) => 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,21 @@
using NosCore.Packets.ClientPackets.Npcs;
using NosCore.Packets.Enumerations;
using NosCore.Packets.ServerPackets.Chats;
using NosCore.Packets.ServerPackets.UI;
using NosCore.GameObject.Services.InventoryService;
using NosCore.Shared.Enumerations;

namespace NosCore.GameObject.Messaging.Handlers.Nrun
{
// An NPC's teleport menu: the option index picks one of the destinations recorded for that NPC
// under this menu's runner, which also sets the fare.
// under this menu's runner, and that destination carries its fare.
public abstract class NpcTeleportHandler(IMapChangeService mapChangeService, List<TeleporterDto> teleporters)
: INrunEventHandler
{
public abstract NrunRunnerType Runner { get; }

public bool RequiresNpc => true;

protected abstract long Cost(NpcComponentBundle npc, short index);

// Checks the menu makes before the fare; false leaves the player where they are.
protected virtual Task<bool> MayTravelAsync(ClientSession session, NpcComponentBundle npc) => Task.FromResult(true);

protected virtual Task TravelAsync(ClientSession session, TeleporterDto destination) =>
mapChangeService.ChangeMapAsync(session, destination.MapId, destination.MapX, destination.MapY);

Expand All @@ -52,25 +49,44 @@ public async Task HandleAsync(ClientSession session, IAliveEntity? target, NrunP
return;
}

if (!await MayTravelAsync(session, npc))
var character = session.Character;
if (character.HeroLevel < destination.MinimumHeroLevel)
{
// Without any champion level the menu does not answer at all.
if (character.HeroLevel > 0)
{
await session.SendPacketAsync(new MsgiPacket
{
Type = MessageType.Default,
Message = Game18NConstString.ChampionLevelRequirement,
});
}

return;
}

var character = session.Character;
var cost = Cost(npc, index);
if (character.Gold < cost)
if (destination.FareItemVNum is { } fareItem && character.InventoryService.CountItem(fareItem) == 0)
{
return;
}

if (character.Gold < destination.Fare)
{
await session.SendPacketAsync(character.GenerateSayi(SayColorType.Yellow, Game18NConstString.NotEnoughGold));
return;
}

if (cost > 0)
if (destination.Fare > 0)
{
character.RemoveGold(cost);
character.RemoveGold(destination.Fare);
await session.SendPacketAsync(character.GenerateGold());
}

if (destination.FareItemVNum is { } usedItem)
{
await session.SendPacketsAsync(character.InventoryService.RemoveItemAmountByVNum(usedItem, 1));
}

await TravelAsync(session, destination);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Collections.Generic;
using JetBrains.Annotations;
using NosCore.Data.StaticEntities;
using NosCore.GameObject.Ecs;
using NosCore.GameObject.Services.MapChangeService;
using NosCore.Packets.Enumerations;

Expand All @@ -18,7 +17,5 @@ public sealed class ReturnFromGlacernonHandler(IMapChangeService mapChangeServic
: NpcTeleportHandler(mapChangeService, teleporters)
{
public override NrunRunnerType Runner => NrunRunnerType.ReturnFromGlacernon;

protected override long Cost(NpcComponentBundle npc, short index) => 0;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Collections.Generic;
using JetBrains.Annotations;
using NosCore.Data.StaticEntities;
using NosCore.GameObject.Ecs;
using NosCore.GameObject.Services.MapChangeService;
using NosCore.Packets.Enumerations;

Expand All @@ -18,7 +17,5 @@ public sealed class TeleporterHandler(IMapChangeService mapChangeService, List<T
: NpcTeleportHandler(mapChangeService, teleporters)
{
public override NrunRunnerType Runner => NrunRunnerType.Teleport;

protected override long Cost(NpcComponentBundle npc, short index) => 1000L * index;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
using System.Collections.Generic;
using JetBrains.Annotations;
using NosCore.Data.StaticEntities;
using NosCore.GameObject.Ecs;
using NosCore.GameObject.Services.MapChangeService;
using NosCore.Packets.Enumerations;

Expand All @@ -18,7 +17,5 @@ public sealed class TravelToMapHandler(IMapChangeService mapChangeService, List<
: NpcTeleportHandler(mapChangeService, teleporters)
{
public override NrunRunnerType Runner => NrunRunnerType.TravelToMap;

protected override long Cost(NpcComponentBundle npc, short index) => 0;
}
}
Loading