Skip to content

Commit

Permalink
Add Archon of Sun's Grace
Browse files Browse the repository at this point in the history
  • Loading branch information
radar committed Oct 27, 2024
1 parent 42ffd08 commit 71e37f7
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 2 deletions.
54 changes: 54 additions & 0 deletions lib/magic/cards/archon_of_suns_grace.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
module Magic
module Cards
ArchonOfSunsGrace = Creature("Archon of Sun's Grace") do
cost generic: 2, white: 2
power 3
toughness 4
creature_type "Archon"
keywords :flying, :lifelink
end

class ArchonOfSunsGrace < Creature
PegasusToken = Token.create "Pegasus" do
type "Creature —- Pegasus"
power 2
toughness 2
colors :white
keywords :flying
end

class EntersTrigger < TriggeredAbility::EnterTheBattlefield
def should_perform?
# Whenever an enchantment enters the battlefield under your control ...
enchantment? && under_your_control?
end

def call
actor.create_token(token_class: PegasusToken)
end
end

class LifelinkAddition < StaticAbility
def initialize(source:)
@source = source
end

def keywords
[Cards::Keywords::LIFELINK]
end

def applicable_targets
source.controller.creatures.of_type("Pegasus")
end
end

def static_abilities = [LifelinkAddition]

def event_handlers
{
Events::EnteredTheBattlefield => EntersTrigger
}
end
end
end
end
4 changes: 3 additions & 1 deletion lib/magic/static_abilities.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ def from(card)
end

def applies_to(card)
select { |ability| ability.applies_to?(card) }
select do |ability|
ability.applies_to?(card)
end
end
end
end
4 changes: 4 additions & 0 deletions lib/magic/static_ability.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,9 @@ def toughness
def keywords
[]
end

def applies_to?(_permanent)
true
end
end
end
6 changes: 5 additions & 1 deletion lib/magic/token.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ def keywords(*keywords)
end
end

def initialize(game:, owner:, base_power:, base_toughness:)
def initialize(game:, owner:, base_power: self.class::POWER, base_toughness: self.class::TOUGHNESS)
@name = self.class::NAME
@type_line = self.class::TYPE_LINE
@keywords = self.class::KEYWORDS
Expand Down Expand Up @@ -70,6 +70,10 @@ def colorless?
colors.count == 0
end

def enters_tapped?
false
end

def receive_notification(...)
end

Expand Down
7 changes: 7 additions & 0 deletions lib/magic/triggered_ability/enter_the_battlefield.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
module Magic
class TriggeredAbility
class EnterTheBattlefield < TriggeredAbility
def under_your_control?
event.permanent.controller?(controller)
end

def enchantment?
event.permanent.enchantment?
end
end
end
end
57 changes: 57 additions & 0 deletions spec/cards/archon_of_suns_grace_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
require 'spec_helper'

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

subject { ResolvePermanent("Archon of Sun's Grace") }

it "has flying" do
expect(subject).to have_keyword(:flying)
end

it "has lifelink" do
expect(subject).to have_keyword(:lifelink)
end

context "grants pegasi lifelink" do
let(:pegasus) { described_class::PegasusToken.new(game: game, owner: p1).resolve!}
context "if archon is on the battlefield" do
before do
subject
end

it "has lifelink" do
expect(pegasus).to have_keyword(:lifelink)
end
end

context "if archon is not on the battlefield" do
it "does not have lifelink" do
expect(pegasus).not_to have_keyword(:lifelink)
end
end
end

context "whenever an enchantment enters the battlefield" do
before do
subject
end

it "... under your control, create a pegasus" do
p1.add_mana(white: 3)
p1.cast(card: Card("Nine Lives")) do
_1.pay_mana(generic: { white: 1 }, white: 2)
end

game.tick!

pegasus = creatures.by_name("Pegasus").first
expect(pegasus).not_to be_nil
expect(pegasus.power).to eq(2)
expect(pegasus.toughness).to eq(2)
expect(pegasus).to have_keyword(:flying)
# Pegasus gains lifelink because Archon is on the battlefield
expect(pegasus).to have_keyword(:lifelink)
end
end
end

0 comments on commit 71e37f7

Please sign in to comment.