Skip to content

Commit

Permalink
Profane Memento: Trigger on Card, not Permanent
Browse files Browse the repository at this point in the history
  • Loading branch information
radar committed Feb 16, 2024
1 parent d9fff6e commit 96135c4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 13 deletions.
18 changes: 11 additions & 7 deletions lib/magic/cards/profane_memento.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,20 @@ class ProfaneMemento < Card
COST = { any: 1 }
TYPE_LINE = "Artifact"

class PermanentEnteredZoneTrigger < TriggeredAbility::Base
def should_perform?
event.to.graveyard? && event.card.creature? && event.card.controller != controller
end

def call
actor.trigger_effect(:gain_life, life: 1)
end
end

def event_handlers
{
# Whenever a creature card is put into an opponent’s graveyard from anywhere, you gain 1 life.
Events::PermanentEnteredZone => -> (receiver, event) do
return unless event.to.graveyard?
return if event.permanent.controller?(receiver.controller)
return unless event.permanent.creature?

receiver.trigger_effect(:gain_life, life: 1)
end
Events::CardEnteredZone => PermanentEnteredZoneTrigger
}
end
end
Expand Down
12 changes: 6 additions & 6 deletions spec/cards/profane_memento_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@

context "receive notification" do
context "when creature enters controller's graveyard" do
let(:p1_creature) { ResolvePermanent("Loxodon Wayfarer", owner: p1) }
let(:p1_creature) { Card("Loxodon Wayfarer", owner: p1) }
let(:event) do
Magic::Events::PermanentEnteredZone.new(
Magic::Events::CardEnteredZone.new(
p1_creature,
from: game.battlefield,
to: p1.graveyard
Expand All @@ -22,9 +22,9 @@
end

context "when a creature enters opponent's graveyard" do
let(:p2_creature) { ResolvePermanent("Loxodon Wayfarer", owner: p2) }
let(:p2_creature) { Card("Loxodon Wayfarer", owner: p2) }
let(:event) do
Magic::Events::PermanentEnteredZone.new(
Magic::Events::CardEnteredZone.new(
p2_creature,
from: game.battlefield,
to: p2.graveyard,
Expand All @@ -37,9 +37,9 @@
end

context "when an artifact enters opponent's graveyard" do
let(:p2_artifact) { ResolvePermanent("Profane Memento", owner: p2) }
let(:p2_artifact) { Card("Profane Memento", owner: p2) }
let(:event) do
Magic::Events::PermanentEnteredZone.new(
Magic::Events::CardEnteredZone.new(
p2_artifact,
from: game.battlefield,
to: p2.graveyard,
Expand Down

0 comments on commit 96135c4

Please sign in to comment.