Skip to content

Commit

Permalink
Ensure boss NPCs can still be attacked when under siege
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed Sep 14, 2022
1 parent 43c9729 commit a33c682
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions EOLib/Domain/Character/AttackValidationActions.cs
Expand Up @@ -2,7 +2,6 @@
using EOLib.Domain.Extensions;
using EOLib.Domain.Map;
using EOLib.IO.Repositories;
using Optional.Collections;
using System.Linq;

namespace EOLib.Domain.Character
Expand All @@ -13,14 +12,17 @@ public class AttackValidationActions : IAttackValidationActions
private readonly ICharacterProvider _characterProvider;
private readonly IMapCellStateProvider _mapCellStateProvider;
private readonly IEIFFileProvider _eifFileProvider;
private readonly IENFFileProvider _enfFileProvider;

public AttackValidationActions(ICharacterProvider characterProvider,
IMapCellStateProvider mapCellStateProvider,
IEIFFileProvider eifFileProvider)
IEIFFileProvider eifFileProvider,
IENFFileProvider enfFileProvider)
{
_characterProvider = characterProvider;
_mapCellStateProvider = mapCellStateProvider;
_eifFileProvider = eifFileProvider;
_enfFileProvider = enfFileProvider;
}

public AttackValidationError ValidateCharacterStateBeforeAttacking()
Expand All @@ -40,7 +42,14 @@ public AttackValidationError ValidateCharacterStateBeforeAttacking()
.GetCellStateAt(rp.GetDestinationX(), rp.GetDestinationY())
.NPC.Match(
some: npc => npc.OpponentID.Match(
some: id => id != _characterProvider.MainCharacter.ID ? AttackValidationError.NotYourBattle : AttackValidationError.OK,
some: id =>
{
var notYourBattle = id != _characterProvider.MainCharacter.ID;
var isBossNpc = _enfFileProvider.ENFFile[npc.ID].Boss > 0;
return notYourBattle && !isBossNpc
? AttackValidationError.NotYourBattle
: AttackValidationError.OK;
},
none: () => AttackValidationError.OK),
none: () => AttackValidationError.OK);
}
Expand Down

0 comments on commit a33c682

Please sign in to comment.