From 299a9e8b9887caf3a1e90b30971c6ec1585bd96d Mon Sep 17 00:00:00 2001 From: Timothy Schenk Date: Sun, 19 Nov 2023 20:06:02 +0100 Subject: [PATCH] refactor: extract firstJob and items --- .../CharacterCreationHandler.cs | 46 +++++++++++-------- 1 file changed, 28 insertions(+), 18 deletions(-) diff --git a/Server/PacketHandlers/CharacterCreationHandler.cs b/Server/PacketHandlers/CharacterCreationHandler.cs index 089237f..049f45a 100644 --- a/Server/PacketHandlers/CharacterCreationHandler.cs +++ b/Server/PacketHandlers/CharacterCreationHandler.cs @@ -38,31 +38,16 @@ public class CharacterCreationHandler : IPacketHandler 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 }).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 +