58 lines
1.8 KiB
C#
58 lines
1.8 KiB
C#
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();
|
|
|
|
}
|
|
}
|