-
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 #243
- Loading branch information
Showing
7 changed files
with
131 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
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 | ||
MazemindTome = Artifact("Mazemind Tome") do | ||
cost generic: 2 | ||
end | ||
|
||
class MazemindTome < Artifact | ||
class ActivatedAbility < TapActivatedAbility | ||
def costs | ||
[ | ||
Costs::Tap.new(source), | ||
Costs::AddCounter.new(counter_type: Counters::Page, target: source) | ||
] | ||
end | ||
|
||
def resolve! | ||
add_choice(:scry, source: source) | ||
end | ||
end | ||
|
||
class ActivatedAbility2 < Magic::ActivatedAbility | ||
def costs | ||
[ | ||
Costs::Mana.new(generic: 2), | ||
Costs::Tap.new(source), | ||
Costs::AddCounter.new(counter_type: Counters::Page, target: source) | ||
] | ||
end | ||
|
||
def resolve! | ||
source.controller.draw! | ||
end | ||
end | ||
|
||
def activated_abilities = [ActivatedAbility, ActivatedAbility2] | ||
|
||
def event_handlers | ||
{ | ||
Events::CounterAdded => ->(receiver, event) { | ||
return unless event.permanent == receiver | ||
|
||
if receiver.counters.of_type(Magic::Counters::Page).count >= 4 | ||
receiver.trigger_effect(:exile, target: receiver) | ||
receiver.trigger_effect(:gain_life, life: 4) | ||
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,16 @@ | ||
module Magic | ||
module Costs | ||
class AddCounter | ||
attr_reader :counter_type, :target | ||
|
||
def initialize(counter_type:, target:) | ||
@counter_type = counter_type | ||
@target = target | ||
end | ||
|
||
def finalize!(_player) | ||
target.add_counter(counter_type) | ||
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,7 @@ | ||
module Magic | ||
module Counters | ||
class Page | ||
|
||
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,10 @@ | ||
module Magic | ||
class TapActivatedAbility < ActivatedAbility | ||
attr_reader :costs | ||
|
||
def initialize(**args) | ||
super(**args) | ||
@costs = [Costs::Tap.new(source)] | ||
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,44 @@ | ||
require "spec_helper" | ||
|
||
RSpec.describe Magic::Cards::MazemindTome do | ||
include_context "two player game" | ||
|
||
subject { ResolvePermanent("Mazemind Tome") } | ||
|
||
|
||
context "taps, puts a page counter on mazemind tome, scries one" do | ||
let(:ability) { subject.activated_abilities.first } | ||
|
||
it "activates the ability" do | ||
p1.activate_ability(ability: ability) | ||
|
||
expect(subject.counters.of_type(Magic::Counters::Page).count).to eq(1) | ||
|
||
choice = game.choices.last | ||
expect(choice).to be_a(Magic::Choice::Scry) | ||
|
||
game.resolve_choice!(top: [], bottom: choice.choices) | ||
end | ||
end | ||
context "pay 2, taps, puts a page counter, draws a card" do | ||
let(:ability) { subject.activated_abilities[1] } | ||
|
||
it "activates the ability" do | ||
expect(p1).to receive(:draw!) | ||
|
||
p1.add_mana(blue: 2) | ||
p1.activate_ability(ability: ability) do | ||
_1.pay_mana(generic: { blue: 2 }) | ||
end | ||
|
||
expect(subject.counters.of_type(Magic::Counters::Page).count).to eq(1) | ||
end | ||
end | ||
|
||
it "when there are four or more page counters, exile it. Gain 4 life." do | ||
subject.add_counter(Magic::Counters::Page, amount: 4) | ||
|
||
expect(subject.card.zone).to be_exile | ||
expect(p1.life).to eq(24) | ||
end | ||
end |