-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
147 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |