Only alive participants can act
This commit is contained in:
parent
a5a96edf25
commit
adc84f9aba
5 changed files with 44 additions and 8 deletions
|
|
@ -18,6 +18,7 @@ public abstract class BaseCard
|
||||||
this.effectText = effectText;
|
this.effectText = effectText;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public BattleParticipant Owner {get => this.owner;}
|
||||||
public string GetDisplayName() {return this.displayName;}
|
public string GetDisplayName() {return this.displayName;}
|
||||||
public int GetCost() {return this.cost;}
|
public int GetCost() {return this.cost;}
|
||||||
public string GetDisplayType() {
|
public string GetDisplayType() {
|
||||||
|
|
|
||||||
|
|
@ -62,6 +62,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
||||||
BattleParticipantSprite bps = heroSprites[i].AddComponent<BattleParticipantSprite>();
|
BattleParticipantSprite bps = heroSprites[i].AddComponent<BattleParticipantSprite>();
|
||||||
bps.Init(battlePlayerControls, heroes[i]);
|
bps.Init(battlePlayerControls, heroes[i]);
|
||||||
bps.OnSpriteClicked += battlePlayerControls.NotifyParticipantSpriteClicked;
|
bps.OnSpriteClicked += battlePlayerControls.NotifyParticipantSpriteClicked;
|
||||||
|
heroes[i].OnDeath += bps.NotifyDeath;
|
||||||
|
|
||||||
heroUIs[i] = (HeroInfoUI) Instantiate(heroUIPrefab.gameObject, uiCanvas.transform).GetComponent(typeof(HeroInfoUI));
|
heroUIs[i] = (HeroInfoUI) Instantiate(heroUIPrefab.gameObject, uiCanvas.transform).GetComponent(typeof(HeroInfoUI));
|
||||||
heroUIs[i].Init(heroSprites[i], heroes[i]);
|
heroUIs[i].Init(heroSprites[i], heroes[i]);
|
||||||
|
|
@ -82,6 +83,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
||||||
BattleParticipantSprite bps = monsterSprites[i].AddComponent<BattleParticipantSprite>();
|
BattleParticipantSprite bps = monsterSprites[i].AddComponent<BattleParticipantSprite>();
|
||||||
bps.Init(battlePlayerControls, monsters[i]);
|
bps.Init(battlePlayerControls, monsters[i]);
|
||||||
bps.OnSpriteClicked += battlePlayerControls.NotifyParticipantSpriteClicked;
|
bps.OnSpriteClicked += battlePlayerControls.NotifyParticipantSpriteClicked;
|
||||||
|
monsters[i].OnDeath += bps.NotifyDeath;
|
||||||
|
|
||||||
monsterUIs[i] = (HeroInfoUI) Instantiate(heroUIPrefab.gameObject, uiCanvas.transform).GetComponent(typeof(HeroInfoUI));
|
monsterUIs[i] = (HeroInfoUI) Instantiate(heroUIPrefab.gameObject, uiCanvas.transform).GetComponent(typeof(HeroInfoUI));
|
||||||
monsterUIs[i].Init(monsterSprites[i], monsters[i]);
|
monsterUIs[i].Init(monsterSprites[i], monsters[i]);
|
||||||
|
|
@ -237,11 +239,11 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CanUseHeroCard(HeroCard card) {
|
public bool CanUseHeroCard(HeroCard card) {
|
||||||
return this.heroTurn && this.heroEnergy.CanPayForCard(card);
|
return this.heroTurn && card.Owner.IsAlive() && this.heroEnergy.CanPayForCard(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool CanUseMonsterCard(MonsterCard card) {
|
public bool CanUseMonsterCard(MonsterCard card) {
|
||||||
return !this.heroTurn && this.monsterEnergy.CanPayForCard(card);
|
return !this.heroTurn && card.Owner.IsAlive() && this.monsterEnergy.CanPayForCard(card);
|
||||||
}
|
}
|
||||||
|
|
||||||
public BattleDeck<HeroCard> GetHeroDeck() {
|
public BattleDeck<HeroCard> GetHeroDeck() {
|
||||||
|
|
|
||||||
|
|
@ -5,11 +5,15 @@ using UnityEngine;
|
||||||
|
|
||||||
public class BattleParticipant
|
public class BattleParticipant
|
||||||
{
|
{
|
||||||
|
public delegate void DeathAction(BattleParticipant participant);
|
||||||
|
public event DeathAction OnDeath;
|
||||||
|
|
||||||
protected bool isHero;
|
protected bool isHero;
|
||||||
protected string displayName;
|
protected string displayName;
|
||||||
protected int hp;
|
protected int hp;
|
||||||
protected int maxHP;
|
protected int maxHP;
|
||||||
protected int block;
|
protected int block;
|
||||||
|
protected bool dead;
|
||||||
|
|
||||||
public BattleParticipant(bool isHero) {
|
public BattleParticipant(bool isHero) {
|
||||||
this.isHero = isHero;
|
this.isHero = isHero;
|
||||||
|
|
@ -32,7 +36,7 @@ public class BattleParticipant
|
||||||
}
|
}
|
||||||
|
|
||||||
public bool IsAlive() {
|
public bool IsAlive() {
|
||||||
return this.hp > 0;
|
return !this.dead;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int DealDamage(int damage) {
|
public int DealDamage(int damage) {
|
||||||
|
|
@ -43,6 +47,10 @@ public class BattleParticipant
|
||||||
}
|
}
|
||||||
damage = Math.Min(this.hp, damage);
|
damage = Math.Min(this.hp, damage);
|
||||||
this.hp -= damage;
|
this.hp -= damage;
|
||||||
|
if (this.hp <= 0) {
|
||||||
|
this.dead = true;
|
||||||
|
TriggerOnDeath();
|
||||||
|
}
|
||||||
return damage;
|
return damage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -78,4 +86,10 @@ public class BattleParticipant
|
||||||
this.hp += amount;
|
this.hp += amount;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void TriggerOnDeath() {
|
||||||
|
if (this.OnDeath != null) {
|
||||||
|
this.OnDeath(this);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -9,10 +9,12 @@ public class BattleParticipantSprite : MonoBehaviour
|
||||||
|
|
||||||
private BattlePlayerControls playerControls;
|
private BattlePlayerControls playerControls;
|
||||||
private BattleParticipant participant;
|
private BattleParticipant participant;
|
||||||
|
private bool removedFromBattle;
|
||||||
|
|
||||||
public void Init(BattlePlayerControls playerControls, BattleParticipant participant) {
|
public void Init(BattlePlayerControls playerControls, BattleParticipant participant) {
|
||||||
this.playerControls = playerControls;
|
this.playerControls = playerControls;
|
||||||
this.participant = participant;
|
this.participant = participant;
|
||||||
|
this.removedFromBattle = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start is called before the first frame update
|
// Start is called before the first frame update
|
||||||
|
|
@ -22,20 +24,22 @@ public class BattleParticipantSprite : MonoBehaviour
|
||||||
|
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update() {
|
void Update() {
|
||||||
if (colorChanged && !this.playerControls.CouldTarget(participant)) {
|
if (this.colorChanged && !this.playerControls.CouldTarget(participant)) {
|
||||||
OnMouseExit();
|
OnMouseExit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void OnMouseDown() {
|
void OnMouseDown() {
|
||||||
OnSpriteClicked(participant);
|
if (!this.removedFromBattle) {
|
||||||
|
OnSpriteClicked(participant);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private Color savedColor;
|
private Color savedColor;
|
||||||
private bool colorChanged;
|
private bool colorChanged;
|
||||||
|
|
||||||
void OnMouseEnter() {
|
void OnMouseEnter() {
|
||||||
if (this.playerControls.CouldTarget(participant)) {
|
if (!this.removedFromBattle && this.playerControls.CouldTarget(participant)) {
|
||||||
SpriteRenderer sprite = GetComponent<SpriteRenderer>();
|
SpriteRenderer sprite = GetComponent<SpriteRenderer>();
|
||||||
this.savedColor = sprite.color;
|
this.savedColor = sprite.color;
|
||||||
sprite.color = Color.Lerp(this.savedColor, Color.white, .5f);
|
sprite.color = Color.Lerp(this.savedColor, Color.white, .5f);
|
||||||
|
|
@ -50,4 +54,19 @@ public class BattleParticipantSprite : MonoBehaviour
|
||||||
this.colorChanged = false;
|
this.colorChanged = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void NotifyDeath(BattleParticipant deadParticipant) {
|
||||||
|
if (deadParticipant != this.participant) {
|
||||||
|
throw new System.InvalidOperationException(
|
||||||
|
"BattleParticipantSprite received NotifyDeath from another battle participant.");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.removedFromBattle) {
|
||||||
|
SpriteRenderer sprite = GetComponent<SpriteRenderer>();
|
||||||
|
sprite.enabled = false;
|
||||||
|
BoxCollider2D collider = GetComponent<BoxCollider2D>();
|
||||||
|
collider.enabled = false;
|
||||||
|
this.removedFromBattle = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
4
TODO.txt
4
TODO.txt
|
|
@ -1,3 +1,3 @@
|
||||||
- Make battle end
|
- Make battle end as state based effect
|
||||||
- Do not allow dead heroes to act
|
- Check death as state based effect
|
||||||
- Rename CardId to HCardId
|
- Rename CardId to HCardId
|
||||||
Loading…
Add table
Add a link
Reference in a new issue