Create TurnIntentions

This commit is contained in:
henriquenakashima 2020-09-30 23:56:59 -04:00
parent 838c30af99
commit 94b3309bb7
9 changed files with 181 additions and 32 deletions

View file

@ -3,6 +3,13 @@ using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public enum PlayabilityState {
None,
PlayableImmediately,
PlayableInOwnTurn,
Unplayable,
}
public class HandPlayability<BaseCardT> where BaseCardT : BaseCard {
public delegate void HandPlayabilityChangedAction();
public event HandPlayabilityChangedAction OnPlayabilityChanged;
@ -10,7 +17,8 @@ public class HandPlayability<BaseCardT> where BaseCardT : BaseCard {
private EnergyPool energyPool;
private TeamChoice team;
private BattleDeck<BaseCardT> deck;
private Dictionary<BaseCardT, bool> playable = new Dictionary<BaseCardT, bool>();
private Dictionary<BaseCardT, PlayabilityState> playable =
new Dictionary<BaseCardT, PlayabilityState>();
public HandPlayability(BattleState battleState, EnergyPool energyPool, TeamChoice team,
BattleDeck<BaseCardT> deck) {
@ -25,11 +33,15 @@ public class HandPlayability<BaseCardT> where BaseCardT : BaseCard {
UpdatePlayability();
}
public bool IsPlayable(BaseCardT card) {
bool value;
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 false;
return PlayabilityState.None;
}
return value;
}
@ -47,19 +59,23 @@ public class HandPlayability<BaseCardT> where BaseCardT : BaseCard {
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);
if (!card.Owner.CanUseCard(card)) {
this.playable[card] = PlayabilityState.Unplayable;
continue;
}
canPlay = canPlay
&& this.battleState.IsTeamsTurn(this.team)
&& card.Owner.CanUseCard(card);
this.playable[card] = canPlay;
bool canPlayNow = this.battleState.IsTeamsTurn(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;
} else {
this.playable[card] = PlayabilityState.PlayableInOwnTurn;
}
}
TriggerOnPlayabilityChanged();
}
}