-
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.
Fixes #69
- Loading branch information
Showing
7 changed files
with
141 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
module Magic | ||
module Cards | ||
Opt = Instant("Opt") do | ||
cost blue: 1 | ||
end | ||
|
||
class Opt < Instant | ||
def resolve!(_controller) | ||
game.add_effect( | ||
Effects::Scry.new(source: self, amount: 1, then_do: -> do | ||
game.add_effect(Effects::DrawCards.new(source: self, player: controller)) | ||
end) | ||
) | ||
|
||
super | ||
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,25 @@ | ||
module Magic | ||
module Effects | ||
class Scry < Effect | ||
attr_reader :player, :amount | ||
|
||
def initialize(source:, amount:, then_do:) | ||
@source = source | ||
@amount = amount | ||
super(source: source, then_do: then_do) | ||
|
||
end | ||
|
||
def requires_choices? | ||
true | ||
end | ||
|
||
def resolve(top: [], bottom: []) | ||
source.controller.scry(amount:, top:, bottom:) | ||
|
||
super | ||
|
||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
module Magic | ||
module Events | ||
class Scry | ||
attr_reader :player, :top, :bottom | ||
|
||
def initialize(player:, top:, bottom:) | ||
@player = player | ||
@top = top | ||
@bottom = bottom | ||
end | ||
|
||
def inspect | ||
"#<Events::Scry player: #{player}, top: #{top}, bottom: #{bottom}>" | ||
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
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,55 @@ | ||
require 'spec_helper' | ||
|
||
RSpec.describe Magic::Cards::Opt do | ||
include_context "two player game" | ||
|
||
let(:opt) { described_class.new(game: game) } | ||
|
||
def p1_library | ||
[ | ||
Card("Forest"), | ||
Card("Forest"), | ||
Card("Forest"), | ||
Card("Forest"), | ||
Card("Forest"), | ||
Card("Forest"), | ||
Card("Forest"), | ||
# End initial card draw | ||
Card("Sol Ring"), | ||
Card("Forest"), | ||
] | ||
end | ||
|
||
it "scries to the top" do | ||
top_card = p1.library.first | ||
p1.add_mana(blue: 1) | ||
action = cast_action(player: p1, card: opt) | ||
action.pay_mana(blue: 1) | ||
game.take_action(action) | ||
game.tick! | ||
effect = game.effects.first | ||
expect(effect).to be_a(Magic::Effects::Scry) | ||
game.resolve_pending_effect(top: [top_card]) | ||
|
||
expect(opt.zone).to be_graveyard | ||
expect(p1.library.first.name).to eq("Forest") | ||
expect(p1.hand.map(&:name)).to include("Sol Ring") | ||
end | ||
|
||
it "scries to the bottom" do | ||
top_card = p1.library.first | ||
p1.add_mana(blue: 1) | ||
action = cast_action(player: p1, card: opt) | ||
action.pay_mana(blue: 1) | ||
game.take_action(action) | ||
game.tick! | ||
effect = game.effects.first | ||
expect(effect).to be_a(Magic::Effects::Scry) | ||
game.resolve_pending_effect(bottom: [top_card]) | ||
|
||
expect(opt.zone).to be_graveyard | ||
expect(p1.library.last).to eq(top_card) | ||
|
||
expect(p1.hand.map(&:name)).not_to include("Sol Ring") | ||
end | ||
end |