Skip to content

Commit

Permalink
Add Epitaph Golem
Browse files Browse the repository at this point in the history
Fixes #230
  • Loading branch information
radar committed Feb 4, 2024
1 parent acaa285 commit 97f7f9f
Show file tree
Hide file tree
Showing 5 changed files with 96 additions and 28 deletions.
54 changes: 26 additions & 28 deletions lib/magic/card.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,32 @@ def move_to_exile!
move_zone!(game.exile)
end

def move_zone!(new_zone)
old_zone = zone
if old_zone
game.notify!(
Events::CardLeavingZoneTransition.new(
self,
from: old_zone,
to: new_zone
)
)

old_zone.remove(self)
end

new_zone.add(self) unless new_zone.is_a?(Magic::Zones::Battlefield)

game.notify!(
Events::CardEnteredZoneTransition.new(
self,
from: old_zone,
to: new_zone
)
)

end

def resolve!(enters_tapped: enters_tapped?, kicked: false)
if permanent?
permanent = Magic::Permanent.resolve(
Expand Down Expand Up @@ -216,33 +242,5 @@ def add_choice(choice, **args)
def opponents
game.opponents(controller)
end

private

def move_zone!(new_zone)
old_zone = zone
if old_zone
game.notify!(
Events::CardLeavingZoneTransition.new(
self,
from: old_zone,
to: new_zone
)
)

old_zone.remove(self)
end

new_zone.add(self) unless new_zone.is_a?(Magic::Zones::Battlefield)

game.notify!(
Events::CardEnteredZoneTransition.new(
self,
from: old_zone,
to: new_zone
)
)

end
end
end
25 changes: 25 additions & 0 deletions lib/magic/cards/epitaph_golem.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
module Magic
module Cards
class EpitaphGolem < Creature
name "Epitaph Golem"
artifact_creature_type "Golem"
cost generic: 4

class Ability < ActivatedAbility
costs "{2}"

def target_choices
controller.graveyard
end

def resolve!(target:)
trigger_effect(:move_zone, source: source, target: target, destination: controller.library)
end
end

def activated_abilities
[Ability]
end
end
end
end
2 changes: 2 additions & 0 deletions lib/magic/cards/shared/events.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ def trigger_effect(effect, source: self, **args)
game.add_effect(Effects::LoseLife.new(source: source, **args))
when :modify_power_toughness
game.add_effect(Effects::ApplyPowerToughnessModification.new(source: source, **args))
when :move_zone
game.add_effect(Effects::MoveZone.new(source: source, **args))
when :phase_out
game.add_effect(Effects::PhaseOut.new(source: source, **args))
when :return_to_owners_hand
Expand Down
20 changes: 20 additions & 0 deletions lib/magic/effects/move_zone.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
module Magic
module Effects
class MoveZone < TargetedEffect
attr_reader :destination

def initialize(destination:, **args)
@destination = destination
super(**args)
end

def requires_choices?
false
end

def resolve!
target.move_zone!(destination)
end
end
end
end
23 changes: 23 additions & 0 deletions spec/cards/epitaph_golem_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require "spec_helper"

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

let!(:permanent) { ResolvePermanent("Epitaph Golem") }
let!(:wood_elves) { Card("Wood Elves") }

before do
p1.graveyard.add(wood_elves)
end

it "can move card from graveyard to library" do
p1.add_mana(white: 2)
p1.activate_ability(ability: permanent.activated_abilities.first) do
_1.pay_mana(generic: { white: 2 })
_1.targeting(wood_elves)
end

expect(wood_elves.zone).to be_library
expect(p1.library.last).to eq(wood_elves)
end
end

0 comments on commit 97f7f9f

Please sign in to comment.