diff --git a/EOLib/Domain/Spells/SpellCastValidationActions.cs b/EOLib/Domain/Spells/SpellCastValidationActions.cs index 4361f2bc3..329b91cdb 100644 --- a/EOLib/Domain/Spells/SpellCastValidationActions.cs +++ b/EOLib/Domain/Spells/SpellCastValidationActions.cs @@ -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]; @@ -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 || @@ -65,6 +76,8 @@ public SpellCastValidationResult ValidateSpellCast(int spellId, ISpellTargetable public interface ISpellCastValidationActions { + SpellCastValidationResult ValidateSpellCast(int spellId); + SpellCastValidationResult ValidateSpellCast(int spellId, ISpellTargetable spellTarget); } } diff --git a/EndlessClient/Controllers/FunctionKeyController.cs b/EndlessClient/Controllers/FunctionKeyController.cs index 8f5a368a6..ec66f9f24 100644 --- a/EndlessClient/Controllers/FunctionKeyController.cs +++ b/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 { @@ -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; @@ -25,6 +30,8 @@ public class FunctionKeyController : IFunctionKeyController ICharacterActions characterActions, ISpellSelectActions spellSelectActions, ICharacterAnimationActions characterAnimationActions, + ISpellCastValidationActions spellCastValidationActions, + IStatusLabelSetter statusLabelSetter, ICharacterProvider characterProvider, IESFFileProvider esfFileProvider, ISpellSlotDataProvider spellSlotDataProvider) @@ -33,6 +40,8 @@ public class FunctionKeyController : IFunctionKeyController _characterActions = characterActions; _spellSelectActions = spellSelectActions; _characterAnimationActions = characterAnimationActions; + _spellCastValidationActions = spellCastValidationActions; + _statusLabelSetter = statusLabelSetter; _characterProvider = characterProvider; _esfFileProvider = esfFileProvider; _spellSlotDataProvider = spellSlotDataProvider; @@ -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); } }); diff --git a/EndlessClient/HUD/Spells/SpellSelectActions.cs b/EndlessClient/HUD/Spells/SpellSelectActions.cs index 51b943e5d..28bf09044 100644 --- a/EndlessClient/HUD/Spells/SpellSelectActions.cs +++ b/EndlessClient/HUD/Spells/SpellSelectActions.cs @@ -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: () => { diff --git a/EndlessClient/Input/FunctionKeyHandler.cs b/EndlessClient/Input/FunctionKeyHandler.cs index 95a712128..b68d84184 100644 --- a/EndlessClient/Input/FunctionKeyHandler.cs +++ b/EndlessClient/Input/FunctionKeyHandler.cs @@ -22,7 +22,7 @@ public class FunctionKeyHandler : InputHandlerBase protected override Option HandleInput() { - for (var key = Keys.F1; key < Keys.F8; key++) + for (var key = Keys.F1; key <= Keys.F8; key++) { if (IsKeyHeld(key)) {