diff --git a/Assets/Battle/BattleController.cs b/Assets/Battle/BattleController.cs index a4e1c11..20788da 100644 --- a/Assets/Battle/BattleController.cs +++ b/Assets/Battle/BattleController.cs @@ -19,8 +19,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe // Private private HeroCardDatabase heroCardDatabase; private MonsterCardDatabase monsterCardDatabase; - private BattleDeck heroDeck; - private BattleDeck monsterDeck; private PlayArea playArea; private BattleHero[] heroes; @@ -78,31 +76,31 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe for (int i = 0; i < parameters.HCardIds.Length; i++) { cardOwners[i] = this.heroes[parameters.HCardOwnerIndexes[i]]; } - this.heroDeck = new BattleDeck( + BattleDeck heroDeck = new BattleDeck( this.heroCardDatabase, parameters.HCardIds.Cast().ToArray(), cardOwners); BattleParticipant[] mCardOwners = new BattleParticipant[parameters.MCardIds.Length]; for (int i = 0; i < parameters.MCardIds.Length; i++) { mCardOwners[i] = this.monsters[parameters.MCardOwnerIndexes[i]]; } - this.monsterDeck = new BattleDeck( + BattleDeck monsterDeck = new BattleDeck( this.monsterCardDatabase, parameters.MCardIds.Cast().ToArray(), mCardOwners); - + this.state.SetDecks(heroDeck, monsterDeck); this.participantActivity = new ParticipantActivity(); this.playArea = new PlayArea(); this.heroHandPlayability = new HandPlayability( - this.state, this.state.HeroEnergy, TeamChoice.Heroes, this.heroDeck); + this.state, this.state.HeroEnergy, TeamChoice.Heroes, this.state.HeroDeck); this.OnBattleStateChanged += this.heroHandPlayability.NotifyBattleStateChanged; this.monsterHandPlayability = new HandPlayability( - this.state, this.state.MonsterEnergy, TeamChoice.Monsters, this.monsterDeck); + this.state, this.state.MonsterEnergy, TeamChoice.Monsters, this.state.MonsterDeck); this.OnBattleStateChanged += this.monsterHandPlayability.NotifyBattleStateChanged; this.monsterIntentions = new TurnIntentions( - this.monsterDeck, this.state.MonsterEnergy, this.monsterHandPlayability); + this.state.MonsterDeck, this.state.MonsterEnergy, this.monsterHandPlayability); this.battlePlayerControls.Init( - this.heroDeck, this.monsterDeck, this.playArea, this.insightLevel, + this.state.HeroDeck, this.state.MonsterDeck, this.playArea, this.insightLevel, this.heroHandPlayability, this.monsterHandPlayability, this.monsterIntentions, this.uiCanvas.transform.localScale.x); this.insightLevel.OnChanged += this.battlePlayerControls.NotifyInsightLevelChanged; @@ -137,8 +135,8 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe private IEnumerator RunBattleRounds() { if (STABLE_HAND_STYLE) { - this.heroDeck.DrawCards(6); - this.monsterDeck.DrawCards(6); + this.state.HeroDeck.DrawCards(6); + this.state.MonsterDeck.DrawCards(6); } while (true) { @@ -156,12 +154,12 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe if (STABLE_HAND_STYLE) { if (this.state.Clock.Now.RoundNumber > 1) { - this.heroDeck.DrawCards(3); - this.monsterDeck.DrawCards(3); + this.state.HeroDeck.DrawCards(3); + this.state.MonsterDeck.DrawCards(3); } } else { - this.heroDeck.DrawCards(5); - this.monsterDeck.DrawCards(5); + this.state.HeroDeck.DrawCards(5); + this.state.MonsterDeck.DrawCards(5); } yield return RunHeroTurn(); @@ -202,9 +200,9 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe // End of hero turn yield return this.playArea.UseHeroDefaults(this.heroes, this.participantActivity, UseHeroDefault); if (STABLE_HAND_STYLE) { - this.heroDeck.DiscardInExcessOf(3); + this.state.HeroDeck.DiscardInExcessOf(3); } else { - this.heroDeck.DiscardHand(); + this.state.HeroDeck.DiscardHand(); } foreach (BattleHero hero in this.heroes) { hero.TickStatuses(); @@ -229,7 +227,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe yield return new WaitForSeconds(0.5f); // Monsters play an emotion - List monsterHand = this.monsterDeck.GetHandPile(); + List monsterHand = this.state.MonsterDeck.GetHandPile(); for (int i = 0; i < monsterHand.Count; i++) { MonsterCard monsterCard = monsterHand[i]; if (monsterCard.Type == CardType.Emotion && CanUseMonsterCard(monsterCard)) { @@ -252,9 +250,9 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe // End of monster turn if (STABLE_HAND_STYLE) { - this.monsterDeck.DiscardInExcessOf(3); + this.state.MonsterDeck.DiscardInExcessOf(3); } else { - this.monsterDeck.DiscardHand(); + this.state.MonsterDeck.DiscardHand(); } foreach (BattleMonster monster in this.monsters) { monster.TickStatuses(); @@ -265,7 +263,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe } private MonsterCard FirstMonsterActionToPlay() { - List monsterHand = monsterHand = this.monsterDeck.GetHandPile(); + List monsterHand = monsterHand = this.state.MonsterDeck.GetHandPile(); for (int i = 0; i < monsterHand.Count; i++) { MonsterCard monsterCard = monsterHand[i]; @@ -282,7 +280,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe } this.state.HeroEnergy.PayForCard(card); - this.heroDeck.RemoveCardFromHand(card); + this.state.HeroDeck.RemoveCardFromHand(card); this.participantActivity.NotifyParticipantUsedCard(card.Owner, card); yield return card.Use(this, this, battlePlayerControls); if (card.Type == CardType.Default) { @@ -290,9 +288,9 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe } else if (card.IsPermanent()) { this.playArea.AddPlayedHeroPermanent(card); } else if (card.IsEphemeral()) { - this.heroDeck.MoveCardToOblivion(card); + this.state.HeroDeck.MoveCardToOblivion(card); } else { - this.heroDeck.MoveCardToDiscard(card); + this.state.HeroDeck.MoveCardToDiscard(card); } CheckState(); @@ -312,14 +310,14 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe public IEnumerator UseMonsterCard(MonsterCard card) { this.state.MonsterEnergy.PayForCard(card); - this.monsterDeck.RemoveCardFromHand(card); + this.state.MonsterDeck.RemoveCardFromHand(card); yield return card.Use(this, this); if (card.IsPermanent()) { this.playArea.AddPlayedMonsterPermanent(card); } else if (card.IsEphemeral()) { - this.monsterDeck.MoveCardToOblivion(card); + this.state.MonsterDeck.MoveCardToOblivion(card); } else { - this.monsterDeck.MoveCardToDiscard(card); + this.state.MonsterDeck.MoveCardToDiscard(card); } yield return new WaitForSeconds(0.5f); @@ -335,14 +333,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe return this.monsterHandPlayability.IsPlayableImmediately(card); } - public BattleDeck GetHeroDeck() { - return this.heroDeck; - } - - public PlayArea GetPlayArea() { - return this.playArea; - } - private void EnqueueActivatedTrigger(Trigger trigger) { this.activatedTriggers.Add(trigger); } @@ -378,6 +368,8 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe : this.monsters.Cast().ToArray()); } + public BattleState State {get => this.state;} + // IBattleEffectApplier public void Apply(IBattleEffect effect) { effect.Apply(this); @@ -414,11 +406,11 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe public void DrawCards(DrawCardsEffect effect) { if (effect.Team == TeamChoice.Heroes) { for (int i = 0; i < effect.Amount; i++) { - this.heroDeck.DrawCard(); + this.state.HeroDeck.DrawCard(); } } else { for (int i = 0; i < effect.Amount; i++) { - this.monsterDeck.DrawCard(); + this.state.MonsterDeck.DrawCard(); } } } @@ -427,9 +419,9 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe if (effect.Participant == null) return; if (effect.Participant.Team == TeamChoice.Heroes) { - this.AcquireCardsTyped(effect, this.heroDeck, this.heroCardDatabase); + this.AcquireCardsTyped(effect, this.state.HeroDeck, this.heroCardDatabase); } else { - this.AcquireCardsTyped(effect, this.monsterDeck, this.monsterCardDatabase); + this.AcquireCardsTyped(effect, this.state.MonsterDeck, this.monsterCardDatabase); } } @@ -584,7 +576,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe public void SetupDefault(DefaultEffect effect) { DefaultHeroCard previousDefault = this.playArea.SetupDefault(effect); if (previousDefault != null) { - this.heroDeck.MoveCardToDiscard(previousDefault); + this.state.HeroDeck.MoveCardToDiscard(previousDefault); } } diff --git a/Assets/Battle/BattleState.cs b/Assets/Battle/BattleState.cs index 29d738c..d0b4456 100644 --- a/Assets/Battle/BattleState.cs +++ b/Assets/Battle/BattleState.cs @@ -10,6 +10,8 @@ public class BattleState private BuffManager buffManager; private EnergyPool heroEnergy; private EnergyPool monsterEnergy; + private BattleDeck heroDeck; + private BattleDeck monsterDeck; public BattleState() { this.clock = new BattleClock(); @@ -18,6 +20,11 @@ public class BattleState this.monsterEnergy = new EnergyPool(); } + public void SetDecks(BattleDeck heroDeck, BattleDeck monsterDeck) { + this.heroDeck = heroDeck; + this.monsterDeck = monsterDeck; + } + public bool IsTeamsTurnToPlay(TeamChoice team) { if (team == TeamChoice.Heroes) { return this.clock.Now.RoundStep == RoundStep.StartOfHeroTurn; @@ -48,4 +55,6 @@ public class BattleState public EnergyPool HeroEnergy {get => this.heroEnergy;} public EnergyPool MonsterEnergy {get => this.monsterEnergy;} + public BattleDeck HeroDeck {get => this.heroDeck;} + public BattleDeck MonsterDeck {get => this.monsterDeck;} } diff --git a/Assets/Battle/UI/DiscardPileUI.cs b/Assets/Battle/UI/DiscardPileUI.cs index f8af11d..67213ae 100644 --- a/Assets/Battle/UI/DiscardPileUI.cs +++ b/Assets/Battle/UI/DiscardPileUI.cs @@ -9,11 +9,11 @@ public class DiscardPileUI : MonoBehaviour public BattleController battleController; void Start() { - this.battleController.GetHeroDeck().OnDiscardPileChanged += NotifyDiscardPileChanged; + this.battleController.State.HeroDeck.OnDiscardPileChanged += NotifyDiscardPileChanged; NotifyDiscardPileChanged(); } public void NotifyDiscardPileChanged() { - text.text = "Discard pile: " + this.battleController.GetHeroDeck().GetDiscardPile().Count; + text.text = "Discard pile: " + this.battleController.State.HeroDeck.GetDiscardPile().Count; } } diff --git a/Assets/Battle/UI/DrawPileUI.cs b/Assets/Battle/UI/DrawPileUI.cs index 6e2a62d..a4531d6 100644 --- a/Assets/Battle/UI/DrawPileUI.cs +++ b/Assets/Battle/UI/DrawPileUI.cs @@ -9,11 +9,11 @@ public class DrawPileUI : MonoBehaviour public BattleController battleController; void Start() { - this.battleController.GetHeroDeck().OnDrawPileChanged += NotifyDrawPileChanged; + this.battleController.State.HeroDeck.OnDrawPileChanged += NotifyDrawPileChanged; NotifyDrawPileChanged(); } public void NotifyDrawPileChanged() { - text.text = "Draw pile: " + this.battleController.GetHeroDeck().GetDrawPile().Count; + text.text = "Draw pile: " + this.battleController.State.HeroDeck.GetDrawPile().Count; } }