using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; public class HandPlayability where BaseCardT : BaseCard { public delegate void HandPlayabilityChangedAction(); public event HandPlayabilityChangedAction OnPlayabilityChanged; private BattleState battleState; private EnergyPool energyPool; private TeamChoice team; private BattleDeck deck; private Dictionary playable = new Dictionary(); public HandPlayability(BattleState battleState, EnergyPool energyPool, TeamChoice team, BattleDeck deck) { this.battleState = battleState; this.energyPool = energyPool; this.team = team; this.deck = deck; deck.OnHandPileChanged += NotifyHeroHandPileChanged; } public void NotifyBattleStateChanged() { UpdatePlayability(); } public bool IsPlayable(BaseCardT card) { bool value; if (!this.playable.TryGetValue(card, out value)) { Debug.Log("Card " + card.GetDisplayName() + " not playable because not in hand!"); return false; } return value; } private void TriggerOnPlayabilityChanged() { if (this.OnPlayabilityChanged != null) { this.OnPlayabilityChanged(); } } private void NotifyHeroHandPileChanged() { UpdatePlayability(); } private void UpdatePlayability() { this.playable.Clear(); foreach (BaseCardT card in this.deck.GetHandPile()) { bool canPlay; if (card.Type == CardType.Emotion) { canPlay = this.battleState.CanPlayEmotion(this.team); } else { canPlay = this.energyPool.CanPayForCard(card); } canPlay = canPlay && this.battleState.IsTeamsTurn(this.team) && card.Owner.CanUseCard(card); this.playable[card] = canPlay; } TriggerOnPlayabilityChanged(); } }