Create MonsterCard
This commit is contained in:
parent
169210efbe
commit
cce0b2891c
22 changed files with 203 additions and 27 deletions
|
|
@ -5,24 +5,19 @@ using UnityEngine;
|
|||
public abstract class BaseCard
|
||||
{
|
||||
protected BattleParticipant owner;
|
||||
protected CardId id;
|
||||
protected string displayName;
|
||||
protected int cost;
|
||||
protected CardType type;
|
||||
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.id = id;
|
||||
this.displayName = displayName;
|
||||
this.cost = cost;
|
||||
this.type = type;
|
||||
this.effectText = effectText;
|
||||
}
|
||||
|
||||
public abstract IEnumerator Use(IBattleEffectApplier effectApplier, BattlePlayerControls playerControls);
|
||||
|
||||
public CardId GetId() {return this.id;}
|
||||
public string GetDisplayName() {return this.displayName;}
|
||||
public int GetCost() {return this.cost;}
|
||||
public string GetDisplayType() {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffectResolver
|
||||
public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffectResolver, MonsterViewpoint
|
||||
{
|
||||
public HeroId[] heroIds;
|
||||
public MonsterId[] monsterIds;
|
||||
|
|
@ -77,8 +77,8 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
this.playArea = new PlayArea();
|
||||
|
||||
this.battlePlayerControls.Init(this.heroDeck, this.playArea);
|
||||
this.battlePlayerControls.OnCardUsed += this.NotifyCardUsed;
|
||||
this.battlePlayerControls.OnTurnPassed += this.NotifyTurnPassed;
|
||||
this.battlePlayerControls.OnCardUsed += this.NotifyHeroCardUsed;
|
||||
this.battlePlayerControls.OnTurnPassed += this.NotifyHeroTurnPassed;
|
||||
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());
|
||||
}
|
||||
|
||||
public void NotifyCardUsed(BaseCard card) {
|
||||
if (!CanUseCard(card)) {
|
||||
public void NotifyHeroCardUsed(HeroCard card) {
|
||||
if (!CanUseHeroCard(card)) {
|
||||
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);
|
||||
PayCardCost(card);
|
||||
this.heroDeck.RemoveCardFromHand(card);
|
||||
|
|
@ -159,17 +159,17 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
}
|
||||
}
|
||||
|
||||
public void NotifyTurnPassed() {
|
||||
public void NotifyHeroTurnPassed() {
|
||||
if (this.heroTurn) {
|
||||
StartEnemyTurn();
|
||||
}
|
||||
}
|
||||
|
||||
public bool CanUseCard(BaseCard card) {
|
||||
public bool CanUseHeroCard(HeroCard card) {
|
||||
return this.heroTurn && this.energy >= card.GetCost();
|
||||
}
|
||||
|
||||
private void PayCardCost(BaseCard card) {
|
||||
private void PayCardCost(HeroCard card) {
|
||||
this.energy -= card.GetCost();
|
||||
}
|
||||
|
||||
|
|
@ -237,6 +237,11 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
return damageDealt;
|
||||
}
|
||||
|
||||
public int Heal(HealEffect effect) {
|
||||
int healedAmount = effect.Target.Heal(effect.Amount);
|
||||
return healedAmount;
|
||||
}
|
||||
|
||||
public void AddBlock(BattleParticipant target, int amount) {
|
||||
target.AddBlock(amount);
|
||||
}
|
||||
|
|
@ -258,4 +263,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
// Cleanup expired triggers
|
||||
this.damageTriggers.RemoveAll(t => t.Expired);
|
||||
}
|
||||
|
||||
// MonsterViewpoint
|
||||
public BattleHero[] Heroes {get => this.heroes;}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,12 @@ public class BattleParticipant
|
|||
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) {
|
||||
this.block += block;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
|
|
@ -9,7 +10,7 @@ public class BattlePlayerControls : MonoBehaviour
|
|||
public GameObject uiCanvas;
|
||||
public GameObject cardPrefab;
|
||||
|
||||
public delegate void CardUsedAction(BaseCard card);
|
||||
public delegate void CardUsedAction(HeroCard card);
|
||||
public event CardUsedAction OnCardUsed;
|
||||
public delegate void TurnPassedAction();
|
||||
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) {
|
||||
foreach (GameObject cardInHandUI in this.cardsInHandUIs) {
|
||||
Destroy(cardInHandUI);
|
||||
|
|
@ -48,7 +49,7 @@ public class BattlePlayerControls : MonoBehaviour
|
|||
|
||||
this.cardsInHandUIs = new List<GameObject>();
|
||||
for (int i = 0; i < hand.Count; i++) {
|
||||
BaseCard card = hand[i];
|
||||
HeroCard card = hand[i];
|
||||
GameObject cardUI = Instantiate(this.cardPrefab, this.uiCanvas.transform);
|
||||
this.cardsInHandUIs.Add(cardUI);
|
||||
cardUI.transform.position = CalculateHandCardPosition(i, hand.Count);
|
||||
|
|
@ -70,9 +71,9 @@ public class BattlePlayerControls : MonoBehaviour
|
|||
0);
|
||||
}
|
||||
|
||||
private void OnCardClicked(BaseCard card) {
|
||||
private void OnCardClicked(HeroCard card) {
|
||||
if (this.singleTargeting == null) {
|
||||
if (this.battleController.CanUseCard(card)) {
|
||||
if (this.battleController.CanUseHeroCard(card)) {
|
||||
OnCardUsed(card);
|
||||
}
|
||||
}
|
||||
|
|
@ -103,7 +104,7 @@ public class BattlePlayerControls : MonoBehaviour
|
|||
}
|
||||
|
||||
public void NotifyHandPileChanged() {
|
||||
SetHand(this.heroDeck.GetHandPile());
|
||||
SetHand(this.heroDeck.GetHandPile().Cast<HeroCard>().ToList());
|
||||
}
|
||||
|
||||
private void NotifyPlayAreaChanged() {
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CardCover : BaseCard
|
||||
public class CardCover : HeroCard
|
||||
{
|
||||
public CardCover(BattleParticipant owner)
|
||||
: base(owner, CardId.Cover, "Cover", 1, CardType.Skill,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CardCrashingPunch : BaseCard
|
||||
public class CardCrashingPunch : HeroCard
|
||||
{
|
||||
public CardCrashingPunch(BattleParticipant owner)
|
||||
: base(owner, CardId.CrashingPunch, "Crashing Punch", 3, CardType.Attack,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CardLightningStrike : BaseCard
|
||||
public class CardLightningStrike : HeroCard
|
||||
{
|
||||
public CardLightningStrike(BattleParticipant owner)
|
||||
: base(owner, CardId.LightningStrike, "Lightning Strike", 2, CardType.Attack,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ using System.Collections;
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CardScarring : BaseCard
|
||||
public class CardScarring : HeroCard
|
||||
{
|
||||
public CardScarring(BattleParticipant owner)
|
||||
: base(owner, CardId.Scarring, "Scarring", 2, CardType.Skill,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public class CardThunderstorm : BaseCard
|
||||
public class CardThunderstorm : HeroCard
|
||||
{
|
||||
public CardThunderstorm(BattleParticipant owner)
|
||||
: base(owner, CardId.Thunderstorm, "Thunderstorm", 3, CardType.Enchantment,
|
||||
|
|
|
|||
26
Assets/Battle/CardsMonsters/MCardVampireFangs.cs
Normal file
26
Assets/Battle/CardsMonsters/MCardVampireFangs.cs
Normal 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];
|
||||
}
|
||||
}
|
||||
11
Assets/Battle/CardsMonsters/MCardVampireFangs.cs.meta
Normal file
11
Assets/Battle/CardsMonsters/MCardVampireFangs.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6958b53630a12ff42b90786d9ce5ff1b
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
21
Assets/Battle/Effects/HealEffect.cs
Normal file
21
Assets/Battle/Effects/HealEffect.cs
Normal 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;}
|
||||
}
|
||||
11
Assets/Battle/Effects/HealEffect.cs.meta
Normal file
11
Assets/Battle/Effects/HealEffect.cs.meta
Normal 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
18
Assets/Battle/HeroCard.cs
Normal 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;}
|
||||
}
|
||||
11
Assets/Battle/HeroCard.cs.meta
Normal file
11
Assets/Battle/HeroCard.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: cf5116ff6cdebb74398b8f8d441f0a00
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
|
|
@ -4,6 +4,7 @@ using UnityEngine;
|
|||
|
||||
public interface IBattleEffectResolver {
|
||||
int DealDamage(DealDamageEffect effect);
|
||||
int Heal(HealEffect effect);
|
||||
void AddBlock(BattleParticipant target, int amount);
|
||||
void IncreaseHeroMaxEnergy(int delta);
|
||||
void IncreaseMaxHP(IncreaseMaxHPEffect effect);
|
||||
|
|
|
|||
16
Assets/Battle/MonsterCard.cs
Normal file
16
Assets/Battle/MonsterCard.cs
Normal 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);
|
||||
}
|
||||
11
Assets/Battle/MonsterCard.cs.meta
Normal file
11
Assets/Battle/MonsterCard.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 0aa2fbe8443d291409d7d31e64516572
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
11
Assets/Battle/MonsterCardDatabase.cs
Normal file
11
Assets/Battle/MonsterCardDatabase.cs
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public enum MCardId {
|
||||
VampireFangs,
|
||||
}
|
||||
|
||||
public static class MonsterCardDatabase
|
||||
{
|
||||
}
|
||||
11
Assets/Battle/MonsterCardDatabase.cs.meta
Normal file
11
Assets/Battle/MonsterCardDatabase.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 6a2709429808ed54293ff6ce26aa1fe0
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
7
Assets/Battle/MonsterViewpoint.cs
Normal file
7
Assets/Battle/MonsterViewpoint.cs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
public interface MonsterViewpoint {
|
||||
BattleHero[] Heroes {get;}
|
||||
}
|
||||
11
Assets/Battle/MonsterViewpoint.cs.meta
Normal file
11
Assets/Battle/MonsterViewpoint.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c235e6491d6458a4ab8dbb587ebd8866
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Loading…
Add table
Add a link
Reference in a new issue