IBattleEffectResolver takes in the effects as params

This commit is contained in:
henriquenakashima 2020-09-20 11:58:35 -04:00
parent 8b539e1b5c
commit c2e8b526b6
6 changed files with 43 additions and 33 deletions

View file

@ -186,24 +186,39 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
return this.playArea;
}
private void EnqueueActivatedTrigger(Trigger trigger) {
this.activatedTriggers.Add(trigger);
}
private void RunActivatedTriggers() {
foreach (Trigger t in this.activatedTriggers) {
t.Run(this);
}
this.activatedTriggers.Clear();
// Cleanup expired triggers
this.damageTriggers.RemoveAll(t => t.Expired);
}
// IBattleEffectApplier
public void Apply(IBattleEffect effect) {
effect.Apply(this);
}
// IBattleEffectResolver
public void IncreaseHeroMaxEnergy(int delta) {
this.maxEnergy += delta;
public void IncreaseHeroMaxEnergy(IncreaseMaxEnergyEffect effect) {
this.maxEnergy += effect.Amount;
}
public void IncreaseMaxHP(IncreaseMaxHPEffect effect) {
effect.Target.IncreaseMaxHP(effect.Amount);
}
public void AcquireHeroCards(CardId[] cardIds, BattleZone zone, BattleHero owner) {
foreach (CardId cardId in cardIds) {
BaseCard acquiredCard = CardDatabase.CreateCard(cardId, owner);
switch (zone) {
public void AcquireHeroCards(AcquireCardsEffect effect) {
BattleHero hero = (BattleHero) effect.Participant;
foreach (CardId cardId in effect.CardIds) {
BaseCard acquiredCard = CardDatabase.CreateCard(cardId, hero);
switch (effect.Zone) {
case BattleZone.DrawPile:
this.GetHeroDeck().PutCardOnTopOfDrawPile(acquiredCard);
break;
@ -212,7 +227,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
}
}
if (zone == BattleZone.DrawPile) {
if (effect.Zone == BattleZone.DrawPile) {
this.GetHeroDeck().ShuffleDrawPile();
}
}
@ -239,28 +254,14 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
return healedAmount;
}
public void AddBlock(BattleParticipant target, int amount) {
target.AddBlock(amount);
public void AddBlock(BlockEffect effect) {
effect.Target.AddBlock(effect.Amount);
}
public void ArmDamageTrigger(DamageTrigger damageTrigger) {
this.damageTriggers.Add(damageTrigger);
}
private void EnqueueActivatedTrigger(Trigger trigger) {
this.activatedTriggers.Add(trigger);
}
private void RunActivatedTriggers() {
foreach (Trigger t in this.activatedTriggers) {
t.Run(this);
}
this.activatedTriggers.Clear();
// Cleanup expired triggers
this.damageTriggers.RemoveAll(t => t.Expired);
}
// MonsterViewpoint
public BattleHero[] Heroes {get => this.heroes;}
}

View file

@ -16,9 +16,13 @@ public class AcquireCardsEffect : IBattleEffect
public void Apply(IBattleEffectResolver resolver) {
if (this.participant.IsHero()) {
resolver.AcquireHeroCards(this.cardIds, this.zone, (BattleHero) this.participant);
resolver.AcquireHeroCards(this);
} else {
throw new System.NotImplementedException();
}
}
public CardId[] CardIds {get => this.cardIds;}
public BattleZone Zone {get => this.zone;}
public BattleParticipant Participant {get => this.participant;}
}

View file

@ -13,6 +13,9 @@ public class BlockEffect : IBattleEffect
}
public void Apply(IBattleEffectResolver resolver) {
resolver.AddBlock(this.target, this.amount);
resolver.AddBlock(this);
}
public BattleParticipant Target {get => this.target;}
public int Amount {get => this.amount;}
}

View file

@ -4,13 +4,15 @@ using UnityEngine;
public class IncreaseMaxEnergyEffect : IBattleEffect
{
private int delta;
private int amount;
public IncreaseMaxEnergyEffect(int delta) {
this.delta = delta;
public IncreaseMaxEnergyEffect(int amount) {
this.amount = amount;
}
public void Apply(IBattleEffectResolver resolver) {
resolver.IncreaseHeroMaxEnergy(this.delta);
resolver.IncreaseHeroMaxEnergy(this);
}
public int Amount {get => this.amount;}
}

View file

@ -5,9 +5,10 @@ using UnityEngine;
public interface IBattleEffectResolver {
int DealDamage(DealDamageEffect effect);
int Heal(HealEffect effect);
void AddBlock(BattleParticipant target, int amount);
void IncreaseHeroMaxEnergy(int delta);
void AddBlock(BlockEffect effect);
void IncreaseHeroMaxEnergy(IncreaseMaxEnergyEffect delta);
void IncreaseMaxHP(IncreaseMaxHPEffect effect);
void AcquireHeroCards(CardId[] cardIds, BattleZone zone, BattleHero owner);
void AcquireHeroCards(AcquireCardsEffect effect);
void ArmDamageTrigger(DamageTrigger damageTrigger);
}