Skip to content

Commit

Permalink
Fix casting of self target spells and anything bound to F8
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed Apr 18, 2022
1 parent a5bc32d commit 094eac5
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
15 changes: 14 additions & 1 deletion EOLib/Domain/Spells/SpellCastValidationActions.cs
Expand Up @@ -23,7 +23,7 @@ public class SpellCastValidationActions : ISpellCastValidationActions
_characterProvider = characterProvider;
}

public SpellCastValidationResult ValidateSpellCast(int spellId, ISpellTargetable spellTarget)
public SpellCastValidationResult ValidateSpellCast(int spellId)
{
var spellData = _pubFileProvider.ESFFile[spellId];

Expand All @@ -33,6 +33,17 @@ public SpellCastValidationResult ValidateSpellCast(int spellId, ISpellTargetable
if (stats[CharacterStat.TP] - spellData.TP < 0)
return SpellCastValidationResult.ExhaustedNoTp;

return SpellCastValidationResult.Ok;
}

public SpellCastValidationResult ValidateSpellCast(int spellId, ISpellTargetable spellTarget)
{
var res = ValidateSpellCast(spellId);
if (res != SpellCastValidationResult.Ok)
return res;

var spellData = _pubFileProvider.ESFFile[spellId];

if (spellTarget is INPC)
{
if (spellData.TargetRestrict == SpellTargetRestrict.Friendly ||
Expand Down Expand Up @@ -65,6 +76,8 @@ public SpellCastValidationResult ValidateSpellCast(int spellId, ISpellTargetable

public interface ISpellCastValidationActions
{
SpellCastValidationResult ValidateSpellCast(int spellId);

SpellCastValidationResult ValidateSpellCast(int spellId, ISpellTargetable spellTarget);
}
}
21 changes: 18 additions & 3 deletions EndlessClient/Controllers/FunctionKeyController.cs
@@ -1,12 +1,15 @@
using AutomaticTypeMapper;
using EndlessClient.HUD;
using EndlessClient.HUD.Panels;
using EndlessClient.HUD.Spells;
using EndlessClient.Rendering.Character;
using EOLib.Domain.Character;
using EOLib.Domain.Extensions;
using EOLib.Domain.Map;
using EOLib.Domain.Spells;
using EOLib.IO;
using EOLib.IO.Repositories;
using EOLib.Localization;

namespace EndlessClient.Controllers
{
Expand All @@ -17,6 +20,8 @@ public class FunctionKeyController : IFunctionKeyController
private readonly ICharacterActions _characterActions;
private readonly ISpellSelectActions _spellSelectActions;
private readonly ICharacterAnimationActions _characterAnimationActions;
private readonly ISpellCastValidationActions _spellCastValidationActions;
private readonly IStatusLabelSetter _statusLabelSetter;
private readonly ICharacterProvider _characterProvider;
private readonly IESFFileProvider _esfFileProvider;
private readonly ISpellSlotDataProvider _spellSlotDataProvider;
Expand All @@ -25,6 +30,8 @@ public class FunctionKeyController : IFunctionKeyController
ICharacterActions characterActions,
ISpellSelectActions spellSelectActions,
ICharacterAnimationActions characterAnimationActions,
ISpellCastValidationActions spellCastValidationActions,
IStatusLabelSetter statusLabelSetter,
ICharacterProvider characterProvider,
IESFFileProvider esfFileProvider,
ISpellSlotDataProvider spellSlotDataProvider)
Expand All @@ -33,6 +40,8 @@ public class FunctionKeyController : IFunctionKeyController
_characterActions = characterActions;
_spellSelectActions = spellSelectActions;
_characterAnimationActions = characterAnimationActions;
_spellCastValidationActions = spellCastValidationActions;
_statusLabelSetter = statusLabelSetter;
_characterProvider = characterProvider;
_esfFileProvider = esfFileProvider;
_spellSlotDataProvider = spellSlotDataProvider;
Expand All @@ -47,10 +56,16 @@ public bool SelectSpell(int index, bool isAlternate)
_spellSlotDataProvider.SelectedSpellInfo.MatchSome(x =>
{
var spellData = _esfFileProvider.ESFFile[x.ID];
if ((spellData.Target == SpellTarget.Self || spellData.Target == SpellTarget.Group) &&
_characterAnimationActions.PrepareMainCharacterSpell(x.ID, _characterProvider.MainCharacter))
if (spellData.Target == SpellTarget.Self || spellData.Target == SpellTarget.Group)
{
_characterActions.PrepareCastSpell(x.ID);
var castResult = _spellCastValidationActions.ValidateSpellCast(x.ID);
if (castResult == SpellCastValidationResult.ExhaustedNoTp)
_statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_WARNING, EOResourceID.ATTACK_YOU_ARE_EXHAUSTED_TP);
else if (castResult == SpellCastValidationResult.ExhaustedNoSp)
_statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_WARNING, EOResourceID.ATTACK_YOU_ARE_EXHAUSTED_SP);
else if (_characterAnimationActions.PrepareMainCharacterSpell(x.ID, _characterProvider.MainCharacter))
_characterActions.PrepareCastSpell(x.ID);
}
});

Expand Down
10 changes: 5 additions & 5 deletions EndlessClient/HUD/Spells/SpellSelectActions.cs
Expand Up @@ -28,16 +28,16 @@ public void SelectSpellBySlot(int slot)
{
var spellData = _esfFileProvider.ESFFile[si.ID];
if (spellData.Target == EOLib.IO.SpellTarget.Normal)
if (spellData.Target == EOLib.IO.SpellTarget.Group /*&& not in party*/) // todo: parties
{
_statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_WARNING, EOResourceID.SPELL_ONLY_WORKS_ON_GROUP);
}
else
{
_statusLabelSetter.SetStatusLabel(EOResourceID.SKILLMASTER_WORD_SPELL, $"{spellData.Name} ", EOResourceID.SPELL_WAS_SELECTED);
_spellSlotDataRepository.SelectedSpellSlot = Option.Some(slot);
_spellSlotDataRepository.SpellIsPrepared = true;
}
else if (spellData.Target == EOLib.IO.SpellTarget.Group /*&& not in party*/) // todo: parties
{
_statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_WARNING, EOResourceID.SPELL_ONLY_WORKS_ON_GROUP);
}
},
none: () =>
{
Expand Down
2 changes: 1 addition & 1 deletion EndlessClient/Input/FunctionKeyHandler.cs
Expand Up @@ -22,7 +22,7 @@ public class FunctionKeyHandler : InputHandlerBase

protected override Option<Keys> HandleInput()
{
for (var key = Keys.F1; key < Keys.F8; key++)
for (var key = Keys.F1; key <= Keys.F8; key++)
{
if (IsKeyHeld(key))
{
Expand Down

0 comments on commit 094eac5

Please sign in to comment.