Implement Meditate

This commit is contained in:
henriquenakashima 2020-09-22 01:09:20 -04:00
parent 03ca23d484
commit ceb46f98b2
14 changed files with 207 additions and 28 deletions

View file

@ -35,6 +35,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
private bool heroPassedTurn;
private EnergyPool heroEnergy;
private EnergyPool monsterEnergy;
private InsightLevel insightLevel;
void Awake() {
this.heroCardDatabase = new HeroCardDatabase();
@ -47,6 +48,8 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
this.monsterEnergyUI.Init(this.monsterEnergy);
this.monsterEnergy.OnEnergyChanged += this.monsterEnergyUI.NotifyEnergyChanged;
this.insightLevel = new InsightLevel(1);
heroes = new BattleHero[3];
heroSprites = new GameObject[3];
heroUIs = new HeroInfoUI[3];
@ -109,9 +112,11 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
this.playArea = new PlayArea();
this.battlePlayerControls.Init(this.heroDeck, this.monsterDeck, this.playArea);
this.battlePlayerControls.Init(
this.heroDeck, this.monsterDeck, this.playArea, this.insightLevel);
this.battlePlayerControls.OnCardUsed += this.NotifyHeroCardUsed;
this.battlePlayerControls.OnTurnPassed += this.NotifyHeroTurnPassed;
this.insightLevel.OnChanged += this.battlePlayerControls.NotifyInsightLevelChanged;
this.heroDeck.OnHandPileChanged += this.battlePlayerControls.NotifyHeroHandPileChanged;
this.monsterDeck.OnHandPileChanged += this.battlePlayerControls.NotifyMonsterHandPileChanged;
}
@ -215,9 +220,9 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
}
public IEnumerator UseHeroCard(HeroCard card) {
yield return card.Use(this, battlePlayerControls);
this.heroEnergy.PayForCard(card);
this.heroDeck.RemoveCardFromHand(card);
yield return card.Use(this, battlePlayerControls);
if (card.IsPermanent()) {
this.playArea.AddPlayedHeroPermanent(card);
} else {
@ -229,9 +234,9 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
}
public IEnumerator UseMonsterCard(MonsterCard card) {
yield return card.Use(this, this);
this.monsterEnergy.PayForCard(card);
this.monsterDeck.RemoveCardFromHand(card);
yield return card.Use(this, this);
if (card.IsPermanent()) {
this.playArea.AddPlayedMonsterPermanent(card);
} else {
@ -311,6 +316,22 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
effect.Target.IncreaseMaxHP(effect.Amount);
}
public void ModifyInsight(ModifyInsightEffect effect) {
this.insightLevel.Modify(effect.Amount);
}
public void DrawCards(DrawCardsEffect effect) {
if (effect.Team == TeamChoice.Heroes) {
for (int i = 0; i < effect.Amount; i++) {
this.heroDeck.DrawCard();
}
} else {
for (int i = 0; i < effect.Amount; i++) {
this.monsterDeck.DrawCard();
}
}
}
public void AcquireCards(AcquireCardsEffect effect) {
if (effect.Participant == null) return;
@ -349,11 +370,9 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
private List<DamageTrigger> damageTriggers = new List<DamageTrigger>();
public int DealDamage(DealDamageEffect effect) {
Debug.Log("DealDamage to " + effect.Target.GetDisplayName() + " " + effect.Amount);
if (effect.Target == null) return 0;
int damageDealt = effect.Target.DealDamage(effect.Amount);
Debug.Log("damageDealt " + damageDealt);
foreach (DamageTrigger dt in this.damageTriggers) {
if (dt.IsTriggeredBy(effect)) {
EnqueueActivatedTrigger(dt);

View file

@ -20,22 +20,27 @@ public class BattlePlayerControls : MonoBehaviour
private BattleDeck<HeroCard> heroDeck;
private BattleDeck<MonsterCard> monsterDeck;
private PlayArea playArea;
private InsightLevel insightLevel;
private HandControls<HeroCard> heroHandControls;
private HandControls<MonsterCard> monsterHandControls;
private Dictionary<BaseCard, GameObject> cardsInPlayUIs;
public void Init(
BattleDeck<HeroCard> heroDeck, BattleDeck<MonsterCard> monsterDeck, PlayArea playArea) {
BattleDeck<HeroCard> heroDeck, BattleDeck<MonsterCard> monsterDeck, PlayArea playArea,
InsightLevel insightLevel) {
this.heroDeck = heroDeck;
this.monsterDeck = monsterDeck;
this.playArea = playArea;
this.insightLevel = insightLevel;
this.heroHandControls = new HandControls<HeroCard>(this.uiCanvas, this.cardPrefab, HandControlsPosition.Bottom, int.MaxValue);
this.heroHandControls.OnCardClicked += OnHeroCardClicked;
this.monsterHandControls = new HandControls<MonsterCard>(this.uiCanvas, this.cardPrefab, HandControlsPosition.Top, 1);
this.monsterHandControls.OnCardClicked += OnMonsterCardClicked;
this.cardsInPlayUIs = new Dictionary<BaseCard, GameObject>();
NotifyInsightLevelChanged();
}
// Start is called before the first frame update
@ -143,4 +148,8 @@ public class BattlePlayerControls : MonoBehaviour
Screen.height - PADDING - DELTA * index - BattleCardPrefabConstants.CARD_HEIGHT / 2,
0);
}
public void NotifyInsightLevelChanged() {
this.monsterHandControls.InsightLevel = this.insightLevel.Level;
}
}

View file

@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MeditateHCard : HeroCard
{
public MeditateHCard(BattleParticipant owner)
: base(owner, CardId.Meditate, "Meditate", 2, CardType.Skill, "+1 insight. Draw a card.") {
}
public override IEnumerator Use(
IBattleEffectApplier effectApplier, BattlePlayerControls playerControls) {
effectApplier.Apply(new ModifyInsightEffect(+1));
yield return new WaitForSeconds(1f);
effectApplier.Apply(new DrawCardsEffect(1, TeamChoice.Heroes));
yield break;
}
}

View file

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

View file

@ -0,0 +1,26 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public enum TeamChoice {
Heroes,
Monsters,
}
public class DrawCardsEffect : IBattleEffect
{
private int amount;
private TeamChoice team;
public DrawCardsEffect(int amount, TeamChoice team) {
this.amount = amount;
this.team = team;
}
public void Apply(IBattleEffectResolver resolver) {
resolver.DrawCards(this);
}
public int Amount {get => this.amount;}
public TeamChoice Team {get => this.team;}
}

View file

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

View file

@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
public class ModifyInsightEffect : IBattleEffect
{
private int amount;
public ModifyInsightEffect(int amount) {
this.amount = amount;
}
public void Apply(IBattleEffectResolver resolver) {
resolver.ModifyInsight(this);
}
public int Amount {get => this.amount;}
}

View file

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

View file

@ -18,6 +18,7 @@ public class HandControls<BaseCardT> where BaseCardT : BaseCard
private GameObject cardPrefab;
private HandControlsPosition position;
private List<BaseCardT> hand;
private List<GameObject> cardsInHandUIs;
private int insightLevel;
@ -30,27 +31,8 @@ public class HandControls<BaseCardT> where BaseCardT : BaseCard
}
public void SetHand(List<BaseCardT> hand) {
if (this.cardsInHandUIs != null) {
foreach (GameObject cardInHandUI in this.cardsInHandUIs) {
GameObject.Destroy(cardInHandUI);
}
}
this.cardsInHandUIs = new List<GameObject>();
for (int i = 0; i < hand.Count; i++) {
BaseCardT card = hand[i];
GameObject cardUI = GameObject.Instantiate(this.cardPrefab, this.uiCanvas.transform);
this.cardsInHandUIs.Add(cardUI);
cardUI.transform.position = CalculateHandCardPosition(i, hand.Count);
CardUI cardUIScript = cardUI.GetComponent<CardUI>();
if (i < this.insightLevel) {
cardUIScript.Init(card);
} else {
cardUIScript.InitHidden();
}
int cardIndex = i;
cardUI.GetComponent<Button>().onClick.AddListener(delegate {OnCardClicked(card);});
}
this.hand = hand;
DrawHand();
}
private Vector3 CalculateHandCardPosition(int index, int count) {
@ -65,5 +47,39 @@ public class HandControls<BaseCardT> where BaseCardT : BaseCard
return new Vector3(x, y, 0);
}
public int InsightLevel {get => this.insightLevel; set => this.insightLevel = value;}
public int InsightLevel {
get => this.insightLevel;
set {
this.insightLevel = value;
DrawHand();
}
}
private void DrawHand() {
if (this.hand == null) {
return;
}
if (this.cardsInHandUIs != null) {
foreach (GameObject cardInHandUI in this.cardsInHandUIs) {
GameObject.Destroy(cardInHandUI);
}
}
this.cardsInHandUIs = new List<GameObject>();
for (int i = 0; i < this.hand.Count; i++) {
BaseCardT card = this.hand[i];
GameObject cardUI = GameObject.Instantiate(this.cardPrefab, this.uiCanvas.transform);
this.cardsInHandUIs.Add(cardUI);
cardUI.transform.position = CalculateHandCardPosition(i, this.hand.Count);
CardUI cardUIScript = cardUI.GetComponent<CardUI>();
if (i < this.insightLevel) {
cardUIScript.Init(card);
} else {
cardUIScript.InitHidden();
}
int cardIndex = i;
cardUI.GetComponent<Button>().onClick.AddListener(delegate {OnCardClicked(card);});
}
}
}

View file

@ -29,6 +29,7 @@ public class HeroCardDatabase : CardDatabase<HeroCard>
{CardId.LightningStrike, HeroId.Shaman},
{CardId.Scarring, HeroId.Brute},
{CardId.Thunderstorm, HeroId.Shaman},
{CardId.Meditate, HeroId.Shaman},
};
public override HeroCard CreateCard(int id, BattleParticipant owner) {
@ -45,6 +46,8 @@ public class HeroCardDatabase : CardDatabase<HeroCard>
return new CardScarring(owner);
case CardId.Thunderstorm:
return new CardThunderstorm(owner);
case CardId.Meditate:
return new MeditateHCard(owner);
default:
throw new System.ArgumentException("CardId unknown", "id");
}

View file

@ -9,6 +9,8 @@ public interface IBattleEffectResolver {
void AddStatus(StatusEffect effect);
void IncreaseHeroMaxEnergy(IncreaseMaxEnergyEffect delta);
void IncreaseMaxHP(IncreaseMaxHPEffect effect);
void ModifyInsight(ModifyInsightEffect effect);
void DrawCards(DrawCardsEffect effect);
void AcquireCards(AcquireCardsEffect effect);
void ArmDamageTrigger(DamageTrigger damageTrigger);

View file

@ -0,0 +1,23 @@
public class InsightLevel {
public delegate void InsightLevelChangedAction();
public event InsightLevelChangedAction OnChanged;
private int level;
public InsightLevel(int initialLevel) {
this.level = initialLevel;
}
public void Modify(int amount) {
int previousLevel = this.level;
this.level += amount;
if (this.level < 0) this.level = 0;
if (this.level != previousLevel && this.OnChanged != null) {
this.OnChanged();
}
}
public int Level {get => this.level;}
}

View file

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

View file

@ -3,3 +3,4 @@
- Make hero cards be used in sequence Coroutines, not in parallel
- Do not Highlight unusable cards
- Dim unusable cards
- Rename HCard classes