diff --git a/lib/magic/cards/experimental_overload.rb b/lib/magic/cards/experimental_overload.rb new file mode 100644 index 0000000..085ae49 --- /dev/null +++ b/lib/magic/cards/experimental_overload.rb @@ -0,0 +1,39 @@ +module Magic + module Cards + class ExperimentalOverload < Sorcery + card_name "Experimental Overload" + cost "{2}{U}{R}" + + class WeirdToken < Token + token_name "Weird" + colors :blue, :red + creature_type "Weird" + end + + class Choice < Magic::Choice::SearchGraveyard + def choices + source.controller.graveyard + end + + def amount + 1 + end + + def resolve!(target:) + target.move_to_hand! + end + end + + def resolve! + weird_power = controller.graveyard.cards.count { |card| card.instant? || card.sorcery? } + weird = controller.create_token( + token_class: WeirdToken, + base_power: weird_power, + base_toughness: weird_power + ) + + game.choices.add(Choice.new(source: self)) + end + end + end +end diff --git a/lib/magic/player.rb b/lib/magic/player.rb index bf43d74..832eec4 100644 --- a/lib/magic/player.rb +++ b/lib/magic/player.rb @@ -111,9 +111,14 @@ def declare_attacker(attacker:, target: nil, **args) action end - def create_tokens(token_class:, amount: 1, enters_tapped: false) + def create_tokens(token_class:, amount: 1, enters_tapped: false, base_power: nil, base_toughness: nil) tokens = amount.times.map do - token_class.new(game: game, owner: self).resolve!(enters_tapped: enters_tapped) + token_class.new( + game: game, + owner: self, + base_power: base_power, + base_toughness: base_toughness + ).resolve!(enters_tapped: enters_tapped) end end diff --git a/lib/magic/token.rb b/lib/magic/token.rb index 3a1fd7d..c6a07d4 100644 --- a/lib/magic/token.rb +++ b/lib/magic/token.rb @@ -3,7 +3,7 @@ class Token include Cards::Shared::Events include Cards::Shared::Types - attr_reader :game, :owner, :name, :type_line, :keywords, :keyword_grants, :protections + attr_reader :game, :owner, :name, :type_line, :keywords, :keyword_grants, :protections, :base_power, :base_toughness KEYWORDS = [] PROTECTIONS = [] @@ -15,6 +15,10 @@ def create(name, &block) token end + def token_name(name) + const_set(:NAME, name) + end + def power(power) const_set(:POWER, power) end @@ -23,8 +27,8 @@ def toughness(power) const_set(:TOUGHNESS, power) end - def colors(colors) - const_set(:COLORS, [*colors]) + def colors(*colors) + const_set(:COLORS, colors) end def keywords(*keywords) @@ -34,12 +38,14 @@ def keywords(*keywords) end end - def initialize(game:, owner:) + def initialize(game:, owner:, base_power: nil, base_toughness: nil) @name = self.class::NAME @type_line = self.class::TYPE_LINE @keywords = self.class::KEYWORDS @keyword_grants = [] @protections = self.class::PROTECTIONS + @base_power = base_power || self.class::POWER + @base_toughness = base_toughness || self.class::TOUGHNESS @owner = owner @game = game end @@ -52,14 +58,6 @@ def resolve!(**args) Permanent.resolve(game: game, card: self, **args) end - def base_power - self.class::POWER - end - - def base_toughness - self.class::TOUGHNESS - end - def colors self.class.const_defined?(:COLORS) ? self.class::COLORS : [] end diff --git a/spec/cards/experimental_overload_spec.rb b/spec/cards/experimental_overload_spec.rb new file mode 100644 index 0000000..ad9853f --- /dev/null +++ b/spec/cards/experimental_overload_spec.rb @@ -0,0 +1,33 @@ +require "spec_helper" + +RSpec.describe Magic::Cards::ExperimentalOverload do + include_context "two player game" + let(:card) { Card("Experimental Overload") } + + before do + p1.graveyard.add(Card("Shock")) + end + + it "creates an X/X blue and red Weird creature token, with X being instant/sorceries in GY" do + p1.add_mana(blue: 3, red: 1) + p1.cast(card: card) do + _1.pay_mana(generic: { blue: 2 }, blue: 1, red: 1) + end + + game.tick! + + weird = creatures.first + expect(weird.name).to eq("Weird") + expect(weird.power).to eq(1) + expect(weird.toughness).to eq(1) + expect(weird.colors).to eq([:blue, :red]) + + choice = game.choices.first + expect(choice).to be_a(Magic::Choice::SearchGraveyard) + + choice.resolve!(target: p1.graveyard.cards.first) + + shock = p1.hand.by_name("Shock").first + expect(shock).to be_a(Magic::Cards::Shock) + end +end