using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; public enum PlayabilityState { None, PlayableImmediately, PlayableInOwnTurn, Unplayable, } 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 IsPlayableImmediately(BaseCardT card) { return GetCardPlayability(card) == PlayabilityState.PlayableImmediately; } public PlayabilityState GetCardPlayability(BaseCardT card) { PlayabilityState value; if (!this.playable.TryGetValue(card, out value)) { Debug.Log("Card " + card.GetDisplayName() + " not playable because not in hand!"); return PlayabilityState.None; } 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()) { if (!card.Owner.CanUseCard(card)) { this.playable[card] = PlayabilityState.Unplayable; // Debug.Log("Playability of " + card.GetDisplayName() + " = Unplayable"); continue; } bool canPlayNow = this.battleState.IsTeamsTurnToPlay(this.team); if (card.Type == CardType.Emotion) { canPlayNow = canPlayNow && this.battleState.CanPlayEmotion(this.team); } else { canPlayNow = canPlayNow && this.energyPool.CanPayForCard(card); } if (canPlayNow) { this.playable[card] = PlayabilityState.PlayableImmediately; // Debug.Log("Playability of " + card.GetDisplayName() + " = PlayableImmediately"); } else { this.playable[card] = PlayabilityState.PlayableInOwnTurn; // Debug.Log("Playability of " + card.GetDisplayName() + " = PlayableInOwnTurn"); } } TriggerOnPlayabilityChanged(); } }