Create PlayerAction and use hero cards in parallel

This commit is contained in:
henriquenakashima 2020-09-26 18:52:30 -04:00
parent d48780d629
commit a2ced7a003
5 changed files with 61 additions and 25 deletions

View file

@ -30,7 +30,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
private Dictionary<BattleMonster, HeroInfoUI> monsterUIs;
private BattleState state;
private bool heroPassedTurn;
private EnergyPool heroEnergy;
private EnergyPool monsterEnergy;
private InsightLevel insightLevel;
@ -207,8 +206,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
this.battlePlayerControls.Init(
this.heroDeck, this.monsterDeck, this.playArea, this.insightLevel,
this.heroHandPlayability, this.uiCanvas.transform.localScale.x);
this.battlePlayerControls.OnCardUsed += this.NotifyHeroCardUsed;
this.battlePlayerControls.OnTurnPassed += this.NotifyHeroTurnPassed;
this.insightLevel.OnChanged += this.battlePlayerControls.NotifyInsightLevelChanged;
}
@ -272,10 +269,19 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
OnBattleStateChanged();
// Heroes act until they pass
while (!this.heroPassedTurn) {
yield return null;
while (true) {
PlayerAction playerAction = this.battlePlayerControls.RetrievePlayerAction();
if (playerAction != null) {
if (playerAction.IsTurnPassed()) {
break;
} else {
HeroCard card = playerAction.GetCardUsed();
yield return UseHeroCard(card);
}
} else {
yield return null;
}
}
this.heroPassedTurn = false;
// End of hero turn
this.heroDeck.DiscardHand();
@ -317,14 +323,11 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
OnBattleStateChanged();
}
public void NotifyHeroCardUsed(HeroCard card) {
public IEnumerator UseHeroCard(HeroCard card) {
if (!CanUseHeroCard(card)) {
throw new System.InvalidOperationException("Cannot use card " + card.GetDisplayName());
}
StartCoroutine(UseHeroCard(card));
}
public IEnumerator UseHeroCard(HeroCard card) {
this.heroEnergy.PayForCard(card);
this.heroDeck.RemoveCardFromHand(card);
yield return card.Use(this, this, battlePlayerControls);
@ -356,12 +359,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
CheckState();
}
public void NotifyHeroTurnPassed() {
if (this.state.HeroTurn) {
this.heroPassedTurn = true;
}
}
public bool CanUseHeroCard(HeroCard card) {
return this.heroHandPlayability.IsPlayable(card);
}