Check win and loss states
This commit is contained in:
parent
adc84f9aba
commit
8c641f5524
8 changed files with 69 additions and 7 deletions
|
|
@ -217,6 +217,9 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
||||||
} else {
|
} else {
|
||||||
this.heroDeck.MoveCardToDiscard(card);
|
this.heroDeck.MoveCardToDiscard(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
yield return new WaitForSeconds(0.5f);
|
||||||
|
CheckState();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerator UseMonsterCard(MonsterCard card) {
|
public IEnumerator UseMonsterCard(MonsterCard card) {
|
||||||
|
|
@ -230,6 +233,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
||||||
}
|
}
|
||||||
|
|
||||||
yield return new WaitForSeconds(0.5f);
|
yield return new WaitForSeconds(0.5f);
|
||||||
|
CheckState();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void NotifyHeroTurnPassed() {
|
public void NotifyHeroTurnPassed() {
|
||||||
|
|
@ -267,7 +271,22 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
||||||
// Cleanup expired triggers
|
// Cleanup expired triggers
|
||||||
this.damageTriggers.RemoveAll(t => t.Expired);
|
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 HeroEnergy {get => this.heroEnergy;}
|
||||||
public EnergyPool MonsterEnergy {get => this.monsterEnergy;}
|
public EnergyPool MonsterEnergy {get => this.monsterEnergy;}
|
||||||
|
|
||||||
|
|
@ -282,10 +301,12 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
||||||
}
|
}
|
||||||
|
|
||||||
public void IncreaseMaxHP(IncreaseMaxHPEffect effect) {
|
public void IncreaseMaxHP(IncreaseMaxHPEffect effect) {
|
||||||
|
if (effect.Target == null) return;
|
||||||
effect.Target.IncreaseMaxHP(effect.Amount);
|
effect.Target.IncreaseMaxHP(effect.Amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AcquireHeroCards(AcquireCardsEffect effect) {
|
public void AcquireHeroCards(AcquireCardsEffect effect) {
|
||||||
|
if (effect.Participant == null) return;
|
||||||
BattleHero hero = (BattleHero) effect.Participant;
|
BattleHero hero = (BattleHero) effect.Participant;
|
||||||
foreach (CardId cardId in effect.CardIds) {
|
foreach (CardId cardId in effect.CardIds) {
|
||||||
HeroCard acquiredCard = this.heroCardDatabase.CreateCard((int) cardId, hero);
|
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>();
|
private List<DamageTrigger> damageTriggers = new List<DamageTrigger>();
|
||||||
|
|
||||||
public int DealDamage(DealDamageEffect effect) {
|
public int DealDamage(DealDamageEffect effect) {
|
||||||
|
if (effect.Target == null) return 0;
|
||||||
|
|
||||||
int damageDealt = effect.Target.DealDamage(effect.Amount);
|
int damageDealt = effect.Target.DealDamage(effect.Amount);
|
||||||
foreach (DamageTrigger dt in this.damageTriggers) {
|
foreach (DamageTrigger dt in this.damageTriggers) {
|
||||||
if (dt.IsTriggeredBy(effect)) {
|
if (dt.IsTriggeredBy(effect)) {
|
||||||
|
|
@ -321,11 +344,14 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Heal(HealEffect effect) {
|
public int Heal(HealEffect effect) {
|
||||||
|
if (effect.Target == null) return 0;
|
||||||
|
|
||||||
int healedAmount = effect.Target.Heal(effect.Amount);
|
int healedAmount = effect.Target.Heal(effect.Amount);
|
||||||
return healedAmount;
|
return healedAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddBlock(BlockEffect effect) {
|
public void AddBlock(BlockEffect effect) {
|
||||||
|
if (effect.Target == null) return;
|
||||||
effect.Target.AddBlock(effect.Amount);
|
effect.Target.AddBlock(effect.Amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -47,11 +47,14 @@ public class BattleParticipant
|
||||||
}
|
}
|
||||||
damage = Math.Min(this.hp, damage);
|
damage = Math.Min(this.hp, damage);
|
||||||
this.hp -= damage;
|
this.hp -= damage;
|
||||||
|
return damage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void CheckState() {
|
||||||
if (this.hp <= 0) {
|
if (this.hp <= 0) {
|
||||||
this.dead = true;
|
this.dead = true;
|
||||||
TriggerOnDeath();
|
TriggerOnDeath();
|
||||||
}
|
}
|
||||||
return damage;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Heal(int amount) {
|
public int Heal(int amount) {
|
||||||
|
|
|
||||||
|
|
@ -306,8 +306,8 @@ MonoBehaviour:
|
||||||
heroIds: 010000000000000002000000
|
heroIds: 010000000000000002000000
|
||||||
monsterIds: 000000000100000000000000
|
monsterIds: 000000000100000000000000
|
||||||
cardIds: 00000000000000000000000000000000010000000100000001000000030000000300000004000000
|
cardIds: 00000000000000000000000000000000010000000100000001000000030000000300000004000000
|
||||||
mCardIds: 00000000000000000000000000000000000000000000000000000000000000000000000000000000
|
mCardIds: 01000000010000000100000001000000000000000000000000000000000000000200000002000000
|
||||||
mCardOwnerIndexes: 00000000000000000000000000000000000000000200000002000000020000000200000002000000
|
mCardOwnerIndexes: 01000000010000000100000001000000000000000000000000000000020000000200000002000000
|
||||||
heroUIPrefab: {fileID: 6641511084601005557, guid: ef1b469b45cedee418e4c4adf577cd00,
|
heroUIPrefab: {fileID: 6641511084601005557, guid: ef1b469b45cedee418e4c4adf577cd00,
|
||||||
type: 3}
|
type: 3}
|
||||||
uiCanvas: {fileID: 35522588}
|
uiCanvas: {fileID: 35522588}
|
||||||
|
|
|
||||||
18
Assets/Battle/CardsMonsters/QuickSwiftDeathMCard.cs
Normal file
18
Assets/Battle/CardsMonsters/QuickSwiftDeathMCard.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Battle/CardsMonsters/QuickSwiftDeathMCard.cs.meta
Normal file
11
Assets/Battle/CardsMonsters/QuickSwiftDeathMCard.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: cc74c54a87a767f47bd838afb171504e
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
|
@ -17,6 +17,7 @@ public class AIUtils {
|
||||||
nearestDistance = distance;
|
nearestDistance = distance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (nearestHeroIndex == -1) return null;
|
||||||
return monsterViewpoint.Heroes[nearestHeroIndex];
|
return monsterViewpoint.Heroes[nearestHeroIndex];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -38,6 +39,7 @@ public class AIUtils {
|
||||||
highestHP = heroHP;
|
highestHP = heroHP;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (highestHPHeroIndex == -1) return null;
|
||||||
return monsterViewpoint.Heroes[highestHPHeroIndex];
|
return monsterViewpoint.Heroes[highestHPHeroIndex];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ using UnityEngine;
|
||||||
public enum MCardId {
|
public enum MCardId {
|
||||||
VampireFangs,
|
VampireFangs,
|
||||||
GolemFist,
|
GolemFist,
|
||||||
|
QuickSwiftDeath,
|
||||||
}
|
}
|
||||||
|
|
||||||
public class MonsterCardDatabase : CardDatabase<MonsterCard>
|
public class MonsterCardDatabase : CardDatabase<MonsterCard>
|
||||||
|
|
@ -17,6 +18,8 @@ public class MonsterCardDatabase : CardDatabase<MonsterCard>
|
||||||
return new VampireFangsMCard(owner);
|
return new VampireFangsMCard(owner);
|
||||||
case MCardId.GolemFist:
|
case MCardId.GolemFist:
|
||||||
return new GolemFistMCard(owner);
|
return new GolemFistMCard(owner);
|
||||||
|
case MCardId.QuickSwiftDeath:
|
||||||
|
return new QuickSwiftDeathMCard(owner);
|
||||||
default:
|
default:
|
||||||
throw new System.ArgumentException("MCardId unknown", "id");
|
throw new System.ArgumentException("MCardId unknown", "id");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
5
TODO.txt
5
TODO.txt
|
|
@ -1,3 +1,2 @@
|
||||||
- Make battle end as state based effect
|
- Rename CardId to HCardId
|
||||||
- Check death as state based effect
|
- Animate rearrange hand after card is used
|
||||||
- Rename CardId to HCardId
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue