Skip to content

Commit

Permalink
Add Lorescale Coatl
Browse files Browse the repository at this point in the history
Fixes #232
  • Loading branch information
radar committed Feb 5, 2024
1 parent d2bc4df commit 7e7698a
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 22 deletions.
21 changes: 21 additions & 0 deletions lib/magic/cards/lorescale_coatl.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module Magic
module Cards
class LorescaleCoatl < Creature
card_name "Lorescale Coatl"
cost "{1}{G}{U}"
creature_type "Snake"
power 2
toughness 2

def event_handlers
{
Events::CardDraw => ->(receiver, event) {
return unless receiver.controller == event.player

trigger_effect(:add_counter, source: receiver, counter_type: Counters::Plus1Plus1, target: receiver)
}
}
end
end
end
end
2 changes: 1 addition & 1 deletion lib/magic/cards/mazemind_tome.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def activated_abilities = [ActivatedAbility, ActivatedAbility2]

def event_handlers
{
Events::CounterAdded => ->(receiver, event) {
Events::CounterAddedToPermanent => ->(receiver, event) {
return unless event.permanent == receiver

if receiver.counters.of_type(Magic::Counters::Page).count >= 4
Expand Down
2 changes: 1 addition & 1 deletion lib/magic/cards/nine_lives.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def event_handlers

receiver.controller.lose!
end,
Events::CounterAdded => -> (receiver, event) do
Events::CounterAddedToPermanent => -> (receiver, event) do
if receiver.counters.of_type(Counters::Incarnation).count >= 9
receiver.trigger_effect(:exile, target: receiver)

Expand Down
18 changes: 0 additions & 18 deletions lib/magic/events/counter_added.rb

This file was deleted.

17 changes: 17 additions & 0 deletions lib/magic/events/counter_added_to_permanent.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Magic
module Events
class CounterAddedToPermanent
attr_reader :permanent, :counter_type, :amount

def initialize(permanent: nil, counter_type:, amount:)
@permanent = permanent
@counter_type = counter_type
@amount = amount
end

def inspect
"#<Events::CounterAdded permanent: #{permanent.name}, type: #{counter_type}, amount: #{amount}>"
end
end
end
end
17 changes: 17 additions & 0 deletions lib/magic/events/counter_added_to_player.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module Magic
module Events
class CounterAddedToPlayer
attr_reader :player, :counter_type, :amount

def initialize(player: nil, counter_type:, amount:)
@player = player
@counter_type = counter_type
@amount = amount
end

def inspect
"#<Events::CounterAdded player: #{player.name}, type: #{counter_type}, amount: #{amount}>"
end
end
end
end
15 changes: 15 additions & 0 deletions lib/magic/events/player_lost.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module Magic
module Events
class PlayerLost
attr_reader :player

def initialize(player:)
@player = player
end

def inspect
"#<Events::PlayerLost player: #{player.name}>"
end
end
end
end
2 changes: 1 addition & 1 deletion lib/magic/permanent.rb
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ def cleanup!

def add_counter(counter_type, amount: 1)
@counters = Counters::Collection.new(@counters + [counter_type.new] * amount)
counter_added = Events::CounterAdded.new(
counter_added = Events::CounterAddedToPermanent.new(
permanent: self,
counter_type: counter_type,
amount: amount
Expand Down
8 changes: 7 additions & 1 deletion lib/magic/player.rb
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,12 @@ def lost?
end

def lose!
game.notify!(
Events::PlayerLost.new(
player: self,
)
)

@lost = true
end

Expand Down Expand Up @@ -283,7 +289,7 @@ def protected_from?(card)

def add_counter(counter_type, amount: 1)
@counters = Counters::Collection.new(@counters + [counter_type.new] * amount)
counter_added = Events::CounterAdded.new(
counter_added = Events::CounterAddedToPlayer.new(
player: self,
counter_type: counter_type,
amount: amount
Expand Down
19 changes: 19 additions & 0 deletions spec/cards/lorescale_coatl_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
require "spec_helper"

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

subject(:lorescale_coatl) { ResolvePermanent("Lorescale Coatl") }

before do
p1.library.add(Card("Forest"))
end

it "gets a +1/+1 counter whenever its controller draws a card" do
expect(lorescale_coatl.power).to eq(2)
expect(lorescale_coatl.toughness).to eq(2)

p1.draw!
expect(lorescale_coatl.counters.of_type(Magic::Counters::Plus1Plus1).count).to eq(1)
end
end

0 comments on commit 7e7698a

Please sign in to comment.