Skip to content

Commit

Permalink
Target others with spells
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanmoffat committed Apr 18, 2022
1 parent 8272314 commit 47faba6
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 45 deletions.
2 changes: 1 addition & 1 deletion EOLib.Localization/EOResourceID.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public enum EOResourceID
STRING_SERVER = 118,
SERVER_MESSAGE_MAP_MUTATION = 119,
STATUS_LABEL_NOTHING_HAPPENED = 120,

YOU_CANNOT_ATTACK_THIS_NPC = 121,
DIALOG_SHOP_BUY_ITEMS = 122,
DIALOG_SHOP_SELL_ITEMS = 123,
DIALOG_SHOP_CRAFT_ITEMS = 124,
Expand Down
82 changes: 60 additions & 22 deletions EndlessClient/Controllers/MapInteractionController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using EndlessClient.HUD.Controls;
using EndlessClient.HUD.Inventory;
using EndlessClient.HUD.Panels;
using EndlessClient.HUD.Spells;
using EndlessClient.Input;
using EndlessClient.Rendering;
using EndlessClient.Rendering.Character;
Expand All @@ -15,7 +16,10 @@
using EOLib.Domain.Interact;
using EOLib.Domain.Item;
using EOLib.Domain.Map;
using EOLib.Domain.NPC;
using EOLib.Domain.Spells;
using EOLib.IO.Map;
using EOLib.IO.Repositories;
using EOLib.Localization;
using Optional;
using Optional.Collections;
Expand All @@ -32,6 +36,7 @@ public class MapInteractionController : IMapInteractionController
private readonly IInGameDialogActions _inGameDialogActions;
private readonly IPaperdollActions _paperdollActions;
private readonly IUnwalkableTileActions _unwalkableTileActions;
private readonly ICharacterAnimationActions _characterAnimationActions;
private readonly ICurrentMapStateProvider _currentMapStateProvider;
private readonly ICharacterProvider _characterProvider;
private readonly IStatusLabelSetter _statusLabelSetter;
Expand All @@ -44,12 +49,15 @@ public class MapInteractionController : IMapInteractionController
private readonly IContextMenuRendererFactory _contextMenuRendererFactory;
private readonly IActiveDialogProvider _activeDialogProvider;
private readonly IUserInputRepository _userInputRepository;
private readonly ISpellSlotDataRepository _spellSlotDataRepository;
private readonly IENFFileProvider _enfFileProvider;

public MapInteractionController(IMapActions mapActions,
ICharacterActions characterActions,
IInGameDialogActions inGameDialogActions,
IPaperdollActions paperdollActions,
IUnwalkableTileActions unwalkableTileActions,
ICharacterAnimationActions characterAnimationActions,
ICurrentMapStateProvider currentMapStateProvider,
ICharacterProvider characterProvider,
IStatusLabelSetter statusLabelSetter,
Expand All @@ -61,13 +69,16 @@ public MapInteractionController(IMapActions mapActions,
IEOMessageBoxFactory messageBoxFactory,
IContextMenuRendererFactory contextMenuRendererFactory,
IActiveDialogProvider activeDialogProvider,
IUserInputRepository userInputRepository)
IUserInputRepository userInputRepository,
ISpellSlotDataRepository spellSlotDataRepository,
IENFFileProvider enfFileProvider)
{
_mapActions = mapActions;
_characterActions = characterActions;
_inGameDialogActions = inGameDialogActions;
_paperdollActions = paperdollActions;
_unwalkableTileActions = unwalkableTileActions;
_characterAnimationActions = characterAnimationActions;
_currentMapStateProvider = currentMapStateProvider;
_characterProvider = characterProvider;
_statusLabelSetter = statusLabelSetter;
Expand All @@ -80,6 +91,8 @@ public MapInteractionController(IMapActions mapActions,
_contextMenuRendererFactory = contextMenuRendererFactory;
_activeDialogProvider = activeDialogProvider;
_userInputRepository = userInputRepository;
_spellSlotDataRepository = spellSlotDataRepository;
_enfFileProvider = enfFileProvider;
}

public void LeftClick(IMapCellState cellState, Option<IMouseCursorRenderer> mouseRenderer)
Expand Down Expand Up @@ -151,32 +164,55 @@ public void LeftClick(IMapCellState cellState, Option<IMouseCursorRenderer> mous
_userInputTimeRepository.LastInputTime = DateTime.Now;
}

// todo: move to new controller for character interaction
public void RightClick(IMapCellState cellState)
public void LeftClick(ISpellTargetable spellTarget)
{
if (!cellState.Character.HasValue || _activeDialogProvider.ActiveDialogs.Any(x => x.HasValue))
return;

cellState.Character.MatchSome(c =>
if (_spellSlotDataRepository.SpellIsPrepared)
{
if (c == _characterProvider.MainCharacter)
var npcTarget = spellTarget as INPC;
if (npcTarget != null && _enfFileProvider.ENFFile[npcTarget.ID].Type != EOLib.IO.NPCType.Passive && _enfFileProvider.ENFFile[npcTarget.ID].Type != EOLib.IO.NPCType.Aggressive)
{
_paperdollActions.RequestPaperdoll(_characterProvider.MainCharacter.ID);
_inGameDialogActions.ShowPaperdollDialog(_characterProvider.MainCharacter, isMainCharacter: true);
_userInputTimeRepository.LastInputTime = DateTime.Now;
_statusLabelSetter.SetStatusLabel(EOResourceID.STATUS_LABEL_TYPE_WARNING, EOResourceID.YOU_CANNOT_ATTACK_THIS_NPC);
}
else if (_characterRendererProvider.CharacterRenderers.ContainsKey(c.ID))
else
{
_contextMenuRepository.ContextMenu = _contextMenuRepository.ContextMenu.Match(
some: cmr =>
{
cmr.Dispose();
return Option.Some(_contextMenuRendererFactory.CreateContextMenuRenderer(_characterRendererProvider.CharacterRenderers[c.ID]));
},
none: () => Option.Some(_contextMenuRendererFactory.CreateContextMenuRenderer(_characterRendererProvider.CharacterRenderers[c.ID])));
_contextMenuRepository.ContextMenu.MatchSome(r => r.Initialize());
_spellSlotDataRepository.SelectedSpellInfo.MatchSome(si =>
{
if (_characterAnimationActions.PrepareMainCharacterSpell(si.ID, spellTarget))
_characterActions.PrepareCastSpell(si.ID);
});
}
});

_spellSlotDataRepository.SpellIsPrepared = false;
_spellSlotDataRepository.SelectedSpellSlot = Option.None<int>();

_userInputRepository.ClickHandled = true;
}

_userInputTimeRepository.LastInputTime = DateTime.Now;
}

public void RightClick(ICharacter character)
{
if (_activeDialogProvider.ActiveDialogs.Any(x => x.HasValue))
return;

if (character == _characterProvider.MainCharacter)
{
_paperdollActions.RequestPaperdoll(_characterProvider.MainCharacter.ID);
_inGameDialogActions.ShowPaperdollDialog(_characterProvider.MainCharacter, isMainCharacter: true);
_userInputTimeRepository.LastInputTime = DateTime.Now;
}
else if (_characterRendererProvider.CharacterRenderers.ContainsKey(character.ID))
{
_contextMenuRepository.ContextMenu = _contextMenuRepository.ContextMenu.Match(
some: cmr =>
{
cmr.Dispose();
return Option.Some(_contextMenuRendererFactory.CreateContextMenuRenderer(_characterRendererProvider.CharacterRenderers[character.ID]));
},
none: () => Option.Some(_contextMenuRendererFactory.CreateContextMenuRenderer(_characterRendererProvider.CharacterRenderers[character.ID])));
_contextMenuRepository.ContextMenu.MatchSome(r => r.Initialize());
}
}

private void HandlePickupResult(ItemPickupResult pickupResult, IItem item)
Expand Down Expand Up @@ -246,6 +282,8 @@ public interface IMapInteractionController
{
void LeftClick(IMapCellState cellState, Option<IMouseCursorRenderer> mouseRenderer);

void RightClick(IMapCellState cellState);
void LeftClick(ISpellTargetable spellTarget);

void RightClick(ICharacter character);
}
}
11 changes: 6 additions & 5 deletions EndlessClient/HUD/Controls/HudControlsFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using EndlessClient.GameExecution;
using EndlessClient.HUD.Chat;
using EndlessClient.HUD.Panels;
using EndlessClient.HUD.Spells;
using EndlessClient.HUD.StatusBars;
using EndlessClient.Input;
using EndlessClient.Network;
Expand Down Expand Up @@ -51,12 +52,12 @@ public class HudControlsFactory : IHudControlsFactory
private readonly ICurrentMapProvider _currentMapProvider;
private readonly IChatModeCalculator _chatModeCalculator;
private readonly IExperienceTableProvider _experienceTableProvider;
private readonly IArrowKeyController _arrowKeyController;
private readonly IPathFinder _pathFinder;
private readonly ICharacterActions _characterActions;
private readonly IWalkValidationActions _walkValidationActions;
private readonly IPacketSendService _packetSendService;
private readonly IUserInputTimeProvider _userInputTimeProvider;
private readonly ISpellSlotDataRepository _spellSlotDataRepository;
private IChatController _chatController;

public HudControlsFactory(IHudButtonController hudButtonController,
Expand All @@ -77,12 +78,12 @@ public HudControlsFactory(IHudButtonController hudButtonController,
ICurrentMapProvider currentMapProvider,
IChatModeCalculator chatModeCalculator,
IExperienceTableProvider experienceTableProvider,
IArrowKeyController arrowKeyController,
IPathFinder pathFinder,
ICharacterActions characterActions,
IWalkValidationActions walkValidationActions,
IPacketSendService packetSendService,
IUserInputTimeProvider userInputTimeProvider)
IUserInputTimeProvider userInputTimeProvider,
ISpellSlotDataRepository spellSlotDataRepository)
{
_hudButtonController = hudButtonController;
_hudPanelFactory = hudPanelFactory;
Expand All @@ -102,12 +103,12 @@ public HudControlsFactory(IHudButtonController hudButtonController,
_currentMapProvider = currentMapProvider;
_chatModeCalculator = chatModeCalculator;
_experienceTableProvider = experienceTableProvider;
_arrowKeyController = arrowKeyController;
_pathFinder = pathFinder;
_characterActions = characterActions;
_walkValidationActions = walkValidationActions;
_packetSendService = packetSendService;
_userInputTimeProvider = userInputTimeProvider;
_spellSlotDataRepository = spellSlotDataRepository;
}

public void InjectChatController(IChatController chatController)
Expand Down Expand Up @@ -426,7 +427,7 @@ private IUserInputHandler CreateUserInputHandler()

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

private INPCAnimator CreateNPCAnimator()
Expand Down
1 change: 1 addition & 0 deletions EndlessClient/Network/UnknownEntitiesRequester.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public class UnknownEntitiesRequester : GameComponent
private DateTime _lastRequestTime;
private const double REQUEST_INTERVAL_SECONDS = 1;

// todo: create actions in EOLib.Domain for requesting unknown entities, instead of using packetsendservice directly
public UnknownEntitiesRequester(IEndlessGameProvider gameProvider,
ICurrentMapStateRepository currentMapStateRepository,
IPacketSendService packetSendService)
Expand Down
7 changes: 7 additions & 0 deletions EndlessClient/Rendering/Character/CharacterAnimator.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using EndlessClient.GameExecution;
using EndlessClient.HUD;
using EndlessClient.HUD.Spells;
using EndlessClient.Input;
using EOLib;
using EOLib.Domain.Character;
Expand All @@ -26,6 +27,7 @@ public class CharacterAnimator : GameComponent, ICharacterAnimator
private readonly ICharacterRepository _characterRepository;
private readonly ICurrentMapStateRepository _currentMapStateRepository;
private readonly ICurrentMapProvider _currentMapProvider;
private readonly ISpellSlotDataRepository _spellSlotDataRepository;
private readonly ICharacterActions _characterActions;
private readonly IWalkValidationActions _walkValidationActions;
private readonly IPathFinder _pathFinder;
Expand All @@ -48,6 +50,7 @@ public CharacterAnimator(IEndlessGameProvider gameProvider,
ICharacterRepository characterRepository,
ICurrentMapStateRepository currentMapStateRepository,
ICurrentMapProvider currentMapProvider,
ISpellSlotDataRepository spellSlotDataRepository,
ICharacterActions characterActions,
IWalkValidationActions walkValidationActions,
IPathFinder pathFinder)
Expand All @@ -56,6 +59,7 @@ public CharacterAnimator(IEndlessGameProvider gameProvider,
_characterRepository = characterRepository;
_currentMapStateRepository = currentMapStateRepository;
_currentMapProvider = currentMapProvider;
_spellSlotDataRepository = spellSlotDataRepository;
_characterActions = characterActions;
_walkValidationActions = walkValidationActions;
_pathFinder = pathFinder;
Expand Down Expand Up @@ -159,6 +163,9 @@ public void MainCharacterCancelSpellPrep()
_mainPlayerStartShoutTime = Option.None<Stopwatch>();
_shoutSpellData = null;
_spellTarget = null;

_spellSlotDataRepository.SelectedSpellSlot = Option.None<int>();
_spellSlotDataRepository.SpellIsPrepared = false;
}

public void StartOtherCharacterWalkAnimation(int characterID, byte destinationX, byte destinationY, EODirection direction)
Expand Down
35 changes: 21 additions & 14 deletions EndlessClient/Rendering/Character/CharacterRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using EndlessClient.Controllers;
using EndlessClient.GameExecution;
using EndlessClient.HUD.Spells;
using EndlessClient.Input;
using EndlessClient.Rendering.CharacterProperties;
using EndlessClient.Rendering.Chat;
Expand Down Expand Up @@ -180,11 +181,19 @@ public override void Update(GameTime gameTime)
{
UpdateNameLabel(gameTime);

if (DrawArea.Contains(_userInputProvider.CurrentMouseState.Position) &&
_userInputProvider.CurrentMouseState.RightButton == ButtonState.Released &&
_userInputProvider.PreviousMouseState.RightButton == ButtonState.Pressed)
if (DrawArea.Contains(_userInputProvider.CurrentMouseState.Position))
{
_mapInteractionController.RightClick(new MapCellState { Character = Option.Some(Character) });
if (_userInputProvider.CurrentMouseState.RightButton == ButtonState.Released &&
_userInputProvider.PreviousMouseState.RightButton == ButtonState.Pressed)
{
_mapInteractionController.RightClick(Character);
}
else if (_userInputProvider.CurrentMouseState.LeftButton == ButtonState.Released &&
_userInputProvider.PreviousMouseState.LeftButton == ButtonState.Pressed &&
!_userInputProvider.ClickHandled)
{
_mapInteractionController.LeftClick(Character);
}
}

_healthBarRenderer.Update(gameTime);
Expand All @@ -198,17 +207,15 @@ public override void Draw(GameTime gameTime)
if (!Visible || _sb.IsDisposed)
return;

//todo: check if this is the renderer for the main player
// if hidden, draw if: they are not active character and active character is admin

_sb.Begin();
DrawToSpriteBatch(_sb);

if (_sb.IsDisposed)
return;
_sb.End();
if (!Character.RenderProperties.IsHidden || _characterProvider.MainCharacter.AdminLevel > 0)
{
_sb.Begin();
DrawToSpriteBatch(_sb);

//todo: draw effect over character
if (_sb.IsDisposed)
return;
_sb.End();
}

base.Draw(gameTime);
}
Expand Down
Loading

0 comments on commit 47faba6

Please sign in to comment.