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 @@ -5045,6 +5045,8 @@ confirms "Do you want to create the raid map?".
map they started from
- [ ] A member with a full inventory gets "Not enough space" instead of the box, and the others
still get theirs
- [ ] A member who knows the Collector's Guide (skill 136) sometimes gets a second Raid Box of
Mother Cuby, with a second "received" line; a member without it never gets two
- [ ] A, B, C and D all hit Mother Cuby, D the least, and A lands the killing blow: after the reward
lines the damage ranking window opens for every member still inside and lists A, B and C,
highest damage first, each with their class, name, damage and share of the boss's HP. D is
Expand Down
19 changes: 18 additions & 1 deletion src/NosCore.GameObject/Services/RaidService/RaidService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,16 @@
using NosCore.GameObject.Ecs.Extensions;
using NosCore.GameObject.Messaging;
using NosCore.GameObject.Networking.ClientSession;
using NosCore.Data.Enumerations.Buff;
using NosCore.GameObject.Services.BattleService;
using NosCore.GameObject.Services.BroadcastService;
using NosCore.GameObject.Services.GroupService;
using NosCore.GameObject.Services.InventoryService;
using NosCore.GameObject.Services.ItemGenerationService;
using NosCore.GameObject.Services.MapChangeService;
using NosCore.GameObject.Services.MapInstanceGenerationService;
using NosCore.GameObject.Services.ScriptedInstanceService;
using NosCore.GameObject.Services.SkillService;
using NosCore.Instances.Abstractions;
using NosCore.Networking.SessionGroup;
using NosCore.Packets.ClientPackets.Event;
Expand All @@ -43,7 +46,8 @@ namespace NosCore.GameObject.Services.RaidService
public class RaidService(IScriptedInstanceService scriptedInstanceService, IMapChangeService mapChangeService,
ISessionRegistry sessionRegistry, ISessionGroupFactory sessionGroupFactory, IIdService<Group> groupIdService,
IItemGenerationService itemProvider, IClock clock, Wolverine.IMessageBus messageBus, IGameEventDispatcher gameEvents, ILogger<RaidService> logger,
ILogLanguageLocalizer<LogLanguageKey> logLanguage)
ILogLanguageLocalizer<LogLanguageKey> logLanguage, IPassiveSkillService passiveSkillService, IBuffService buffService,
IRandomProvider random)
: IRaidService
{
private const byte InTeam = 1;
Expand Down Expand Up @@ -670,6 +674,19 @@ private async Task ReturnAsync(ClientSession session)
}

private async Task RewardAsync(ClientSession member, ScriptedInstance raid)
{
await GiveRaidBoxAsync(member, raid);
var extraBoxChance = buffService.GetActiveBuffs(member.Character).SelectMany(b => b.BCards)
.Concat(passiveSkillService.GetBCards(member.Character))
.Where(b => b.Effect() == BCardEffect.ExtraRaidBoxChance)
.Sum(b => b.FirstData);
if (extraBoxChance > 0 && random.Next(0, 100) < extraBoxChance)
{
await GiveRaidBoxAsync(member, raid);
}
}

private async Task GiveRaidBoxAsync(ClientSession member, ScriptedInstance raid)
{
var character = member.Character;
foreach (var gift in raid.Definition?.GiftItems ?? [])
Expand Down
2 changes: 2 additions & 0 deletions src/NosCore.Parser/Parsers/SkillParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ private sealed record CourseCard(BCardEffect Effect, int DataField, int Multipli
[36] = AttackAndDefenceTome,
[37] = AttackAndDefenceTome,
[38] = AttackAndDefenceTome,
// c3 is the extra raid token chance; NosCore hands out no raid tokens yet.
[39] = [new(BCardEffect.ExtraRaidBoxChance, DataC2)],
[40] = [new(BCardEffect.MaxHpmpMaximumHpIncreased, DataC2), new(BCardEffect.MaxHpmpMaximumMpIncreased, DataC3)],
[41] = AttackAndDefenceTome,
[42] = AttackAndDefenceTome,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Moq;
using NodaTime;
using NosCore.Data.Enumerations.Buff;
using NosCore.Data.Enumerations.Interaction;
using NosCore.Data.StaticEntities;
using NosCore.GameObject.Ecs;
Expand All @@ -15,11 +16,13 @@
using NosCore.GameObject.Messaging.Handlers.TimeSpace;
using NosCore.GameObject.Networking.ClientSession;
using NosCore.GameObject.Networking.ClientSession.DisconnectHandlers;
using NosCore.GameObject.Services.BattleService;
using NosCore.GameObject.Services.BroadcastService;
using NosCore.GameObject.Services.GroupService;
using NosCore.GameObject.Services.InventoryService;
using NosCore.GameObject.Services.MapChangeService;
using NosCore.GameObject.Services.MapInstanceGenerationService;
using NosCore.GameObject.Services.SkillService;
using NosCore.Instances.Abstractions;
using NosCore.Packets.ClientPackets.Event;
using NosCore.Networking.SessionGroup;
Expand Down Expand Up @@ -141,6 +144,11 @@ public async Task SetupAsync()
World.Inject(new Lazy<IMapChangeService>(World.MapChangeService));
World.Inject<ScriptedInstances.IScriptedInstanceService>(World.Create<ScriptedInstances.ScriptedInstanceService>());
World.Inject(new Lazy<ScriptedInstances.IScriptedInstanceService>(World.Create<ScriptedInstances.IScriptedInstanceService>));
_combatCatalog = World.Freeze<Mock<INpcCombatCatalog>>();
_combatCatalog.Setup(c => c.GetSkillBCards(It.IsAny<short>())).Returns(Array.Empty<BCardDto>());
World.UseReal<IPassiveSkillService, PassiveSkillService>();
_random = World.Freeze<Mock<IRandomProvider>>();
_random.Setup(r => r.Next(It.IsAny<int>(), It.IsAny<int>())).Returns((int min, int max) => min);
_raids = World.Create<ServiceUnderTest>();
}

Expand Down Expand Up @@ -396,6 +404,31 @@ public async Task KillingTheBossRewardsEveryMember()
.ExecuteAsync();
}

[TestMethod]
public async Task TheCollectorsGuideCanGiveASecondBox()
{
await new Spec("A member who knows the Collector's Guide gets a second box when its chance comes up")
.GivenAsync(AStartedRaidOf_Async, 2)
.And(Player_KnowsTheCollectorsGuide, 0)
.And(TheNextRollIs_, 0)
.WhenAsync(TheBossDiesAsync)
.Then(Player_Holds_BoxesInAll, 0, (int)(2 * BoxesWon))
.And(Player_Holds_BoxesInAll, 1, (int)BoxesWon)
.ExecuteAsync();
}

[TestMethod]
public async Task TheCollectorsGuideGivesNoSecondBoxOnAMissedRoll()
{
await new Spec("The Collector's Guide gives nothing more when its chance does not come up")
.GivenAsync(AStartedRaidOf_Async, 2)
.And(Player_KnowsTheCollectorsGuide, 0)
.And(TheNextRollIs_, CollectorsGuideChance)
.WhenAsync(TheBossDiesAsync)
.Then(Player_Holds_BoxesInAll, 0, (int)BoxesWon)
.ExecuteAsync();
}

[TestMethod]
public async Task ARewardSplitOverTwoStacksShowsBothSlots()
{
Expand Down Expand Up @@ -1260,6 +1293,31 @@ private void Player_IsShownSlot_With_(int player, int slot, int amount)
Assert.AreEqual(amount, shown.RareAmount);
}

private const short CollectorsGuide = 136;
private const int CollectorsGuideChance = 5;
private Mock<INpcCombatCatalog> _combatCatalog;
private Mock<IRandomProvider> _random;

private void Player_KnowsTheCollectorsGuide(int player)
{
_combatCatalog.Setup(c => c.GetSkillBCards(CollectorsGuide)).Returns(new[]
{
new BCardDto
{
SkillVNum = CollectorsGuide, Type = BCardEffect.ExtraRaidBoxChance.Type(),
SubType = BCardEffect.ExtraRaidBoxChance.SubType(), FirstData = CollectorsGuideChance
}
});
var guide = new SkillDto { SkillVNum = CollectorsGuide, SkillType = 0, CastId = 39 };
_players[player].Character.Skills[CollectorsGuide] = new CharacterSkill { SkillVNum = CollectorsGuide, Skill = guide };
}

private void TheNextRollIs_(int roll) =>
_random.Setup(r => r.Next(0, 100)).Returns(roll);

private void Player_Holds_BoxesInAll(int player, int amount) =>
Assert.AreEqual(amount, _players[player].Character.InventoryService.CountItem(Box));

private void NobodyHasTheBox() =>
Assert.IsTrue(_players.All(s => s.Character.InventoryService.CountItem(Box) == 0));

Expand Down
1 change: 1 addition & 0 deletions test/NosCore.Parser.Tests/SkillParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ public async Task ATrainingCourseCarriesWhatItRaises(short kind, BCardEffect eff
[DataRow((short)28, BCardEffect.ElementResistanceAllIncreased)]
[DataRow((short)29, BCardEffect.ItemExpIncreased)]
[DataRow((short)30, BCardEffect.ItemIncreaseEarnedGold)]
[DataRow((short)39, BCardEffect.ExtraRaidBoxChance)]
[DataRow((short)44, BCardEffect.IncreaseFairyElement)]
[DataRow((short)46, BCardEffect.DropX2Chance)]
public async Task ATomeRaisesItsStatByItsSecondDataField(short kind, BCardEffect effect)
Expand Down