IBattleEffectResolver takes in the effects as params
This commit is contained in:
parent
8b539e1b5c
commit
c2e8b526b6
6 changed files with 43 additions and 33 deletions
|
|
@ -186,24 +186,39 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
||||||
return this.playArea;
|
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
|
// IBattleEffectApplier
|
||||||
public void Apply(IBattleEffect effect) {
|
public void Apply(IBattleEffect effect) {
|
||||||
effect.Apply(this);
|
effect.Apply(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
// IBattleEffectResolver
|
// IBattleEffectResolver
|
||||||
public void IncreaseHeroMaxEnergy(int delta) {
|
public void IncreaseHeroMaxEnergy(IncreaseMaxEnergyEffect effect) {
|
||||||
this.maxEnergy += delta;
|
this.maxEnergy += effect.Amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void IncreaseMaxHP(IncreaseMaxHPEffect effect) {
|
public void IncreaseMaxHP(IncreaseMaxHPEffect effect) {
|
||||||
effect.Target.IncreaseMaxHP(effect.Amount);
|
effect.Target.IncreaseMaxHP(effect.Amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AcquireHeroCards(CardId[] cardIds, BattleZone zone, BattleHero owner) {
|
public void AcquireHeroCards(AcquireCardsEffect effect) {
|
||||||
foreach (CardId cardId in cardIds) {
|
BattleHero hero = (BattleHero) effect.Participant;
|
||||||
BaseCard acquiredCard = CardDatabase.CreateCard(cardId, owner);
|
foreach (CardId cardId in effect.CardIds) {
|
||||||
switch (zone) {
|
BaseCard acquiredCard = CardDatabase.CreateCard(cardId, hero);
|
||||||
|
switch (effect.Zone) {
|
||||||
case BattleZone.DrawPile:
|
case BattleZone.DrawPile:
|
||||||
this.GetHeroDeck().PutCardOnTopOfDrawPile(acquiredCard);
|
this.GetHeroDeck().PutCardOnTopOfDrawPile(acquiredCard);
|
||||||
break;
|
break;
|
||||||
|
|
@ -212,7 +227,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (zone == BattleZone.DrawPile) {
|
if (effect.Zone == BattleZone.DrawPile) {
|
||||||
this.GetHeroDeck().ShuffleDrawPile();
|
this.GetHeroDeck().ShuffleDrawPile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -239,28 +254,14 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
||||||
return healedAmount;
|
return healedAmount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void AddBlock(BattleParticipant target, int amount) {
|
public void AddBlock(BlockEffect effect) {
|
||||||
target.AddBlock(amount);
|
effect.Target.AddBlock(effect.Amount);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ArmDamageTrigger(DamageTrigger damageTrigger) {
|
public void ArmDamageTrigger(DamageTrigger damageTrigger) {
|
||||||
this.damageTriggers.Add(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
|
// MonsterViewpoint
|
||||||
public BattleHero[] Heroes {get => this.heroes;}
|
public BattleHero[] Heroes {get => this.heroes;}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -16,9 +16,13 @@ public class AcquireCardsEffect : IBattleEffect
|
||||||
|
|
||||||
public void Apply(IBattleEffectResolver resolver) {
|
public void Apply(IBattleEffectResolver resolver) {
|
||||||
if (this.participant.IsHero()) {
|
if (this.participant.IsHero()) {
|
||||||
resolver.AcquireHeroCards(this.cardIds, this.zone, (BattleHero) this.participant);
|
resolver.AcquireHeroCards(this);
|
||||||
} else {
|
} else {
|
||||||
throw new System.NotImplementedException();
|
throw new System.NotImplementedException();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public CardId[] CardIds {get => this.cardIds;}
|
||||||
|
public BattleZone Zone {get => this.zone;}
|
||||||
|
public BattleParticipant Participant {get => this.participant;}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -13,6 +13,9 @@ public class BlockEffect : IBattleEffect
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Apply(IBattleEffectResolver resolver) {
|
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;}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,15 @@ using UnityEngine;
|
||||||
|
|
||||||
public class IncreaseMaxEnergyEffect : IBattleEffect
|
public class IncreaseMaxEnergyEffect : IBattleEffect
|
||||||
{
|
{
|
||||||
private int delta;
|
private int amount;
|
||||||
|
|
||||||
public IncreaseMaxEnergyEffect(int delta) {
|
public IncreaseMaxEnergyEffect(int amount) {
|
||||||
this.delta = delta;
|
this.amount = amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Apply(IBattleEffectResolver resolver) {
|
public void Apply(IBattleEffectResolver resolver) {
|
||||||
resolver.IncreaseHeroMaxEnergy(this.delta);
|
resolver.IncreaseHeroMaxEnergy(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int Amount {get => this.amount;}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,9 +5,10 @@ using UnityEngine;
|
||||||
public interface IBattleEffectResolver {
|
public interface IBattleEffectResolver {
|
||||||
int DealDamage(DealDamageEffect effect);
|
int DealDamage(DealDamageEffect effect);
|
||||||
int Heal(HealEffect effect);
|
int Heal(HealEffect effect);
|
||||||
void AddBlock(BattleParticipant target, int amount);
|
void AddBlock(BlockEffect effect);
|
||||||
void IncreaseHeroMaxEnergy(int delta);
|
void IncreaseHeroMaxEnergy(IncreaseMaxEnergyEffect delta);
|
||||||
void IncreaseMaxHP(IncreaseMaxHPEffect effect);
|
void IncreaseMaxHP(IncreaseMaxHPEffect effect);
|
||||||
void AcquireHeroCards(CardId[] cardIds, BattleZone zone, BattleHero owner);
|
void AcquireHeroCards(AcquireCardsEffect effect);
|
||||||
|
|
||||||
void ArmDamageTrigger(DamageTrigger damageTrigger);
|
void ArmDamageTrigger(DamageTrigger damageTrigger);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
1
TODO.txt
1
TODO.txt
|
|
@ -1,4 +1,3 @@
|
||||||
- Make API of IBattleEffectResolver take in effects instead of params
|
|
||||||
- Control flow of battle with state machine or coroutines
|
- Control flow of battle with state machine or coroutines
|
||||||
- Make battle end
|
- Make battle end
|
||||||
- Do not allow dead heroes to act
|
- Do not allow dead heroes to act
|
||||||
Loading…
Add table
Add a link
Reference in a new issue