diff --git a/lib/magic/cards/battle_for_bretagard.rb b/lib/magic/cards/battle_for_bretagard.rb index bd3f248..3ba6865 100644 --- a/lib/magic/cards/battle_for_bretagard.rb +++ b/lib/magic/cards/battle_for_bretagard.rb @@ -19,19 +19,19 @@ class BattleForBretagard < Saga end class Chapter1 < Chapter - def start + def resolve actor.trigger_effect(:create_token, token_class: HumanWarriorToken) end end class Chapter2 < Chapter - def start + def resolve actor.trigger_effect(:create_token, token_class: ElfWarriorToken) end end class Chapter3 < Chapter - def start + def resolve actor.game.add_choice(BattleForBretagard::Choice.new(actor: actor)) end end diff --git a/lib/magic/cards/saga.rb b/lib/magic/cards/saga.rb index cf62366..1e7f7ed 100644 --- a/lib/magic/cards/saga.rb +++ b/lib/magic/cards/saga.rb @@ -7,6 +7,29 @@ class Chapter def initialize(actor:) @actor = actor end + + def name + self.class.name.split("::").last + end + + def resolve! + resolve + + if final_chapter? + card.game.notify!(Events::FinalChapterAbilityResolved, actor: actor) + actor.sacrifice! + end + end + + def final_chapter? + card.chapters.count == actor.counters.of_type(Counters::Lore).count + end + + private + + def card + actor.card + end end type T::Enchantment, "Saga" @@ -23,9 +46,7 @@ def should_perform? def call lore_counters = actor.counters.of_type(Counters::Lore) chapter_class = card.chapter(lore_counters) - chapter_class.new(actor: actor).start - - actor.sacrifice! if card.chapters.count == lore_counters.count + game.stack.add(chapter_class.new(actor: actor)) end end diff --git a/spec/game/integration/saga_lore_counters_spec.rb b/spec/game/integration/saga_lore_counters_spec.rb index 5b6381b..774813d 100644 --- a/spec/game/integration/saga_lore_counters_spec.rb +++ b/spec/game/integration/saga_lore_counters_spec.rb @@ -14,7 +14,7 @@ context "as a card" do let(:card) { Card("Battle For Bretagard") } - it "adds a lore counter when it enters" do + it "adds a lore counter when it enters, and for each main phase" do p1.add_mana(white: 2, green: 1) p1.cast(card: card) do _1.auto_pay_mana @@ -40,6 +40,8 @@ expect(permanent.counters.of_type(Magic::Counters::Lore).count).to eq(2) + game.stack.resolve! + elf_warrior = game.battlefield.by_name("Elf Warrior") expect(elf_warrior.count).to eq(1) @@ -52,6 +54,8 @@ turn_5.draw! turn_5.first_main! + game.stack.resolve! + expect(game.battlefield.by_name("Battle for Bretagard")).to be_empty expect(card.zone).to be_graveyard