Skip to content

Commit

Permalink
Add Composer of Spring
Browse files Browse the repository at this point in the history
  • Loading branch information
radar committed Oct 27, 2024
1 parent 71e37f7 commit 1e961fd
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/magic/card_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ def permanents
by_any_type(T::Artifact, T::Creature, T::Enchantment, T::Land, T::Planeswalker)
end

def enchantments
select(&:enchantment?)
end

def dead
select(&:dead?)
end
Expand Down
56 changes: 56 additions & 0 deletions lib/magic/cards/composer_of_spring.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
module Magic
module Cards
ComposerOfSpring = Creature("Composer of Spring") do
cost "{1}{G}"
creature_type "Satyr Bard"
power 2
toughness 3
end

class ComposerOfSpring < Creature
class EntersTrigger < TriggeredAbility::EnterTheBattlefield
def should_perform?
enchantment? && under_your_control?
end


def call
choice = if battlefield.controlled_by(controller).enchantments.count > 6
LandOrCreatureChoice
else
LandChoice
end

game.add_choice(choice.new(actor: actor))
end
end

class LandChoice < Magic::Choice::May
def choices
controller.hand.lands
end

def resolve!(target:)
target.resolve!(enters_tapped: true)
end
end

class LandOrCreatureChoice < Magic::Choice::May
def choices
controller.hand.lands + controller.hand.creatures
end

def resolve!(target:)
target.resolve!(enters_tapped: true)
end
end

def event_handlers
{
Events::EnteredTheBattlefield => EntersTrigger
}
end

end
end
end
4 changes: 4 additions & 0 deletions lib/magic/zone.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,5 +51,9 @@ def battlefield?
def exile?
false
end

def lands
cards.lands
end
end
end
63 changes: 63 additions & 0 deletions spec/cards/composer_of_spring_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
require "spec_helper"

RSpec.describe Magic::Cards::ComposerOfSpring do
include_context "two player game"

subject { ResolvePermanent("Composer of Spring") }

context "when an enchantment enters under your control" do
it "may put a land from your hand into play tapped" do
subject

p1.add_mana(white: 3)
p1.cast(card: Card("Nine Lives")) do
_1.pay_mana(generic: { white: 1 }, white: 2)
end

game.tick!

expect(game.choices.last).to be_a(Magic::Cards::ComposerOfSpring::LandChoice)
expect(game.choices.last.choices).to eq(p1.hand.lands)

chosen_land = p1.hand.lands.first

game.resolve_choice!(target: chosen_land)

game.tick!

expect(game.battlefield.by_name("Forest").count).to eq(1)
end

context "when there are 6 or more enchantments" do
before do
6.times { ResolvePermanent("Nine Lives", owner: p1) }

p1.hand.add(Card("Wood Elves"))
end

it "may put a land or creature from your hand into play tapped" do
subject

p1.add_mana(white: 3)
p1.cast(card: Card("Nine Lives")) do
_1.pay_mana(generic: { white: 1 }, white: 2)
end

game.tick!

expect(game.choices.last).to be_a(Magic::Cards::ComposerOfSpring::LandOrCreatureChoice)
expect(game.choices.last.choices).to eq(p1.hand.lands + p1.hand.creatures)

chosen_creature = p1.hand.creatures.first

game.resolve_choice!(target: chosen_creature)

game.tick!

expect(game.battlefield.by_name(chosen_creature.name).count).to eq(1)
end


end
end
end

0 comments on commit 1e961fd

Please sign in to comment.