diff --git a/Assets/Battle/BattleController.cs b/Assets/Battle/BattleController.cs index 3204fe6..a4e1c11 100644 --- a/Assets/Battle/BattleController.cs +++ b/Assets/Battle/BattleController.cs @@ -28,8 +28,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe private BattleMonster[] monsters; private BattleState state; - private EnergyPool heroEnergy; - private EnergyPool monsterEnergy; private InsightLevel insightLevel; private HandPlayability heroHandPlayability; private HandPlayability monsterHandPlayability; @@ -51,12 +49,8 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe this.state = new BattleState(); - this.heroEnergy = new EnergyPool(); - this.heroEnergyUI.Init(this.heroEnergy); - this.heroEnergy.OnEnergyChanged += this.heroEnergyUI.NotifyEnergyChanged; - this.monsterEnergy = new EnergyPool(); - this.monsterEnergyUI.Init(this.monsterEnergy); - this.monsterEnergy.OnEnergyChanged += this.monsterEnergyUI.NotifyEnergyChanged; + this.heroEnergyUI.Init(this.state.HeroEnergy); + this.monsterEnergyUI.Init(this.state.MonsterEnergy); this.insightLevel = new InsightLevel(STARTING_INSIGHT); @@ -98,14 +92,14 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe this.playArea = new PlayArea(); this.heroHandPlayability = new HandPlayability( - this.state, this.heroEnergy, TeamChoice.Heroes, this.heroDeck); + this.state, this.state.HeroEnergy, TeamChoice.Heroes, this.heroDeck); this.OnBattleStateChanged += this.heroHandPlayability.NotifyBattleStateChanged; this.monsterHandPlayability = new HandPlayability( - this.state, this.monsterEnergy, TeamChoice.Monsters, this.monsterDeck); + this.state, this.state.MonsterEnergy, TeamChoice.Monsters, this.monsterDeck); this.OnBattleStateChanged += this.monsterHandPlayability.NotifyBattleStateChanged; this.monsterIntentions = new TurnIntentions( - this.monsterDeck, this.monsterEnergy, this.monsterHandPlayability); + this.monsterDeck, this.state.MonsterEnergy, this.monsterHandPlayability); this.battlePlayerControls.Init( this.heroDeck, this.monsterDeck, this.playArea, this.insightLevel, @@ -157,8 +151,8 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe this.damageTriggers.RemoveAll(t => t.Expiration == TriggerExpiration.StartOfNextHeroTurn); - heroEnergy.Replenish(); - monsterEnergy.Replenish(); + this.state.HeroEnergy.Replenish(); + this.state.MonsterEnergy.Replenish(); if (STABLE_HAND_STYLE) { if (this.state.Clock.Now.RoundNumber > 1) { @@ -287,7 +281,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe throw new System.InvalidOperationException("Cannot use card " + card.GetDisplayName()); } - this.heroEnergy.PayForCard(card); + this.state.HeroEnergy.PayForCard(card); this.heroDeck.RemoveCardFromHand(card); this.participantActivity.NotifyParticipantUsedCard(card.Owner, card); yield return card.Use(this, this, battlePlayerControls); @@ -317,7 +311,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe } public IEnumerator UseMonsterCard(MonsterCard card) { - this.monsterEnergy.PayForCard(card); + this.state.MonsterEnergy.PayForCard(card); this.monsterDeck.RemoveCardFromHand(card); yield return card.Use(this, this); if (card.IsPermanent()) { @@ -384,9 +378,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe : this.monsters.Cast().ToArray()); } - public EnergyPool HeroEnergy {get => this.heroEnergy;} - public EnergyPool MonsterEnergy {get => this.monsterEnergy;} - // IBattleEffectApplier public void Apply(IBattleEffect effect) { effect.Apply(this); @@ -399,15 +390,15 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe } this.state.NotifyPlayedEmotion(effect.Team); - EnergyPool pool = (effect.Team == TeamChoice.Heroes ? this.heroEnergy : this.monsterEnergy); + EnergyPool pool = (effect.Team == TeamChoice.Heroes ? this.state.HeroEnergy : this.state.MonsterEnergy); pool.MaxEnergy += effect.Amount; pool.Energy += effect.Amount; } public void IncreaseHeroMaxEnergy(IncreaseMaxEnergyEffect effect) { - this.heroEnergy.MaxEnergy += effect.Amount; + this.state.HeroEnergy.MaxEnergy += effect.Amount; if (effect.Immediate) { - this.heroEnergy.Energy += effect.Amount; + this.state.HeroEnergy.Energy += effect.Amount; } } diff --git a/Assets/Battle/BattleState.cs b/Assets/Battle/BattleState.cs index 6422e0e..29d738c 100644 --- a/Assets/Battle/BattleState.cs +++ b/Assets/Battle/BattleState.cs @@ -8,10 +8,14 @@ public class BattleState private bool playedEmotion; private BattleClock clock; private BuffManager buffManager; + private EnergyPool heroEnergy; + private EnergyPool monsterEnergy; public BattleState() { this.clock = new BattleClock(); this.buffManager = new BuffManager(this.clock); + this.heroEnergy = new EnergyPool(); + this.monsterEnergy = new EnergyPool(); } public bool IsTeamsTurnToPlay(TeamChoice team) { @@ -41,4 +45,7 @@ public class BattleState public BattleClock Clock {get => this.clock;} public BuffManager BuffManager {get => this.buffManager;} + + public EnergyPool HeroEnergy {get => this.heroEnergy;} + public EnergyPool MonsterEnergy {get => this.monsterEnergy;} } diff --git a/Assets/Battle/UI/EnergyUI.cs b/Assets/Battle/UI/EnergyUI.cs index 967a6c7..e43d8b2 100644 --- a/Assets/Battle/UI/EnergyUI.cs +++ b/Assets/Battle/UI/EnergyUI.cs @@ -11,6 +11,7 @@ public class EnergyUI : MonoBehaviour public void Init(EnergyPool pool) { this.pool = pool; + pool.OnEnergyChanged += this.NotifyEnergyChanged; } // Start is called before the first frame update