Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions lib/magic/cards/black_lotus.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Magic
module Cards
BlackLotus = Artifact("Black Lotus") do
cost generic: 0
end

class BlackLotus < Artifact
class ManaAbility < Magic::ManaAbility
costs "{T}, Sacrifice {this}"
choices :all
amount 3
end

def activated_abilities = [ManaAbility]
end
end
end
16 changes: 14 additions & 2 deletions lib/magic/mana_ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ def self.choices(*choices)
end
end

def self.amount(value)
define_method(:amount) { value }
end

def initialize(**args)
super(**args)
end
Expand All @@ -22,11 +26,19 @@ def choose(color)
@choice = color
end

def resolve!
def amount
1
end

def validate_choice!
@choice ||= choices.first if choices.length == 1

raise "Invalid choice made for mana ability. Choice: #{choice}, Choices: #{choices}" unless choices.include?(choice)
source.controller.add_mana(choice => 1)
end

def resolve!
validate_choice!
source.controller.add_mana(choice => amount)
end
end
end
42 changes: 42 additions & 0 deletions spec/cards/black_lotus_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# frozen_string_literal: true

require 'spec_helper'

RSpec.describe Magic::Cards::BlackLotus do
include_context "two player game"
subject { ResolvePermanent("Black Lotus", owner: p1) }

context "tap and sacrifice" do
it "adds three mana of chosen color" do
ability = subject.activated_abilities.first
ability.choose(:green)
p1.activate_ability(ability: ability)
expect(p1.mana_pool[:green]).to eq(3)
end

it "sacrifices the artifact when activated" do
ability = subject.activated_abilities.first
ability.choose(:blue)
expect {
p1.activate_ability(ability: ability)
}.to change { p1.permanents.count }.by(-1)
expect(p1.graveyard.map(&:name)).to include("Black Lotus")
end

it "can add mana of different colors" do
# Test red
lotus = ResolvePermanent("Black Lotus", owner: p1)
ability = lotus.activated_abilities.first
ability.choose(:red)
p1.activate_ability(ability: ability)
expect(p1.mana_pool[:red]).to eq(3)

# Test white
lotus2 = ResolvePermanent("Black Lotus", owner: p1)
ability2 = lotus2.activated_abilities.first
ability2.choose(:white)
p1.activate_ability(ability: ability2)
expect(p1.mana_pool[:white]).to eq(3)
end
end
end