Skip to content

Commit

Permalink
Add Mazemind Tome
Browse files Browse the repository at this point in the history
Fixes #243
  • Loading branch information
radar committed Feb 2, 2024
1 parent 0b99856 commit bb6accd
Show file tree
Hide file tree
Showing 7 changed files with 131 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/magic/card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,8 @@ def add_choice(choice, **args)
case choice
when :discard
game.add_choice(Magic::Choice::Discard.new(player: controller, **args))
when :scry
game.add_choice(Magic::Choice::Scry.new(**args))
else
raise "Unknown choice: #{choice.inspect}"
end
Expand Down
51 changes: 51 additions & 0 deletions lib/magic/cards/mazemind_tome.rb
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
16 changes: 16 additions & 0 deletions lib/magic/costs/add_counter.rb
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
7 changes: 7 additions & 0 deletions lib/magic/counters/page.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
module Magic
module Counters
class Page

end
end
end
1 change: 1 addition & 0 deletions lib/magic/mana_ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ def choose(color)
end

def resolve!
# binding.pry
raise "Invalid choice made for mana ability:" unless choices.include?(choice)
source.controller.add_mana(choice => 1)
end
Expand Down
10 changes: 10 additions & 0 deletions lib/magic/tap_activated_ability.rb
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
44 changes: 44 additions & 0 deletions spec/cards/mazemind_tome_spec.rb
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

0 comments on commit bb6accd

Please sign in to comment.