refactor: extract firstJob and items

This commit is contained in:
Timothy Schenk 2023-11-19 20:06:02 +01:00
parent a351d95bdc
commit 299a9e8b98

View file

@ -38,31 +38,16 @@ public class CharacterCreationHandler : IPacketHandler<CharacterCreationPacket>
var mappedDefaultItems = _characterStatsMapping.DefaultCharacterMapping.Items
.Select(i => _itemObjectPoolService.GetBaseInventoryItem(i.Id, i.Quantity)).ToArray();
var firstJobConfig = packet.FirstJob switch
{
1 => _characterStatsMapping.Swordsman,
2 => _characterStatsMapping.Mage,
3 => _characterStatsMapping.Thief,
4 => _characterStatsMapping.Scout,
_ => _characterStatsMapping.Swordsman
};
var firstJobConfig = SelectFirstJobConfig(packet.FirstJob);
var mappedJobItems = firstJobConfig.Items
.Select(i => _itemObjectPoolService.GetBaseInventoryItem(i.Id, i.Quantity)).ToArray();
var defaultItems = GenerateDefaultItems(packet);
InventoryItem[] items =
[
.. mappedDefaultItems,
.. mappedJobItems,
_itemObjectPoolService.GetBaseInventoryItem((ushort)((packet.FirstJob - 1) * 6 +
((byte)packet.Gender - 1) * 3 +
packet.Hair + 1)),
_itemObjectPoolService.GetBaseInventoryItem((ushort)((packet.FirstJob - 1) * 6 +
((byte)packet.Gender - 1) * 3 +
packet.Eyes + 25)),
_itemObjectPoolService.GetBaseInventoryItem((ushort)(((byte)packet.Gender - 1) * 3 +
packet.Shirt + 49)),
_itemObjectPoolService.GetBaseInventoryItem((ushort)(((byte)packet.Gender - 1) * 3 +
packet.Pants + 58))
.. defaultItems
];
var calculateCurrentMana = CalculateCurrentMana(1, firstJobConfig);
@ -119,6 +104,31 @@ public class CharacterCreationHandler : IPacketHandler<CharacterCreationPacket>
}).ConfigureAwait(false);
}
private JobSpecificMapping SelectFirstJobConfig(byte firstJob) =>
firstJob switch
{
1 => _characterStatsMapping.Swordsman,
2 => _characterStatsMapping.Mage,
3 => _characterStatsMapping.Thief,
4 => _characterStatsMapping.Scout,
_ => _characterStatsMapping.Swordsman
};
private InventoryItem[] GenerateDefaultItems(CharacterCreationPacket packet) =>
new[]
{
_itemObjectPoolService.GetBaseInventoryItem((ushort)((packet.FirstJob - 1) * 6 +
((byte)packet.Gender - 1) * 3 +
packet.Hair + 1)),
_itemObjectPoolService.GetBaseInventoryItem((ushort)((packet.FirstJob - 1) * 6 +
((byte)packet.Gender - 1) * 3 +
packet.Eyes + 25)),
_itemObjectPoolService.GetBaseInventoryItem((ushort)(((byte)packet.Gender - 1) * 3 +
packet.Shirt + 49)),
_itemObjectPoolService.GetBaseInventoryItem((ushort)(((byte)packet.Gender - 1) * 3 +
packet.Pants + 58))
};
private static int CalculateCurrentHealth(ushort level, JobSpecificMapping firstJobConfig)
{
return (int)((level - 1) * firstJobConfig.DynamicStats.HealthPerLevel +