From 86715b790dba07c5a397091f3e68293e16f18288 Mon Sep 17 00:00:00 2001 From: henriquenakashima Date: Tue, 13 Oct 2020 23:19:09 -0400 Subject: [PATCH] Move ParticipantActivity to BattleState --- Assets/Battle/BattleController.cs | 9 +++------ Assets/Battle/BattleState.cs | 3 +++ Assets/Battle/ParticipantActivity.cs | 13 ++++++++----- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Assets/Battle/BattleController.cs b/Assets/Battle/BattleController.cs index 1b652ee..dc325d4 100644 --- a/Assets/Battle/BattleController.cs +++ b/Assets/Battle/BattleController.cs @@ -20,7 +20,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe private HandPlayability heroHandPlayability; private HandPlayability monsterHandPlayability; private TurnIntentions monsterIntentions; - private ParticipantActivity participantActivity; private delegate void BattleStateChangedAction(); private event BattleStateChangedAction OnBattleStateChanged; @@ -39,8 +38,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe this.battleSprites.Init(this.state.Heroes, this.state.Monsters, this.state); - this.participantActivity = new ParticipantActivity(); - this.heroHandPlayability = new HandPlayability( this.state, this.state.HeroEnergy, TeamChoice.Heroes, this.state.HeroDeck); this.OnBattleStateChanged += this.heroHandPlayability.NotifyBattleStateChanged; @@ -116,7 +113,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe yield return RunMonsterTurn(); this.state.Clock.AdvanceToStep(RoundStep.EndOfRound); - this.participantActivity.NextRound(); } private IEnumerator RunHeroTurn() { @@ -153,7 +149,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe } // End of hero turn - yield return this.state.PlayArea.UseHeroDefaults(this.state.Heroes, this.participantActivity, UseHeroDefault); + yield return this.state.PlayArea.UseHeroDefaults(this.state.Heroes, this.state.ParticipantActivity, UseHeroDefault); // TODO: Implement a stack/queue to resolve triggers in order. // Do this after the card resolution is over to avoid reentraint effects. this.state.TriggerManager.RunActivatedTriggers(this); @@ -253,7 +249,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe this.state.HeroEnergy.PayForCard(card); this.state.HeroDeck.RemoveCardFromHand(card); - this.participantActivity.NotifyParticipantUsedCard(card.Owner, card); + this.state.ParticipantActivity.NotifyParticipantUsedCard(card.Owner, card); yield return card.Use(this, this.state, this.battlePlayerControls); if (card.Type == CardType.Default) { // Already added to playArea by effect @@ -283,6 +279,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe public IEnumerator UseMonsterCard(MonsterCard card) { this.state.MonsterEnergy.PayForCard(card); this.state.MonsterDeck.RemoveCardFromHand(card); + this.state.ParticipantActivity.NotifyParticipantUsedCard(card.Owner, card); yield return card.Use(this, this.state); if (card.IsPermanent()) { this.state.PlayArea.AddPlayedMonsterPermanent(card); diff --git a/Assets/Battle/BattleState.cs b/Assets/Battle/BattleState.cs index c164fcd..bb79c6e 100644 --- a/Assets/Battle/BattleState.cs +++ b/Assets/Battle/BattleState.cs @@ -22,6 +22,7 @@ public class BattleState: MonsterViewpoint private BattleDeck monsterDeck; private PlayArea playArea; private InsightLevel insightLevel; + private ParticipantActivity participantActivity; private bool playedEmotion; @@ -35,6 +36,7 @@ public class BattleState: MonsterViewpoint this.monsterEnergy = new EnergyPool(); this.playArea = new PlayArea(); this.insightLevel = new InsightLevel(STARTING_INSIGHT); + this.participantActivity = new ParticipantActivity(this.clock); InitHeroesAndMonsters(parameters); } @@ -139,4 +141,5 @@ public class BattleState: MonsterViewpoint public BattleDeck MonsterDeck {get => this.monsterDeck;} public PlayArea PlayArea {get => this.playArea;} public InsightLevel InsightLevel {get => this.insightLevel;} + public ParticipantActivity ParticipantActivity {get => this.participantActivity;} } diff --git a/Assets/Battle/ParticipantActivity.cs b/Assets/Battle/ParticipantActivity.cs index 54560d2..5342c3e 100644 --- a/Assets/Battle/ParticipantActivity.cs +++ b/Assets/Battle/ParticipantActivity.cs @@ -5,7 +5,14 @@ public class ParticipantActivity { private Dictionary> mCardsUsedThisRound = new Dictionary>(); - public ParticipantActivity() { + public ParticipantActivity(BattleClock clock) { + clock.OnTimeChanged += this.NotifyTimeChanged; + } + + private void NotifyTimeChanged(BattleTime now) { + if (now.RoundStep == RoundStep.StartOfRound) { + mCardsUsedThisRound.Clear(); + } } public void NotifyParticipantUsedCard(BattleParticipant participant, BaseCard card) { @@ -23,8 +30,4 @@ public class ParticipantActivity { return 0; } } - - public void NextRound() { - mCardsUsedThisRound.Clear(); - } } \ No newline at end of file