Mark cards that are not playable

This commit is contained in:
henriquenakashima 2020-09-24 23:00:36 -04:00
parent aa78658949
commit 45b91ed352
9 changed files with 162 additions and 14 deletions

View file

@ -0,0 +1,58 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class HandPlayability<BaseCardT> where BaseCardT : BaseCard {
public delegate void HandPlayabilityChangedAction();
public event HandPlayabilityChangedAction OnPlayabilityChanged;
private BattleState battleState;
private EnergyPool energyPool;
private TeamChoice team;
private BattleDeck<BaseCardT> deck;
private Dictionary<BaseCardT, bool> playable = new Dictionary<BaseCardT, bool>();
public HandPlayability(BattleState battleState, EnergyPool energyPool, TeamChoice team,
BattleDeck<BaseCardT> 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()) {
this.playable[card] =
this.battleState.IsTeamsTurn(this.team)
&& card.Owner.CanUseCard(card)
&& this.energyPool.CanPayForCard(card);
}
TriggerOnPlayabilityChanged();
}
}