Restructure battle with Coroutines, monsters play from hand
This commit is contained in:
parent
28db788635
commit
6135ea1b24
4 changed files with 80 additions and 21 deletions
|
|
@ -30,8 +30,11 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
private HeroInfoUI[] monsterUIs;
|
||||
|
||||
private bool heroTurn;
|
||||
private bool heroPassedTurn;
|
||||
private int maxEnergy;
|
||||
private int energy;
|
||||
private int maxMEnergy;
|
||||
private int mEnergy;
|
||||
|
||||
void Awake() {
|
||||
this.heroCardDatabase = new HeroCardDatabase();
|
||||
|
|
@ -113,7 +116,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
StartHeroTurn();
|
||||
StartCoroutine(RunBattleRounds());
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
|
|
@ -121,37 +124,66 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
{
|
||||
}
|
||||
|
||||
private void StartHeroTurn() {
|
||||
private IEnumerator RunBattleRounds() {
|
||||
while (true) {
|
||||
yield return RunBattleRound();
|
||||
}
|
||||
}
|
||||
|
||||
private IEnumerator RunBattleRound() {
|
||||
this.heroTurn = true;
|
||||
|
||||
this.damageTriggers.RemoveAll(t => t.Expiration == TriggerExpiration.StartOfNextHeroTurn);
|
||||
|
||||
this.energy = this.maxEnergy;
|
||||
foreach (BattleHero hero in this.heroes) {
|
||||
hero.ResetBlock();
|
||||
}
|
||||
this.mEnergy = this.maxMEnergy;
|
||||
this.heroDeck.DrawHand();
|
||||
this.battlePlayerControls.NotifyHandPileChanged();
|
||||
|
||||
this.monsterDeck.DrawHand();
|
||||
|
||||
yield return RunHeroTurn();
|
||||
|
||||
this.heroTurn = false;
|
||||
yield return RunMonsterTurn();
|
||||
}
|
||||
|
||||
private IEnumerator RunHeroTurn() {
|
||||
// Start of hero turn
|
||||
if (this.maxEnergy < 9) {
|
||||
this.maxEnergy++;
|
||||
this.energy++;
|
||||
}
|
||||
foreach (BattleHero hero in this.heroes) {
|
||||
hero.ResetBlock();
|
||||
}
|
||||
|
||||
// Heroes act until they pas
|
||||
while (!this.heroPassedTurn) {
|
||||
yield return null;
|
||||
}
|
||||
this.heroPassedTurn = false;
|
||||
|
||||
// End of hero turn
|
||||
this.heroDeck.DiscardHand();
|
||||
}
|
||||
|
||||
private void StartEnemyTurn() {
|
||||
this.heroTurn = false;
|
||||
|
||||
this.heroDeck.DiscardHand();
|
||||
|
||||
private IEnumerator RunMonsterTurn() {
|
||||
// Start of monster turn
|
||||
if (this.maxMEnergy < 9) {
|
||||
this.maxMEnergy++;
|
||||
this.mEnergy++;
|
||||
}
|
||||
foreach (BattleMonster monster in this.monsters) {
|
||||
monster.ResetBlock();
|
||||
}
|
||||
|
||||
MonsterCard card = this.monsterCardDatabase.CreateCard((int) MCardId.VampireFangs, this.monsters[0]);
|
||||
StartCoroutine(UseMonsterCard(card));
|
||||
|
||||
StartHeroTurn();
|
||||
// Start of monster turn
|
||||
List<MonsterCard> monsterHand = this.monsterDeck.GetHandPile();
|
||||
for (int i = 0; i < monsterHand.Count; i++) {
|
||||
MonsterCard monsterCard = monsterHand[i];
|
||||
if (CanUseMonsterCard(monsterCard)) {
|
||||
yield return UseMonsterCard(monsterCard);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void NotifyHeroCardUsed(HeroCard card) {
|
||||
|
|
@ -163,7 +195,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
|
||||
public IEnumerator UseHeroCard(HeroCard card) {
|
||||
yield return card.Use(this, battlePlayerControls);
|
||||
PayCardCost(card);
|
||||
PayHeroCardCost(card);
|
||||
this.heroDeck.RemoveCardFromHand(card);
|
||||
if (card.IsPermanent()) {
|
||||
this.playArea.AddPlayedHeroPermanent(card);
|
||||
|
|
@ -174,12 +206,18 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
|
||||
public IEnumerator UseMonsterCard(MonsterCard card) {
|
||||
yield return card.Use(this, this);
|
||||
// TODO: Manage monster deck.
|
||||
PayMonsterCardCost(card);
|
||||
this.monsterDeck.RemoveCardFromHand(card);
|
||||
if (card.IsPermanent()) {
|
||||
this.playArea.AddPlayedMonsterPermanent(card);
|
||||
} else {
|
||||
this.monsterDeck.MoveCardToDiscard(card);
|
||||
}
|
||||
}
|
||||
|
||||
public void NotifyHeroTurnPassed() {
|
||||
if (this.heroTurn) {
|
||||
StartEnemyTurn();
|
||||
this.heroPassedTurn = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -187,10 +225,18 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
return this.heroTurn && this.energy >= card.GetCost();
|
||||
}
|
||||
|
||||
private void PayCardCost(HeroCard card) {
|
||||
public bool CanUseMonsterCard(MonsterCard card) {
|
||||
return !this.heroTurn && this.mEnergy >= card.GetCost();
|
||||
}
|
||||
|
||||
private void PayHeroCardCost(HeroCard card) {
|
||||
this.energy -= card.GetCost();
|
||||
}
|
||||
|
||||
private void PayMonsterCardCost(MonsterCard card) {
|
||||
this.mEnergy -= card.GetCost();
|
||||
}
|
||||
|
||||
public int GetEnergy() {
|
||||
return this.energy;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue