Skip to content

Commit

Permalink
Add Shacklegeist
Browse files Browse the repository at this point in the history
Fixes #80
  • Loading branch information
radar committed Jan 28, 2024
1 parent 114866f commit 235ddc1
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 8 deletions.
4 changes: 4 additions & 0 deletions lib/magic/activated_ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ def battlefield
game.battlefield
end

def controller
source.controller
end

def trigger_effect(effect, **args)
source.trigger_effect(effect, source: self, **args)
end
Expand Down
4 changes: 3 additions & 1 deletion lib/magic/card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def choose_mode(mode)
end

def can_attack? = !defender?
def can_block? = true
def can_block?(_) = true
def can_activate_ability?(_) = true

def add_choice(choice, **args)
Expand Down Expand Up @@ -242,6 +242,8 @@ def trigger_effect(effect, source: self, **args)
game.add_effect(Effects::ApplyPowerToughnessModification.new(source: source, **args))
when :return_to_owners_hand
game.add_effect(Effects::ReturnToOwnersHand.new(source: source, **args))
when :tap
game.add_effect(Effects::Tap.new(source: source, **args))
else
raise "Unknown trigger: #{effect.inspect}"
end
Expand Down
2 changes: 1 addition & 1 deletion lib/magic/cards/faiths_fetters.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def can_attack?
false
end

def can_block?
def can_block?(_)
false
end

Expand Down
30 changes: 30 additions & 0 deletions lib/magic/cards/shacklegeist.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module Magic
module Cards
Shacklegeist = Creature("Shacklegeist") do
creature_type "Spirit"
power 2
toughness 2
keywords :flying

def can_block?(permanent)
permanent.flying?
end
end

class Shacklegeist < Creature
class ActivatedAbility < Magic::ActivatedAbility
def costs = [Costs::MultiTap.new(-> (c) { c.type?("Spirit") }, 2)]

def target_choices
game.battlefield.not_controlled_by(controller).creatures
end

def resolve!(target:)
trigger_effect(:tap, target: target)
end
end

def activated_abilities = [ActivatedAbility]
end
end
end
10 changes: 10 additions & 0 deletions lib/magic/effects/tap.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
module Magic
module Effects
class Tap < TargetedEffect

def resolve!
target.tap!
end
end
end
end
4 changes: 2 additions & 2 deletions lib/magic/permanent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ def can_attack?
card.can_attack? && attachments.all?(&:can_attack?)
end

def can_block?
card.can_block? && attachments.all?(&:can_block?)
def can_block?(permanent)
card.can_block?(permanent) && attachments.all? { |attachment| attachment.can_block?(permanent) }
end


Expand Down
11 changes: 7 additions & 4 deletions spec/cards/faiths_fetters_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ def cast_faiths_fetters(target)

context "with wood elves" do
let!(:wood_elves) { ResolvePermanent("Wood Elves", owner: p2) }
let!(:llanowar_elves) { ResolvePermanent("Llanowar Elves", owner: p1) }

it "makes the controller gain 4 life" do
expect { cast_faiths_fetters(wood_elves) }.to change { p1.life }.by(4)
Expand All @@ -26,30 +27,32 @@ def cast_faiths_fetters(target)
it "enchants the wood elves" do
cast_faiths_fetters(wood_elves)
expect(wood_elves.can_attack?).to eq(false)
expect(wood_elves.can_block?).to eq(false)
expect(wood_elves.can_block?(llanowar_elves)).to eq(false)
end
end

context "with llanowar elves" do
let!(:llanowar_elves) { ResolvePermanent("Llanowar Elves", owner: p2) }
let!(:wood_elves) { ResolvePermanent("Wood Elves", owner: p2) }
let(:mana_ability) { llanowar_elves.activated_abilities.first }

it "enchants the llanowar elves" do
it "enchants the llanowar elves, allows for mana ability" do
cast_faiths_fetters(llanowar_elves)
expect(llanowar_elves.can_attack?).to eq(false)
expect(llanowar_elves.can_block?).to eq(false)
expect(llanowar_elves.can_block?(wood_elves)).to eq(false)
expect(llanowar_elves.can_activate_ability?(mana_ability)).to eq(true)
end
end

context "with hellkite punisher" do
let!(:hellkite_punisher) { ResolvePermanent("Hellkite Punisher", owner: p2) }
let!(:wood_elves) { ResolvePermanent("Wood Elves", owner: p2) }
let(:activated_ability) { hellkite_punisher.activated_abilities.first }

it "enchants the hellkite punisher" do
cast_faiths_fetters(hellkite_punisher)
expect(hellkite_punisher.can_attack?).to eq(false)
expect(hellkite_punisher.can_block?).to eq(false)
expect(hellkite_punisher.can_block?(wood_elves)).to eq(false)
expect(hellkite_punisher.can_activate_ability?(activated_ability)).to eq(false)
end
end
Expand Down
32 changes: 32 additions & 0 deletions spec/cards/shacklegeist_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
require 'spec_helper'

RSpec.describe Magic::Cards::Shacklegeist do
include_context "two player game"
let(:roaming_ghostlight) { ResolvePermanent("Roaming Ghostlight", owner: p2) }
let(:wood_elves) { ResolvePermanent("Wood Elves", owner: p2) }
subject(:shacklegeist) { ResolvePermanent("Shacklegeist") }

it "can only block creatures with flying" do
expect(shacklegeist.can_block?(roaming_ghostlight)).to eq(true)
expect(shacklegeist.can_block?(wood_elves)).to eq(false)
end

context "taps two untapped spirits, to tap another creature" do
before do
p1.create_token(token: Magic::Tokens::Spirit)
end

it "taps the creature" do
token_spirit = p1.creatures.by_name("Spirit").first

p1.activate_ability(ability: shacklegeist.activated_abilities.first) do
_1.pay_multi_tap([shacklegeist, token_spirit])
_1.targeting(wood_elves)
end

game.tick!

expect(wood_elves).to be_tapped
end
end
end

0 comments on commit 235ddc1

Please sign in to comment.