Skip to content

Commit

Permalink
Add Experimental Overload
Browse files Browse the repository at this point in the history
Fixes #229
  • Loading branch information
radar committed Feb 6, 2024
1 parent f298e04 commit 6e2c0bd
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 14 deletions.
39 changes: 39 additions & 0 deletions lib/magic/cards/experimental_overload.rb
Original file line number Diff line number Diff line change
@@ -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
9 changes: 7 additions & 2 deletions lib/magic/player.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 10 additions & 12 deletions lib/magic/token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 = []
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand Down
33 changes: 33 additions & 0 deletions spec/cards/experimental_overload_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6e2c0bd

Please sign in to comment.