From 737a85128304b668122dd29accb626d384d733f5 Mon Sep 17 00:00:00 2001 From: henriquenakashima Date: Thu, 1 Oct 2020 22:52:50 -0400 Subject: [PATCH] Enemies drop energy before, intentions are more accurate --- Assets/Battle/BattleController.cs | 45 ++++++++++++++++++++++++++----- Assets/Battle/CheatBattle.cs | 4 +++ Assets/Battle/HandControls.cs | 3 +++ Assets/Battle/HandPlayability.cs | 5 +++- Assets/Battle/TurnIntentions.cs | 17 +++++++++--- TODO.txt | 3 --- 6 files changed, 64 insertions(+), 13 deletions(-) diff --git a/Assets/Battle/BattleController.cs b/Assets/Battle/BattleController.cs index fdc043d..49e6d93 100644 --- a/Assets/Battle/BattleController.cs +++ b/Assets/Battle/BattleController.cs @@ -6,8 +6,8 @@ using UnityEngine.SceneManagement; public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffectResolver, MonsterViewpoint { - private bool STABLE_HAND_STYLE = false; - private int STARTING_INSIGHT = 1; + private bool STABLE_HAND_STYLE = true; + private int STARTING_INSIGHT = 3; // Inspector public public HeroInfoUI heroUIPrefab; @@ -139,7 +139,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe this.OnBattleStateChanged += this.monsterHandPlayability.NotifyBattleStateChanged; this.monsterIntentions = new TurnIntentions( - this.monsterDeck, this.monsterEnergy); + this.monsterDeck, this.monsterEnergy, this.monsterHandPlayability); this.battlePlayerControls.Init( this.heroDeck, this.monsterDeck, this.playArea, this.insightLevel, @@ -170,6 +170,14 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe cheat.OnInsightCode += delegate { this.insightLevel.Modify(+5); }; + cheat.OnOneHPCode += delegate { + foreach (BattleMonster m in this.monsters) { + if (m.IsAlive()) { + m.DealDamage(m.GetHP() - 1); + } + } + OnBattleStateChanged(); + }; } // Update is called once per frame @@ -260,13 +268,25 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe } OnBattleStateChanged(); - // Monsters act until they pass + // Monsters play an emotion List monsterHand = this.monsterDeck.GetHandPile(); for (int i = 0; i < monsterHand.Count; i++) { MonsterCard monsterCard = monsterHand[i]; - if (CanUseMonsterCard(monsterCard)) { + if (monsterCard.Type == CardType.Emotion && CanUseMonsterCard(monsterCard)) { + yield return UseMonsterCard(monsterCard); + } + } + + // Monsters play as many actions from the top as possible + bool anyCardPlayed = true; + while (anyCardPlayed) { + anyCardPlayed = false; + + MonsterCard monsterCard = FirstMonsterActionToPlay(); + if (monsterCard != null) { yield return UseMonsterCard(monsterCard); OnBattleStateChanged(); + anyCardPlayed = true; } } @@ -282,6 +302,18 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe OnBattleStateChanged(); } + private MonsterCard FirstMonsterActionToPlay() { + List monsterHand = monsterHand = this.monsterDeck.GetHandPile(); + + for (int i = 0; i < monsterHand.Count; i++) { + MonsterCard monsterCard = monsterHand[i]; + if (monsterCard.Type != CardType.Emotion && CanUseMonsterCard(monsterCard)) { + return monsterCard; + } + } + return null; + } + public IEnumerator UseHeroCard(HeroCard card) { if (!CanUseHeroCard(card)) { throw new System.InvalidOperationException("Cannot use card " + card.GetDisplayName()); @@ -298,8 +330,8 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe this.heroDeck.MoveCardToDiscard(card); } - OnBattleStateChanged(); CheckState(); + OnBattleStateChanged(); } public IEnumerator UseMonsterCard(MonsterCard card) { @@ -316,6 +348,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe yield return new WaitForSeconds(0.5f); CheckState(); + OnBattleStateChanged(); } public bool CanUseHeroCard(HeroCard card) { diff --git a/Assets/Battle/CheatBattle.cs b/Assets/Battle/CheatBattle.cs index 7b080c0..11dee07 100644 --- a/Assets/Battle/CheatBattle.cs +++ b/Assets/Battle/CheatBattle.cs @@ -78,6 +78,7 @@ public class CheatBattle: MonoBehaviour public delegate void CheatAction(); public event CheatAction OnWinCode; public event CheatAction OnInsightCode; + public event CheatAction OnOneHPCode; private string lastCommands = ""; @@ -94,6 +95,9 @@ public class CheatBattle: MonoBehaviour } else if (this.lastCommands.EndsWith("insight")) { this.OnInsightCode(); this.lastCommands = ""; + } else if (this.lastCommands.EndsWith("onehp")) { + this.OnOneHPCode(); + this.lastCommands = ""; } } } diff --git a/Assets/Battle/HandControls.cs b/Assets/Battle/HandControls.cs index 64ac18c..ae156c0 100644 --- a/Assets/Battle/HandControls.cs +++ b/Assets/Battle/HandControls.cs @@ -124,11 +124,14 @@ public class HandControls where BaseCardT : BaseCard if (cardPlayability == PlayabilityState.PlayableImmediately || cardPlayability == PlayabilityState.PlayableInOwnTurn) { if (this.intentions.WillUseCard(card)) { + // Debug.Log("Display state of " + card.GetDisplayName() + " = IntendedToPlay"); cardUI.State = PlayableState.IntendedToPlay; } else { + // Debug.Log("Display state of " + card.GetDisplayName() + " = Playable"); cardUI.State = PlayableState.Playable; } } else { + // Debug.Log("Display state of " + card.GetDisplayName() + " = Unplayable"); cardUI.State = PlayableState.Unplayable; } } diff --git a/Assets/Battle/HandPlayability.cs b/Assets/Battle/HandPlayability.cs index 64d55f4..58e781d 100644 --- a/Assets/Battle/HandPlayability.cs +++ b/Assets/Battle/HandPlayability.cs @@ -61,9 +61,10 @@ public class HandPlayability where BaseCardT : BaseCard { foreach (BaseCardT card in this.deck.GetHandPile()) { if (!card.Owner.CanUseCard(card)) { this.playable[card] = PlayabilityState.Unplayable; + // Debug.Log("Playability of " + card.GetDisplayName() + " = Unplayable"); continue; } - + bool canPlayNow = this.battleState.IsTeamsTurn(this.team); if (card.Type == CardType.Emotion) { canPlayNow = canPlayNow && this.battleState.CanPlayEmotion(this.team); @@ -72,8 +73,10 @@ public class HandPlayability where BaseCardT : BaseCard { } if (canPlayNow) { this.playable[card] = PlayabilityState.PlayableImmediately; + // Debug.Log("Playability of " + card.GetDisplayName() + " = PlayableImmediately"); } else { this.playable[card] = PlayabilityState.PlayableInOwnTurn; + // Debug.Log("Playability of " + card.GetDisplayName() + " = PlayableInOwnTurn"); } } TriggerOnPlayabilityChanged(); diff --git a/Assets/Battle/TurnIntentions.cs b/Assets/Battle/TurnIntentions.cs index c526e01..7bd9923 100644 --- a/Assets/Battle/TurnIntentions.cs +++ b/Assets/Battle/TurnIntentions.cs @@ -12,13 +12,15 @@ public class TurnIntentions where BaseCardT: BaseCard private bool mActive; private List mCardsToUse = new List(); - public TurnIntentions(BattleDeck deck, EnergyPool energyPool) { + public TurnIntentions(BattleDeck deck, EnergyPool energyPool, + HandPlayability playability) { mDeck = deck; mEnergyPool = energyPool; mActive = true; mDeck.OnDrawPileChanged += OnDependencyChanged; mEnergyPool.OnEnergyChanged += OnDependencyChanged; + playability.OnPlayabilityChanged += OnDependencyChanged; } public void ResumeIntentions() { @@ -46,14 +48,23 @@ public class TurnIntentions where BaseCardT: BaseCard private void UpdateState() { int projectedEnergy = mEnergyPool.Energy; - // TODO: Account for emotions mCardsToUse.Clear(); List hand = mDeck.GetHandPile(); + for (int i = 0; i < hand.Count; i++) { BaseCardT card = hand[i]; - if (card.Owner.CanUseCard(card) + if (card.Type == CardType.Emotion && card.Owner.CanUseCard(card)) { + projectedEnergy ++; + mCardsToUse.Add(card); + break; + } + } + for (int i = 0; i < hand.Count; i++) { + BaseCardT card = hand[i]; + if (card.Type != CardType.Emotion + && card.Owner.CanUseCard(card) && projectedEnergy >= card.GetCost()) { projectedEnergy -= card.GetCost(); mCardsToUse.Add(card); diff --git a/TODO.txt b/TODO.txt index 09e8970..dc00ce1 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,9 +1,6 @@ Battle - Animate rearrange hand after card is used - Do not Highlight unusable cards -+ Make enemies play energy before anything else -+ Limit intentions to drop one energy -+ Account for one dropped energy in intentions - Show on who enemies will use the cards - Highlight which card is targeting - Allow cancelling targeting