Skip to content

Commit

Permalink
Add Roaming Ghostlight
Browse files Browse the repository at this point in the history
Fixes #75
  • Loading branch information
radar committed Jan 17, 2024
1 parent e21997b commit bcbe586
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lib/magic/card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,15 @@ def keywords(*keywords)
def protections(*protections)
const_set(:PROTECTIONS, *protections)
end

def enters_the_battlefield(&block)
etb = Class.new(TriggeredAbility::EnterTheBattlefield)
etb.define_method(:perform, &block)

define_method(:etb_triggers) do
[etb]
end
end
end

def initialize(game: Game.new, owner:)
Expand Down
4 changes: 4 additions & 0 deletions lib/magic/card_list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ def by_any_type(*types)
end
alias_method :by_type, :by_any_type

def excluding_type(*types)
reject { |c| c.any_type?(*types) }
end

def except(target)
self.class.new(reject { |c| c == target })
end
Expand Down
16 changes: 16 additions & 0 deletions lib/magic/cards/roaming_ghostlight.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module Magic
module Cards
RoamingGhostlight = Creature("Roaming Ghostlight") do
cost generic: 3, blue: 2
type "Creature -- Spirit"
power 3
toughness 2
keywords :flying

enters_the_battlefield do
choices = game.battlefield.creatures.excluding_type(T::Creatures['Spirit'])
game.add_effect(Effects::ReturnToOwnersHand.new(source: self, choices: choices))
end
end
end
end
17 changes: 17 additions & 0 deletions spec/cards/roaming_ghostlight_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
require 'spec_helper'

RSpec.describe Magic::Cards::RoamingGhostlight do
include_context "two player game"

before do
ResolvePermanent("Wood Elves", owner: p2)
end

context "when it enters the battlefield" do
it "returns non-Spirit creature to its owner's hand" do
ResolvePermanent("Roaming Ghostlight", owner: p1)

expect(p2.hand.by_name("Wood Elves").count).to eq(1)
end
end
end

0 comments on commit bcbe586

Please sign in to comment.