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 HeroCardDatabase heroCardDatabase;
private MonsterCardDatabase monsterCardDatabase;
private BattleDeck<HeroCard> heroDeck;
private BattleDeck<MonsterCard> 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<HeroCard>(
BattleDeck<HeroCard> heroDeck = new BattleDeck<HeroCard>(
this.heroCardDatabase, parameters.HCardIds.Cast<int>().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<MonsterCard>(
BattleDeck<MonsterCard> monsterDeck = new BattleDeck<MonsterCard>(
this.monsterCardDatabase, parameters.MCardIds.Cast<int>().ToArray(), mCardOwners);
this.state.SetDecks(heroDeck, monsterDeck);
this.participantActivity = new ParticipantActivity();
this.playArea = new PlayArea();
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.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.monsterIntentions = new TurnIntentions<MonsterCard>(
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<MonsterCard> monsterHand = this.monsterDeck.GetHandPile();
List<MonsterCard> 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<MonsterCard> monsterHand = monsterHand = this.monsterDeck.GetHandPile();
List<MonsterCard> 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<HeroCard> 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<BattleParticipant>().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);
}
}