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: 2 additions & 2 deletions Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
<PackageVersion Include="NosCore.Algorithm" Version="8.1.0" />
<PackageVersion Include="NosCore.Analyzers" Version="2.6.0" />
<PackageVersion Include="NosCore.Dao" Version="6.1.1" />
<PackageVersion Include="NosCore.Networking" Version="11.0.0" />
<PackageVersion Include="NosCore.Packets" Version="55.0.1" />
<PackageVersion Include="NosCore.Networking" Version="12.0.0" />
<PackageVersion Include="NosCore.Packets" Version="56.0.0" />
<PackageVersion Include="NosCore.PathFinder" Version="3.0.0" />
<PackageVersion Include="NosCore.Shared" Version="7.0.1" />
<PackageVersion Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="11.0.0-rc.3" />
Expand Down
15 changes: 9 additions & 6 deletions src/NosCore.PacketHandlers/Mates/SuCtlPacketHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,18 @@ public class SuCtlPacketHandler(IMateControlService mateControlService)
: PacketHandler<SuCtlPacket>, IWorldPacketHandler
{
// A mate counts as an ally of every player and npc, so a monster is the only target it can hit.
public override Task ExecuteAsync(SuCtlPacket packet, ClientSession session)
public override async Task ExecuteAsync(SuCtlPacket packet, ClientSession session)
{
if (packet.TargetType != VisualType.Monster
|| session.Character.MapInstance.FindMonster(s => s.VisualId == packet.TargetId) is not { } target)
foreach (var order in packet.Mates ?? [])
{
return Task.CompletedTask;
}
if (order is not { TargetType: VisualType.Monster }
|| session.Character.MapInstance.FindMonster(s => s.VisualId == order.TargetId) is not { } target)
{
continue;
}

return mateControlService.AttackAsync(session.Character, packet.MateTransportId, target);
await mateControlService.AttackAsync(session.Character, order.MateTransportId, target);
}
}
}
}
2 changes: 1 addition & 1 deletion test/NosCore.EndToEnd.Tests/Scenarios/PetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public async Task APetSentAtAMonsterHitsItWithItsBasicAttackNotItsSkill()
var pet = await PetOfAsync(alice);
var sent = alice.Mark();

await alice.SendAsync(new SuCtlPacket { MateTransportId = pet, TargetType = VisualType.Monster, TargetId = WorldData.SturdyMonster });
await alice.SendAsync(new SuCtlPacket { MapId = WorldData.Meadow, Amount = 1, Mates = [new SuCtlSubPacket { MateTransportId = pet, TargetType = VisualType.Monster, TargetId = WorldData.SturdyMonster }] });

var hit = await alice.ExpectSinceAsync(sent, HitBy(pet), "the pet's hit");
Assert.AreEqual(0L, hit.SkillVnum, "no skill");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void APetsSpeechReachesItsHandler()
[TestMethod]
public void AnOrderToAttackReachesItsHandler()
{
var packet = new SuCtlPacket { MateTransportId = 1135623, TargetType = VisualType.Monster, TargetId = 2045 };
var packet = new SuCtlPacket { MapId = 1, Amount = 1, Mates = [new SuCtlSubPacket { MateTransportId = 1135623, TargetType = VisualType.Monster, TargetId = 2045 }] };

Assert.IsInstanceOfType(RoundTrip(packet), HandledBy(typeof(SuCtlPacketHandler)));
}
Expand Down
54 changes: 30 additions & 24 deletions test/NosCore.PacketHandlers.Tests/Mates/SuCtlPacketHandlerTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ public async Task AnOwnPetHitsAMonsterWithItsBasicAttack()
}

[TestMethod]
public async Task TheFirstFieldOfTheOrderPicksNoSkill()
public async Task TheMapIdLeadingTheOrderPicksNoSkill()
{
await new Spec("An order whose first field matches one of the pet's skills still sends the pet in with its basic attack")
await new Spec("An order sent from a map whose id matches one of the pet's skills still sends the pet in with its basic attack")
.GivenAsync(APetOf_IsOut, "owner")
.WhenAsync(TheOwnerSendsThePetAtMonster_WithFirstField_, NearMonsterId, PetCastId)
.WhenAsync(TheOwnerSendsThePetAtMonster_OnMap_, NearMonsterId, PetCastId)
.Then(ThePetShouldHitMonster_WithItsBasicAttack, NearMonsterId)
.ExecuteAsync();
}
Expand Down Expand Up @@ -179,6 +179,18 @@ public async Task AnEscortHitsAMonsterItsLeaderPoints()
.ExecuteAsync();
}

[TestMethod]
public async Task OneOrderSendsEveryMateItNames()
{
await new Spec("A single order naming the pet and the escort sends both at the monster")
.GivenAsync(APetOf_IsOut, "owner")
.And(AnEscortLedBy_, "owner")
.WhenAsync(TheOwnerSendsThePetAndTheEscortAtMonster_, NearMonsterId)
.Then(ThePetShouldHitMonster_WithItsBasicAttack, NearMonsterId)
.And(TheEscortShouldHitMonster_WithItsBasicAttack, NearMonsterId)
.ExecuteAsync();
}

[TestMethod]
public async Task AnEscortLedByAnotherPlayerIgnoresTheOrder()
{
Expand All @@ -200,12 +212,17 @@ private void AnEscortLedBy_(string whose)
}

private Task TheOwnerSendsTheEscortAtMonster_(int monsterId) =>
_handler.ExecuteAsync(new SuCtlPacket
{
MateTransportId = _escort.VisualId,
TargetType = VisualType.Monster,
TargetId = monsterId
}, _session);
_handler.ExecuteAsync(Order(0, (_escort.VisualId, VisualType.Monster, monsterId)), _session);

private Task TheOwnerSendsThePetAndTheEscortAtMonster_(int monsterId) =>
_handler.ExecuteAsync(Order(0, (_pet.MateTransportId, VisualType.Monster, monsterId), (_escort.VisualId, VisualType.Monster, monsterId)), _session);

private static SuCtlPacket Order(short mapId, params (long Mate, VisualType TargetType, long TargetId)[] orders) => new()
{
MapId = mapId,
Amount = (byte)orders.Length,
Mates = orders.Select(o => (SuCtlSubPacket?)new SuCtlSubPacket { MateTransportId = o.Mate, TargetType = o.TargetType, TargetId = o.TargetId }).ToList()
};

private Task APetOf_IsOut(string whose) => SpawnAsync(whose, TestMates.Pet((whose == "owner" ? _session : _otherSession).Character.CharacterId));

Expand All @@ -226,24 +243,13 @@ private void _SecondsPass(int seconds)
World.Clock.Advance(Duration.FromSeconds(seconds));
}

private Task TheOwnerSendsThePetAtMonster_(int monsterId) => TheOwnerSendsThePetAtMonster_WithFirstField_(monsterId, 0);
private Task TheOwnerSendsThePetAtMonster_(int monsterId) => TheOwnerSendsThePetAtMonster_OnMap_(monsterId, 0);

private Task TheOwnerSendsThePetAtMonster_WithFirstField_(int monsterId, int firstField) =>
_handler.ExecuteAsync(new SuCtlPacket
{
CastId = firstField,
MateTransportId = _pet.MateTransportId,
TargetType = VisualType.Monster,
TargetId = monsterId
}, _session);
private Task TheOwnerSendsThePetAtMonster_OnMap_(int monsterId, int mapId) =>
_handler.ExecuteAsync(Order((short)mapId, (_pet.MateTransportId, VisualType.Monster, monsterId)), _session);

private Task TheOwnerSendsThePetAtTheOtherPlayer() =>
_handler.ExecuteAsync(new SuCtlPacket
{
MateTransportId = _pet.MateTransportId,
TargetType = VisualType.Player,
TargetId = _otherSession.Character.VisualId
}, _session);
_handler.ExecuteAsync(Order(0, (_pet.MateTransportId, VisualType.Player, _otherSession.Character.VisualId)), _session);

private void ThePetShouldHitMonster_WithItsBasicAttack(int monsterId) =>
ShouldHitWithABasicAttack(_pet.MateTransportId, monsterId);
Expand Down