-
-
Notifications
You must be signed in to change notification settings - Fork 78
feat(mate): read back the mates the capture service has been writing #2281
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
erwan-joly
merged 15 commits into
NosCoreIO:master
from
denislauri1999:pr/nosmate-pet-list
Aug 29, 2026
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
a0a4812
feat(mate): read back the mates the capture service has been writing
denislauri1999 ecefaf0
chore: address review — drop the narrative comments
denislauri1999 2cebbc7
chore: let the serializer escape the mate name
denislauri1999 f38286e
feat(mate): the mate walks onto the map with its owner
denislauri1999 59a1a10
feat(mate): the mate keeps up
denislauri1999 fcb5d4f
fix(mate): three from review
denislauri1999 caa103b
fix(mate): two more from review — hidden owners, and one square each
denislauri1999 e297afc
feat(mate): a mate that can fight
denislauri1999 8245100
fix(mate): a hidden player's mates stay hidden from newcomers too
denislauri1999 c112a13
chore(mate): take the experience curve from NosCore.Algorithm
denislauri1999 f4f89cf
refactor(mate): move mate packet generators to ECS extensions
denislauri1999 7964177
chore(mate): cut the comments, drop the BOMs
denislauri1999 38f1b03
chore: put back the two BOMs master actually has
denislauri1999 20e617e
style: drop the comments, upstream keeps only what a reader would get…
denislauri1999 95638f7
style: leave the registrar's own comments alone, and keep the one com…
denislauri1999 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
11 changes: 11 additions & 0 deletions
11
src/NosCore.GameObject/Ecs/Components/MateStateComponent.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| // __ _ __ __ ___ __ ___ ___ | ||
| // | \| |/__\ /' _/ / _//__\| _ \ __| | ||
| // | | ' | \/ |`._`.| \_| \/ | v / _| | ||
| // |_|\__|\__/ |___/ \__/\__/|_|_\___| | ||
| // | ||
|
|
||
| using NosCore.GameObject.Services.MateService; | ||
|
|
||
| namespace NosCore.GameObject.Ecs.Components; | ||
|
|
||
| public record struct MateStateComponent(Mate Mate, long OwnerId); |
12 changes: 12 additions & 0 deletions
12
src/NosCore.GameObject/Ecs/Components/PlayerMatesComponent.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| // __ _ __ __ ___ __ ___ ___ | ||
| // | \| |/__\ /' _/ / _//__\| _ \ __| | ||
| // | | ' | \/ |`._`.| \_| \/ | v / _| | ||
| // |_|\__|\__/ |___/ \__/\__/|_|_\___| | ||
| // | ||
|
|
||
| using NosCore.GameObject.Services.MateService; | ||
| using System.Collections.Concurrent; | ||
|
|
||
| namespace NosCore.GameObject.Ecs.Components; | ||
|
|
||
| public record struct PlayerMatesComponent(ConcurrentDictionary<long, Mate> Mates); |
200 changes: 200 additions & 0 deletions
200
src/NosCore.GameObject/Ecs/Extensions/MateExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,200 @@ | ||
| // __ _ __ __ ___ __ ___ ___ | ||
| // | \| |/__\ /' _/ / _//__\| _ \ __| | ||
| // | | ' | \/ |`._`.| \_| \/ | v / _| | ||
| // |_|\__|\__/ |___/ \__/\__/|_|_\___| | ||
| // | ||
|
|
||
| using NosCore.Data.Enumerations.Character; | ||
| using NosCore.GameObject.Services.MateService; | ||
| using NosCore.Packets.Enumerations; | ||
| using NosCore.Packets.ServerPackets.Entities; | ||
| using NosCore.Packets.ServerPackets.Mates; | ||
| using NosCore.Packets.ServerPackets.Parcel; | ||
| using NosCore.Packets.ServerPackets.Player; | ||
| using NosCore.Packets.ServerPackets.Visibility; | ||
| using NosCore.Shared.Enumerations; | ||
| using System.Globalization; | ||
|
|
||
| namespace NosCore.GameObject.Ecs.Extensions | ||
| { | ||
| public static class MateExtensions | ||
| { | ||
| public static ScpPacket GenerateScp(this Mate mate, RegionType language) | ||
| { | ||
| return new ScpPacket | ||
| { | ||
| PetId = mate.PetSlot, | ||
| NpcMonsterVNum = mate.VNum, | ||
| TransportId = mate.MateTransportId, | ||
| Level = mate.Level, | ||
| Loyalty = mate.Loyalty, | ||
| Experience = mate.Experience, | ||
| Unknow1 = 0, | ||
| AttackUpgrade = mate.NpcMonster.AttackUpgrade, | ||
| DamageMinimum = mate.NpcMonster.DamageMinimum, | ||
| DamageMaximum = mate.NpcMonster.DamageMaximum, | ||
| Concentrate = mate.NpcMonster.Concentrate, | ||
| CriticalChance = mate.NpcMonster.CriticalChance, | ||
| CriticalRate = mate.NpcMonster.CriticalRate, | ||
| DefenceUpgrade = mate.NpcMonster.DefenceUpgrade, | ||
| CloseDefence = mate.NpcMonster.CloseDefence, | ||
| DefenceDodge = mate.NpcMonster.DefenceDodge, | ||
| DistanceDefence = mate.NpcMonster.DistanceDefence, | ||
| DistanceDefenceDodge = mate.NpcMonster.DistanceDefenceDodge, | ||
| MagicDefence = mate.NpcMonster.MagicDefence, | ||
| Element = mate.NpcMonster.Element, | ||
| FireResistance = mate.NpcMonster.FireResistance, | ||
| WaterResistance = mate.NpcMonster.WaterResistance, | ||
| LightResistance = mate.NpcMonster.LightResistance, | ||
| DarkResistance = mate.NpcMonster.DarkResistance, | ||
| Hp = mate.Hp, | ||
| MaxHp = mate.MaxHp, | ||
| Mp = mate.Mp, | ||
| MaxMp = mate.MaxMp, | ||
| IsTeamMember = mate.IsTeamMember, | ||
| XpLoad = mate.XpLoad, | ||
| CanPickUp = mate.CanPickUp, | ||
| Name = mate.DisplayName(language), | ||
| IsSummonable = mate.IsSummonable | ||
| }; | ||
| } | ||
|
|
||
| public static ScnPacket GenerateScn(this Mate mate, RegionType language) | ||
| { | ||
| return new ScnPacket | ||
| { | ||
| PetId = mate.PetSlot, | ||
| NpcMonsterVNum = mate.VNum, | ||
| TransportId = mate.MateTransportId, | ||
| Level = mate.Level, | ||
| Loyalty = mate.Loyalty, | ||
| Experience = mate.Experience, | ||
| WeaponInstanceDetails = EmptySlot, | ||
| ArmorInstanceDetails = EmptySlot, | ||
| GauntletInstanceDetails = EmptySlot, | ||
| BootsInstanceDetails = EmptySlot, | ||
| AttackUpgrade = mate.NpcMonster.AttackUpgrade, | ||
| MinimumAttack = mate.NpcMonster.DamageMinimum, | ||
| MaximumAttack = mate.NpcMonster.DamageMaximum, | ||
| Precision = mate.NpcMonster.Concentrate, | ||
| CriticalRate = mate.NpcMonster.CriticalChance, | ||
| CriticalDamageRate = mate.NpcMonster.CriticalRate, | ||
| DefenceUpgrade = mate.NpcMonster.DefenceUpgrade, | ||
| Defence = mate.NpcMonster.CloseDefence, | ||
| DefenceDodge = mate.NpcMonster.DefenceDodge, | ||
| DistanceDefence = mate.NpcMonster.DistanceDefence, | ||
| DistanceDodge = mate.NpcMonster.DistanceDefenceDodge, | ||
| DodgeRate = mate.NpcMonster.MagicDefence, | ||
| ElementRate = mate.NpcMonster.Element, | ||
| FireResistance = mate.NpcMonster.FireResistance, | ||
| WaterResistance = mate.NpcMonster.WaterResistance, | ||
| LightResistance = mate.NpcMonster.LightResistance, | ||
| DarkResistance = mate.NpcMonster.DarkResistance, | ||
| Hp = mate.Hp, | ||
| HpMax = mate.MaxHp, | ||
| Mp = mate.Mp, | ||
| MpMax = mate.MaxMp, | ||
| IsTeamMember = mate.IsTeamMember, | ||
| LevelXp = (int)mate.XpLoad, | ||
| Name = mate.DisplayName(language), | ||
| MorphId = mate.Skin != 0 ? mate.Skin : -1, | ||
| IsSummonable = mate.IsSummonable, | ||
| SpDetails = null, | ||
| Skill1Details = null, | ||
| Skill2Details = null, | ||
| Skill3Details = null | ||
| }; | ||
| } | ||
|
|
||
| public static InPacket GenerateIn(this Mate mate, RegionType language) | ||
| { | ||
| return new InPacket | ||
| { | ||
| VisualType = VisualType.Npc, | ||
| VNum = mate.VNum.ToString(CultureInfo.InvariantCulture), | ||
| VisualId = mate.MateTransportId, | ||
| PositionX = mate.PositionX, | ||
| PositionY = mate.PositionY, | ||
| Direction = mate.Direction, | ||
| InNonPlayerSubPacket = new InNonPlayerSubPacket | ||
| { | ||
| InAliveSubPacket = new InAliveSubPacket | ||
| { | ||
| Hp = Percent(mate.Hp, mate.MaxHp, 100), | ||
| Mp = Percent(mate.Mp, mate.MaxMp, 100) | ||
| }, | ||
| Dialog = 0, | ||
| Faction = 0, | ||
| GroupEffect = 3, | ||
| Owner = mate.CharacterId, | ||
| SpawnEffect = SpawnEffectType.NoEffect, | ||
| IsSitting = false, | ||
| Morph = (short?)(mate.Skin != 0 ? mate.Skin : -1), | ||
| Name = mate.DisplayName(language), | ||
| Unknow1 = (byte)(mate.MateType == MateType.Partner ? 1 : 0) | ||
| } | ||
| }; | ||
| } | ||
|
|
||
| public static OutPacket GenerateOut(this Mate mate) | ||
| { | ||
| return new OutPacket | ||
| { | ||
| VisualType = VisualType.Npc, | ||
| VisualId = mate.MateTransportId | ||
| }; | ||
| } | ||
|
|
||
| public static PstPacket GeneratePst(this Mate mate) | ||
| { | ||
| return new PstPacket | ||
| { | ||
| Type = VisualType.Npc, | ||
| VisualId = mate.MateTransportId, | ||
| GroupOrder = (int)mate.MateType, | ||
| HpLeft = Percent(mate.Hp, mate.MaxHp, 0), | ||
| MpLeft = Percent(mate.Mp, mate.MaxMp, 0), | ||
| HpLoad = mate.MaxHp, | ||
| MpLoad = mate.MaxMp, | ||
| Race = 0, | ||
| Gender = GenderType.Male, | ||
| Morph = 0, | ||
| BuffIds = null | ||
| }; | ||
| } | ||
|
|
||
| public static CondPacket GenerateCond(this Mate mate) | ||
| { | ||
| return new CondPacket | ||
| { | ||
| VisualType = VisualType.Npc, | ||
| VisualId = mate.MateTransportId, | ||
| NoAttack = false, | ||
| NoMove = false, | ||
| Speed = mate.NpcMonster.Speed | ||
| }; | ||
| } | ||
|
|
||
| private static string DisplayName(this Mate mate, RegionType language) | ||
| { | ||
| if (!string.IsNullOrEmpty(mate.Name)) | ||
| { | ||
| return mate.Name; | ||
| } | ||
|
|
||
| return mate.NpcMonster.Name.TryGetValue(language, out var localized) | ||
| ? localized | ||
| : mate.NpcMonster.Name[RegionType.EN]; | ||
| } | ||
|
|
||
| private static int Percent(int current, int maximum, int whenUnknown) => | ||
| maximum > 0 ? (int)(current / (float)maximum * 100) : whenUnknown; | ||
|
|
||
| private static ScnPacket.ScEquipmentDetails EmptySlot => new() | ||
| { | ||
| ItemId = -1, | ||
| ItemRare = 0, | ||
| ItemUpgrade = 0 | ||
| }; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| using NosCore.GameObject.Ecs.Attributes; | ||
| using NosCore.GameObject.Ecs.Components; | ||
| using NosCore.GameObject.Ecs.Interfaces; | ||
|
|
||
| namespace NosCore.GameObject.Ecs; | ||
|
|
||
| [ComponentBundle( | ||
| typeof(EntityIdentityComponent), | ||
| typeof(HealthComponent), | ||
| typeof(ManaComponent), | ||
| typeof(PositionComponent), | ||
| typeof(VisualComponent), | ||
| typeof(NpcDataComponent), | ||
| typeof(SpawnComponent), | ||
| typeof(EffectComponent), | ||
| typeof(TimingComponent), | ||
| typeof(NpcStateComponent), | ||
| typeof(BuffStateComponent), | ||
| typeof(AggroComponent), | ||
| typeof(SkillCooldownComponent), | ||
| typeof(MateStateComponent) | ||
| )] | ||
| public readonly partial struct MateComponentBundle : INonPlayableEntity | ||
| { | ||
| public Arch.Core.Entity Handle => Entity; | ||
|
|
||
| public short MapX => PositionX; | ||
| public short MapY => PositionY; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
src/NosCore.GameObject/Messaging/Handlers/Mate/MateFollowHandler.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| // __ _ __ __ ___ __ ___ ___ | ||
| // | \| |/__\ /' _/ / _//__\| _ \ __| | ||
| // | | ' | \/ |`._`.| \_| \/ | v / _| | ||
| // |_|\__|\__/ |___/ \__/\__/|_|_\___| | ||
| // | ||
|
|
||
| using JetBrains.Annotations; | ||
| using NosCore.GameObject.Ecs; | ||
| using NosCore.GameObject.Ecs.Extensions; | ||
| using NosCore.GameObject.Messaging.Events; | ||
| using NosCore.GameObject.Services.MateService; | ||
| using NosCore.Networking; | ||
| using NosCore.Packets.ServerPackets.Entities; | ||
| using NosCore.Shared.Enumerations; | ||
| using System.Linq; | ||
| using System.Threading.Tasks; | ||
|
|
||
| namespace NosCore.GameObject.Messaging.Handlers.Mate | ||
| { | ||
| // Mates follow on the same event the owner's own step publishes. | ||
| [UsedImplicitly] | ||
| public sealed class MateFollowHandler | ||
| { | ||
| [UsedImplicitly] | ||
| public async Task Handle(CharacterMovedEvent evt) | ||
| { | ||
| if (evt.Character is not PlayerComponentBundle character) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| var mates = character.Mates.Values.Where(s => s.IsTeamMember).ToList(); | ||
| if (mates.Count == 0) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| var map = character.MapInstance; | ||
| MatePlacement.Arrange(character.PositionX, character.PositionY, map.Map, mates); | ||
|
|
||
| foreach (var mate in mates) | ||
| { | ||
| // The entity carries the position aggro and range checks read, not the packet. | ||
| if (mate.Entity is { } handle) | ||
| { | ||
| handle.PositionX = mate.PositionX; | ||
| handle.PositionY = mate.PositionY; | ||
| } | ||
|
|
||
| var move = new MovePacket | ||
| { | ||
| VisualType = VisualType.Npc, | ||
| VisualEntityId = mate.MateTransportId, | ||
| MapX = mate.PositionX, | ||
| MapY = mate.PositionY, | ||
| Speed = mate.NpcMonster.Speed | ||
| }; | ||
|
|
||
| // Broadcasting a hidden owner's mates would put the owner back on screen. | ||
| if (character.Invisible) | ||
| { | ||
| await character.SendPacketAsync(move).ConfigureAwait(false); | ||
| continue; | ||
| } | ||
|
|
||
| await map.SendPacketAsync(move).ConfigureAwait(false); | ||
| } | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just checked the other are also like this so most likely it's for another PR but ideally we only use the visualEntity one so we need to merge them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, and I counted them so the follow-up has a shape: there are six
GenerateInextensions today.The general one already does most of it, and it already special-cases two of the others inline —
visualEntity is INamedEntityfor the name andvisualEntity is NpcComponentBundlefor the dialog. So the merge is mostly a matter of moving the remaining per-type bits behind the same kind of test, or better, behind something the bundles expose themselves.Three of the five carry an extra argument the general one has no place for yet: the mate's
RegionType(it feedsDisplayName), the npc'sdialogoverride, and the player'sprefix. Those are the part that needs a decision, not just a move.Happy to take it as its own PR — it touches five files and none of this one's behaviour, so it would only make this one harder to read. Say the word and I'll open it.