Skip to content

Commit

Permalink
Alert when final chapter ability is resolving
Browse files Browse the repository at this point in the history
  • Loading branch information
radar committed Nov 11, 2024
1 parent 39454d7 commit e0741bf
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
6 changes: 3 additions & 3 deletions lib/magic/cards/battle_for_bretagard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
27 changes: 24 additions & 3 deletions lib/magic/cards/saga.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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

Expand Down
6 changes: 5 additions & 1 deletion spec/game/integration/saga_lore_counters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand All @@ -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

Expand Down

0 comments on commit e0741bf

Please sign in to comment.