Skip to content

Commit

Permalink
Merge pull request #329 from ethanmoffat/weapon_metadata
Browse files Browse the repository at this point in the history
Add weapon metadata loading and usage
  • Loading branch information
ethanmoffat authored Dec 18, 2023
2 parents 1dcf446 + 5eda2e9 commit e956d4e
Show file tree
Hide file tree
Showing 49 changed files with 374 additions and 228 deletions.
2 changes: 1 addition & 1 deletion BatchMap/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ private static void Main(string[] args)
{
var actions = _typeRegistry.Resolve<IPubFileLoadActions>();

actions.LoadItemFileByName(Path.Combine(pubFilePath, "dat001.eif"), rangedWeaponIds: Constants.RangedWeaponIDs.Concat(Constants.InstrumentIDs));
actions.LoadItemFileByName(Path.Combine(pubFilePath, "dat001.eif"));
actions.LoadNPCFileByName(Path.Combine(pubFilePath, "dtn001.enf"));
}
catch
Expand Down
4 changes: 2 additions & 2 deletions EOLib.IO/Actions/IPubFileLoadActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ namespace EOLib.IO.Actions
{
public interface IPubFileLoadActions
{
void LoadItemFile(IEnumerable<int> rangedWeaponIds);
void LoadItemFile();

void LoadItemFileByName(string fileName, IEnumerable<int> rangedWeaponIds);
void LoadItemFileByName(string fileName);

void LoadNPCFile();

Expand Down
22 changes: 5 additions & 17 deletions EOLib.IO/Actions/PubFileLoadActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,12 @@
using EOLib.IO.Pub;
using EOLib.IO.Repositories;
using EOLib.IO.Services;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace EOLib.IO.Actions
{
[MappedType(BaseType = typeof(IPubFileLoadActions))]
[AutoMappedType]
public class PubFileLoadActions : IPubFileLoadActions
{
private readonly IPubFileRepository _pubFileRepository;
Expand All @@ -31,18 +30,18 @@ public PubFileLoadActions(IPubFileRepository pubFileRepository,
_classFileLoadService = classFileLoadService;
}

public void LoadItemFile(IEnumerable<int> rangedWeaponIds)
public void LoadItemFile()
{
var itemFiles = _itemFileLoadService.LoadPubFromDefaultFile();
_pubFileRepository.EIFFiles = itemFiles.ToList();
_pubFileRepository.EIFFile = OverrideRangedWeapons(PubFileExtensions.Merge(_pubFileRepository.EIFFiles), rangedWeaponIds);
_pubFileRepository.EIFFile = PubFileExtensions.Merge(_pubFileRepository.EIFFiles);
}

public void LoadItemFileByName(string fileName, IEnumerable<int> rangedWeaponIds)
public void LoadItemFileByName(string fileName)
{
var itemFiles = _itemFileLoadService.LoadPubFromExplicitFile(Path.GetDirectoryName(fileName), Path.GetFileName(fileName));
_pubFileRepository.EIFFiles = itemFiles.ToList();
_pubFileRepository.EIFFile = OverrideRangedWeapons(PubFileExtensions.Merge(_pubFileRepository.EIFFiles), rangedWeaponIds);
_pubFileRepository.EIFFile = PubFileExtensions.Merge(_pubFileRepository.EIFFiles);
}

public void LoadNPCFile()
Expand Down Expand Up @@ -86,16 +85,5 @@ public void LoadClassFileByName(string fileName)
_pubFileRepository.ECFFiles = classFiles.ToList();
_pubFileRepository.ECFFile = PubFileExtensions.Merge(_pubFileRepository.ECFFiles);
}

private static IPubFile<EIFRecord> OverrideRangedWeapons(IPubFile<EIFRecord> inputFile, IEnumerable<int> rangedWeaponIds)
{
var rangedItemOverrides = inputFile.Where(x => x.Type == ItemType.Weapon && rangedWeaponIds.Contains(x.ID)).ToList();

var retFile = inputFile;
foreach (var item in rangedItemOverrides)
retFile = retFile.WithUpdatedRecord((EIFRecord)item.WithProperty(PubRecordProperty.ItemSubType, (int)ItemSubType.Ranged));

return retFile;
}
}
}
14 changes: 0 additions & 14 deletions EOLib.IO/Extensions/EIFFileExtensions.cs

This file was deleted.

9 changes: 8 additions & 1 deletion EOLib/Domain/Character/AttackValidationActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,14 @@ public AttackValidationError ValidateCharacterStateBeforeAttacking()

var rp = _characterProvider.MainCharacter.RenderProperties;

if (rp.IsRangedWeapon && (rp.ShieldGraphic == 0 || !_eifFileProvider.EIFFile.Any(x => x.DollGraphic == rp.ShieldGraphic && x.SubType == IO.ItemSubType.Arrows)))
var isRangedWeapon = _eifFileProvider.EIFFile
.Where(x => x.Type == IO.ItemType.Weapon && x.SubType == IO.ItemSubType.Ranged)
.Any(x => x.Graphic == rp.WeaponGraphic);
var isArrows = _eifFileProvider.EIFFile
.Where(x => x.Type == IO.ItemType.Shield && x.SubType == IO.ItemSubType.Arrows)
.Any(x => x.Graphic == rp.ShieldGraphic);

if (isRangedWeapon && (rp.ShieldGraphic == 0 || !isArrows))
return AttackValidationError.MissingArrows;

return _mapCellStateProvider
Expand Down
2 changes: 0 additions & 2 deletions EOLib/Domain/Character/CharacterRenderProperties.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,5 @@ public sealed partial class CharacterRenderProperties
public bool IsHidden { get; }
public bool IsDead { get; }
public bool IsDrunk { get; }

public bool IsRangedWeapon { get; }
}
}
3 changes: 1 addition & 2 deletions EOLib/Domain/Extensions/CharacterExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace EOLib.Domain.Extensions
{
public static class CharacterExtensions
{
public static Character.Character WithAppliedData(this Character.Character original, Character.Character updatedData, bool isRangedWeapon)
public static Character.Character WithAppliedData(this Character.Character original, Character.Character updatedData)
{
var existingRenderProps = original.RenderProperties;
var newRenderProps = updatedData.RenderProperties.ToBuilder();
Expand All @@ -14,7 +14,6 @@ public static Character.Character WithAppliedData(this Character.Character origi
? CharacterActionState.Standing
: CharacterActionState.Sitting;
newRenderProps.IsDead = existingRenderProps.IsDead;
newRenderProps.IsRangedWeapon = isRangedWeapon;
newRenderProps.IsDrunk = existingRenderProps.IsDrunk;
newRenderProps.IsHidden = existingRenderProps.IsHidden;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ public static CharacterRenderProperties WithNextWalkFrame(this CharacterRenderPr
return props.ToImmutable();
}

public static CharacterRenderProperties WithNextAttackFrame(this CharacterRenderProperties rp)
public static CharacterRenderProperties WithNextAttackFrame(this CharacterRenderProperties rp, bool isRangedWeapon)
{
var props = rp.ToBuilder();
props.ActualAttackFrame = (props.ActualAttackFrame + 1) % CharacterRenderProperties.MAX_NUMBER_OF_WALK_FRAMES;
props.RenderAttackFrame = props.ActualAttackFrame;

if (props.IsRangedWeapon)
if (isRangedWeapon)
{
// ranged attack ticks: 0 0 1 1 1
props.RenderAttackFrame /= CharacterRenderProperties.MAX_NUMBER_OF_RANGED_ATTACK_FRAMES;
Expand Down
5 changes: 1 addition & 4 deletions EOLib/Domain/Spells/SpellCastValidationActions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
using AutomaticTypeMapper;
using EOLib.Domain.Character;
using EOLib.Domain.Map;
using EOLib.Domain.NPC;
using EOLib.IO;
using EOLib.IO.Repositories;
using Optional.Collections;
using System.Linq;

namespace EOLib.Domain.Spells
Expand Down Expand Up @@ -78,8 +76,7 @@ public SpellCastValidationResult ValidateSpellCast(int spellId, ISpellTargetable
public bool ValidateBard()
{
var weapon = _characterProvider.MainCharacter.RenderProperties.WeaponGraphic;
return _pubFileProvider.EIFFile.SingleOrNone(x => x.DollGraphic == weapon && x.Type == ItemType.Weapon)
.Match(some => Constants.InstrumentIDs.Any(x => x == some.ID), () => false);
return Constants.Instruments.Any(x => x == weapon);
}
}

Expand Down
9 changes: 3 additions & 6 deletions EOLib/Net/Translators/CharacterDisplayPacketTranslator.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Collections.Generic;
using System.IO;
using EOLib.Domain.Character;
using EOLib.IO.Extensions;
using EOLib.Domain.Character;
using EOLib.IO.Repositories;
using System.Collections.Generic;

namespace EOLib.Net.Translators
{
Expand Down Expand Up @@ -69,8 +67,7 @@ private Character GetNextCharacter(IPacket packet)
ArmorGraphic = armor,
HatGraphic = hat,
ShieldGraphic = shield,
WeaponGraphic = weapon,
IsRangedWeapon = _eifFileProvider.EIFFile.IsRangedWeapon(weapon),
WeaponGraphic = weapon
};

character.Stats = stats;
Expand Down
6 changes: 2 additions & 4 deletions EOLib/Net/Translators/CharacterFromPacketFactory.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System.IO;
using AutomaticTypeMapper;
using AutomaticTypeMapper;
using EOLib.Domain.Character;
using EOLib.IO.Extensions;
using EOLib.IO.Repositories;
using System.IO;

namespace EOLib.Net.Translators
{
Expand Down Expand Up @@ -71,7 +70,6 @@ public Character CreateCharacter(IPacket packet)
HatGraphic = hat,
ShieldGraphic = shield,
WeaponGraphic = weapon,
IsRangedWeapon = _eifFileProvider.EIFFile.IsRangedWeapon(weapon),
SitState = sitState,
CurrentAction = sitState == SitState.Standing ? CharacterActionState.Standing : CharacterActionState.Sitting,
IsHidden = hidden,
Expand Down
9 changes: 2 additions & 7 deletions EOLib/PacketHandlers/Avatar/AvatarAgreeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using EOLib.Domain.Character;
using EOLib.Domain.Login;
using EOLib.Domain.Map;
using EOLib.IO.Extensions;
using EOLib.IO.Repositories;
using EOLib.Net;
using EOLib.Net.Handlers;
Expand Down Expand Up @@ -61,12 +60,8 @@ public override bool HandlePacket(IPacket packet)
currentRenderProps = currentRenderProps
.WithBootsGraphic(packet.ReadShort())
.WithArmorGraphic(packet.ReadShort())
.WithHatGraphic(packet.ReadShort());

var weaponGraphic = packet.ReadShort();
currentRenderProps = currentRenderProps
.WithWeaponGraphic(weaponGraphic)
.WithIsRangedWeapon(_eifFileProvider.EIFFile.IsRangedWeapon(weaponGraphic))
.WithHatGraphic(packet.ReadShort())
.WithWeaponGraphic(packet.ReadShort())
.WithShieldGraphic(packet.ReadShort());

break;
Expand Down
2 changes: 1 addition & 1 deletion EOLib/PacketHandlers/Items/ItemReplyHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ public override bool HandlePacket(IPacket packet)
else if (loc == EquipLocation.Hat)
renderProps = renderProps.WithHatGraphic(0);
else if (loc == EquipLocation.Weapon)
renderProps = renderProps.WithWeaponGraphic(0).WithIsRangedWeapon(false);
renderProps = renderProps.WithWeaponGraphic(0);
else if (loc == EquipLocation.Shield)
renderProps = renderProps.WithShieldGraphic(0);
}
Expand Down
4 changes: 1 addition & 3 deletions EOLib/PacketHandlers/MapInfo/MapInfoReplyHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using EOLib.Domain.Extensions;
using EOLib.Domain.Login;
using EOLib.Domain.Map;
using EOLib.IO.Extensions;
using EOLib.IO.Repositories;
using EOLib.Net;
using EOLib.Net.Handlers;
Expand Down Expand Up @@ -47,8 +46,7 @@ public override bool HandlePacket(IPacket packet)
var character = _characterFromPacketFactory.CreateCharacter(packet);
if (_currentMapStateRepository.Characters.TryGetValue(character.ID, out var existingCharacter))
{
var isRangedWeapon = _eifFileProvider.EIFFile.IsRangedWeapon(character.RenderProperties.WeaponGraphic);
character = existingCharacter.WithAppliedData(character, isRangedWeapon);
character = existingCharacter.WithAppliedData(character);
}

_currentMapStateRepository.Characters.Update(existingCharacter, character);
Expand Down
7 changes: 2 additions & 5 deletions EOLib/PacketHandlers/Players/PlayersAgreeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using EOLib.Domain.Login;
using EOLib.Domain.Map;
using EOLib.Domain.Notifiers;
using EOLib.IO.Extensions;
using EOLib.IO.Repositories;
using EOLib.Net;
using EOLib.Net.Handlers;
Expand Down Expand Up @@ -69,14 +68,12 @@ public override bool HandlePacket(IPacket packet)
if (_characterRepository.MainCharacter.ID == character.ID)
{
var existingCharacter = _characterRepository.MainCharacter;
var isRangedWeapon = _eifFileProvider.EIFFile.IsRangedWeapon(character.RenderProperties.WeaponGraphic);
_characterRepository.MainCharacter = existingCharacter.WithAppliedData(character, isRangedWeapon);
_characterRepository.MainCharacter = existingCharacter.WithAppliedData(character);
_characterRepository.HasAvatar = true;
}
else if (_mapStateRepository.Characters.TryGetValue(character.ID, out var existingCharacter))
{
var isRangedWeapon = _eifFileProvider.EIFFile.IsRangedWeapon(character.RenderProperties.WeaponGraphic);
_mapStateRepository.Characters.Update(existingCharacter, existingCharacter.WithAppliedData(character, isRangedWeapon));
_mapStateRepository.Characters.Update(existingCharacter, existingCharacter.WithAppliedData(character));
}
else
{
Expand Down
3 changes: 1 addition & 2 deletions EOLib/PacketHandlers/Warp/WarpAgreeHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using EOLib.Domain.Login;
using EOLib.Domain.Map;
using EOLib.Domain.Notifiers;
using EOLib.IO.Extensions;
using EOLib.IO.Repositories;
using EOLib.Net;
using EOLib.Net.Handlers;
Expand Down Expand Up @@ -68,7 +67,7 @@ public override bool HandlePacket(IPacket packet)
var bringBackToLife = _characterRepository.MainCharacter.RenderProperties.WithIsDead(false);
_characterRepository.MainCharacter = _characterRepository.MainCharacter
.WithRenderProperties(bringBackToLife)
.WithAppliedData(updatedMainCharacter, _eifFileProvider.EIFFile.IsRangedWeapon(updatedMainCharacter.RenderProperties.WeaponGraphic));
.WithAppliedData(updatedMainCharacter);

var withoutMainCharacter = warpAgreePacketData.Characters.Where(x => !MainCharacterIDMatches(x));
warpAgreePacketData = warpAgreePacketData.WithCharacters(withoutMainCharacter.ToList());
Expand Down
6 changes: 2 additions & 4 deletions EOLib/misc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,8 @@ public static class Constants
//not a config option because this shouldn't be exposed at the user level
public static readonly int[] TrapSpikeGFXObjectIDs = { 449, 450, 451, 452 };

// Item IDs of instruments (there is no pub flag for this)
public static readonly int[] InstrumentIDs = { 349, 350 };
// Item IDs of ranged weapons (overrides pub value)
public static readonly int[] RangedWeaponIDs = { 365 };
// Weapon graphics of instruments (there is no pub flag for this)
public static readonly int[] Instruments = { 49, 50 };
public const string FontSize07 = @"BitmapFonts/sans_09px";
public const string FontSize08 = @"BitmapFonts/sans_11px";
public const string FontSize08pt5 = @"BitmapFonts/sans_11px_103pct";
Expand Down
2 changes: 1 addition & 1 deletion EndlessClient/Audio/SoundEffectID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public enum SoundEffectID
Craft,
UnknownBuzzSound = 28,
AdminChatReceived,
UnknownAttackLikeSound,
AlternateMeleeAttack,
PotionOfFlamesEffect,
AdminWarp = 32,
NoWallWalk,
Expand Down
2 changes: 1 addition & 1 deletion EndlessClient/EndlessClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
<PropertyGroup />
<ItemGroup>
<PackageReference Include="Amadevus.RecordGenerator" Version="0.6.0" />
<PackageReference Include="EndlessClient.Binaries" Version="1.3.3.2" />
<PackageReference Include="EndlessClient.Binaries" Version="1.3.4.2" />
<PackageReference Include="managed-midi" Version="1.9.14" />
<PackageReference Include="Monogame.Content.Builder.Task" Version="3.8.1.303" />
<PackageReference Include="MonoGame.Extended.Content.Pipeline" Version="3.8.0" />
Expand Down
2 changes: 1 addition & 1 deletion EndlessClient/GameExecution/EndlessGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ private void AttemptToLoadPubFiles()

try
{
_pubFileLoadActions.LoadItemFile(rangedWeaponIds: Constants.RangedWeaponIDs.Concat(Constants.InstrumentIDs));
_pubFileLoadActions.LoadItemFile();
}
catch (Exception ex) when (ex is IOException || ex is ArgumentException)
{
Expand Down
13 changes: 11 additions & 2 deletions EndlessClient/HUD/Controls/HudControlsFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
using EndlessClient.Rendering.Character;
using EndlessClient.Rendering.Factories;
using EndlessClient.Rendering.Map;
using EndlessClient.Rendering.Metadata;
using EndlessClient.Rendering.Metadata.Models;
using EndlessClient.Rendering.NPC;
using EndlessClient.UIControls;
using EOLib;
Expand Down Expand Up @@ -67,6 +69,7 @@ public class HudControlsFactory : IHudControlsFactory
private readonly INewsProvider _newsProvider;
private readonly IFixedTimeStepRepository _fixedTimeStepRepository;
private readonly IClickDispatcherFactory _clickDispatcherFactory;
private readonly IMetadataProvider<WeaponMetadata> _weaponMetadataProvider;

private IChatController _chatController;
private IMainButtonController _mainButtonController;
Expand Down Expand Up @@ -99,7 +102,8 @@ public HudControlsFactory(IHudButtonController hudButtonController,
IMiniMapRendererFactory miniMapRendererFactory,
INewsProvider newsProvider,
IFixedTimeStepRepository fixedTimeStepRepository,
IClickDispatcherFactory clickDispatcherFactory)
IClickDispatcherFactory clickDispatcherFactory,
IMetadataProvider<WeaponMetadata> weaponMetadataProvider)
{
_hudButtonController = hudButtonController;
_hudPanelFactory = hudPanelFactory;
Expand Down Expand Up @@ -130,6 +134,7 @@ public HudControlsFactory(IHudButtonController hudButtonController,
_newsProvider = newsProvider;
_fixedTimeStepRepository = fixedTimeStepRepository;
_clickDispatcherFactory = clickDispatcherFactory;
_weaponMetadataProvider = weaponMetadataProvider;
}

public void InjectChatController(IChatController chatController,
Expand Down Expand Up @@ -561,7 +566,11 @@ private IUserInputHandler CreateUserInputHandler()

private ICharacterAnimator CreateCharacterAnimator()
{
return new CharacterAnimator(_endlessGameProvider, _characterRepository, _currentMapStateRepository, _currentMapProvider, _spellSlotDataRepository, _characterActions, _walkValidationActions, _pathFinder, _fixedTimeStepRepository);
return new CharacterAnimator(
_endlessGameProvider, _characterRepository, _currentMapStateRepository,
_currentMapProvider, _spellSlotDataRepository, _characterActions,
_walkValidationActions, _pathFinder, _fixedTimeStepRepository,
_weaponMetadataProvider);
}

private INPCAnimator CreateNPCAnimator()
Expand Down
Loading

0 comments on commit e956d4e

Please sign in to comment.