Implement BattleEffects, add Thunderstorm
This commit is contained in:
parent
fc427bd276
commit
00448fe919
20 changed files with 215 additions and 18 deletions
|
|
@ -3,7 +3,8 @@ using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public enum CardType {
|
public enum CardType {
|
||||||
Action
|
Action,
|
||||||
|
Enchantment,
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract class BaseCard
|
public abstract class BaseCard
|
||||||
|
|
@ -24,18 +25,24 @@ public abstract class BaseCard
|
||||||
this.effectText = effectText;
|
this.effectText = effectText;
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract IEnumerator Use(BattlePlayerControls playerControls);
|
public abstract IEnumerator Use(IBattleEffectApplier effectApplier, BattlePlayerControls playerControls);
|
||||||
|
|
||||||
public CardId GetId() {return id;}
|
public CardId GetId() {return this.id;}
|
||||||
public string GetDisplayName() {return displayName;}
|
public string GetDisplayName() {return this.displayName;}
|
||||||
public int GetCost() {return cost;}
|
public int GetCost() {return this.cost;}
|
||||||
public string GetDisplayType() {
|
public string GetDisplayType() {
|
||||||
switch (type) {
|
switch (this.type) {
|
||||||
case CardType.Action:
|
case CardType.Action:
|
||||||
return "";
|
return "Action";
|
||||||
|
case CardType.Enchantment:
|
||||||
|
return "Enchantment";
|
||||||
default:
|
default:
|
||||||
throw new System.ArgumentException("CardType unknown", "cardType");
|
throw new System.ArgumentException("CardType unknown", "cardType");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
public string GetEffectText() {return effectText;}
|
public string GetEffectText() {return this.effectText;}
|
||||||
|
|
||||||
|
public bool IsPermanent() {
|
||||||
|
return this.type == CardType.Enchantment;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
public class BattleController : MonoBehaviour
|
public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffectResolver
|
||||||
{
|
{
|
||||||
public HeroId[] heroIds;
|
public HeroId[] heroIds;
|
||||||
public MonsterId[] monsterIds;
|
public MonsterId[] monsterIds;
|
||||||
|
|
@ -13,6 +13,7 @@ public class BattleController : MonoBehaviour
|
||||||
public BattlePlayerControls battlePlayerControls;
|
public BattlePlayerControls battlePlayerControls;
|
||||||
|
|
||||||
private HeroDeck heroDeck;
|
private HeroDeck heroDeck;
|
||||||
|
private PlayArea playArea;
|
||||||
|
|
||||||
public BattleHero[] heroes;
|
public BattleHero[] heroes;
|
||||||
private GameObject[] heroSprites;
|
private GameObject[] heroSprites;
|
||||||
|
|
@ -77,6 +78,8 @@ public class BattleController : MonoBehaviour
|
||||||
this.battlePlayerControls.OnCardUsed += this.NotifyCardUsed;
|
this.battlePlayerControls.OnCardUsed += this.NotifyCardUsed;
|
||||||
this.battlePlayerControls.OnTurnPassed += this.NotifyTurnPassed;
|
this.battlePlayerControls.OnTurnPassed += this.NotifyTurnPassed;
|
||||||
this.heroDeck.OnHandPileChanged += this.battlePlayerControls.NotifyHandPileChanged;
|
this.heroDeck.OnHandPileChanged += this.battlePlayerControls.NotifyHandPileChanged;
|
||||||
|
|
||||||
|
this.playArea = new PlayArea();
|
||||||
}
|
}
|
||||||
|
|
||||||
private BattleParticipant FindHeroByClass(HeroId heroId) {
|
private BattleParticipant FindHeroByClass(HeroId heroId) {
|
||||||
|
|
@ -144,9 +147,14 @@ public class BattleController : MonoBehaviour
|
||||||
}
|
}
|
||||||
|
|
||||||
public IEnumerator UseCard(BaseCard card) {
|
public IEnumerator UseCard(BaseCard card) {
|
||||||
yield return card.Use(battlePlayerControls);
|
yield return card.Use(this, battlePlayerControls);
|
||||||
PayCardCost(card);
|
PayCardCost(card);
|
||||||
this.heroDeck.DiscardPlayedCard(card);
|
this.heroDeck.RemoveCardFromHand(card);
|
||||||
|
if (card.IsPermanent()) {
|
||||||
|
this.playArea.AddPlayedHeroPermanent(card);
|
||||||
|
} else {
|
||||||
|
this.heroDeck.MoveCardToDiscard(card);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void NotifyTurnPassed() {
|
public void NotifyTurnPassed() {
|
||||||
|
|
@ -175,4 +183,18 @@ public class BattleController : MonoBehaviour
|
||||||
public HeroDeck GetHeroDeck() {
|
public HeroDeck GetHeroDeck() {
|
||||||
return this.heroDeck;
|
return this.heroDeck;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public PlayArea GetPlayArea() {
|
||||||
|
return this.playArea;
|
||||||
|
}
|
||||||
|
|
||||||
|
// IBattleEffectApplier
|
||||||
|
public void Apply(IBattleEffect effect) {
|
||||||
|
effect.Apply(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// IBattleEffectResolver
|
||||||
|
public void IncreaseMaxEnergy(int delta) {
|
||||||
|
this.maxEnergy += delta;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -305,8 +305,7 @@ MonoBehaviour:
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
heroIds: 010000000000000002000000
|
heroIds: 010000000000000002000000
|
||||||
monsterIds: 000000000100000000000000
|
monsterIds: 000000000100000000000000
|
||||||
maxEnergy: 1
|
cardIds: 00000000000000000000000000000000000000000100000001000000010000000100000002000000
|
||||||
cardIds: 00000000000000000000000000000000000000000100000001000000010000000100000001000000
|
|
||||||
heroUIPrefab: {fileID: 6641511084601005557, guid: ef1b469b45cedee418e4c4adf577cd00,
|
heroUIPrefab: {fileID: 6641511084601005557, guid: ef1b469b45cedee418e4c4adf577cd00,
|
||||||
type: 3}
|
type: 3}
|
||||||
uiCanvas: {fileID: 35522588}
|
uiCanvas: {fileID: 35522588}
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,8 @@ using UnityEngine;
|
||||||
|
|
||||||
public enum CardId {
|
public enum CardId {
|
||||||
CrashingPunch,
|
CrashingPunch,
|
||||||
Cover
|
Cover,
|
||||||
|
Thunderstorm,
|
||||||
}
|
}
|
||||||
|
|
||||||
public class CardDatabase
|
public class CardDatabase
|
||||||
|
|
@ -12,6 +13,7 @@ public class CardDatabase
|
||||||
private static Dictionary<CardId, HeroId> CARD_TO_HERO = new Dictionary<CardId, HeroId>() {
|
private static Dictionary<CardId, HeroId> CARD_TO_HERO = new Dictionary<CardId, HeroId>() {
|
||||||
{CardId.CrashingPunch, HeroId.Brute},
|
{CardId.CrashingPunch, HeroId.Brute},
|
||||||
{CardId.Cover, HeroId.Brute},
|
{CardId.Cover, HeroId.Brute},
|
||||||
|
{CardId.Thunderstorm, HeroId.Shaman},
|
||||||
};
|
};
|
||||||
|
|
||||||
public static BaseCard CreateCard(CardId id, BattleParticipant owner) {
|
public static BaseCard CreateCard(CardId id, BattleParticipant owner) {
|
||||||
|
|
@ -21,6 +23,8 @@ public class CardDatabase
|
||||||
return new CardCrashingPunch(owner);
|
return new CardCrashingPunch(owner);
|
||||||
case CardId.Cover:
|
case CardId.Cover:
|
||||||
return new CardCover(owner);
|
return new CardCover(owner);
|
||||||
|
case CardId.Thunderstorm:
|
||||||
|
return new CardThunderstorm(owner);
|
||||||
default:
|
default:
|
||||||
throw new System.ArgumentException("CardId unknown", "id");
|
throw new System.ArgumentException("CardId unknown", "id");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ public class CardCover : BaseCard
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IEnumerator Use(BattlePlayerControls playerControls) {
|
public override IEnumerator Use(IBattleEffectApplier effectApplier, BattlePlayerControls playerControls) {
|
||||||
SingleTargeting singleTargeting = new SingleTargeting(new OtherHeroTargetPolicy(this.owner));
|
SingleTargeting singleTargeting = new SingleTargeting(new OtherHeroTargetPolicy(this.owner));
|
||||||
yield return playerControls.StartCoroutine(playerControls.ChooseTarget(singleTargeting));
|
yield return playerControls.StartCoroutine(playerControls.ChooseTarget(singleTargeting));
|
||||||
BattleParticipant target = singleTargeting.GetTarget();
|
BattleParticipant target = singleTargeting.GetTarget();
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ public class CardCrashingPunch : BaseCard
|
||||||
"Deals 3 damage to target.") {
|
"Deals 3 damage to target.") {
|
||||||
}
|
}
|
||||||
|
|
||||||
public override IEnumerator Use(BattlePlayerControls playerControls) {
|
public override IEnumerator Use(IBattleEffectApplier effectApplier, BattlePlayerControls playerControls) {
|
||||||
SingleTargeting singleTargeting = new SingleTargeting(new AnyTargetPolicy());
|
SingleTargeting singleTargeting = new SingleTargeting(new AnyTargetPolicy());
|
||||||
yield return playerControls.StartCoroutine(playerControls.ChooseTarget(singleTargeting));
|
yield return playerControls.StartCoroutine(playerControls.ChooseTarget(singleTargeting));
|
||||||
BattleParticipant target = singleTargeting.GetTarget();
|
BattleParticipant target = singleTargeting.GetTarget();
|
||||||
|
|
|
||||||
17
Assets/Battle/Cards/CardThunderstorm.cs
Normal file
17
Assets/Battle/Cards/CardThunderstorm.cs
Normal file
|
|
@ -0,0 +1,17 @@
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class CardThunderstorm : BaseCard
|
||||||
|
{
|
||||||
|
public CardThunderstorm(BattleParticipant owner)
|
||||||
|
: base(owner, CardId.Thunderstorm, "Thunderstorm", 3, CardType.Enchantment,
|
||||||
|
"Adds 1 energy.") {
|
||||||
|
}
|
||||||
|
|
||||||
|
public override IEnumerator Use(IBattleEffectApplier effectApplier, BattlePlayerControls playerControls) {
|
||||||
|
Debug.Log("A storm is brewing.");
|
||||||
|
effectApplier.Apply(new IncreaseMaxEnergyEffect(1));
|
||||||
|
yield break;
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Battle/Cards/CardThunderstorm.cs.meta
Normal file
11
Assets/Battle/Cards/CardThunderstorm.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 7effe1a2ba7096c49ac374b25ed92865
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
8
Assets/Battle/Effects.meta
Normal file
8
Assets/Battle/Effects.meta
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 96d74ab445eb27f42a7f7e774d3eb77f
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
16
Assets/Battle/Effects/IncreaseMaxEnergyEffect.cs
Normal file
16
Assets/Battle/Effects/IncreaseMaxEnergyEffect.cs
Normal file
|
|
@ -0,0 +1,16 @@
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class IncreaseMaxEnergyEffect : IBattleEffect
|
||||||
|
{
|
||||||
|
private int delta;
|
||||||
|
|
||||||
|
public IncreaseMaxEnergyEffect(int delta) {
|
||||||
|
this.delta = delta;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Apply(IBattleEffectResolver bc) {
|
||||||
|
bc.IncreaseMaxEnergy(this.delta);
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Battle/Effects/IncreaseMaxEnergyEffect.cs.meta
Normal file
11
Assets/Battle/Effects/IncreaseMaxEnergyEffect.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1d7496e1bf53a764c9ae43a3806f6a1c
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
|
@ -70,15 +70,18 @@ public class HeroDeck
|
||||||
this.handPile.Add(drawnCard);
|
this.handPile.Add(drawnCard);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DiscardPlayedCard(BaseCard card) {
|
public void RemoveCardFromHand(BaseCard card) {
|
||||||
if (!this.handPile.Contains(card)) {
|
if (!this.handPile.Contains(card)) {
|
||||||
throw new InvalidOperationException("Cannot discard card " + card.GetDisplayName()
|
throw new InvalidOperationException("Cannot discard card " + card.GetDisplayName()
|
||||||
+ " because not in hand.");
|
+ " because not in hand.");
|
||||||
}
|
}
|
||||||
|
|
||||||
this.discardPile.Insert(0, card);
|
|
||||||
this.handPile.Remove(card);
|
this.handPile.Remove(card);
|
||||||
TriggerHandPileChanged();
|
TriggerHandPileChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void MoveCardToDiscard(BaseCard card) {
|
||||||
|
this.discardPile.Insert(0, card);
|
||||||
TriggerDiscardPileChanged();
|
TriggerDiscardPileChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
7
Assets/Battle/IBattleEffect.cs
Normal file
7
Assets/Battle/IBattleEffect.cs
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public interface IBattleEffect {
|
||||||
|
void Apply(IBattleEffectResolver controller);
|
||||||
|
}
|
||||||
11
Assets/Battle/IBattleEffect.cs.meta
Normal file
11
Assets/Battle/IBattleEffect.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3125f31a929d67c44a5333d4714d9c22
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
7
Assets/Battle/IBattleEffectApplier.cs
Normal file
7
Assets/Battle/IBattleEffectApplier.cs
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public interface IBattleEffectApplier {
|
||||||
|
void Apply(IBattleEffect effect);
|
||||||
|
}
|
||||||
11
Assets/Battle/IBattleEffectApplier.cs.meta
Normal file
11
Assets/Battle/IBattleEffectApplier.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 5cc85c528f9080e45b3fc70c6fc07b2d
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
7
Assets/Battle/IBattleEffectResolver.cs
Normal file
7
Assets/Battle/IBattleEffectResolver.cs
Normal file
|
|
@ -0,0 +1,7 @@
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public interface IBattleEffectResolver {
|
||||||
|
void IncreaseMaxEnergy(int delta);
|
||||||
|
}
|
||||||
11
Assets/Battle/IBattleEffectResolver.cs.meta
Normal file
11
Assets/Battle/IBattleEffectResolver.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3b77e25b7ed61214dac4f79e0c92eacf
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
34
Assets/Battle/PlayArea.cs
Normal file
34
Assets/Battle/PlayArea.cs
Normal file
|
|
@ -0,0 +1,34 @@
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
public class PlayArea
|
||||||
|
{
|
||||||
|
public delegate void PlayAreaChangedAction();
|
||||||
|
public event PlayAreaChangedAction OnPlayAreaChanged;
|
||||||
|
|
||||||
|
private List<BaseCard> heroPermanents;
|
||||||
|
|
||||||
|
public PlayArea() {
|
||||||
|
this.heroPermanents = new List<BaseCard>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<BaseCard> GetHeroPermanents() {
|
||||||
|
return heroPermanents;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void AddPlayedHeroPermanent(BaseCard permanent) {
|
||||||
|
this.heroPermanents.Add(permanent);
|
||||||
|
TriggerPlayAreaChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveHeroPermanent(BaseCard permanent) {
|
||||||
|
this.heroPermanents.Remove(permanent);
|
||||||
|
TriggerPlayAreaChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void TriggerPlayAreaChanged() {
|
||||||
|
if (OnPlayAreaChanged != null) OnPlayAreaChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
11
Assets/Battle/PlayArea.cs.meta
Normal file
11
Assets/Battle/PlayArea.cs.meta
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 909d3afbe3a4b624b89876ad93fdcbe8
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
Loading…
Add table
Add a link
Reference in a new issue