Skip to content

Commit

Permalink
Update instrument attacks to render as ranged weapons instead of mele…
Browse files Browse the repository at this point in the history
…e weapons
  • Loading branch information
ethanmoffat committed Apr 27, 2022
1 parent 3b8b042 commit bea0e27
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 15 deletions.
1 change: 1 addition & 0 deletions BatchMap/BatchMap.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,6 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\EOLib.IO\EOLib.IO.csproj" />
<ProjectReference Include="..\EOLib\EOLib.csproj" />
</ItemGroup>
</Project>
4 changes: 3 additions & 1 deletion BatchMap/Program.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System;
using System.IO;
using System.Linq;
using AutomaticTypeMapper;
using EOLib;
using EOLib.IO.Actions;
using EOLib.IO.Map;
using EOLib.IO.Repositories;
Expand Down Expand Up @@ -101,7 +103,7 @@ private static void Main(string[] args)
{
var actions = _typeRegistry.Resolve<IPubFileLoadActions>();

actions.LoadItemFileByName(Path.Combine(pubFilePath, "dat001.eif"));
actions.LoadItemFileByName(Path.Combine(pubFilePath, "dat001.eif"), rangedWeaponIds: Constants.RangedWeaponIDs.Concat(Constants.InstrumentIDs));
actions.LoadNPCFileByName(Path.Combine(pubFilePath, "dtn001.enf"));
}
catch
Expand Down
8 changes: 5 additions & 3 deletions EOLib.IO/Actions/IPubFileLoadActions.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
namespace EOLib.IO.Actions
using System.Collections.Generic;

namespace EOLib.IO.Actions
{
public interface IPubFileLoadActions
{
void LoadItemFile();
void LoadItemFile(IEnumerable<int> rangedWeaponIds);

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

void LoadNPCFile();

Expand Down
21 changes: 17 additions & 4 deletions EOLib.IO/Actions/PubFileLoadActions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
using EOLib.IO.Pub;
using EOLib.IO.Repositories;
using EOLib.IO.Services;
using System.Collections.Generic;
using System.Linq;

namespace EOLib.IO.Actions
{
Expand All @@ -27,16 +29,16 @@ public PubFileLoadActions(IPubFileRepository pubFileRepository,
_classFileLoadService = classFileLoadService;
}

public void LoadItemFile()
public void LoadItemFile(IEnumerable<int> rangedWeaponIds)
{
var itemFile = _itemFileLoadService.LoadPubFromDefaultFile();
_pubFileRepository.EIFFile = itemFile;
_pubFileRepository.EIFFile = OverrideRangedWeapons(itemFile, rangedWeaponIds);
}

public void LoadItemFileByName(string fileName)
public void LoadItemFileByName(string fileName, IEnumerable<int> rangedWeaponIds)
{
var itemFile = _itemFileLoadService.LoadPubFromExplicitFile(fileName);
_pubFileRepository.EIFFile = itemFile;
_pubFileRepository.EIFFile = OverrideRangedWeapons(itemFile, rangedWeaponIds);
}

public void LoadNPCFile()
Expand Down Expand Up @@ -74,5 +76,16 @@ public void LoadClassFileByName(string fileName)
var classFile = _classFileLoadService.LoadPubFromExplicitFile(fileName);
_pubFileRepository.ECFFile = classFile;
}

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;
}
}
}
8 changes: 2 additions & 6 deletions EOLib.IO/Extensions/EIFFileExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ public static bool IsShieldOnBack(this IPubFile<EIFRecord> itemFile, short graph

public static bool IsRangedWeapon(this IPubFile<EIFRecord> itemFile, short graphic)
{
if (itemFile == null)
return false;

var weaponInfo = itemFile.FirstOrDefault(x => x.Type == ItemType.Weapon && x.DollGraphic == graphic);

return weaponInfo != null && (weaponInfo.Name == "Gun" || weaponInfo.SubType == ItemSubType.Ranged);
var weaponInfo = itemFile?.FirstOrDefault(x => x.Type == ItemType.Weapon && x.DollGraphic == graphic);
return weaponInfo?.SubType == ItemSubType.Ranged;
}
}
}
2 changes: 2 additions & 0 deletions EOLib/misc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public static class Constants

// 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 };

public const string FontSize07 = @"Fonts/InGame_Main_07";
public const string FontSize08 = @"Fonts/InGame_Main_08";
Expand Down
3 changes: 2 additions & 1 deletion EndlessClient/GameExecution/EndlessGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
using EndlessClient.Rendering.Chat;
using EndlessClient.Test;
using EndlessClient.UIControls;
using EOLib;
using EOLib.Domain.Character;
using EOLib.Graphics;
using EOLib.IO;
Expand Down Expand Up @@ -159,7 +160,7 @@ private void AttemptToLoadPubFiles()

try
{
_pubFileLoadActions.LoadItemFile();
_pubFileLoadActions.LoadItemFile(rangedWeaponIds: Constants.RangedWeaponIDs.Concat(Constants.InstrumentIDs));
}
catch (IOException ioe)
{
Expand Down

0 comments on commit bea0e27

Please sign in to comment.