diff --git a/lib/magic/cards/black_lotus.rb b/lib/magic/cards/black_lotus.rb new file mode 100644 index 00000000..a791769c --- /dev/null +++ b/lib/magic/cards/black_lotus.rb @@ -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 diff --git a/lib/magic/mana_ability.rb b/lib/magic/mana_ability.rb index c39e5d72..97719ae8 100644 --- a/lib/magic/mana_ability.rb +++ b/lib/magic/mana_ability.rb @@ -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 @@ -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 diff --git a/spec/cards/black_lotus_spec.rb b/spec/cards/black_lotus_spec.rb new file mode 100644 index 00000000..7e0799dd --- /dev/null +++ b/spec/cards/black_lotus_spec.rb @@ -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