diff --git a/lib/magic/cards/phyrexian_arena.rb b/lib/magic/cards/phyrexian_arena.rb new file mode 100644 index 0000000..ba1becb --- /dev/null +++ b/lib/magic/cards/phyrexian_arena.rb @@ -0,0 +1,27 @@ +module Magic + module Cards + PhyrexianArena = Card("Phyrexian Arena") do + cost generic: 1, black: 2 + type "Enchantment" + end + + class PhyrexianArena < Card + class BeginningOfUpkeepTrigger < TriggeredAbility + def should_perform? + you? + end + + def call + actor.trigger_effect(:draw_cards, source: actor) + actor.trigger_effect(:lose_life, target: controller, life: 1) + end + end + + def event_handlers + { + Events::BeginningOfUpkeep => BeginningOfUpkeepTrigger + } + end + end + end +end diff --git a/lib/magic/events/beginning_of_upkeep.rb b/lib/magic/events/beginning_of_upkeep.rb index b8da622..f70a9ba 100644 --- a/lib/magic/events/beginning_of_upkeep.rb +++ b/lib/magic/events/beginning_of_upkeep.rb @@ -1,6 +1,12 @@ module Magic module Events class BeginningOfUpkeep + attr_reader :player + + def initialize(player:) + @player = player + end + def inspect "#" end diff --git a/lib/magic/game/turn.rb b/lib/magic/game/turn.rb index 9bf888a..71b7e48 100644 --- a/lib/magic/game/turn.rb +++ b/lib/magic/game/turn.rb @@ -24,7 +24,7 @@ class Turn after_transition to: :upkeep do |turn| turn.notify!( - Events::BeginningOfUpkeep.new + Events::BeginningOfUpkeep.new(player: turn.active_player) ) end diff --git a/spec/cards/phyrexian_arena_spec.rb b/spec/cards/phyrexian_arena_spec.rb new file mode 100644 index 0000000..b3108a1 --- /dev/null +++ b/spec/cards/phyrexian_arena_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +RSpec.describe Magic::Cards::PhyrexianArena do + include_context "two player game" + + subject! { ResolvePermanent("Phyrexian Arena", owner: p1) } + + context "at the beginning of your upkeep" do + it "loses a life, draws a card" do + turn_1 = game.current_turn + + turn_1.untap! + + expect(p1.life).to eq(20) + turn_1 = game.current_turn + expect(p1).to receive(:draw!) + turn_1.upkeep! + expect(p1.life).to eq(19) + end + end +end