Skip to content

Commit

Permalink
Add Leaf-Crowned Visionary
Browse files Browse the repository at this point in the history
  • Loading branch information
radar committed Apr 26, 2024
1 parent 50eccfb commit 438573e
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ GEM
rspec-support (~> 3.12.0)
rspec-support (3.12.0)
state_machines (0.5.0)
zeitwerk (2.5.4)
zeitwerk (2.6.13)

PLATFORMS
arm64-darwin-21
Expand Down
11 changes: 11 additions & 0 deletions lib/magic/cards/grizzly_bears.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module Magic
module Cards
class GrizzlyBears < Creature
card_name "Grizzly Bears"
cost "{1}{G}"
creature_type "Bear"
power 2
toughness 2
end
end
end
71 changes: 71 additions & 0 deletions lib/magic/cards/leaf_crowned_visionary.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
module Magic
module Cards
class LeafCrownedVisionary < Creature
card_name "Leaf-Crowned Visionary"
cost "{G}{G}"
creature_type "Elf Druid"
power 1
toughness 1

class PowerAndToughnessModification < Abilities::Static::PowerAndToughnessModification
def initialize(source:)
@source = source
end

def power
1
end

def toughness
1
end

def applicable_targets
source.controller.creatures.by_type("Elf") - [source]
end
end

class Choice < Magic::Choice
attr_reader :owner

def initialize(owner:)
@owner = owner
end

def costs
@costs ||= [Costs::Mana.new(green: 1)]
end

def pay(player:, payment:)
cost = costs.first
cost.pay!(player:, payment:)
end

def resolve!
if !costs.all?(&:paid?)
owner.draw!
end
end
end

def static_abilities = [PowerAndToughnessModification]

# Whenever you cast an Elf spell,
# you may pay {G}. If you do, draw a card.
def event_handlers
{
Events::SpellCast => ->(receiver, event) do
return if event.player != receiver.controller
return unless event.spell.type?("Elf")

game
.choices
.add(
Magic::Cards::LeafCrownedVisionary::Choice.new(owner: receiver.controller)
)
end
}
end
end
end
end
2 changes: 1 addition & 1 deletion magic.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
# spec.add_dependency "example-gem", "~> 1.0"
spec.add_dependency 'state_machines'
spec.add_dependency 'zeitwerk'
spec.add_dependency "dry-types"
spec.add_dependency "dry-types", "~> 1.7"

# For more information and examples about making a new gem, checkout our
# guide at: https://bundler.io/guides/creating_gem.html
Expand Down
63 changes: 63 additions & 0 deletions spec/cards/leaf_crowned_visionary_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
require "spec_helper"

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

subject!(:leaf_crowned_visionary) { ResolvePermanent("Leaf-Crowned Visionary") }

context "with another elf on the field" do
let(:wood_elves) { ResolvePermanent("Wood Elves") }

it "gives all other elves +1/+1" do
expect(leaf_crowned_visionary.power).to eq(1)
expect(leaf_crowned_visionary.toughness).to eq(1)

expect(wood_elves.power).to eq(2)
expect(wood_elves.toughness).to eq(2)
end
end

context "when an Elf spell is cast, you may pay {G}" do
subject(:leaf_crowned_visionary) { ResolvePermanent("Leaf-Crowned Visionary") }

let(:wood_elves) { Card("Wood Elves") }
let(:grizzly_bears) { Card("Grizzly Bears") }

it "doesn't trigger on the bears" do
p1.add_mana(green: 4)
p1.cast(card: grizzly_bears) do
_1.pay_mana(green: 1, generic: { green: 1 })
end

game.stack.resolve!
expect(game.choices).to be_empty
end

it "triggers on elves, and opts draw a card" do
p1.add_mana(green: 4)
p1.cast(card: wood_elves) do
_1.pay_mana(green: 1, generic: { green: 2 })
end

game.stack.resolve!

choice = game.choices.first
expect(choice).to be_a(Magic::Cards::LeafCrownedVisionary::Choice)
choice.pay(player: p1, payment: {green: 1})
choice.resolve!
end

it "skips choice" do
p1.add_mana(green: 4)
p1.cast(card: wood_elves) do
_1.pay_mana(green: 1, generic: { green: 2 })
end

game.stack.resolve!

choice = game.choices.first
p1.skip_choice(choice)
expect(game.choices).to be_empty
end
end
end

0 comments on commit 438573e

Please sign in to comment.