Skip to content

Commit

Permalink
Spell attack should no longer be usable if Card has no spell
Browse files Browse the repository at this point in the history
  • Loading branch information
Arcidev committed Aug 26, 2024
1 parent de94574 commit 55b5c32
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Client.UI/ViewModels/MainGame/PlayingGameViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Client.UI.Enums;
using System;
using System.Linq;
using System.Windows;

namespace Client.UI.ViewModels.MainGame
{
Expand Down Expand Up @@ -31,7 +32,7 @@ public PlayingGameViewModel()
Opponent = new (Game.Opponent);

AttackCmd = new (() => InvokeCardAction(CardAction.BasicAttack));
SpellAttackCmd = new (() => InvokeCardAction(CardAction.SpellUse));
SpellAttackCmd = new (() => InvokeCardAction(CardAction.SpellUse), () => Game.Player.ActiveCard?.Spell != null);
DefendCmd = new (Game.DefendSelfAsync);

Game.PacketProcessed += OnPacketProcessed;
Expand All @@ -47,13 +48,18 @@ private void OnPacketProcessed(UInt16 packet)

foreach (var card in Opponent.Cards)
card.SelectionType = SelectionType.None;

Application.Current.Dispatcher.Invoke(SpellAttackCmd.NotifyCanExecuteChanged);
}

private void InvokeCardAction(CardAction action)
{
if (action == CardAction.SpellUse)
{
var targets = Game.Player.ActiveCard.Spell?.GetPossibleTargets(Game.Player, Game.Opponent);
if (targets == null)
return;

foreach (var playerCards in Player.Cards.Where(x => targets.Contains(x.Guid)).Concat(Opponent.Cards.Where(x => targets.Contains(x.Guid))))
{
playerCards.SelectionType = SelectionType.SpellUsable;
Expand Down

0 comments on commit 55b5c32

Please sign in to comment.