diff --git a/Assets/Battle/BaseCard.cs b/Assets/Battle/BaseCard.cs index 616017f..d9caf9c 100644 --- a/Assets/Battle/BaseCard.cs +++ b/Assets/Battle/BaseCard.cs @@ -5,24 +5,19 @@ using UnityEngine; public abstract class BaseCard { protected BattleParticipant owner; - protected CardId id; protected string displayName; protected int cost; protected CardType type; protected string effectText; - public BaseCard(BattleParticipant owner, CardId id, string displayName, int cost, CardType type, string effectText) { + public BaseCard(BattleParticipant owner, string displayName, int cost, CardType type, string effectText) { this.owner = owner; - this.id = id; this.displayName = displayName; this.cost = cost; this.type = type; this.effectText = effectText; } - public abstract IEnumerator Use(IBattleEffectApplier effectApplier, BattlePlayerControls playerControls); - - public CardId GetId() {return this.id;} public string GetDisplayName() {return this.displayName;} public int GetCost() {return this.cost;} public string GetDisplayType() { diff --git a/Assets/Battle/BattleController.cs b/Assets/Battle/BattleController.cs index f20d278..b884848 100644 --- a/Assets/Battle/BattleController.cs +++ b/Assets/Battle/BattleController.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using UnityEngine; -public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffectResolver +public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffectResolver, MonsterViewpoint { public HeroId[] heroIds; public MonsterId[] monsterIds; @@ -77,8 +77,8 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe this.playArea = new PlayArea(); this.battlePlayerControls.Init(this.heroDeck, this.playArea); - this.battlePlayerControls.OnCardUsed += this.NotifyCardUsed; - this.battlePlayerControls.OnTurnPassed += this.NotifyTurnPassed; + this.battlePlayerControls.OnCardUsed += this.NotifyHeroCardUsed; + this.battlePlayerControls.OnTurnPassed += this.NotifyHeroTurnPassed; this.heroDeck.OnHandPileChanged += this.battlePlayerControls.NotifyHandPileChanged; } @@ -141,14 +141,14 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe Debug.Log("Will attack " + this.heroes[this.enemyTarget].GetDisplayName()); } - public void NotifyCardUsed(BaseCard card) { - if (!CanUseCard(card)) { + public void NotifyHeroCardUsed(HeroCard card) { + if (!CanUseHeroCard(card)) { throw new System.InvalidOperationException("Cannot use card " + card.GetDisplayName()); } - StartCoroutine(UseCard(card)); + StartCoroutine(UseHeroCard(card)); } - public IEnumerator UseCard(BaseCard card) { + public IEnumerator UseHeroCard(HeroCard card) { yield return card.Use(this, battlePlayerControls); PayCardCost(card); this.heroDeck.RemoveCardFromHand(card); @@ -159,17 +159,17 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe } } - public void NotifyTurnPassed() { + public void NotifyHeroTurnPassed() { if (this.heroTurn) { StartEnemyTurn(); } } - public bool CanUseCard(BaseCard card) { + public bool CanUseHeroCard(HeroCard card) { return this.heroTurn && this.energy >= card.GetCost(); } - private void PayCardCost(BaseCard card) { + private void PayCardCost(HeroCard card) { this.energy -= card.GetCost(); } @@ -237,6 +237,11 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe return damageDealt; } + public int Heal(HealEffect effect) { + int healedAmount = effect.Target.Heal(effect.Amount); + return healedAmount; + } + public void AddBlock(BattleParticipant target, int amount) { target.AddBlock(amount); } @@ -258,4 +263,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe // Cleanup expired triggers this.damageTriggers.RemoveAll(t => t.Expired); } + + // MonsterViewpoint + public BattleHero[] Heroes {get => this.heroes;} } diff --git a/Assets/Battle/BattleParticipant.cs b/Assets/Battle/BattleParticipant.cs index c82cf00..bb9ac33 100644 --- a/Assets/Battle/BattleParticipant.cs +++ b/Assets/Battle/BattleParticipant.cs @@ -42,6 +42,12 @@ public class BattleParticipant return damage; } + public int Heal(int amount) { + amount = Math.Min(this.maxHP - this.hp, amount); + this.hp += amount; + return amount; + } + public void AddBlock(int block) { this.block += block; } diff --git a/Assets/Battle/BattlePlayerControls.cs b/Assets/Battle/BattlePlayerControls.cs index 386b1e2..2ac02f1 100644 --- a/Assets/Battle/BattlePlayerControls.cs +++ b/Assets/Battle/BattlePlayerControls.cs @@ -1,5 +1,6 @@ using System.Collections; using System.Collections.Generic; +using System.Linq; using UnityEngine; using UnityEngine.UI; @@ -9,7 +10,7 @@ public class BattlePlayerControls : MonoBehaviour public GameObject uiCanvas; public GameObject cardPrefab; - public delegate void CardUsedAction(BaseCard card); + public delegate void CardUsedAction(HeroCard card); public event CardUsedAction OnCardUsed; public delegate void TurnPassedAction(); public event TurnPassedAction OnTurnPassed; @@ -39,7 +40,7 @@ public class BattlePlayerControls : MonoBehaviour } - private void SetHand(List hand) { + private void SetHand(List hand) { if (this.cardsInHandUIs != null) { foreach (GameObject cardInHandUI in this.cardsInHandUIs) { Destroy(cardInHandUI); @@ -48,7 +49,7 @@ public class BattlePlayerControls : MonoBehaviour this.cardsInHandUIs = new List(); for (int i = 0; i < hand.Count; i++) { - BaseCard card = hand[i]; + HeroCard card = hand[i]; GameObject cardUI = Instantiate(this.cardPrefab, this.uiCanvas.transform); this.cardsInHandUIs.Add(cardUI); cardUI.transform.position = CalculateHandCardPosition(i, hand.Count); @@ -70,9 +71,9 @@ public class BattlePlayerControls : MonoBehaviour 0); } - private void OnCardClicked(BaseCard card) { + private void OnCardClicked(HeroCard card) { if (this.singleTargeting == null) { - if (this.battleController.CanUseCard(card)) { + if (this.battleController.CanUseHeroCard(card)) { OnCardUsed(card); } } @@ -103,7 +104,7 @@ public class BattlePlayerControls : MonoBehaviour } public void NotifyHandPileChanged() { - SetHand(this.heroDeck.GetHandPile()); + SetHand(this.heroDeck.GetHandPile().Cast().ToList()); } private void NotifyPlayAreaChanged() { diff --git a/Assets/Battle/CardsHeroes/CardCover.cs b/Assets/Battle/CardsHeroes/CardCover.cs index c123f6d..9608a8c 100644 --- a/Assets/Battle/CardsHeroes/CardCover.cs +++ b/Assets/Battle/CardsHeroes/CardCover.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using UnityEngine; -public class CardCover : BaseCard +public class CardCover : HeroCard { public CardCover(BattleParticipant owner) : base(owner, CardId.Cover, "Cover", 1, CardType.Skill, diff --git a/Assets/Battle/CardsHeroes/CardCrashingPunch.cs b/Assets/Battle/CardsHeroes/CardCrashingPunch.cs index f8d8ecc..d32161d 100644 --- a/Assets/Battle/CardsHeroes/CardCrashingPunch.cs +++ b/Assets/Battle/CardsHeroes/CardCrashingPunch.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using UnityEngine; -public class CardCrashingPunch : BaseCard +public class CardCrashingPunch : HeroCard { public CardCrashingPunch(BattleParticipant owner) : base(owner, CardId.CrashingPunch, "Crashing Punch", 3, CardType.Attack, diff --git a/Assets/Battle/CardsHeroes/CardLightningStrike.cs b/Assets/Battle/CardsHeroes/CardLightningStrike.cs index 4e3dec1..2cdc723 100644 --- a/Assets/Battle/CardsHeroes/CardLightningStrike.cs +++ b/Assets/Battle/CardsHeroes/CardLightningStrike.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using UnityEngine; -public class CardLightningStrike : BaseCard +public class CardLightningStrike : HeroCard { public CardLightningStrike(BattleParticipant owner) : base(owner, CardId.LightningStrike, "Lightning Strike", 2, CardType.Attack, diff --git a/Assets/Battle/CardsHeroes/CardScarring.cs b/Assets/Battle/CardsHeroes/CardScarring.cs index e573055..cac91d3 100644 --- a/Assets/Battle/CardsHeroes/CardScarring.cs +++ b/Assets/Battle/CardsHeroes/CardScarring.cs @@ -2,7 +2,7 @@ using System.Collections; using System.Collections.Generic; using UnityEngine; -public class CardScarring : BaseCard +public class CardScarring : HeroCard { public CardScarring(BattleParticipant owner) : base(owner, CardId.Scarring, "Scarring", 2, CardType.Skill, diff --git a/Assets/Battle/CardsHeroes/CardThunderstorm.cs b/Assets/Battle/CardsHeroes/CardThunderstorm.cs index da7a5cd..07a6c21 100644 --- a/Assets/Battle/CardsHeroes/CardThunderstorm.cs +++ b/Assets/Battle/CardsHeroes/CardThunderstorm.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using UnityEngine; -public class CardThunderstorm : BaseCard +public class CardThunderstorm : HeroCard { public CardThunderstorm(BattleParticipant owner) : base(owner, CardId.Thunderstorm, "Thunderstorm", 3, CardType.Enchantment, diff --git a/Assets/Battle/CardsMonsters/MCardVampireFangs.cs b/Assets/Battle/CardsMonsters/MCardVampireFangs.cs new file mode 100644 index 0000000..cefb794 --- /dev/null +++ b/Assets/Battle/CardsMonsters/MCardVampireFangs.cs @@ -0,0 +1,26 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class MCardVampireFangs : MonsterCard +{ + public MCardVampireFangs(BattleParticipant owner) + : base(owner, MCardId.VampireFangs, "VampireFangs", 2, CardType.Attack, + "Steals 2 HP from target.") { + } + + public override IEnumerator Use(IBattleEffectApplier effectApplier, MonsterViewpoint monsterViewpoint) { + BattleParticipant target = DetermineTarget(monsterViewpoint); + DealDamageEffect damageEffect = new DealDamageEffect(target, 2); + effectApplier.Apply(damageEffect); + if (damageEffect.AmountDealt > 0) { + HealEffect healEffect = new HealEffect(this.owner, damageEffect.AmountDealt); + effectApplier.Apply(healEffect); + } + yield break; + } + + private BattleParticipant DetermineTarget(MonsterViewpoint monsterViewpoint) { + return monsterViewpoint.Heroes[0]; + } +} diff --git a/Assets/Battle/CardsMonsters/MCardVampireFangs.cs.meta b/Assets/Battle/CardsMonsters/MCardVampireFangs.cs.meta new file mode 100644 index 0000000..409a015 --- /dev/null +++ b/Assets/Battle/CardsMonsters/MCardVampireFangs.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6958b53630a12ff42b90786d9ce5ff1b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Battle/Effects/HealEffect.cs b/Assets/Battle/Effects/HealEffect.cs new file mode 100644 index 0000000..8a29787 --- /dev/null +++ b/Assets/Battle/Effects/HealEffect.cs @@ -0,0 +1,21 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class HealEffect : IBattleEffect +{ + private BattleParticipant target; + private int amount; + + public HealEffect(BattleParticipant target, int amount) { + this.target = target; + this.amount = amount; + } + + public void Apply(IBattleEffectResolver resolver) { + resolver.Heal(this); + } + + public BattleParticipant Target {get => this.target;} + public int Amount {get => this.amount;} +} diff --git a/Assets/Battle/Effects/HealEffect.cs.meta b/Assets/Battle/Effects/HealEffect.cs.meta new file mode 100644 index 0000000..c64fe6e --- /dev/null +++ b/Assets/Battle/Effects/HealEffect.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: a520366dc6140c4499e2c3f09ded6ee8 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Battle/HeroCard.cs b/Assets/Battle/HeroCard.cs new file mode 100644 index 0000000..270cea0 --- /dev/null +++ b/Assets/Battle/HeroCard.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public abstract class HeroCard : BaseCard +{ + private CardId id; + + public HeroCard(BattleParticipant owner, CardId id, string displayName, int cost, CardType type, + string effectText) + : base(owner, displayName, cost, type, effectText) { + this.id = id; + } + + public abstract IEnumerator Use(IBattleEffectApplier effectApplier, BattlePlayerControls playerControls); + + public CardId GetId() {return this.id;} +} diff --git a/Assets/Battle/HeroCard.cs.meta b/Assets/Battle/HeroCard.cs.meta new file mode 100644 index 0000000..8f0a836 --- /dev/null +++ b/Assets/Battle/HeroCard.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cf5116ff6cdebb74398b8f8d441f0a00 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Battle/IBattleEffectResolver.cs b/Assets/Battle/IBattleEffectResolver.cs index cb4a3ec..4f4e945 100644 --- a/Assets/Battle/IBattleEffectResolver.cs +++ b/Assets/Battle/IBattleEffectResolver.cs @@ -4,6 +4,7 @@ using UnityEngine; public interface IBattleEffectResolver { int DealDamage(DealDamageEffect effect); + int Heal(HealEffect effect); void AddBlock(BattleParticipant target, int amount); void IncreaseHeroMaxEnergy(int delta); void IncreaseMaxHP(IncreaseMaxHPEffect effect); diff --git a/Assets/Battle/MonsterCard.cs b/Assets/Battle/MonsterCard.cs new file mode 100644 index 0000000..96aad0f --- /dev/null +++ b/Assets/Battle/MonsterCard.cs @@ -0,0 +1,16 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public abstract class MonsterCard : BaseCard +{ + private MCardId id; + + public MonsterCard(BattleParticipant owner, MCardId id, string displayName, int cost, CardType type, + string effectText) + : base(owner, displayName, cost, type, effectText) { + this.id = id; + } + + public abstract IEnumerator Use(IBattleEffectApplier effectApplier, MonsterViewpoint monsterViewpoint); +} diff --git a/Assets/Battle/MonsterCard.cs.meta b/Assets/Battle/MonsterCard.cs.meta new file mode 100644 index 0000000..747f906 --- /dev/null +++ b/Assets/Battle/MonsterCard.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 0aa2fbe8443d291409d7d31e64516572 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Battle/MonsterCardDatabase.cs b/Assets/Battle/MonsterCardDatabase.cs new file mode 100644 index 0000000..447634b --- /dev/null +++ b/Assets/Battle/MonsterCardDatabase.cs @@ -0,0 +1,11 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public enum MCardId { + VampireFangs, +} + +public static class MonsterCardDatabase +{ +} diff --git a/Assets/Battle/MonsterCardDatabase.cs.meta b/Assets/Battle/MonsterCardDatabase.cs.meta new file mode 100644 index 0000000..b1d6f2c --- /dev/null +++ b/Assets/Battle/MonsterCardDatabase.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 6a2709429808ed54293ff6ce26aa1fe0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Battle/MonsterViewpoint.cs b/Assets/Battle/MonsterViewpoint.cs new file mode 100644 index 0000000..0f9cc21 --- /dev/null +++ b/Assets/Battle/MonsterViewpoint.cs @@ -0,0 +1,7 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public interface MonsterViewpoint { + BattleHero[] Heroes {get;} +} diff --git a/Assets/Battle/MonsterViewpoint.cs.meta b/Assets/Battle/MonsterViewpoint.cs.meta new file mode 100644 index 0000000..abd4534 --- /dev/null +++ b/Assets/Battle/MonsterViewpoint.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c235e6491d6458a4ab8dbb587ebd8866 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: