Create HeroDeck with state of cards

This commit is contained in:
henriquenakashima 2020-09-19 13:52:16 -04:00
parent 967c871ed9
commit 567b732f85
7 changed files with 175 additions and 17 deletions

View file

@ -6,14 +6,14 @@ public class BattleController : MonoBehaviour
{
public HeroId[] heroIds;
public MonsterId[] monsterIds;
public int maxEnergy = 6;
public int maxEnergy;
public CardId[] cardIds;
public HeroInfoUI heroUIPrefab;
public GameObject uiCanvas;
public BattlePlayerControls battlePlayerControls;
private List<BaseCard> hand;
private HeroDeck heroDeck;
public BattleHero[] heroes;
private GameObject[] heroSprites;
@ -32,11 +32,7 @@ public class BattleController : MonoBehaviour
// Start is called before the first frame update
void Start()
{
this.hand = new List<BaseCard>();
for (int i = 0; i < cardIds.Length; i++) {
BaseCard newCard = CardDatabase.CreateCard(cardIds[i]);
this.hand.Add(newCard);
}
this.heroDeck = new HeroDeck(cardIds);
heroes = new BattleHero[3];
heroSprites = new GameObject[3];
@ -78,9 +74,10 @@ public class BattleController : MonoBehaviour
monsterUIs[i].Init(monsterSprites[i], monsters[i]);
}
this.battlePlayerControls.OnCardUsed += this.OnCardUsed;
this.battlePlayerControls.OnTurnPassed += this.OnTurnPassed;
this.battlePlayerControls.SetHand(this.hand);
this.battlePlayerControls.Init(this.heroDeck);
this.battlePlayerControls.OnCardUsed += this.NotifyCardUsed;
this.battlePlayerControls.OnTurnPassed += this.NotifyTurnPassed;
this.heroDeck.OnHandPileChanged += this.battlePlayerControls.NotifyHandPileChanged;
DecideEnemyTarget();
StartHeroTurn();
@ -97,11 +94,15 @@ public class BattleController : MonoBehaviour
foreach (BattleHero hero in this.heroes) {
hero.ResetBlock();
}
this.heroDeck.DrawHand();
this.battlePlayerControls.NotifyHandPileChanged();
}
private void StartEnemyTurn() {
this.heroTurn = false;
this.heroDeck.DiscardHand();
foreach (BattleMonster monster in this.monsters) {
monster.ResetBlock();
}
@ -118,8 +119,8 @@ public class BattleController : MonoBehaviour
Debug.Log("Will attack " + this.heroes[this.enemyTarget].GetDisplayName());
}
public void OnCardUsed(BaseCard card) {
Debug.Log("OnCardUsed " + card);
public void NotifyCardUsed(BaseCard card) {
Debug.Log("NotifyCardUsed " + card);
if (!CanUseCard(card)) {
throw new System.InvalidOperationException("Cannot use card " + card.GetDisplayName());
}
@ -129,11 +130,12 @@ public class BattleController : MonoBehaviour
public IEnumerator UseCard(BaseCard card) {
yield return card.Use(battlePlayerControls);
PayCardCost(card);
this.heroDeck.DiscardPlayedCard(card);
}
public void OnTurnPassed() {
public void NotifyTurnPassed() {
if (this.heroTurn) {
Debug.Log("OnTurnPassed");
Debug.Log("NotifyTurnPassed");
StartEnemyTurn();
}
}