Skip to content

Commit

Permalink
Add Phyrexian Arena
Browse files Browse the repository at this point in the history
  • Loading branch information
radar committed Oct 20, 2024
1 parent 26fd5a0 commit 4e82e82
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
27 changes: 27 additions & 0 deletions lib/magic/cards/phyrexian_arena.rb
Original file line number Diff line number Diff line change
@@ -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
6 changes: 6 additions & 0 deletions lib/magic/events/beginning_of_upkeep.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
module Magic
module Events
class BeginningOfUpkeep
attr_reader :player

def initialize(player:)
@player = player
end

def inspect
"#<Events::BeginningOfUpkeep>"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/magic/game/turn.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
21 changes: 21 additions & 0 deletions spec/cards/phyrexian_arena_spec.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4e82e82

Please sign in to comment.