Check win and loss states

This commit is contained in:
henriquenakashima 2020-09-20 16:45:50 -04:00
parent adc84f9aba
commit 8c641f5524
8 changed files with 69 additions and 7 deletions

View file

@ -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<DamageTrigger> damageTriggers = new List<DamageTrigger>();
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);
}

View file

@ -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) {

View file

@ -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}

View file

@ -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;
}
}

View file

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: cc74c54a87a767f47bd838afb171504e
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

View file

@ -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];
}
}

View file

@ -5,6 +5,7 @@ using UnityEngine;
public enum MCardId {
VampireFangs,
GolemFist,
QuickSwiftDeath,
}
public class MonsterCardDatabase : CardDatabase<MonsterCard>
@ -17,6 +18,8 @@ public class MonsterCardDatabase : CardDatabase<MonsterCard>
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");
}

View file

@ -1,3 +1,2 @@
- Make battle end as state based effect
- Check death as state based effect
- Rename CardId to HCardId
- Rename CardId to HCardId
- Animate rearrange hand after card is used