diff --git a/Assets/Battle/BattleController.cs b/Assets/Battle/BattleController.cs index ec3a997..13ab0c6 100644 --- a/Assets/Battle/BattleController.cs +++ b/Assets/Battle/BattleController.cs @@ -217,6 +217,9 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe } else { this.heroDeck.MoveCardToDiscard(card); } + + yield return new WaitForSeconds(0.5f); + CheckState(); } public IEnumerator UseMonsterCard(MonsterCard card) { @@ -230,6 +233,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe } yield return new WaitForSeconds(0.5f); + CheckState(); } public void NotifyHeroTurnPassed() { @@ -267,7 +271,22 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe // Cleanup expired triggers this.damageTriggers.RemoveAll(t => t.Expired); } - + + private void CheckState() { + foreach (BattleParticipant p in this.heroes) { + p.CheckState(); + } + foreach (BattleParticipant p in this.monsters) { + p.CheckState(); + } + if (System.Array.TrueForAll(this.heroes, h => !h.IsAlive())) { + Debug.Log("You lost!"); + } + if (System.Array.TrueForAll(this.monsters, m => !m.IsAlive())) { + Debug.Log("You won!"); + } + } + public EnergyPool HeroEnergy {get => this.heroEnergy;} public EnergyPool MonsterEnergy {get => this.monsterEnergy;} @@ -282,10 +301,12 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe } public void IncreaseMaxHP(IncreaseMaxHPEffect effect) { + if (effect.Target == null) return; effect.Target.IncreaseMaxHP(effect.Amount); } public void AcquireHeroCards(AcquireCardsEffect effect) { + if (effect.Participant == null) return; BattleHero hero = (BattleHero) effect.Participant; foreach (CardId cardId in effect.CardIds) { HeroCard acquiredCard = this.heroCardDatabase.CreateCard((int) cardId, hero); @@ -307,6 +328,8 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe private List damageTriggers = new List(); public int DealDamage(DealDamageEffect effect) { + if (effect.Target == null) return 0; + int damageDealt = effect.Target.DealDamage(effect.Amount); foreach (DamageTrigger dt in this.damageTriggers) { if (dt.IsTriggeredBy(effect)) { @@ -321,11 +344,14 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe } public int Heal(HealEffect effect) { + if (effect.Target == null) return 0; + int healedAmount = effect.Target.Heal(effect.Amount); return healedAmount; } public void AddBlock(BlockEffect effect) { + if (effect.Target == null) return; effect.Target.AddBlock(effect.Amount); } diff --git a/Assets/Battle/BattleParticipant.cs b/Assets/Battle/BattleParticipant.cs index c296f9f..42ed922 100644 --- a/Assets/Battle/BattleParticipant.cs +++ b/Assets/Battle/BattleParticipant.cs @@ -47,11 +47,14 @@ public class BattleParticipant } damage = Math.Min(this.hp, damage); this.hp -= damage; + return damage; + } + + public void CheckState() { if (this.hp <= 0) { this.dead = true; TriggerOnDeath(); } - return damage; } public int Heal(int amount) { diff --git a/Assets/Battle/BattleScene.unity b/Assets/Battle/BattleScene.unity index c08edc6..33a8689 100644 --- a/Assets/Battle/BattleScene.unity +++ b/Assets/Battle/BattleScene.unity @@ -306,8 +306,8 @@ MonoBehaviour: heroIds: 010000000000000002000000 monsterIds: 000000000100000000000000 cardIds: 00000000000000000000000000000000010000000100000001000000030000000300000004000000 - mCardIds: 00000000000000000000000000000000000000000000000000000000000000000000000000000000 - mCardOwnerIndexes: 00000000000000000000000000000000000000000200000002000000020000000200000002000000 + mCardIds: 01000000010000000100000001000000000000000000000000000000000000000200000002000000 + mCardOwnerIndexes: 01000000010000000100000001000000000000000000000000000000020000000200000002000000 heroUIPrefab: {fileID: 6641511084601005557, guid: ef1b469b45cedee418e4c4adf577cd00, type: 3} uiCanvas: {fileID: 35522588} diff --git a/Assets/Battle/CardsMonsters/QuickSwiftDeathMCard.cs b/Assets/Battle/CardsMonsters/QuickSwiftDeathMCard.cs new file mode 100644 index 0000000..258bd5b --- /dev/null +++ b/Assets/Battle/CardsMonsters/QuickSwiftDeathMCard.cs @@ -0,0 +1,18 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +public class QuickSwiftDeathMCard : MonsterCard +{ + public QuickSwiftDeathMCard(BattleParticipant owner) + : base(owner, MCardId.GolemFist, "Quick Swift Death", 0, CardType.Attack, + "Deals 100 damage to target. Target: nearest hero.") { + } + + public override IEnumerator Use(IBattleEffectApplier effectApplier, MonsterViewpoint monsterViewpoint) { + BattleParticipant target = AIUtils.GetNearestHero(monsterViewpoint, this.owner); + DealDamageEffect damageEffect = new DealDamageEffect(target, 100); + effectApplier.Apply(damageEffect); + yield break; + } +} diff --git a/Assets/Battle/CardsMonsters/QuickSwiftDeathMCard.cs.meta b/Assets/Battle/CardsMonsters/QuickSwiftDeathMCard.cs.meta new file mode 100644 index 0000000..096a17b --- /dev/null +++ b/Assets/Battle/CardsMonsters/QuickSwiftDeathMCard.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: cc74c54a87a767f47bd838afb171504e +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Battle/MonsterAI/AIUtils.cs b/Assets/Battle/MonsterAI/AIUtils.cs index a65b005..fba5687 100644 --- a/Assets/Battle/MonsterAI/AIUtils.cs +++ b/Assets/Battle/MonsterAI/AIUtils.cs @@ -17,6 +17,7 @@ public class AIUtils { nearestDistance = distance; } } + if (nearestHeroIndex == -1) return null; return monsterViewpoint.Heroes[nearestHeroIndex]; } @@ -38,6 +39,7 @@ public class AIUtils { highestHP = heroHP; } } + if (highestHPHeroIndex == -1) return null; return monsterViewpoint.Heroes[highestHPHeroIndex]; } } diff --git a/Assets/Battle/MonsterCardDatabase.cs b/Assets/Battle/MonsterCardDatabase.cs index 046f7cf..76780d7 100644 --- a/Assets/Battle/MonsterCardDatabase.cs +++ b/Assets/Battle/MonsterCardDatabase.cs @@ -5,6 +5,7 @@ using UnityEngine; public enum MCardId { VampireFangs, GolemFist, + QuickSwiftDeath, } public class MonsterCardDatabase : CardDatabase @@ -17,6 +18,8 @@ public class MonsterCardDatabase : CardDatabase return new VampireFangsMCard(owner); case MCardId.GolemFist: return new GolemFistMCard(owner); + case MCardId.QuickSwiftDeath: + return new QuickSwiftDeathMCard(owner); default: throw new System.ArgumentException("MCardId unknown", "id"); } diff --git a/TODO.txt b/TODO.txt index f30f8a5..761b38b 100644 --- a/TODO.txt +++ b/TODO.txt @@ -1,3 +1,2 @@ -- Make battle end as state based effect -- Check death as state based effect -- Rename CardId to HCardId \ No newline at end of file +- Rename CardId to HCardId +- Animate rearrange hand after card is used \ No newline at end of file