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
10 changes: 10 additions & 0 deletions documentation/manual-test-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -2779,6 +2779,16 @@ Lose some HP first, otherwise there is nothing to watch.
- [ ] Relog with a filled bead, enter your Miniland and use it: "Remove the pet from the bead?",
then the pet comes out at the level it was stored with and the bead is gone

`$CreateItem 8570` gives an empty Pet Trainer Bead (8581 is the other one). Run the parser on the
database first so the item carries `"HoldsOnlyTopStarPets"`.

- [ ] Select a pet below 6 stars, double-click the Pet Trainer Bead and confirm: "Cannot put NosMate
in the bead." shows, the pet stays and the bead stays empty
- [ ] Set a pet's `"StarRating"` to 6 in the `"Mate"` table, log in and use the Pet Trainer Bead on
it: the pet goes into the bead as with a Pet Bead
- [ ] Use the plain Pet Bead (285) on that 6-star pet: "Cannot put NosMate in the bead." shows and
the pet stays

### NosMate team blessings

The Celestial Spire floors are maps 2644 to 2648. Owning a team means having its four NosMates in
Expand Down
1 change: 1 addition & 0 deletions src/NosCore.Data/Enumerations/I18N/LanguageKey.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ public enum LogLanguageKey
SERVER_PROCESS_EXITED,
SPEED_BOOSTERS_PARSED,
PARTNER_SPECIALIST_NAMES_PARSED,
PET_TRAINER_BEADS_PARSED,
MOUNT_SCROLLS_PARSED,
NPC_EXCHANGES_PARSED,
UPGRADE_COSTS_PARSED,
Expand Down
3 changes: 3 additions & 0 deletions src/NosCore.Data/Resource/LocalizedResources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -684,6 +684,9 @@
<data name="PARTNER_SPECIALIST_NAMES_PARSED" xml:space="preserve">
<value>{Cards} partner specialist cards get the name shown while transformed</value>
</data>
<data name="PET_TRAINER_BEADS_PARSED" xml:space="preserve">
<value>{Beads} pet beads only take pets at the top star rating</value>
</data>
<data name="MOUNT_SCROLLS_PARSED" xml:space="preserve">
<value>{Scrolls} mount scrolls draw from {Rolls} mounts</value>
</data>
Expand Down
3 changes: 3 additions & 0 deletions src/NosCore.Database/Entities/Item.cs
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,9 @@ public Item()
// Card given when the boost runs out; 0 for none.
public short SpeedBoostEndCardId { get; set; }

// An empty pet bead that only takes a pet at the top star rating, where a plain one refuses it.
public bool HoldsOnlyTopStarPets { get; set; }

// Sound played around the user when a PlayEffect item goes off; 0 for none.
public short UseSound { get; set; }

Expand Down
5,449 changes: 5,449 additions & 0 deletions src/NosCore.Database/Migrations/20261201094502_AddPetTrainerBead.Designer.cs

Large diffs are not rendered by default.

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

#nullable disable

namespace NosCore.Database.Migrations;

/// <inheritdoc />
public partial class _20261201094502_AddPetTrainerBead : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<bool>(
name: "HoldsOnlyTopStarPets",
table: "Item",
type: "boolean",
nullable: false,
defaultValue: false);
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "HoldsOnlyTopStarPets",
table: "Item");
}
}
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 => "20261201092947_KeepBeadPetStarRating";
public override string LastMigrationId => "20261201094502_AddPetTrainerBead";

protected override void BuildModel(ModelBuilder modelBuilder)
{
Expand Down Expand Up @@ -1633,6 +1633,9 @@ protected override void BuildModel(ModelBuilder modelBuilder)
b.Property<short>("HitRate")
.HasColumnType("smallint");

b.Property<bool>("HoldsOnlyTopStarPets")
.HasColumnType("boolean");

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ public sealed class NosMateBeadHandler(IDao<MateDto, long> mateDao, IMateService
{
private const byte PartnerSubType = 1;
private const short NewMateLoyalty = 1000;
private const byte TopStarRating = 6;

[UsedImplicitly]
public async Task Handle(ItemUsedEvent evt)
Expand Down Expand Up @@ -78,6 +79,12 @@ private async Task StoreAsync(ItemUsedEvent evt, MateType mateType, BoxInstance
return;
}

if (mateType == MateType.Pet && holder.Item.HoldsOnlyTopStarPets != (mate.StarRating >= TopStarRating))
{
await SendAsync(owner, Game18NConstString.CanNotPutNosmateInBead);
return;
}

if (mate.EquipmentPocket() is { } pocket && owner.InventoryService.Values.Any(s => s.Type == pocket))
{
await SendAsync(owner, Game18NConstString.DisarmPetToBeadHim);
Expand Down
3 changes: 2 additions & 1 deletion src/NosCore.Parser/ImportFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class ImportFactory(CardParser cardParser, DropParser dropParser, ItemPar
MapNpcParser mapNpcParser, MapParser mapParser, MapTypeMapParser mapTypeMapParser,
MapTypeParser mapTypeParser, NpcMonsterParser npcMonsterParser,
PortalParser portalParser, RespawnMapTypeParser respawnMapTypeParser,
ShopItemParser shopItemParser, ShopSkillParser shopSkillParser, FamilyUpgradeParser familyUpgradeParser, MinigameParser minigameParser, BoxContentParser boxContentParser, MountScrollParser mountScrollParser, RefinerParser refinerParser, NpcExchangeParser npcExchangeParser, UpgradeCostParser upgradeCostParser, SpeedBoostParser speedBoostParser, PartnerSpecialistNameParser partnerSpecialistNameParser, MountMapSpeedParser mountMapSpeedParser, HairStyleDyeParser hairStyleDyeParser, ItemSummonParser itemSummonParser, ItemTargetMonsterParser itemTargetMonsterParser, TeamBlessingParser teamBlessingParser, CostumeMorphParser costumeMorphParser, ShopParser shopParser, ShopTypeServiceParser shopTypeServiceParser, TeleporterParser teleporterParser, RecipeParser recipeParser, SkillParser skillParser, NpcTalkParser npcTalkParser,
ShopItemParser shopItemParser, ShopSkillParser shopSkillParser, FamilyUpgradeParser familyUpgradeParser, MinigameParser minigameParser, BoxContentParser boxContentParser, MountScrollParser mountScrollParser, RefinerParser refinerParser, NpcExchangeParser npcExchangeParser, UpgradeCostParser upgradeCostParser, SpeedBoostParser speedBoostParser, PartnerSpecialistNameParser partnerSpecialistNameParser, PetTrainerBeadParser petTrainerBeadParser, MountMapSpeedParser mountMapSpeedParser, HairStyleDyeParser hairStyleDyeParser, ItemSummonParser itemSummonParser, ItemTargetMonsterParser itemTargetMonsterParser, TeamBlessingParser teamBlessingParser, CostumeMorphParser costumeMorphParser, ShopParser shopParser, ShopTypeServiceParser shopTypeServiceParser, TeleporterParser teleporterParser, RecipeParser recipeParser, SkillParser skillParser, NpcTalkParser npcTalkParser,
QuestPrizeParser questPrizeParser, QuestParser questParser, FamilyQuestParser familyQuestParser, ActParser actParser, ScriptParser scriptParser, ScriptOfferParser scriptOfferParser, ChatterLineParser chatterLineParser,
ConstStringParser constStringParser, ScriptedInstanceParser scriptedInstanceParser, InstantCombatParser instantCombatParser,
AccountParser accountParser, IDao<I18NQuestDto, int> i18NQuestDao, IDao<I18NSkillDto, int> i18NSkillDao,
Expand Down Expand Up @@ -195,6 +195,7 @@ public async Task ImportItemsAsync()
await upgradeCostParser.InsertUpgradeCostsAsync();
await speedBoostParser.InsertSpeedBoostsAsync();
await partnerSpecialistNameParser.InsertPartnerSpecialistNamesAsync();
await petTrainerBeadParser.InsertPetTrainerBeadsAsync();
await mountMapSpeedParser.InsertMountMapSpeedsAsync();
await hairStyleDyeParser.InsertHairStyleDyesAsync();
}
Expand Down
36 changes: 36 additions & 0 deletions src/NosCore.Parser/Parsers/PetTrainerBeadParser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// __ _ __ __ ___ __ ___ ___
// | \| |/__\ /' _/ / _//__\| _ \ __|
// | | ' | \/ |`._`.| \_| \/ | v / _|
// |_|\__|\__/ |___/ \__/\__/|_|_\___|
//

using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;
using NosCore.Core.Dao;
using NosCore.Dao.Interfaces;
using NosCore.Data.Enumerations.I18N;
using NosCore.Data.StaticEntities;
using NosCore.Shared.I18N;

namespace NosCore.Parser.Parsers
{
public class PetTrainerBeadParser(IDao<ItemDto, short> itemDao, ILogger<PetTrainerBeadParser> logger, ILogLanguageLocalizer<LogLanguageKey> logLanguage)
{
public async Task InsertPetTrainerBeadsAsync()
{
var beads = new List<ItemDto>();
foreach (var item in itemDao.LoadAll())
{
if (PetTrainerBeads.All.Contains(item.VNum))
{
item.HoldsOnlyTopStarPets = true;
beads.Add(item);
}
}

await itemDao.TryInsertOrUpdateAsync(beads).OrThrowAsync();
logger.LogInformation(logLanguage[LogLanguageKey.PET_TRAINER_BEADS_PARSED], beads.Count);
}
}
}
16 changes: 16 additions & 0 deletions src/NosCore.Parser/Parsers/PetTrainerBeads.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// __ _ __ __ ___ __ ___ ___
// | \| |/__\ /' _/ / _//__\| _ \ __|
// | | ' | \/ |`._`.| \_| \/ | v / _|
// |_|\__|\__/ |___/ \__/\__/|_|_\___|
//
using System.Collections.Generic;

namespace NosCore.Parser.Parsers
{
// The empty pet beads whose description reads "Can only contain 6-star pets."; Item.dat gives them the same
// box effect as the plain Pet Bead.
public static class PetTrainerBeads
{
public static readonly IReadOnlySet<short> All = new HashSet<short> { 8570, 8581 };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,47 @@ public async Task APetBeadDoesNotTakeAPartner()
Assert.AreEqual(Game18NConstString.CanNotPutNosmateInBead, _session.LastPackets.OfType<MsgiPacket>().Single().Message);
}

[TestMethod]
public async Task APetTrainerBeadRefusesAPetBelowSixStars()
{
var pet = await OwnedAsync(TestMates.Pet(_session.Character.CharacterId, isTeamMember: false));
pet.StarRating = 5;
var bead = HoldingAnEmptyBead(subType: 0, holdsOnlyTopStarPets: true);

await UseOnAsync(pet, 1);

Assert.IsTrue(_session.Character.Mates.ContainsKey(pet.MateTransportId));
Assert.IsNull(bead.HoldingVNum);
Assert.AreEqual(Game18NConstString.CanNotPutNosmateInBead, _session.LastPackets.OfType<MsgiPacket>().Single().Message);
}

[TestMethod]
public async Task APetTrainerBeadTakesASixStarPet()
{
var pet = await OwnedAsync(TestMates.Pet(_session.Character.CharacterId, isTeamMember: false, vnum: MonsterVNum));
pet.StarRating = 6;
var bead = HoldingAnEmptyBead(subType: 0, holdsOnlyTopStarPets: true);

await UseOnAsync(pet, 1);

Assert.IsFalse(_session.Character.Mates.ContainsKey(pet.MateTransportId));
Assert.AreEqual(MonsterVNum, bead.HoldingVNum);
}

[TestMethod]
public async Task APlainPetBeadRefusesASixStarPet()
{
var pet = await OwnedAsync(TestMates.Pet(_session.Character.CharacterId, isTeamMember: false));
pet.StarRating = 6;
var bead = HoldingAnEmptyBead(subType: 0);

await UseOnAsync(pet, 1);

Assert.IsTrue(_session.Character.Mates.ContainsKey(pet.MateTransportId));
Assert.IsNull(bead.HoldingVNum);
Assert.AreEqual(Game18NConstString.CanNotPutNosmateInBead, _session.LastPackets.OfType<MsgiPacket>().Single().Message);
}

[TestMethod]
public async Task APartnerInACostumeIsWarnedTheCostumeIsLost()
{
Expand Down Expand Up @@ -252,7 +293,7 @@ private async Task<Mate> OwnedAsync(Mate mate)
return mate;
}

private BoxInstance HoldingAnEmptyBead(byte subType)
private BoxInstance HoldingAnEmptyBead(byte subType, bool holdsOnlyTopStarPets = false)
{
var item = new Item
{
Expand All @@ -261,6 +302,7 @@ private BoxInstance HoldingAnEmptyBead(byte subType)
ItemType = ItemType.Box,
ItemSubType = subType,
Effect = (ItemEffectType)BoxItemEffectType.NosMateHolder,
HoldsOnlyTopStarPets = holdsOnlyTopStarPets,
};
var instance = new BoxInstance(item) { Amount = 1 };
_bead = InventoryItemInstance.Create(instance, _session.Character.CharacterId);
Expand Down
62 changes: 62 additions & 0 deletions test/NosCore.Parser.Tests/PetTrainerBeadParserTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
// __ _ __ __ ___ __ ___ ___
// | \| |/__\ /' _/ / _//__\| _ \ __|
// | | ' | \/ |`._`.| \_| \/ | v / _|
// |_|\__|\__/ |___/ \__/\__/|_|_\___|
//
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging.Abstractions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using NosCore.Dao.Interfaces;
using NosCore.Data.Enumerations.I18N;
using NosCore.Data.StaticEntities;
using NosCore.Parser.Parsers;
using NosCore.Shared.I18N;

namespace NosCore.Parser.Tests
{
[TestClass]
public class PetTrainerBeadParserTests
{
private const short PetTrainerBead = 8570;
private const short PetBead = 285;

private readonly List<ItemDto> _items = new();
private readonly List<ItemDto> _savedItems = new();
private PetTrainerBeadParser _parser;

[TestInitialize]
public void Setup()
{
var items = new Mock<IDao<ItemDto, short>>();
items.Setup(s => s.LoadAll()).Returns(_items);
items.Setup(s => s.TryInsertOrUpdateAsync(It.IsAny<IEnumerable<ItemDto>>()))
.Callback<IEnumerable<ItemDto>>(rows => _savedItems.AddRange(rows))
.ReturnsAsync(true);
_parser = new PetTrainerBeadParser(items.Object, NullLogger<PetTrainerBeadParser>.Instance, new Mock<ILogLanguageLocalizer<LogLanguageKey>>().Object);
}

[TestMethod]
public async Task APetTrainerBeadOnlyTakesTopStarPets()
{
_items.Add(new ItemDto { VNum = PetTrainerBead });

await _parser.InsertPetTrainerBeadsAsync();

Assert.IsTrue(_savedItems.Single().HoldsOnlyTopStarPets);
}

[TestMethod]
public async Task ThePlainPetBeadIsLeftAlone()
{
_items.Add(new ItemDto { VNum = PetBead });

await _parser.InsertPetTrainerBeadsAsync();

Assert.AreEqual(0, _savedItems.Count);
Assert.IsFalse(_items.Single().HoldsOnlyTopStarPets);
}
}
}