Implement acquiring cards. Thunderstorm acquires Lightning Strikes.

This commit is contained in:
henriquenakashima 2020-09-19 17:26:14 -04:00
parent 60afd791dd
commit 1e8d3bb068
12 changed files with 121 additions and 5 deletions

View file

@ -194,7 +194,24 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
} }
// IBattleEffectResolver // IBattleEffectResolver
public void IncreaseMaxEnergy(int delta) { public void IncreaseHeroMaxEnergy(int delta) {
this.maxEnergy += delta; this.maxEnergy += delta;
} }
public void AcquireHeroCards(CardId[] cardIds, BattleZone zone, BattleHero owner) {
foreach (CardId cardId in cardIds) {
BaseCard acquiredCard = CardDatabase.CreateCard(cardId, owner);
switch (zone) {
case BattleZone.DrawPile:
this.GetHeroDeck().PutCardOnTopOfDrawPile(acquiredCard);
break;
default:
throw new System.NotImplementedException();
}
}
if (zone == BattleZone.DrawPile) {
this.GetHeroDeck().ShuffleDrawPile();
}
}
} }

View file

@ -0,0 +1,7 @@
public enum BattleZone {
DrawPile,
Hand,
DiscardPile,
HeroPlayArea,
MonsterPlayArea,
}

View file

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

View file

@ -5,6 +5,7 @@ using UnityEngine;
public enum CardId { public enum CardId {
CrashingPunch, CrashingPunch,
Cover, Cover,
LightningStrike,
Thunderstorm, Thunderstorm,
} }
@ -13,6 +14,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.LightningStrike, HeroId.Shaman},
{CardId.Thunderstorm, HeroId.Shaman}, {CardId.Thunderstorm, HeroId.Shaman},
}; };
@ -23,6 +25,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.LightningStrike:
return new CardLightningStrike(owner);
case CardId.Thunderstorm: case CardId.Thunderstorm:
return new CardThunderstorm(owner); return new CardThunderstorm(owner);
default: default:

View file

@ -0,0 +1,19 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class CardLightningStrike : BaseCard
{
public CardLightningStrike(BattleParticipant owner)
: base(owner, CardId.LightningStrike, "Lightning Strike", 2, CardType.Action,
"Deals 3 damage to target.") {
}
public override IEnumerator Use(IBattleEffectApplier effectApplier, BattlePlayerControls playerControls) {
SingleTargeting singleTargeting = new SingleTargeting(new AnyTargetPolicy());
yield return playerControls.StartCoroutine(playerControls.ChooseTarget(singleTargeting));
BattleParticipant target = singleTargeting.GetTarget();
Debug.Log("Striking " + target + " with lightning.");
target.DealDamage(3);
}
}

View file

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

View file

@ -6,12 +6,13 @@ public class CardThunderstorm : BaseCard
{ {
public CardThunderstorm(BattleParticipant owner) public CardThunderstorm(BattleParticipant owner)
: base(owner, CardId.Thunderstorm, "Thunderstorm", 3, CardType.Enchantment, : base(owner, CardId.Thunderstorm, "Thunderstorm", 3, CardType.Enchantment,
"Adds 1 energy.") { "Add 1 max energy. Acquire 2 Lightning Strike into draw pile.") {
} }
public override IEnumerator Use(IBattleEffectApplier effectApplier, BattlePlayerControls playerControls) { public override IEnumerator Use(IBattleEffectApplier effectApplier, BattlePlayerControls playerControls) {
Debug.Log("A storm is brewing."); Debug.Log("A storm is brewing.");
effectApplier.Apply(new IncreaseMaxEnergyEffect(1)); effectApplier.Apply(new IncreaseMaxEnergyEffect(1));
effectApplier.Apply(new AcquireCardsEffect(new CardId[] {CardId.LightningStrike, CardId.LightningStrike}, BattleZone.DrawPile, this.owner));
yield break; yield break;
} }
} }

View file

@ -0,0 +1,24 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class AcquireCardsEffect : IBattleEffect
{
private CardId[] cardIds;
private BattleZone zone;
private BattleParticipant participant;
public AcquireCardsEffect(CardId[] cardIds, BattleZone zone, BattleParticipant participant) {
this.cardIds = cardIds;
this.zone = zone;
this.participant = participant;
}
public void Apply(IBattleEffectResolver resolver) {
if (this.participant.IsHero()) {
resolver.AcquireHeroCards(this.cardIds, this.zone, (BattleHero) this.participant);
} else {
throw new System.NotImplementedException();
}
}
}

View file

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

View file

@ -10,7 +10,7 @@ public class IncreaseMaxEnergyEffect : IBattleEffect
this.delta = delta; this.delta = delta;
} }
public void Apply(IBattleEffectResolver bc) { public void Apply(IBattleEffectResolver resolver) {
bc.IncreaseMaxEnergy(this.delta); resolver.IncreaseHeroMaxEnergy(this.delta);
} }
} }

View file

@ -92,6 +92,16 @@ public class HeroDeck
TriggerDiscardPileChanged(); TriggerDiscardPileChanged();
} }
public void PutCardOnTopOfDrawPile(BaseCard card) {
this.drawPile.Insert(0, card);
TriggerDrawPileChanged();
}
public void ShuffleDrawPile() {
this.drawPile.Shuffle();
TriggerDrawPileChanged();
}
private void RemakeDrawPile() { private void RemakeDrawPile() {
this.drawPile.AddRange(this.discardPile); this.drawPile.AddRange(this.discardPile);
this.discardPile.Clear(); this.discardPile.Clear();

View file

@ -3,5 +3,6 @@ using System.Collections.Generic;
using UnityEngine; using UnityEngine;
public interface IBattleEffectResolver { public interface IBattleEffectResolver {
void IncreaseMaxEnergy(int delta); void IncreaseHeroMaxEnergy(int delta);
void AcquireHeroCards(CardId[] cardIds, BattleZone zone, BattleHero owner);
} }