diff --git a/Assets/Battle/BattleController.cs b/Assets/Battle/BattleController.cs index 43f0f54..03a77c0 100644 --- a/Assets/Battle/BattleController.cs +++ b/Assets/Battle/BattleController.cs @@ -30,7 +30,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe private Dictionary 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); } diff --git a/Assets/Battle/BattlePlayerControls.cs b/Assets/Battle/BattlePlayerControls.cs index 2adffeb..9d8d35e 100644 --- a/Assets/Battle/BattlePlayerControls.cs +++ b/Assets/Battle/BattlePlayerControls.cs @@ -12,11 +12,6 @@ public class BattlePlayerControls : MonoBehaviour public GameObject uiCanvas; public GameObject cardPrefab; - public delegate void CardUsedAction(HeroCard card); - public event CardUsedAction OnCardUsed; - public delegate void TurnPassedAction(); - public event TurnPassedAction OnTurnPassed; - private BattleDeck heroDeck; private BattleDeck monsterDeck; private PlayArea playArea; @@ -26,6 +21,7 @@ public class BattlePlayerControls : MonoBehaviour private HandControls heroHandControls; private HandControls monsterHandControls; private Dictionary cardsInPlayUIs; + public PlayerAction playerAction; public void Init( BattleDeck heroDeck, BattleDeck monsterDeck, PlayArea playArea, @@ -65,7 +61,7 @@ public class BattlePlayerControls : MonoBehaviour private void OnHeroCardClicked(HeroCard card) { if (this.singleTargeting == null) { if (this.battleController.CanUseHeroCard(card)) { - OnCardUsed(card); + this.playerAction = new PlayerAction(card); } } } @@ -89,7 +85,7 @@ public class BattlePlayerControls : MonoBehaviour public void PassTurnButtonClicked() { if (this.singleTargeting == null) { - OnTurnPassed(); + this.playerAction = new PlayerAction(null); } } @@ -150,4 +146,10 @@ public class BattlePlayerControls : MonoBehaviour public void NotifyInsightLevelChanged() { this.monsterHandControls.InsightLevel = this.insightLevel.Level; } + + public PlayerAction RetrievePlayerAction() { + PlayerAction result = this.playerAction; + this.playerAction = null; + return result; + } } diff --git a/Assets/Battle/PlayerAction.cs b/Assets/Battle/PlayerAction.cs new file mode 100644 index 0000000..c11156c --- /dev/null +++ b/Assets/Battle/PlayerAction.cs @@ -0,0 +1,25 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class PlayerAction +{ + private bool turnPassed; + private HeroCard cardUsed; + + public PlayerAction(HeroCard cardUsed) { + if (cardUsed != null) { + this.cardUsed = cardUsed; + } else { + this.turnPassed = true; + } + } + + public bool IsTurnPassed() { + return this.turnPassed; + } + + public HeroCard GetCardUsed() { + return this.cardUsed; + } +} diff --git a/Assets/Battle/PlayerAction.cs.meta b/Assets/Battle/PlayerAction.cs.meta new file mode 100644 index 0000000..f8ff204 --- /dev/null +++ b/Assets/Battle/PlayerAction.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 1dd3bc250a935b84da415b58385a6010 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/TODO.txt b/TODO.txt index d41e41e..b769aed 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,7 +1,8 @@ - Animate rearrange hand after card is used -- Make hero cards be used in sequence Coroutines, not in parallel - Do not Highlight unusable cards - Show which cards enemies will use - Show on who enemies will use the cards - Extend BattleState to be more than hero turn true/false -- Create BattleParameters \ No newline at end of file +- Create BattleParameters +- Highlight which card is targeting +- Allow cancelling targeting \ No newline at end of file