diff --git a/lib/magic/cards/profane_memento.rb b/lib/magic/cards/profane_memento.rb index e2e7ba0..d106940 100644 --- a/lib/magic/cards/profane_memento.rb +++ b/lib/magic/cards/profane_memento.rb @@ -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 diff --git a/spec/cards/profane_memento_spec.rb b/spec/cards/profane_memento_spec.rb index 0bdccd9..6fb155a 100644 --- a/spec/cards/profane_memento_spec.rb +++ b/spec/cards/profane_memento_spec.rb @@ -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 @@ -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, @@ -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,