Refactor TriggerManager out of BattleController
This commit is contained in:
parent
6aa13cdbb7
commit
60e8d2e3e0
4 changed files with 94 additions and 36 deletions
|
|
@ -118,8 +118,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
private IEnumerator RunBattleRound() {
|
||||
this.state.Clock.AdvanceRound();
|
||||
|
||||
this.damageTriggers.RemoveAll(t => t.Expiration == TriggerExpiration.StartOfNextHeroTurn);
|
||||
|
||||
this.state.HeroEnergy.Replenish();
|
||||
this.state.MonsterEnergy.Replenish();
|
||||
|
||||
|
|
@ -162,6 +160,12 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
} else {
|
||||
HeroCard card = playerAction.GetCardUsed();
|
||||
yield return UseHeroCard(card);
|
||||
|
||||
// TODO: Implement a stack/queue to resolve triggers in order.
|
||||
// Do this after the card resolution is over to avoid reentraint effects.
|
||||
this.state.TriggerManager.RunActivatedTriggers(this);
|
||||
CheckState();
|
||||
OnBattleStateChanged();
|
||||
}
|
||||
} else {
|
||||
yield return null;
|
||||
|
|
@ -170,6 +174,12 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
|
||||
// End of hero turn
|
||||
yield return this.state.PlayArea.UseHeroDefaults(this.state.Heroes, this.participantActivity, UseHeroDefault);
|
||||
// TODO: Implement a stack/queue to resolve triggers in order.
|
||||
// Do this after the card resolution is over to avoid reentraint effects.
|
||||
this.state.TriggerManager.RunActivatedTriggers(this);
|
||||
CheckState();
|
||||
OnBattleStateChanged();
|
||||
|
||||
if (STABLE_HAND_STYLE) {
|
||||
this.state.HeroDeck.DiscardInExcessOf(3);
|
||||
} else {
|
||||
|
|
@ -203,6 +213,12 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
MonsterCard monsterCard = monsterHand[i];
|
||||
if (monsterCard.Type == CardType.Emotion && CanUseMonsterCard(monsterCard)) {
|
||||
yield return UseMonsterCard(monsterCard);
|
||||
|
||||
// TODO: Implement a stack/queue to resolve triggers in order.
|
||||
// Do this after the card resolution is over to avoid reentraint effects.
|
||||
this.state.TriggerManager.RunActivatedTriggers(this);
|
||||
CheckState();
|
||||
OnBattleStateChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -214,8 +230,13 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
MonsterCard monsterCard = FirstMonsterActionToPlay();
|
||||
if (monsterCard != null) {
|
||||
yield return UseMonsterCard(monsterCard);
|
||||
OnBattleStateChanged();
|
||||
anyCardPlayed = true;
|
||||
|
||||
// TODO: Implement a stack/queue to resolve triggers in order.
|
||||
// Do this after the card resolution is over to avoid reentraint effects.
|
||||
this.state.TriggerManager.RunActivatedTriggers(this);
|
||||
CheckState();
|
||||
OnBattleStateChanged();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -304,20 +325,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
return this.monsterHandPlayability.IsPlayableImmediately(card);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
private void CheckState() {
|
||||
foreach (BattleParticipant p in this.state.Heroes) {
|
||||
p.CheckState();
|
||||
|
|
@ -420,8 +427,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
}
|
||||
}
|
||||
|
||||
private List<Trigger> activatedTriggers = new List<Trigger>();
|
||||
private List<DamageTrigger> damageTriggers = new List<DamageTrigger>();
|
||||
|
||||
public int DealDamage(DealDamageEffect effect) {
|
||||
if (effect.Target == null) return 0;
|
||||
|
|
@ -431,14 +436,7 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
amount += this.state.BuffManager.GetTotalBuffAmountOfType(effect.Source, BuffType.Power);
|
||||
}
|
||||
int damageDealt = effect.Target.DealDamage(amount);
|
||||
foreach (DamageTrigger dt in this.damageTriggers) {
|
||||
if (dt.IsTriggeredBy(effect)) {
|
||||
EnqueueActivatedTrigger(dt);
|
||||
}
|
||||
}
|
||||
|
||||
// Do this after the card resolution is over to avoid reentraint effects.
|
||||
RunActivatedTriggers();
|
||||
this.state.TriggerManager.NotifyResolvedDamageEffect(effect);
|
||||
|
||||
return damageDealt;
|
||||
}
|
||||
|
|
@ -448,15 +446,8 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
BattleParticipant[] affectedTeam = GetTeam(effect.Team);
|
||||
foreach (BattleParticipant bp in affectedTeam) {
|
||||
damageDealt += bp.DealDamage(effect.Amount);
|
||||
foreach (DamageTrigger dt in this.damageTriggers) {
|
||||
if (dt.IsTriggeredBy(effect)) {
|
||||
EnqueueActivatedTrigger(dt);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Do this after the card resolution is over to avoid reentraint effects.
|
||||
RunActivatedTriggers();
|
||||
this.state.TriggerManager.NotifyResolvedMassDamageEffect(effect);
|
||||
|
||||
return damageDealt;
|
||||
}
|
||||
|
|
@ -531,6 +522,6 @@ public class BattleController : MonoBehaviour, IBattleEffectApplier, IBattleEffe
|
|||
}
|
||||
|
||||
public void ArmDamageTrigger(DamageTrigger damageTrigger) {
|
||||
this.damageTriggers.Add(damageTrigger);
|
||||
this.state.TriggerManager.ArmDamageTrigger(damageTrigger);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue