Create MonsterCard

This commit is contained in:
henriquenakashima 2020-09-19 23:25:42 -04:00
parent 169210efbe
commit cce0b2891c
22 changed files with 203 additions and 27 deletions

View file

@ -5,24 +5,19 @@ using UnityEngine;
public abstract class BaseCard public abstract class BaseCard
{ {
protected BattleParticipant owner; protected BattleParticipant owner;
protected CardId id;
protected string displayName; protected string displayName;
protected int cost; protected int cost;
protected CardType type; protected CardType type;
protected string effectText; protected string effectText;
public BaseCard(BattleParticipant owner, CardId id, string displayName, int cost, CardType type, string effectText) { public BaseCard(BattleParticipant owner, string displayName, int cost, CardType type, string effectText) {
this.owner = owner; this.owner = owner;
this.id = id;
this.displayName = displayName; this.displayName = displayName;
this.cost = cost; this.cost = cost;
this.type = type; this.type = type;
this.effectText = effectText; this.effectText = effectText;
} }
public abstract IEnumerator Use(IBattleEffectApplier effectApplier, BattlePlayerControls playerControls);
public CardId GetId() {return this.id;}
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() {

View file

@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffectResolver public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffectResolver, MonsterViewpoint
{ {
public HeroId[] heroIds; public HeroId[] heroIds;
public MonsterId[] monsterIds; public MonsterId[] monsterIds;
@ -77,8 +77,8 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
this.playArea = new PlayArea(); this.playArea = new PlayArea();
this.battlePlayerControls.Init(this.heroDeck, this.playArea); this.battlePlayerControls.Init(this.heroDeck, this.playArea);
this.battlePlayerControls.OnCardUsed += this.NotifyCardUsed; this.battlePlayerControls.OnCardUsed += this.NotifyHeroCardUsed;
this.battlePlayerControls.OnTurnPassed += this.NotifyTurnPassed; this.battlePlayerControls.OnTurnPassed += this.NotifyHeroTurnPassed;
this.heroDeck.OnHandPileChanged += this.battlePlayerControls.NotifyHandPileChanged; this.heroDeck.OnHandPileChanged += this.battlePlayerControls.NotifyHandPileChanged;
} }
@ -141,14 +141,14 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
Debug.Log("Will attack " + this.heroes[this.enemyTarget].GetDisplayName()); Debug.Log("Will attack " + this.heroes[this.enemyTarget].GetDisplayName());
} }
public void NotifyCardUsed(BaseCard card) { public void NotifyHeroCardUsed(HeroCard card) {
if (!CanUseCard(card)) { if (!CanUseHeroCard(card)) {
throw new System.InvalidOperationException("Cannot use card " + card.GetDisplayName()); throw new System.InvalidOperationException("Cannot use card " + card.GetDisplayName());
} }
StartCoroutine(UseCard(card)); StartCoroutine(UseHeroCard(card));
} }
public IEnumerator UseCard(BaseCard card) { public IEnumerator UseHeroCard(HeroCard card) {
yield return card.Use(this, battlePlayerControls); yield return card.Use(this, battlePlayerControls);
PayCardCost(card); PayCardCost(card);
this.heroDeck.RemoveCardFromHand(card); this.heroDeck.RemoveCardFromHand(card);
@ -159,17 +159,17 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
} }
} }
public void NotifyTurnPassed() { public void NotifyHeroTurnPassed() {
if (this.heroTurn) { if (this.heroTurn) {
StartEnemyTurn(); StartEnemyTurn();
} }
} }
public bool CanUseCard(BaseCard card) { public bool CanUseHeroCard(HeroCard card) {
return this.heroTurn && this.energy >= card.GetCost(); return this.heroTurn && this.energy >= card.GetCost();
} }
private void PayCardCost(BaseCard card) { private void PayCardCost(HeroCard card) {
this.energy -= card.GetCost(); this.energy -= card.GetCost();
} }
@ -237,6 +237,11 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
return damageDealt; return damageDealt;
} }
public int Heal(HealEffect effect) {
int healedAmount = effect.Target.Heal(effect.Amount);
return healedAmount;
}
public void AddBlock(BattleParticipant target, int amount) { public void AddBlock(BattleParticipant target, int amount) {
target.AddBlock(amount); target.AddBlock(amount);
} }
@ -258,4 +263,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
// Cleanup expired triggers // Cleanup expired triggers
this.damageTriggers.RemoveAll(t => t.Expired); this.damageTriggers.RemoveAll(t => t.Expired);
} }
// MonsterViewpoint
public BattleHero[] Heroes {get => this.heroes;}
} }

View file

@ -42,6 +42,12 @@ public class BattleParticipant
return damage; return damage;
} }
public int Heal(int amount) {
amount = Math.Min(this.maxHP - this.hp, amount);
this.hp += amount;
return amount;
}
public void AddBlock(int block) { public void AddBlock(int block) {
this.block += block; this.block += block;
} }

View file

@ -1,5 +1,6 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
@ -9,7 +10,7 @@ public class BattlePlayerControls : MonoBehaviour
public GameObject uiCanvas; public GameObject uiCanvas;
public GameObject cardPrefab; public GameObject cardPrefab;
public delegate void CardUsedAction(BaseCard card); public delegate void CardUsedAction(HeroCard card);
public event CardUsedAction OnCardUsed; public event CardUsedAction OnCardUsed;
public delegate void TurnPassedAction(); public delegate void TurnPassedAction();
public event TurnPassedAction OnTurnPassed; public event TurnPassedAction OnTurnPassed;
@ -39,7 +40,7 @@ public class BattlePlayerControls : MonoBehaviour
} }
private void SetHand(List<BaseCard> hand) { private void SetHand(List<HeroCard> hand) {
if (this.cardsInHandUIs != null) { if (this.cardsInHandUIs != null) {
foreach (GameObject cardInHandUI in this.cardsInHandUIs) { foreach (GameObject cardInHandUI in this.cardsInHandUIs) {
Destroy(cardInHandUI); Destroy(cardInHandUI);
@ -48,7 +49,7 @@ public class BattlePlayerControls : MonoBehaviour
this.cardsInHandUIs = new List<GameObject>(); this.cardsInHandUIs = new List<GameObject>();
for (int i = 0; i < hand.Count; i++) { for (int i = 0; i < hand.Count; i++) {
BaseCard card = hand[i]; HeroCard card = hand[i];
GameObject cardUI = Instantiate(this.cardPrefab, this.uiCanvas.transform); GameObject cardUI = Instantiate(this.cardPrefab, this.uiCanvas.transform);
this.cardsInHandUIs.Add(cardUI); this.cardsInHandUIs.Add(cardUI);
cardUI.transform.position = CalculateHandCardPosition(i, hand.Count); cardUI.transform.position = CalculateHandCardPosition(i, hand.Count);
@ -70,9 +71,9 @@ public class BattlePlayerControls : MonoBehaviour
0); 0);
} }
private void OnCardClicked(BaseCard card) { private void OnCardClicked(HeroCard card) {
if (this.singleTargeting == null) { if (this.singleTargeting == null) {
if (this.battleController.CanUseCard(card)) { if (this.battleController.CanUseHeroCard(card)) {
OnCardUsed(card); OnCardUsed(card);
} }
} }
@ -103,7 +104,7 @@ public class BattlePlayerControls : MonoBehaviour
} }
public void NotifyHandPileChanged() { public void NotifyHandPileChanged() {
SetHand(this.heroDeck.GetHandPile()); SetHand(this.heroDeck.GetHandPile().Cast<HeroCard>().ToList());
} }
private void NotifyPlayAreaChanged() { private void NotifyPlayAreaChanged() {

View file

@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class CardCover : BaseCard public class CardCover : HeroCard
{ {
public CardCover(BattleParticipant owner) public CardCover(BattleParticipant owner)
: base(owner, CardId.Cover, "Cover", 1, CardType.Skill, : base(owner, CardId.Cover, "Cover", 1, CardType.Skill,

View file

@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class CardCrashingPunch : BaseCard public class CardCrashingPunch : HeroCard
{ {
public CardCrashingPunch(BattleParticipant owner) public CardCrashingPunch(BattleParticipant owner)
: base(owner, CardId.CrashingPunch, "Crashing Punch", 3, CardType.Attack, : base(owner, CardId.CrashingPunch, "Crashing Punch", 3, CardType.Attack,

View file

@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class CardLightningStrike : BaseCard public class CardLightningStrike : HeroCard
{ {
public CardLightningStrike(BattleParticipant owner) public CardLightningStrike(BattleParticipant owner)
: base(owner, CardId.LightningStrike, "Lightning Strike", 2, CardType.Attack, : base(owner, CardId.LightningStrike, "Lightning Strike", 2, CardType.Attack,

View file

@ -2,7 +2,7 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class CardScarring : BaseCard public class CardScarring : HeroCard
{ {
public CardScarring(BattleParticipant owner) public CardScarring(BattleParticipant owner)
: base(owner, CardId.Scarring, "Scarring", 2, CardType.Skill, : base(owner, CardId.Scarring, "Scarring", 2, CardType.Skill,

View file

@ -2,7 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public class CardThunderstorm : BaseCard public class CardThunderstorm : HeroCard
{ {
public CardThunderstorm(BattleParticipant owner) public CardThunderstorm(BattleParticipant owner)
: base(owner, CardId.Thunderstorm, "Thunderstorm", 3, CardType.Enchantment, : base(owner, CardId.Thunderstorm, "Thunderstorm", 3, CardType.Enchantment,

View file

@ -0,0 +1,26 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MCardVampireFangs : MonsterCard
{
public MCardVampireFangs(BattleParticipant owner)
: base(owner, MCardId.VampireFangs, "VampireFangs", 2, CardType.Attack,
"Steals 2 HP from target.") {
}
public override IEnumerator Use(IBattleEffectApplier effectApplier, MonsterViewpoint monsterViewpoint) {
BattleParticipant target = DetermineTarget(monsterViewpoint);
DealDamageEffect damageEffect = new DealDamageEffect(target, 2);
effectApplier.Apply(damageEffect);
if (damageEffect.AmountDealt > 0) {
HealEffect healEffect = new HealEffect(this.owner, damageEffect.AmountDealt);
effectApplier.Apply(healEffect);
}
yield break;
}
private BattleParticipant DetermineTarget(MonsterViewpoint monsterViewpoint) {
return monsterViewpoint.Heroes[0];
}
}

View file

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

View file

@ -0,0 +1,21 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HealEffect : IBattleEffect
{
private BattleParticipant target;
private int amount;
public HealEffect(BattleParticipant target, int amount) {
this.target = target;
this.amount = amount;
}
public void Apply(IBattleEffectResolver resolver) {
resolver.Heal(this);
}
public BattleParticipant Target {get => this.target;}
public int Amount {get => this.amount;}
}

View file

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

18
Assets/Battle/HeroCard.cs Normal file
View file

@ -0,0 +1,18 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public abstract class HeroCard : BaseCard
{
private CardId id;
public HeroCard(BattleParticipant owner, CardId id, string displayName, int cost, CardType type,
string effectText)
: base(owner, displayName, cost, type, effectText) {
this.id = id;
}
public abstract IEnumerator Use(IBattleEffectApplier effectApplier, BattlePlayerControls playerControls);
public CardId GetId() {return this.id;}
}

View file

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

View file

@ -4,6 +4,7 @@ using UnityEngine;
public interface IBattleEffectResolver { public interface IBattleEffectResolver {
int DealDamage(DealDamageEffect effect); int DealDamage(DealDamageEffect effect);
int Heal(HealEffect effect);
void AddBlock(BattleParticipant target, int amount); void AddBlock(BattleParticipant target, int amount);
void IncreaseHeroMaxEnergy(int delta); void IncreaseHeroMaxEnergy(int delta);
void IncreaseMaxHP(IncreaseMaxHPEffect effect); void IncreaseMaxHP(IncreaseMaxHPEffect effect);

View file

@ -0,0 +1,16 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public abstract class MonsterCard : BaseCard
{
private MCardId id;
public MonsterCard(BattleParticipant owner, MCardId id, string displayName, int cost, CardType type,
string effectText)
: base(owner, displayName, cost, type, effectText) {
this.id = id;
}
public abstract IEnumerator Use(IBattleEffectApplier effectApplier, MonsterViewpoint monsterViewpoint);
}

View file

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

View file

@ -0,0 +1,11 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public enum MCardId {
VampireFangs,
}
public static class MonsterCardDatabase
{
}

View file

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

View file

@ -0,0 +1,7 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public interface MonsterViewpoint {
BattleHero[] Heroes {get;}
}

View file

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