-
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.
Merge pull request #510 from dNitza/add-rhystic-study
Rhystic Study
- Loading branch information
Showing
2 changed files
with
112 additions
and
0 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,51 @@ | ||
module Magic | ||
module Cards | ||
RhysticStudy = Enchantment("Rhystic Study") do | ||
type "Enchantment" | ||
cost generic: 2, blue: 1 | ||
end | ||
|
||
class RhysticStudy < Enchantment | ||
class Choice < Magic::Choice | ||
attr_reader :owner, :caster | ||
|
||
def initialize(owner:, caster:) | ||
@owner = owner | ||
@caster = caster | ||
end | ||
|
||
def costs | ||
@costs ||= [Costs::Mana.new(generic: 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 | ||
|
||
# Whenever an opponent casts a spell, | ||
# you may draw a card unless that player pays {1} | ||
def event_handlers | ||
{ | ||
Events::SpellCast => ->(receiver, event) do | ||
return if event.player == receiver.controller | ||
|
||
game | ||
.choices | ||
.add( | ||
Magic::Cards::RhysticStudy::Choice.new(owner: receiver.controller, | ||
caster: event.player) | ||
) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
require "spec_helper" | ||
|
||
RSpec.describe Magic::Cards::RhysticStudy do | ||
include_context "two player game" | ||
|
||
let!(:rhystic_study) { ResolvePermanent("Rhystic Study", owner: p1) } | ||
|
||
context "when opponent casts spell" do | ||
let!(:wood_elves_1) { Card("Wood Elves") } | ||
|
||
it "p2 casts 1 wood elf, p2 doesn't pay the 1, p1 draws" do | ||
expect(p1).to receive(:draw!) | ||
p2.add_mana({green: 4}) | ||
p2.cast(card: wood_elves_1) do | ||
_1.pay_mana(generic: {green: 2}, green: 1) | ||
end | ||
|
||
choice = game.choices.first | ||
expect(choice).to be_a(Magic::Cards::RhysticStudy::Choice) | ||
game.resolve_choice! | ||
end | ||
|
||
it "p1 casts 1 wood elf, Rhystic Study doesn't trigger" do | ||
expect(p1).to_not receive(:draw!) | ||
p1.add_mana({green: 4}) | ||
p1.cast(card: wood_elves_1) do | ||
_1.pay_mana(generic: {green: 2}, green: 1) | ||
end | ||
|
||
choice = game.choices.first | ||
expect(choice).to be_nil | ||
end | ||
|
||
it "p2 casts 1 wood elf, p2 pays the 1, p1 doesn't draws" do | ||
expect(p1).to_not receive(:draw!) | ||
p2.add_mana({green: 4}) | ||
p2.cast(card: wood_elves_1) do | ||
_1.pay_mana(generic: {green: 2}, green: 1) | ||
end | ||
|
||
choice = game.choices.first | ||
expect(choice).to be_a(Magic::Cards::RhysticStudy::Choice) | ||
choice.pay(player: p2, payment: {generic: {green: 1}}) | ||
choice.resolve! | ||
end | ||
|
||
it "p2 casts 1 wood elf, p2 tries to pay 3, which is not allowed" do | ||
expect { | ||
expect(p1).to_not receive(:draw!) | ||
p2.add_mana({green: 7}) | ||
p2.cast(card: wood_elves_1) do | ||
_1.pay_mana(generic: {green: 2}, green: 1) | ||
end | ||
|
||
choice = game.choices.first | ||
expect(choice).to be_a(Magic::Cards::RhysticStudy::Choice) | ||
choice.pay(player: p2, payment: {generic: {green: 3}}) | ||
}.to raise_error(Magic::Costs::Mana::Overpayment) | ||
end | ||
end | ||
end |