diff --git a/Assets/Battle/BattleController.cs b/Assets/Battle/BattleController.cs index a9b3eac..9efd160 100644 --- a/Assets/Battle/BattleController.cs +++ b/Assets/Battle/BattleController.cs @@ -35,6 +35,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe private bool heroPassedTurn; private EnergyPool heroEnergy; private EnergyPool monsterEnergy; + private InsightLevel insightLevel; void Awake() { this.heroCardDatabase = new HeroCardDatabase(); @@ -47,6 +48,8 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe this.monsterEnergyUI.Init(this.monsterEnergy); this.monsterEnergy.OnEnergyChanged += this.monsterEnergyUI.NotifyEnergyChanged; + this.insightLevel = new InsightLevel(1); + heroes = new BattleHero[3]; heroSprites = new GameObject[3]; heroUIs = new HeroInfoUI[3]; @@ -109,9 +112,11 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe this.playArea = new PlayArea(); - this.battlePlayerControls.Init(this.heroDeck, this.monsterDeck, this.playArea); + this.battlePlayerControls.Init( + this.heroDeck, this.monsterDeck, this.playArea, this.insightLevel); this.battlePlayerControls.OnCardUsed += this.NotifyHeroCardUsed; this.battlePlayerControls.OnTurnPassed += this.NotifyHeroTurnPassed; + this.insightLevel.OnChanged += this.battlePlayerControls.NotifyInsightLevelChanged; this.heroDeck.OnHandPileChanged += this.battlePlayerControls.NotifyHeroHandPileChanged; this.monsterDeck.OnHandPileChanged += this.battlePlayerControls.NotifyMonsterHandPileChanged; } @@ -215,9 +220,9 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe } public IEnumerator UseHeroCard(HeroCard card) { - yield return card.Use(this, battlePlayerControls); this.heroEnergy.PayForCard(card); this.heroDeck.RemoveCardFromHand(card); + yield return card.Use(this, battlePlayerControls); if (card.IsPermanent()) { this.playArea.AddPlayedHeroPermanent(card); } else { @@ -229,9 +234,9 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe } public IEnumerator UseMonsterCard(MonsterCard card) { - yield return card.Use(this, this); this.monsterEnergy.PayForCard(card); this.monsterDeck.RemoveCardFromHand(card); + yield return card.Use(this, this); if (card.IsPermanent()) { this.playArea.AddPlayedMonsterPermanent(card); } else { @@ -311,6 +316,22 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe effect.Target.IncreaseMaxHP(effect.Amount); } + public void ModifyInsight(ModifyInsightEffect effect) { + this.insightLevel.Modify(effect.Amount); + } + + public void DrawCards(DrawCardsEffect effect) { + if (effect.Team == TeamChoice.Heroes) { + for (int i = 0; i < effect.Amount; i++) { + this.heroDeck.DrawCard(); + } + } else { + for (int i = 0; i < effect.Amount; i++) { + this.monsterDeck.DrawCard(); + } + } + } + public void AcquireCards(AcquireCardsEffect effect) { if (effect.Participant == null) return; @@ -349,11 +370,9 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe private List damageTriggers = new List(); public int DealDamage(DealDamageEffect effect) { - Debug.Log("DealDamage to " + effect.Target.GetDisplayName() + " " + effect.Amount); if (effect.Target == null) return 0; int damageDealt = effect.Target.DealDamage(effect.Amount); - Debug.Log("damageDealt " + damageDealt); foreach (DamageTrigger dt in this.damageTriggers) { if (dt.IsTriggeredBy(effect)) { EnqueueActivatedTrigger(dt); diff --git a/Assets/Battle/BattlePlayerControls.cs b/Assets/Battle/BattlePlayerControls.cs index 6ab904d..94b41e6 100644 --- a/Assets/Battle/BattlePlayerControls.cs +++ b/Assets/Battle/BattlePlayerControls.cs @@ -20,22 +20,27 @@ public class BattlePlayerControls : MonoBehaviour private BattleDeck heroDeck; private BattleDeck monsterDeck; private PlayArea playArea; + private InsightLevel insightLevel; private HandControls heroHandControls; private HandControls monsterHandControls; private Dictionary cardsInPlayUIs; public void Init( - BattleDeck heroDeck, BattleDeck monsterDeck, PlayArea playArea) { + BattleDeck heroDeck, BattleDeck monsterDeck, PlayArea playArea, + InsightLevel insightLevel) { this.heroDeck = heroDeck; this.monsterDeck = monsterDeck; this.playArea = playArea; + this.insightLevel = insightLevel; this.heroHandControls = new HandControls(this.uiCanvas, this.cardPrefab, HandControlsPosition.Bottom, int.MaxValue); this.heroHandControls.OnCardClicked += OnHeroCardClicked; this.monsterHandControls = new HandControls(this.uiCanvas, this.cardPrefab, HandControlsPosition.Top, 1); this.monsterHandControls.OnCardClicked += OnMonsterCardClicked; this.cardsInPlayUIs = new Dictionary(); + + NotifyInsightLevelChanged(); } // Start is called before the first frame update @@ -143,4 +148,8 @@ public class BattlePlayerControls : MonoBehaviour Screen.height - PADDING - DELTA * index - BattleCardPrefabConstants.CARD_HEIGHT / 2, 0); } + + public void NotifyInsightLevelChanged() { + this.monsterHandControls.InsightLevel = this.insightLevel.Level; + } } diff --git a/Assets/Battle/CardsHeroes/MeditateHCard.cs b/Assets/Battle/CardsHeroes/MeditateHCard.cs new file mode 100644 index 0000000..ac23235 --- /dev/null +++ b/Assets/Battle/CardsHeroes/MeditateHCard.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class MeditateHCard : HeroCard +{ + public MeditateHCard(BattleParticipant owner) + : base(owner, CardId.Meditate, "Meditate", 2, CardType.Skill, "+1 insight. Draw a card.") { + } + + public override IEnumerator Use( + IBattleEffectApplier effectApplier, BattlePlayerControls playerControls) { + effectApplier.Apply(new ModifyInsightEffect(+1)); + yield return new WaitForSeconds(1f); + effectApplier.Apply(new DrawCardsEffect(1, TeamChoice.Heroes)); + yield break; + } +} diff --git a/Assets/Battle/CardsHeroes/MeditateHCard.cs.meta b/Assets/Battle/CardsHeroes/MeditateHCard.cs.meta new file mode 100644 index 0000000..c9a92f4 --- /dev/null +++ b/Assets/Battle/CardsHeroes/MeditateHCard.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ad0e87d0e8cce5a4098547ac13155717 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Battle/Effects/DrawCardsEffect.cs b/Assets/Battle/Effects/DrawCardsEffect.cs new file mode 100644 index 0000000..b905899 --- /dev/null +++ b/Assets/Battle/Effects/DrawCardsEffect.cs @@ -0,0 +1,26 @@ +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; + +public enum TeamChoice { + Heroes, + Monsters, +} + +public class DrawCardsEffect : IBattleEffect +{ + private int amount; + private TeamChoice team; + + public DrawCardsEffect(int amount, TeamChoice team) { + this.amount = amount; + this.team = team; + } + public void Apply(IBattleEffectResolver resolver) { + resolver.DrawCards(this); + } + + public int Amount {get => this.amount;} + public TeamChoice Team {get => this.team;} +} diff --git a/Assets/Battle/Effects/DrawCardsEffect.cs.meta b/Assets/Battle/Effects/DrawCardsEffect.cs.meta new file mode 100644 index 0000000..370173d --- /dev/null +++ b/Assets/Battle/Effects/DrawCardsEffect.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: f3f95b0d797290f478cd7378af9562e1 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Battle/Effects/ModifyInsightEffect.cs b/Assets/Battle/Effects/ModifyInsightEffect.cs new file mode 100644 index 0000000..e8a17c8 --- /dev/null +++ b/Assets/Battle/Effects/ModifyInsightEffect.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using System.Linq; +using UnityEngine; + +public class ModifyInsightEffect : IBattleEffect +{ + private int amount; + + public ModifyInsightEffect(int amount) { + this.amount = amount; + } + public void Apply(IBattleEffectResolver resolver) { + resolver.ModifyInsight(this); + } + + public int Amount {get => this.amount;} +} diff --git a/Assets/Battle/Effects/ModifyInsightEffect.cs.meta b/Assets/Battle/Effects/ModifyInsightEffect.cs.meta new file mode 100644 index 0000000..95323d3 --- /dev/null +++ b/Assets/Battle/Effects/ModifyInsightEffect.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6f8ec4c4da9aecc4589846cb29f4310a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Battle/HandControls.cs b/Assets/Battle/HandControls.cs index fc98668..270e102 100644 --- a/Assets/Battle/HandControls.cs +++ b/Assets/Battle/HandControls.cs @@ -18,6 +18,7 @@ public class HandControls where BaseCardT : BaseCard private GameObject cardPrefab; private HandControlsPosition position; + private List hand; private List cardsInHandUIs; private int insightLevel; @@ -30,27 +31,8 @@ public class HandControls where BaseCardT : BaseCard } public void SetHand(List hand) { - if (this.cardsInHandUIs != null) { - foreach (GameObject cardInHandUI in this.cardsInHandUIs) { - GameObject.Destroy(cardInHandUI); - } - } - - this.cardsInHandUIs = new List(); - for (int i = 0; i < hand.Count; i++) { - BaseCardT card = hand[i]; - GameObject cardUI = GameObject.Instantiate(this.cardPrefab, this.uiCanvas.transform); - this.cardsInHandUIs.Add(cardUI); - cardUI.transform.position = CalculateHandCardPosition(i, hand.Count); - CardUI cardUIScript = cardUI.GetComponent(); - if (i < this.insightLevel) { - cardUIScript.Init(card); - } else { - cardUIScript.InitHidden(); - } - int cardIndex = i; - cardUI.GetComponent