From 5962ea9fd656bf70aeb90811aafe50232d44891c Mon Sep 17 00:00:00 2001 From: henriquenakashima Date: Tue, 13 Oct 2020 00:25:55 -0400 Subject: [PATCH] Finish merging BattleClock and BattleState --- Assets/Battle/BattleController.cs | 10 +++++----- Assets/Battle/BattleState.cs | 29 +++++++++++------------------ Assets/Battle/HandPlayability.cs | 2 +- TODO.txt | 1 - 4 files changed, 17 insertions(+), 25 deletions(-) diff --git a/Assets/Battle/BattleController.cs b/Assets/Battle/BattleController.cs index 2083a6f..3204fe6 100644 --- a/Assets/Battle/BattleController.cs +++ b/Assets/Battle/BattleController.cs @@ -154,7 +154,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe private IEnumerator RunBattleRound() { this.state.Clock.AdvanceRound(); - this.state.AdvanceToTeamTurn(TeamChoice.Heroes); this.damageTriggers.RemoveAll(t => t.Expiration == TriggerExpiration.StartOfNextHeroTurn); @@ -162,7 +161,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe monsterEnergy.Replenish(); if (STABLE_HAND_STYLE) { - if (this.state.Round > 1) { + if (this.state.Clock.Now.RoundNumber > 1) { this.heroDeck.DrawCards(3); this.monsterDeck.DrawCards(3); } @@ -173,7 +172,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe yield return RunHeroTurn(); - this.state.AdvanceToTeamTurn(TeamChoice.Monsters); yield return RunMonsterTurn(); this.state.Clock.AdvanceToStep(RoundStep.EndOfRound); @@ -183,6 +181,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe private IEnumerator RunHeroTurn() { // Start of hero turn this.state.Clock.AdvanceToStep(RoundStep.StartOfHeroTurn); + this.state.ClearEmotionPlayed(); OnBattleStateChanged(); this.monsterIntentions.ResumeIntentions(); @@ -224,15 +223,16 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe } private IEnumerator RunMonsterTurn() { - this.state.Clock.AdvanceToStep(RoundStep.StartOfMonsterTurn); - OnBattleStateChanged(); yield return new WaitForSeconds(0.5f); // Start of monster turn + this.state.Clock.AdvanceToStep(RoundStep.StartOfMonsterTurn); + this.state.ClearEmotionPlayed(); foreach (BattleMonster monster in this.monsters) { monster.ResetBlock(); } OnBattleStateChanged(); + yield return new WaitForSeconds(0.5f); // Monsters play an emotion List monsterHand = this.monsterDeck.GetHandPile(); diff --git a/Assets/Battle/BattleState.cs b/Assets/Battle/BattleState.cs index c3fe506..6422e0e 100644 --- a/Assets/Battle/BattleState.cs +++ b/Assets/Battle/BattleState.cs @@ -5,9 +5,7 @@ using UnityEngine; public class BattleState { - private TeamChoice mTeamsTurn = TeamChoice.Monsters; - private bool mPlayedEmotion; - private int mRound = 0; + private bool playedEmotion; private BattleClock clock; private BuffManager buffManager; @@ -16,12 +14,16 @@ public class BattleState this.buffManager = new BuffManager(this.clock); } - public bool IsTeamsTurn(TeamChoice team) { - return team == mTeamsTurn; + public bool IsTeamsTurnToPlay(TeamChoice team) { + if (team == TeamChoice.Heroes) { + return this.clock.Now.RoundStep == RoundStep.StartOfHeroTurn; + } else { + return this.clock.Now.RoundStep == RoundStep.StartOfMonsterTurn; + } } public bool CanPlayEmotion(TeamChoice team) { - return !mPlayedEmotion && IsTeamsTurn(team); + return !playedEmotion && IsTeamsTurnToPlay(team); } public void NotifyPlayedEmotion(TeamChoice team) { @@ -30,20 +32,11 @@ public class BattleState + "cannot play emotion"); } - mPlayedEmotion = true; + playedEmotion = true; } - public int Round {get => mRound;} - - public void AdvanceToTeamTurn(TeamChoice team) { - if (team == mTeamsTurn) { - throw new System.InvalidOperationException("Already in turn of team " + team); - } - mTeamsTurn = team; - mPlayedEmotion = false; - if (team == TeamChoice.Heroes) { - mRound++; - } + public void ClearEmotionPlayed() { + this.playedEmotion = false; } public BattleClock Clock {get => this.clock;} diff --git a/Assets/Battle/HandPlayability.cs b/Assets/Battle/HandPlayability.cs index 58e781d..1b416f3 100644 --- a/Assets/Battle/HandPlayability.cs +++ b/Assets/Battle/HandPlayability.cs @@ -65,7 +65,7 @@ public class HandPlayability where BaseCardT : BaseCard { continue; } - bool canPlayNow = this.battleState.IsTeamsTurn(this.team); + bool canPlayNow = this.battleState.IsTeamsTurnToPlay(this.team); if (card.Type == CardType.Emotion) { canPlayNow = canPlayNow && this.battleState.CanPlayEmotion(this.team); } else { diff --git a/TODO.txt b/TODO.txt index 3798e2d..5d95afb 100644 --- a/TODO.txt +++ b/TODO.txt @@ -11,7 +11,6 @@ Battle - Make Enchantments be dropped as an effect like Defaults - No need to start coroutine for targeting - Indicate which Default is triggering -- Merge BattleClock with BattleState Story - Make dialogue show letter by letter.