Skip to content

Commit

Permalink
Add Meteorite
Browse files Browse the repository at this point in the history
Fixes #244
  • Loading branch information
radar committed Feb 2, 2024
1 parent ca52d62 commit 0b99856
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 0 deletions.
29 changes: 29 additions & 0 deletions lib/magic/cards/meteorite.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
module Magic
module Cards
Meteorite = Artifact("Meteorite") do
cost generic: 5

enters_the_battlefield do
game.choices.add(Meteorite::Choice.new(source: source))
end
end

class Meteorite < Artifact
class Choice < Magic::Choice::Targeted
def choices
game.any_target
end

def resolve!(target:)
source.trigger_effect(:deal_damage, target:, damage: 2)
end
end

class ManaAbility < TapManaAbility
choices :all
end

def activated_abilities = [ManaAbility]
end
end
end
2 changes: 2 additions & 0 deletions lib/magic/tap_mana_ability.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module Magic
class TapManaAbility < ManaAbility
attr_reader :costs

def initialize(**args)
super(**args)
@costs = [Costs::Tap.new(source)]
Expand Down
31 changes: 31 additions & 0 deletions spec/cards/meteorite_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
require "spec_helper"

RSpec.describe Magic::Cards::Meteorite do
include_context "two player game"

let(:card) { Card("Meteorite") }

it "deals 2 damage to any target" do
cast_and_resolve(card: card)

choice = game.choices.last
expect(choice).to be_a(described_class::Choice)

game.resolve_choice!(target: p2)

expect(p2.life).to eq(18)
end

context "mana ability" do
subject { ResolvePermanent("Meteorite") }
let(:mana_ability) { subject.activated_abilities.first }

it "lets player choose which mana" do
p1.activate_mana_ability(ability: mana_ability) do
_1.choose(:green)
end

expect(p1.mana_pool[:green]).to eq(1)
end
end
end

0 comments on commit 0b99856

Please sign in to comment.