Move heroDeck and monsterDeck into BattleState

This commit is contained in:
henriquenakashima 2020-10-13 00:58:33 -04:00
parent f1ef7d7d46
commit 12eb97084f
4 changed files with 45 additions and 44 deletions

View file

@ -19,8 +19,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
// Private // Private
private HeroCardDatabase heroCardDatabase; private HeroCardDatabase heroCardDatabase;
private MonsterCardDatabase monsterCardDatabase; private MonsterCardDatabase monsterCardDatabase;
private BattleDeck<HeroCard> heroDeck;
private BattleDeck<MonsterCard> monsterDeck;
private PlayArea playArea; private PlayArea playArea;
private BattleHero[] heroes; private BattleHero[] heroes;
@ -78,31 +76,31 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
for (int i = 0; i < parameters.HCardIds.Length; i++) { for (int i = 0; i < parameters.HCardIds.Length; i++) {
cardOwners[i] = this.heroes[parameters.HCardOwnerIndexes[i]]; cardOwners[i] = this.heroes[parameters.HCardOwnerIndexes[i]];
} }
this.heroDeck = new BattleDeck<HeroCard>( BattleDeck<HeroCard> heroDeck = new BattleDeck<HeroCard>(
this.heroCardDatabase, parameters.HCardIds.Cast<int>().ToArray(), cardOwners); this.heroCardDatabase, parameters.HCardIds.Cast<int>().ToArray(), cardOwners);
BattleParticipant[] mCardOwners = new BattleParticipant[parameters.MCardIds.Length]; BattleParticipant[] mCardOwners = new BattleParticipant[parameters.MCardIds.Length];
for (int i = 0; i < parameters.MCardIds.Length; i++) { for (int i = 0; i < parameters.MCardIds.Length; i++) {
mCardOwners[i] = this.monsters[parameters.MCardOwnerIndexes[i]]; mCardOwners[i] = this.monsters[parameters.MCardOwnerIndexes[i]];
} }
this.monsterDeck = new BattleDeck<MonsterCard>( BattleDeck<MonsterCard> monsterDeck = new BattleDeck<MonsterCard>(
this.monsterCardDatabase, parameters.MCardIds.Cast<int>().ToArray(), mCardOwners); this.monsterCardDatabase, parameters.MCardIds.Cast<int>().ToArray(), mCardOwners);
this.state.SetDecks(heroDeck, monsterDeck);
this.participantActivity = new ParticipantActivity(); this.participantActivity = new ParticipantActivity();
this.playArea = new PlayArea(); this.playArea = new PlayArea();
this.heroHandPlayability = new HandPlayability<HeroCard>( this.heroHandPlayability = new HandPlayability<HeroCard>(
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.OnBattleStateChanged += this.heroHandPlayability.NotifyBattleStateChanged;
this.monsterHandPlayability = new HandPlayability<MonsterCard>( this.monsterHandPlayability = new HandPlayability<MonsterCard>(
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.OnBattleStateChanged += this.monsterHandPlayability.NotifyBattleStateChanged;
this.monsterIntentions = new TurnIntentions<MonsterCard>( this.monsterIntentions = new TurnIntentions<MonsterCard>(
this.monsterDeck, this.state.MonsterEnergy, this.monsterHandPlayability); this.state.MonsterDeck, this.state.MonsterEnergy, this.monsterHandPlayability);
this.battlePlayerControls.Init( 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.heroHandPlayability, this.monsterHandPlayability, this.monsterIntentions,
this.uiCanvas.transform.localScale.x); this.uiCanvas.transform.localScale.x);
this.insightLevel.OnChanged += this.battlePlayerControls.NotifyInsightLevelChanged; this.insightLevel.OnChanged += this.battlePlayerControls.NotifyInsightLevelChanged;
@ -137,8 +135,8 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
private IEnumerator RunBattleRounds() { private IEnumerator RunBattleRounds() {
if (STABLE_HAND_STYLE) { if (STABLE_HAND_STYLE) {
this.heroDeck.DrawCards(6); this.state.HeroDeck.DrawCards(6);
this.monsterDeck.DrawCards(6); this.state.MonsterDeck.DrawCards(6);
} }
while (true) { while (true) {
@ -156,12 +154,12 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
if (STABLE_HAND_STYLE) { if (STABLE_HAND_STYLE) {
if (this.state.Clock.Now.RoundNumber > 1) { if (this.state.Clock.Now.RoundNumber > 1) {
this.heroDeck.DrawCards(3); this.state.HeroDeck.DrawCards(3);
this.monsterDeck.DrawCards(3); this.state.MonsterDeck.DrawCards(3);
} }
} else { } else {
this.heroDeck.DrawCards(5); this.state.HeroDeck.DrawCards(5);
this.monsterDeck.DrawCards(5); this.state.MonsterDeck.DrawCards(5);
} }
yield return RunHeroTurn(); yield return RunHeroTurn();
@ -202,9 +200,9 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
// End of hero turn // End of hero turn
yield return this.playArea.UseHeroDefaults(this.heroes, this.participantActivity, UseHeroDefault); yield return this.playArea.UseHeroDefaults(this.heroes, this.participantActivity, UseHeroDefault);
if (STABLE_HAND_STYLE) { if (STABLE_HAND_STYLE) {
this.heroDeck.DiscardInExcessOf(3); this.state.HeroDeck.DiscardInExcessOf(3);
} else { } else {
this.heroDeck.DiscardHand(); this.state.HeroDeck.DiscardHand();
} }
foreach (BattleHero hero in this.heroes) { foreach (BattleHero hero in this.heroes) {
hero.TickStatuses(); hero.TickStatuses();
@ -229,7 +227,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
yield return new WaitForSeconds(0.5f); yield return new WaitForSeconds(0.5f);
// Monsters play an emotion // Monsters play an emotion
List<MonsterCard> monsterHand = this.monsterDeck.GetHandPile(); List<MonsterCard> monsterHand = this.state.MonsterDeck.GetHandPile();
for (int i = 0; i < monsterHand.Count; i++) { for (int i = 0; i < monsterHand.Count; i++) {
MonsterCard monsterCard = monsterHand[i]; MonsterCard monsterCard = monsterHand[i];
if (monsterCard.Type == CardType.Emotion && CanUseMonsterCard(monsterCard)) { if (monsterCard.Type == CardType.Emotion && CanUseMonsterCard(monsterCard)) {
@ -252,9 +250,9 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
// End of monster turn // End of monster turn
if (STABLE_HAND_STYLE) { if (STABLE_HAND_STYLE) {
this.monsterDeck.DiscardInExcessOf(3); this.state.MonsterDeck.DiscardInExcessOf(3);
} else { } else {
this.monsterDeck.DiscardHand(); this.state.MonsterDeck.DiscardHand();
} }
foreach (BattleMonster monster in this.monsters) { foreach (BattleMonster monster in this.monsters) {
monster.TickStatuses(); monster.TickStatuses();
@ -265,7 +263,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
} }
private MonsterCard FirstMonsterActionToPlay() { private MonsterCard FirstMonsterActionToPlay() {
List<MonsterCard> monsterHand = monsterHand = this.monsterDeck.GetHandPile(); List<MonsterCard> monsterHand = monsterHand = this.state.MonsterDeck.GetHandPile();
for (int i = 0; i < monsterHand.Count; i++) { for (int i = 0; i < monsterHand.Count; i++) {
MonsterCard monsterCard = monsterHand[i]; MonsterCard monsterCard = monsterHand[i];
@ -282,7 +280,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
} }
this.state.HeroEnergy.PayForCard(card); this.state.HeroEnergy.PayForCard(card);
this.heroDeck.RemoveCardFromHand(card); this.state.HeroDeck.RemoveCardFromHand(card);
this.participantActivity.NotifyParticipantUsedCard(card.Owner, card); this.participantActivity.NotifyParticipantUsedCard(card.Owner, card);
yield return card.Use(this, this, battlePlayerControls); yield return card.Use(this, this, battlePlayerControls);
if (card.Type == CardType.Default) { if (card.Type == CardType.Default) {
@ -290,9 +288,9 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
} else if (card.IsPermanent()) { } else if (card.IsPermanent()) {
this.playArea.AddPlayedHeroPermanent(card); this.playArea.AddPlayedHeroPermanent(card);
} else if (card.IsEphemeral()) { } else if (card.IsEphemeral()) {
this.heroDeck.MoveCardToOblivion(card); this.state.HeroDeck.MoveCardToOblivion(card);
} else { } else {
this.heroDeck.MoveCardToDiscard(card); this.state.HeroDeck.MoveCardToDiscard(card);
} }
CheckState(); CheckState();
@ -312,14 +310,14 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
public IEnumerator UseMonsterCard(MonsterCard card) { public IEnumerator UseMonsterCard(MonsterCard card) {
this.state.MonsterEnergy.PayForCard(card); this.state.MonsterEnergy.PayForCard(card);
this.monsterDeck.RemoveCardFromHand(card); this.state.MonsterDeck.RemoveCardFromHand(card);
yield return card.Use(this, this); yield return card.Use(this, this);
if (card.IsPermanent()) { if (card.IsPermanent()) {
this.playArea.AddPlayedMonsterPermanent(card); this.playArea.AddPlayedMonsterPermanent(card);
} else if (card.IsEphemeral()) { } else if (card.IsEphemeral()) {
this.monsterDeck.MoveCardToOblivion(card); this.state.MonsterDeck.MoveCardToOblivion(card);
} else { } else {
this.monsterDeck.MoveCardToDiscard(card); this.state.MonsterDeck.MoveCardToDiscard(card);
} }
yield return new WaitForSeconds(0.5f); yield return new WaitForSeconds(0.5f);
@ -335,14 +333,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
return this.monsterHandPlayability.IsPlayableImmediately(card); return this.monsterHandPlayability.IsPlayableImmediately(card);
} }
public BattleDeck<HeroCard> GetHeroDeck() {
return this.heroDeck;
}
public PlayArea GetPlayArea() {
return this.playArea;
}
private void EnqueueActivatedTrigger(Trigger trigger) { private void EnqueueActivatedTrigger(Trigger trigger) {
this.activatedTriggers.Add(trigger); this.activatedTriggers.Add(trigger);
} }
@ -378,6 +368,8 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
: this.monsters.Cast<BattleParticipant>().ToArray()); : this.monsters.Cast<BattleParticipant>().ToArray());
} }
public BattleState State {get => this.state;}
// IBattleEffectApplier // IBattleEffectApplier
public void Apply(IBattleEffect effect) { public void Apply(IBattleEffect effect) {
effect.Apply(this); effect.Apply(this);
@ -414,11 +406,11 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
public void DrawCards(DrawCardsEffect effect) { public void DrawCards(DrawCardsEffect effect) {
if (effect.Team == TeamChoice.Heroes) { if (effect.Team == TeamChoice.Heroes) {
for (int i = 0; i < effect.Amount; i++) { for (int i = 0; i < effect.Amount; i++) {
this.heroDeck.DrawCard(); this.state.HeroDeck.DrawCard();
} }
} else { } else {
for (int i = 0; i < effect.Amount; i++) { 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 == null) return;
if (effect.Participant.Team == TeamChoice.Heroes) { if (effect.Participant.Team == TeamChoice.Heroes) {
this.AcquireCardsTyped(effect, this.heroDeck, this.heroCardDatabase); this.AcquireCardsTyped(effect, this.state.HeroDeck, this.heroCardDatabase);
} else { } 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) { public void SetupDefault(DefaultEffect effect) {
DefaultHeroCard previousDefault = this.playArea.SetupDefault(effect); DefaultHeroCard previousDefault = this.playArea.SetupDefault(effect);
if (previousDefault != null) { if (previousDefault != null) {
this.heroDeck.MoveCardToDiscard(previousDefault); this.state.HeroDeck.MoveCardToDiscard(previousDefault);
} }
} }

View file

@ -10,6 +10,8 @@ public class BattleState
private BuffManager buffManager; private BuffManager buffManager;
private EnergyPool heroEnergy; private EnergyPool heroEnergy;
private EnergyPool monsterEnergy; private EnergyPool monsterEnergy;
private BattleDeck<HeroCard> heroDeck;
private BattleDeck<MonsterCard> monsterDeck;
public BattleState() { public BattleState() {
this.clock = new BattleClock(); this.clock = new BattleClock();
@ -18,6 +20,11 @@ public class BattleState
this.monsterEnergy = new EnergyPool(); this.monsterEnergy = new EnergyPool();
} }
public void SetDecks(BattleDeck<HeroCard> heroDeck, BattleDeck<MonsterCard> monsterDeck) {
this.heroDeck = heroDeck;
this.monsterDeck = monsterDeck;
}
public bool IsTeamsTurnToPlay(TeamChoice team) { public bool IsTeamsTurnToPlay(TeamChoice team) {
if (team == TeamChoice.Heroes) { if (team == TeamChoice.Heroes) {
return this.clock.Now.RoundStep == RoundStep.StartOfHeroTurn; return this.clock.Now.RoundStep == RoundStep.StartOfHeroTurn;
@ -48,4 +55,6 @@ public class BattleState
public EnergyPool HeroEnergy {get => this.heroEnergy;} public EnergyPool HeroEnergy {get => this.heroEnergy;}
public EnergyPool MonsterEnergy {get => this.monsterEnergy;} public EnergyPool MonsterEnergy {get => this.monsterEnergy;}
public BattleDeck<HeroCard> HeroDeck {get => this.heroDeck;}
public BattleDeck<MonsterCard> MonsterDeck {get => this.monsterDeck;}
} }

View file

@ -9,11 +9,11 @@ public class DiscardPileUI : MonoBehaviour
public BattleController battleController; public BattleController battleController;
void Start() { void Start() {
this.battleController.GetHeroDeck().OnDiscardPileChanged += NotifyDiscardPileChanged; this.battleController.State.HeroDeck.OnDiscardPileChanged += NotifyDiscardPileChanged;
NotifyDiscardPileChanged(); NotifyDiscardPileChanged();
} }
public void NotifyDiscardPileChanged() { public void NotifyDiscardPileChanged() {
text.text = "Discard pile: " + this.battleController.GetHeroDeck().GetDiscardPile().Count; text.text = "Discard pile: " + this.battleController.State.HeroDeck.GetDiscardPile().Count;
} }
} }

View file

@ -9,11 +9,11 @@ public class DrawPileUI : MonoBehaviour
public BattleController battleController; public BattleController battleController;
void Start() { void Start() {
this.battleController.GetHeroDeck().OnDrawPileChanged += NotifyDrawPileChanged; this.battleController.State.HeroDeck.OnDrawPileChanged += NotifyDrawPileChanged;
NotifyDrawPileChanged(); NotifyDrawPileChanged();
} }
public void NotifyDrawPileChanged() { public void NotifyDrawPileChanged() {
text.text = "Draw pile: " + this.battleController.GetHeroDeck().GetDrawPile().Count; text.text = "Draw pile: " + this.battleController.State.HeroDeck.GetDrawPile().Count;
} }
} }