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
17 changes: 15 additions & 2 deletions documentation/manual-test-plan.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ compute and will mask a regression.

### Worn equipment contributes to stats

- [ ] Naked, open the stat window and note min/max attack and the three defences
- [ ] Naked, open the stat window and note min/max attack and the three defences: they are
the level and class values, not zeros
- [ ] `$CreateItem` a weapon and an armour, equip both
- [ ] The stat window changes, and the numbers include the piece's own values
- [ ] The stat window changes as soon as each piece goes on, and again when it comes off,
and the numbers include the piece's own values
- [ ] Level up with the window open: the base attack and defences go up
- [ ] Hit a monster before and after equipping — the damage is visibly different
- [ ] An upgraded piece (`$CreateItem <vnum> 1 <upgrade>`) contributes more than a +0 of
the same vnum
Expand Down Expand Up @@ -145,6 +148,16 @@ This one is easy to eyeball — before the fix everything came back a hundred ti
in the client's language, and the character does not transform
- [ ] With points, transform: the five-second bar runs and the character transforms when it
ends, not before
- [ ] Wear a specialist card whose instance carries attack and defence, hit a monster, then
transform and hit it again: the transformed hits are larger by about the card's attack
- [ ] Untransform: the hits go back to the untransformed size
- [ ] After re-running the parser on an existing database, transform with a card at
specialist level 0: the skill bar shows the card's first six skills and the basic attack
hits. At level 4 the seventh appears, and at level 20 all eleven
- [ ] Wear a fire fairy and use a fire skill on a monster: the hits are larger than the same
skill with no fairy worn
- [ ] Open the character window while transformed and untransformed: attack, defence and
the resistances move with the card, and the card counts for nothing until transformed

### Specialist wings

Expand Down
16 changes: 16 additions & 0 deletions src/NosCore.Data/Enumerations/Battle/AttackType.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// __ _ __ __ ___ __ ___ ___
// | \| |/__\ /' _/ / _//__\| _ \ __|
// | | ' | \/ |`._`.| \_| \/ | v / _|
// |_|\__|\__/ |___/ \__/\__/|_|_\___|
//

namespace NosCore.Data.Enumerations.Battle
{
// The skill file's attack type column, also the profile a character window row shows.
public enum AttackType : byte
{
Melee = 0,
Ranged = 1,
Magical = 2
}
}
41 changes: 41 additions & 0 deletions src/NosCore.GameObject/Ecs/Extensions/PlayerBundleExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using NosCore.Core.I18N;
using NosCore.Data.Dto;
using NosCore.Data.Enumerations;
using NosCore.Data.Enumerations.Battle;
using NosCore.GameObject.Ecs.Extensions;
using NosCore.GameObject.InterChannelCommunication.Hubs.BlacklistHub;
using NosCore.GameObject.InterChannelCommunication.Hubs.ChannelHub;
Expand All @@ -21,6 +22,7 @@
using NosCore.GameObject.InterChannelCommunication.Messages;
using NosCore.GameObject.Networking;
using NosCore.GameObject.Networking.ClientSession;
using NosCore.GameObject.Services.BattleService;
using NosCore.GameObject.Services.BroadcastService;
using NosCore.GameObject.Services.GroupService;
using NosCore.GameObject.Services.InventoryService;
Expand Down Expand Up @@ -663,6 +665,45 @@ public static SpPacket GenerateSpPoint(this PlayerComponentBundle player, IOptio
};
}

// The character window shows exactly what combat uses, worn gear and active effects included.
public static ScPacket GenerateSc(this PlayerComponentBundle player, IBattleStatsProvider battleStatsProvider)
{
var stats = battleStatsProvider.GetStats(player);
var (mainType, secondaryType) = player.Class switch
{
CharacterClassType.Archer => (AttackType.Ranged, AttackType.Melee),
CharacterClassType.Mage => (AttackType.Magical, AttackType.Ranged),
_ => (AttackType.Melee, AttackType.Ranged),
};
return new ScPacket
{
Type = (byte)mainType,
MainWeaponUpgrade = (byte)stats.MeleeUpgrade,
MinHit = stats.MinHit,
MaxHit = stats.MaxHit,
HitRate = stats.HitRate,
CriticalHitRate = (short)stats.CriticalChance,
CriticalHitMultiplier = stats.CriticalRate,
Type2 = (byte)secondaryType,
SecondaryWeaponUpgrade = (short)stats.RangedUpgrade,
SecondaryMinHit = (short)stats.MinDistance,
SecondaryMaxHit = (short)stats.MaxDistance,
SecondaryHitRate = (short)stats.DistanceRate,
SecondaryCriticalHitRate = (short)stats.DistanceCriticalChance,
SecondaryCriticalHitMultiplier = (short)stats.DistanceCriticalRate,
ArmorUpgrade = (byte)stats.DefenceUpgrade,
Defence = (short)stats.Defence,
DefenceRate = (short)stats.DefenceDodge,
DistanceDefence = (short)stats.DistanceDefence,
DistanceDefenceRate = (short)stats.DistanceDefenceDodge,
MagicalDefence = (short)stats.MagicDefence,
FireResistance = (short)stats.FireResistance,
WaterResistance = (short)stats.WaterResistance,
LightResistance = (short)stats.LightResistance,
DarkResistance = (short)stats.DarkResistance,
};
}

public static TitleInfoPacket GenerateTitInfo(this PlayerComponentBundle player)
{
var visibleTitle = player.Titles.FirstOrDefault(s => s.Visible)?.TitleType;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public sealed class WearHandler(
IClock clock,
ILogLanguageLocalizer<LogLanguageKey> logLanguage,
IOptions<WorldConfiguration> worldConfiguration,
Services.BattleService.IVitalityService vitalityService)
Services.BattleService.IVitalityService vitalityService,
Services.BattleService.IBattleStatsProvider battleStatsProvider)
{
[UsedImplicitly]
public async Task Handle(ItemUsedEvent evt)
Expand Down Expand Up @@ -169,6 +170,7 @@ await session.SendPacketAsync(new MsgiPacket
await session.SendPacketAsync(newItem.GeneratePocketChange(packet.Type, packet.Slot));
await session.Character.MapInstance.SendPacketAsync(session.Character.GenerateEq());
await session.SendPacketAsync(session.Character.GenerateEquipment());
await session.SendPacketAsync(session.Character.GenerateSc(battleStatsProvider));

if (itemInstance.ItemInstance.Item.EquipmentSlot == EquipmentType.Sp)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// __ _ __ __ ___ __ ___ ___
// __ _ __ __ ___ __ ___ ___
// | \| |/__\ /' _/ / _//__\| _ \ __|
// | | ' | \/ |`._`.| \_| \/ | v / _|
// |_|\__|\__/ |___/ \__/\__/|_|_\___|
Expand Down Expand Up @@ -64,7 +64,9 @@ stats with
DefenceDodge = stats.DefenceDodge + gear.DefenceDodge,
DistanceDefenceDodge = stats.DistanceDefenceDodge + gear.DistanceDefenceDodge,
DefenceUpgrade = stats.DefenceUpgrade + gear.ArmourUpgrade,
Element = stats.Element != 0 ? stats.Element : (byte)gear.Element,
ElementRate = stats.ElementRate + gear.ElementRate,
ElementRateSp = stats.ElementRateSp + gear.SpecialistElementRate,
FireResistance = stats.FireResistance + gear.FireResistance,
WaterResistance = stats.WaterResistance + gear.WaterResistance,
LightResistance = stats.LightResistance + gear.LightResistance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
namespace NosCore.GameObject.Services.EquipmentService;

// Main weapon feeds melee, secondary feeds range, the rest feed defences and resistances. The
// specialist card goes through SpecialistPointService instead.
// specialist card counts only while the character is transformed into it.
//
// Each stat is summed from both the model and the instance: the model carries the base, the
// instance carries what upgrade and rarity changed.
Expand Down Expand Up @@ -93,9 +93,17 @@ public EquipmentStats Resolve(IAliveEntity entity)
stats = stats with
{
ElementRate = stats.ElementRate + Sum(fairy.ElementRate, fairy.Item?.ElementRate),
Element = fairy.Item?.Element ?? ElementType.Neutral,
};
}

if (character.UseSp
&& inventory.LoadBySlotAndType((byte)EquipmentType.Sp, NoscorePocketType.Wear)?.ItemInstance
is SpecialistInstance specialist)
{
stats = AddSpecialist(stats, specialist);
}

for (byte slot = 0; slot < 16; slot++)
{
var piece = inventory.LoadBySlotAndType(slot, NoscorePocketType.Wear)?.ItemInstance
Expand Down Expand Up @@ -141,6 +149,47 @@ public EquipmentStats Resolve(IAliveEntity entity)
return stats with { BCards = bcards.Count == 0 ? System.Array.Empty<BCardDto>() : bcards };
}

// The card adds to both the melee and the ranged profile, since a transformed character
// attacks with the card's skills whatever the weapon.
private static EquipmentStats AddSpecialist(EquipmentStats stats, SpecialistInstance specialist)
{
var item = specialist.Item;
var minHit = Sum(specialist.DamageMinimum, item?.DamageMinimum);
var maxHit = Sum(specialist.DamageMaximum, item?.DamageMaximum);
var hitRate = Sum(specialist.HitRate, item?.HitRate);
var criticalChance = Sum(specialist.CriticalLuckRate, item?.CriticalLuckRate);
var criticalRate = Sum(specialist.CriticalRate, item?.CriticalRate);
return stats with
{
MinHit = stats.MinHit + minHit,
MaxHit = stats.MaxHit + maxHit,
HitRate = stats.HitRate + hitRate,
CriticalChance = stats.CriticalChance + criticalChance,
CriticalRate = stats.CriticalRate + criticalRate,
MinDistance = stats.MinDistance + minHit,
MaxDistance = stats.MaxDistance + maxHit,
DistanceRate = stats.DistanceRate + hitRate,
DistanceCriticalChance = stats.DistanceCriticalChance + criticalChance,
DistanceCriticalRate = stats.DistanceCriticalRate + criticalRate,
CloseDefence = stats.CloseDefence + Sum(specialist.CloseDefence, item?.CloseDefence),
DistanceDefence = stats.DistanceDefence + Sum(specialist.DistanceDefence, item?.DistanceDefence),
MagicDefence = stats.MagicDefence + Sum(specialist.MagicDefence, item?.MagicDefence),
DefenceDodge = stats.DefenceDodge + Sum(specialist.DefenceDodge, item?.DefenceDodge),
DistanceDefenceDodge = stats.DistanceDefenceDodge
+ Sum(specialist.DistanceDefenceDodge, item?.DistanceDefenceDodge),
FireResistance = stats.FireResistance + Sum(specialist.FireResistance, item?.FireResistance)
+ specialist.SpFire,
WaterResistance = stats.WaterResistance + Sum(specialist.WaterResistance, item?.WaterResistance)
+ specialist.SpWater,
LightResistance = stats.LightResistance + Sum(specialist.LightResistance, item?.LightResistance)
+ specialist.SpLight,
DarkResistance = stats.DarkResistance + Sum(specialist.DarkResistance, item?.DarkResistance)
+ specialist.SpDark,
SpecialistElementRate = stats.SpecialistElementRate
+ Sum(specialist.ElementRate, item?.ElementRate) + specialist.SpElement,
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Resolved
};
}

// The instance-level options added with cells are not reachable from a worn piece:
// WearableInstance has no navigation to EquipmentOption.
private void CollectBCards(List<BCardDto> into, WearableInstance piece)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Collections.Generic;
using NosCore.Data.StaticEntities;
using NosCore.GameObject.Ecs.Interfaces;
using NosCore.Packets.Enumerations;

namespace NosCore.GameObject.Services.EquipmentService;

Expand Down Expand Up @@ -44,7 +45,11 @@ public readonly record struct EquipmentStats(
// yet — max HP is still class and level alone.
int Hp,
int Mp,
IReadOnlyList<BCardDto> BCards)
IReadOnlyList<BCardDto> BCards,
// Kept apart from ElementRate the way CombatStats keeps it, so it can be shown on its own.
int SpecialistElementRate = 0,
// The worn fairy's element is the one a character attacks with.
ElementType Element = ElementType.Neutral)
{
public static EquipmentStats None => new() { BCards = System.Array.Empty<BCardDto>() };
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public sealed class ExperienceProgressionService(
ISpExperienceService spExperienceService,
IFairyExperienceService fairyExperienceService,
ISkillService skillService,
BattleService.IVitalityService vitalityService) : IExperienceProgressionService
BattleService.IVitalityService vitalityService,
BattleService.IBattleStatsProvider battleStatsProvider) : IExperienceProgressionService
{
private const byte MaxLevel = 99;
private const byte MaxJobLevel = 80;
Expand Down Expand Up @@ -206,6 +207,7 @@ public async Task AddExperienceAsync(PlayerComponentBundle player,
await player.SendPacketAsync(new LevelUpPacket { CharacterId = player.CharacterId });
await player.SendPacketAsync(player.GenerateStat());
await player.SendPacketAsync(player.GenerateStatInfo());
await player.SendPacketAsync(player.GenerateSc(battleStatsProvider));

if (leveledUp)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public class MapChangeService(IExperienceService experienceService, IJobExperien
ILogLanguageLocalizer<LogLanguageKey> logLanguage, IMinilandService minilandProvider, ILogger<MapChangeService> logger,
ILogLanguageLocalizer<LogLanguageKey> logLanguageLocalizer, IGameLanguageLocalizer gameLanguageLocalizer,
ISessionRegistry sessionRegistry, Wolverine.IMessageBus messageBus,
ScriptedInstanceService.IScriptedInstanceService scriptedInstanceService)
ScriptedInstanceService.IScriptedInstanceService scriptedInstanceService,
BattleService.IBattleStatsProvider battleStatsProvider)
: IMapChangeService
{
public async Task ChangeMapAsync(ClientSession session, short? mapId = null, short? mapX = null, short? mapY = null)
Expand Down Expand Up @@ -203,6 +204,7 @@ position with
await session.SendPacketAsync(character.GenerateAt(newMapInstance.Map.MapId, newMapInstance.Map.Music));
await session.SendPacketAsync(character.GenerateCond());
await session.SendPacketAsync(newMapInstance.GenerateCMap(true));
await session.SendPacketAsync(character.GenerateSc(battleStatsProvider));
await session.SendPacketAsync(character.GeneratePairy(fairy));
await session.SendPacketsAsync(newMapInstance.GetMapItems(accountLanguage));
await session.SendPacketsAsync(newMapInstance.MapDesignObjects.Values.Select(mp => mp.GenerateEffect()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ public class TransformationService(IClock clock, IExperienceService experienceSe
IJobExperienceService jobExperienceService, IHeroExperienceService heroExperienceService, ILogger<TransformationService> logger,
ILogLanguageLocalizer<LogLanguageKey> logLanguage, IOptions<WorldConfiguration> worldConfiguration,
SpeedCalculationService.ISpeedCalculationService speedCalculationService,
SkillService.ISkillService skillService)
SkillService.ISkillService skillService,
BattleService.IBattleStatsProvider battleStatsProvider)
: ITransformationService
{
public async Task RemoveSpAsync(ClientSession session)
Expand All @@ -54,9 +55,11 @@ public async Task RemoveSpAsync(ClientSession session)
var levPacket = session.Character.GenerateLev(experienceService, jobExperienceService, heroExperienceService);
var cModePacket = session.Character.GenerateCMode();
var statPacket = session.Character.GenerateStat();
var scPacket = session.Character.GenerateSc(battleStatsProvider);

await session.SendPacketAsync(condPacket);
await session.SendPacketAsync(levPacket);
await session.SendPacketAsync(scPacket);
await session.SendPacketAsync(new SayiPacket
{
VisualType = VisualType.Player,
Expand Down Expand Up @@ -158,6 +161,7 @@ await mapInstance.SendPacketAsync(new GuriPacket
await session.SendPacketAsync(spPointPacket);
await session.SendPacketAsync(condPacket);
await session.SendPacketAsync(statPacket);
await session.SendPacketAsync(session.Character.GenerateSc(battleStatsProvider));
}

public async Task ChangeVehicleAsync(ClientSession session, Item item)
Expand Down
4 changes: 3 additions & 1 deletion src/NosCore.PacketHandlers/Inventory/RemovePacketHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@

namespace NosCore.PacketHandlers.Inventory
{
public class RemovePacketHandler(NosCore.GameObject.Services.BattleService.IVitalityService vitalityService)
public class RemovePacketHandler(NosCore.GameObject.Services.BattleService.IVitalityService vitalityService,
NosCore.GameObject.Services.BattleService.IBattleStatsProvider battleStatsProvider)
: PacketHandler<RemovePacket>, IWorldPacketHandler
{
public override async Task ExecuteAsync(RemovePacket removePacket, ClientSession clientSession)
Expand Down Expand Up @@ -61,6 +62,7 @@ await clientSession.SendPacketAsync(new MsgiPacket

await clientSession.Character.MapInstance.SendPacketAsync(clientSession.Character.GenerateEq());
await clientSession.SendPacketAsync(clientSession.Character.GenerateEquipment());
await clientSession.SendPacketAsync(clientSession.Character.GenerateSc(battleStatsProvider));

if (inv.ItemInstance.Item.EquipmentSlot == EquipmentType.Fairy)
{
Expand Down
33 changes: 11 additions & 22 deletions src/NosCore.Parser/Parsers/SkillParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,11 @@ namespace NosCore.Parser.Parsers
public class SkillParser(IDao<BCardDto, int> bCardDao, IDao<ComboDto, int> comboDao,
IDao<SkillDto, short> skillDao, ILoggerFactory loggerFactory, ILogLanguageLocalizer<LogLanguageKey> logLanguage)
{
private const byte SpecialistSkillClass = 32;
private const short SkillsUnlockedAtOnce = 5;
private const short LastLevelledCastId = 10;
private const int LevelsPerUnlock = 4;

private readonly ILogger<SkillParser> _logger = loggerFactory.CreateLogger<SkillParser>();
// VNUM {VNum}
// NAME {Name}
Expand Down Expand Up @@ -84,29 +89,13 @@ public async Task InsertSkillsAsync(string folder)
var parser = BuildParser(folder).Build(loggerFactory, logLanguage);
var skills = await parser.GetDtosAsync();

foreach (var skill in skills.Where(s => s.Class > 31))
// The file gives a specialist's own skills no level: a card unlocks them in cast order,
// the first six straight away and then one every four specialist levels.
foreach (var skill in skills.Where(s => s.Class >= SpecialistSkillClass
&& s.LevelMinimum == 0
&& s.CastId is > SkillsUnlockedAtOnce and <= LastLevelledCastId))
{
var firstskill = skills.Find(s => s.Class == skill.Class);
var skillscount = skills.Count(s => s.Class == skill.Class);
if ((firstskill == null) || (skill.SkillVNum <= firstskill.SkillVNum + 10))
{
skill.LevelMinimum = skill.Class switch
{
8 => (byte)(skillscount - (1 * 10)),
9 => (byte)(skillscount - (4 * 4)),
16 => (byte)skillscount switch
{
6 => 20,
5 => 15,
4 => 10,
3 => 5,
2 => 3,
_ => 0
},
_ => (byte)(skillscount - (5 * 4))
};

}
skill.LevelMinimum = (byte)((skill.CastId - SkillsUnlockedAtOnce) * LevelsPerUnlock);
}

await skillDao.TryInsertOrUpdateAsync(skills);
Expand Down
Loading
Loading